summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2022-11-27 16:57:03 +0100
committerMichael Albinus <michael.albinus@gmx.de>2022-11-27 16:57:03 +0100
commit1cbf2655db40cd474411b77ece57a287eb85ea2c (patch)
tree51c1eb45d553033f76e7d36837cfbaa20778c7b2 /lisp
parentca42ff5f0ee757f0a70f603863c83e85eef683b9 (diff)
downloademacs-1cbf2655db40cd474411b77ece57a287eb85ea2c.tar.gz
emacs-1cbf2655db40cd474411b77ece57a287eb85ea2c.tar.bz2
emacs-1cbf2655db40cd474411b77ece57a287eb85ea2c.zip
Extend memory-info for remote systems
* doc/lispref/files.texi (Magic File Names): Add memory-info. * doc/lispref/internals.texi (Garbage Collection): memory-info can also retrieve values from remote systems. * etc/NEWS: Document changes in memory-info. Fix typos. * lisp/files.el (warn-maybe-out-of-memory): Ensure local memory info. * lisp/net/tramp.el (tramp-handle-memory-info): New defun. (tramp-file-name-for-operation) * lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist): * lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist): * lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist): * lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist): * lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist): * lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist): * lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist): * lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist) * lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist): Add 'memory-info'. * lisp/net/tramp-sshfs.el (tramp-sshfs-handle-exec-path): Let-bind `process-file-side-effects'. * src/alloc.c (Fmemory_info): Support remote systems. (Qmemory_info): Declare. * test/lisp/net/tramp-tests.el (tramp-test31-memory-info): New test.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/files.el3
-rw-r--r--lisp/net/tramp-adb.el1
-rw-r--r--lisp/net/tramp-archive.el1
-rw-r--r--lisp/net/tramp-crypt.el1
-rw-r--r--lisp/net/tramp-gvfs.el1
-rw-r--r--lisp/net/tramp-rclone.el1
-rw-r--r--lisp/net/tramp-sh.el1
-rw-r--r--lisp/net/tramp-smb.el1
-rw-r--r--lisp/net/tramp-sshfs.el4
-rw-r--r--lisp/net/tramp-sudoedit.el1
-rw-r--r--lisp/net/tramp.el80
11 files changed, 92 insertions, 3 deletions
diff --git a/lisp/files.el b/lisp/files.el
index f1f890430f1..cd35fe38350 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2308,7 +2308,8 @@ it returns nil or exits non-locally."
"Warn if an attempt to open file of SIZE bytes may run out of memory."
(when (and (numberp size) (not (zerop size))
(integerp out-of-memory-warning-percentage))
- (let ((meminfo (memory-info)))
+ (let* ((default-directory temporary-file-directory)
+ (meminfo (memory-info)))
(when (consp meminfo)
(let ((total-free-memory (float (+ (nth 1 meminfo) (nth 3 meminfo)))))
(when (> (/ size 1024)
diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index 49cbf526ec3..90020fbb1b6 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -168,6 +168,7 @@ It is used for TCP/IP devices."
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-adb-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-adb-handle-process-file)
(rename-file . tramp-adb-handle-rename-file)
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index 0a8c574d84c..1a64689c53d 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -297,6 +297,7 @@ It must be supported by libarchive(3).")
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-archive-handle-not-implemented)
+ ;; `memory-info' performed by default handler.
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-archive-handle-not-implemented)
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index 09732581574..fa40f968180 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -219,6 +219,7 @@ If NAME doesn't belong to an encrypted remote directory, return nil."
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-crypt-handle-rename-file)
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index 477f8fb3fdd..73f773e8f4d 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -813,6 +813,7 @@ It has been changed in GVFS 1.14.")
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-gvfs-handle-rename-file)
diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el
index 9e379da8c1e..8e583cc4025 100644
--- a/lisp/net/tramp-rclone.el
+++ b/lisp/net/tramp-rclone.el
@@ -133,6 +133,7 @@
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-rclone-handle-rename-file)
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index cfecd32aba5..df5800f4e9d 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1103,6 +1103,7 @@ Format specifiers \"%s\" are replaced before the script is used.")
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-sh-handle-make-process)
(make-symbolic-link . tramp-sh-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-sh-handle-process-file)
(rename-file . tramp-sh-handle-rename-file)
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index e55f6bb6ee5..c720b33b5f2 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -284,6 +284,7 @@ See `tramp-actions-before-shell' for more info.")
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-smb-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . tramp-smb-handle-process-file)
(rename-file . tramp-smb-handle-rename-file)
diff --git a/lisp/net/tramp-sshfs.el b/lisp/net/tramp-sshfs.el
index 3c67fa6ea2f..44c55041ff8 100644
--- a/lisp/net/tramp-sshfs.el
+++ b/lisp/net/tramp-sshfs.el
@@ -139,6 +139,7 @@
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-sshfs-handle-process-file)
(rename-file . tramp-sshfs-handle-rename-file)
@@ -214,7 +215,8 @@ arguments to pass to the OPERATION."
(with-parsed-tramp-file-name default-directory nil
(with-tramp-connection-property (tramp-get-process v) "remote-path"
(with-temp-buffer
- (process-file "getconf" nil t nil "PATH")
+ (let (process-file-side-effects)
+ (process-file "getconf" nil t nil "PATH"))
(split-string
(progn
;; Read the expression.
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index bc8739c4d6c..fcc27dd8343 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -129,6 +129,7 @@ See `tramp-actions-before-shell' for more info.")
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-sudoedit-handle-rename-file)
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index e9f30bea7bf..33e5e80d05f 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -2656,7 +2656,7 @@ Must be handled by the callers."
;; Emacs 27+ only.
exec-path make-process
;; Emacs 29+ only.
- list-system-processes process-attributes))
+ list-system-processes memory-info process-attributes))
default-directory)
;; PROC.
((member operation '(file-notify-rm-watch file-notify-valid-p))
@@ -4884,6 +4884,84 @@ support symbolic links."
(tramp-dissect-file-name (expand-file-name linkname)) 'file-error
"make-symbolic-link not supported"))
+(defun tramp-handle-memory-info ()
+ "Like `memory-info' for Tramp files."
+ (let ((result '(0 0 0 0))
+ process-file-side-effects)
+ (with-temp-buffer
+ (cond
+ ;; GNU/Linux.
+ ((zerop (process-file "cat" nil '(t) nil "/proc/meminfo"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "MemTotal:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 0 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "MemFree:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 1 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "SwapTotal:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 2 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "SwapFree:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 3 result) (string-to-number (match-string 1)))))
+
+ ;; BSD.
+ ;; https://raw.githubusercontent.com/ocochard/myscripts/master/FreeBSD/freebsd-memory.sh
+ ((zerop (process-file "sysctl" nil '(t) nil "-a"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "hw.pagesize:" (* space) (group (+ digit)) eol)
+ nil 'noerror)
+ (let ((pagesize (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "vm.stats.vm.v_page_count:" (* space)
+ (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar
+ (nthcdr 0 result)
+ (/ (* (string-to-number (match-string 1)) pagesize) 1024)))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "vm.stats.vm.v_free_count:" (* space)
+ (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar
+ (nthcdr 1 result)
+ (/ (* (string-to-number (match-string 1)) pagesize) 1024)))))
+ (erase-buffer)
+ (when (zerop (process-file "swapctl" nil '(t) nil "-sk"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "Total:" (* space)
+ (group (+ digit)) (* space) (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar (nthcdr 2 result) (string-to-number (match-string 1)))
+ (setcar
+ (nthcdr 3 result)
+ (- (string-to-number (match-string 1))
+ (string-to-number (match-string 2)))))))))
+
+ ;; Return result.
+ (unless (equal result '(0 0 0 0))
+ result)))
+
(defun tramp-handle-process-attributes (pid)
"Like `process-attributes' for Tramp files."
(catch 'result