aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Antipov2014-07-11 16:19:58 +0400
committerDmitry Antipov2014-07-11 16:19:58 +0400
commit3aa96ff51efd72767f1a4e04c546187269b008c0 (patch)
tree64b09920082278cf2d84137dd1fe66f2179b15bf
parent5f7c30e757680f66be9ef4c399fd1d7ce5b66203 (diff)
downloademacs-3aa96ff51efd72767f1a4e04c546187269b008c0.tar.gz
emacs-3aa96ff51efd72767f1a4e04c546187269b008c0.zip
* src/alloc.c (Fmemory_info) [HAVE_LINUX_SYSINFO]: Return nil if
sysinfo failed. Adjust docstring. * doc/lispref/internals.texi (Garbage Collection): Mention memory-info. * lisp/files.el (out-of-memory-warning-percentage): New defcustom. (warn-maybe-out-of-memory): Use it.
-rw-r--r--doc/lispref/ChangeLog4
-rw-r--r--doc/lispref/internals.texi4
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/files.el23
-rw-r--r--src/ChangeLog5
-rw-r--r--src/alloc.c7
6 files changed, 39 insertions, 9 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 17af128ae49..5f7e00a4f10 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,7 @@
12014-07-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * internals.texi (Garbage Collection): Mention memory-info.
4
12014-07-11 Michael Albinus <michael.albinus@gmx.de> 52014-07-11 Michael Albinus <michael.albinus@gmx.de>
2 6
3 * minibuf.texi (Intro to Minibuffers, Reading a Password): 7 * minibuf.texi (Intro to Minibuffers, Reading a Password):
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 3a5bd4aea7e..626ecad7f42 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -513,6 +513,10 @@ created in this Emacs session. Each of these counters increments for
513a certain kind of object. See the documentation string for details. 513a certain kind of object. See the documentation string for details.
514@end defun 514@end defun
515 515
516@defun memory-info
517This functions returns an amount of total system memory and how much
518of it is free. On an unsupported system, the value may be @code{nil}.
519
516@defvar gcs-done 520@defvar gcs-done
517This variable contains the total number of garbage collections 521This variable contains the total number of garbage collections
518done so far in this Emacs session. 522done so far in this Emacs session.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3965da7287b..faa5a3dffff 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12014-07-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * files.el (out-of-memory-warning-percentage): New defcustom.
4 (warn-maybe-out-of-memory): Use it.
5
12014-07-11 Michael Albinus <michael.albinus@gmx.de> 62014-07-11 Michael Albinus <michael.albinus@gmx.de>
2 7
3 * subr.el (read-passwd): Use `read-hide-char' if non-nil. Bind it 8 * subr.el (read-passwd): Use `read-hide-char' if non-nil. Bind it
diff --git a/lisp/files.el b/lisp/files.el
index 258a37616c1..d3aa063e788 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1786,6 +1786,14 @@ When nil, never request confirmation."
1786 :version "22.1" 1786 :version "22.1"
1787 :type '(choice integer (const :tag "Never request confirmation" nil))) 1787 :type '(choice integer (const :tag "Never request confirmation" nil)))
1788 1788
1789(defcustom out-of-memory-warning-percentage 50
1790 "Warn if file size exceeds this percentage of available free memory.
1791When nil, never issue warning."
1792 :group 'files
1793 :group 'find-file
1794 :version "24.4"
1795 :type '(choice integer (const :tag "Never issue warning" nil)))
1796
1789(defun abort-if-file-too-large (size op-type filename) 1797(defun abort-if-file-too-large (size op-type filename)
1790 "If file SIZE larger than `large-file-warning-threshold', allow user to abort. 1798 "If file SIZE larger than `large-file-warning-threshold', allow user to abort.
1791OP-TYPE specifies the file operation being performed (for message to user)." 1799OP-TYPE specifies the file operation being performed (for message to user)."
@@ -1798,19 +1806,22 @@ OP-TYPE specifies the file operation being performed (for message to user)."
1798 1806
1799(defun warn-maybe-out-of-memory (size) 1807(defun warn-maybe-out-of-memory (size)
1800 "Warn if an attempt to open file of SIZE bytes may run out of memory." 1808 "Warn if an attempt to open file of SIZE bytes may run out of memory."
1801 (when (and (numberp size) (not (zerop size))) 1809 (when (and (numberp size) (not (zerop size))
1810 (integerp out-of-memory-warning-percentage))
1802 (let ((meminfo (memory-info))) 1811 (let ((meminfo (memory-info)))
1803 (when (consp meminfo) 1812 (when (consp meminfo)
1804 (let ((total-free-memory (+ (nth 1 meminfo) (nth 3 meminfo)))) 1813 (let ((total-free-memory (float (+ (nth 1 meminfo) (nth 3 meminfo)))))
1805 (when (> (/ size 1024) total-free-memory) 1814 (when (> (/ size 1024)
1815 (/ (* total-free-memory out-of-memory-warning-percentage)
1816 100.0))
1806 (warn 1817 (warn
1807 "You are trying to open a file whose size (%s) 1818 "You are trying to open a file whose size (%s)
1808exceeds the amount of currently available free memory (%s). 1819exceeds the %S%% of currently available free memory (%s).
1809If that fails, try to open it with `find-file-literally' 1820If that fails, try to open it with `find-file-literally'
1810\(but note that some characters might be displayed incorrectly)." 1821\(but note that some characters might be displayed incorrectly)."
1811 (file-size-human-readable size) 1822 (file-size-human-readable size)
1812 (file-size-human-readable 1823 out-of-memory-warning-percentage
1813 (* (float total-free-memory) 1024))))))))) 1824 (file-size-human-readable (* total-free-memory 1024)))))))))
1814 1825
1815(defun find-file-noselect (filename &optional nowarn rawfile wildcards) 1826(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
1816 "Read file FILENAME into a buffer and return the buffer. 1827 "Read file FILENAME into a buffer and return the buffer.
diff --git a/src/ChangeLog b/src/ChangeLog
index e469880a4ce..52ba04d2f5f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
12014-07-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * alloc.c (Fmemory_info) [HAVE_LINUX_SYSINFO]: Return nil if
4 sysinfo failed. Adjust docstring.
5
12014-07-11 Eli Zaretskii <eliz@gnu.org> 62014-07-11 Eli Zaretskii <eliz@gnu.org>
2 7
3 Implement memory-info for MS-DOS. 8 Implement memory-info for MS-DOS.
diff --git a/src/alloc.c b/src/alloc.c
index 77be94d73d1..a8ad44491fa 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6875,8 +6875,9 @@ gc_sweep (void)
6875 6875
6876DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0, 6876DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0,
6877 doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP). 6877 doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP).
6878All values are in Kbytes. If there is no swap space, last two 6878All values are in Kbytes. If there is no swap space,
6879values are zero. If the system is not supported, return nil. */) 6879last two values are zero. If the system is not supported
6880or memory information can't be obtained, return nil. */)
6880 (void) 6881 (void)
6881{ 6882{
6882#if defined HAVE_LINUX_SYSINFO 6883#if defined HAVE_LINUX_SYSINFO
@@ -6884,7 +6885,7 @@ values are zero. If the system is not supported, return nil. */)
6884 uintmax_t units; 6885 uintmax_t units;
6885 6886
6886 if (sysinfo (&si)) 6887 if (sysinfo (&si))
6887 emacs_abort (); 6888 return Qnil;
6888#ifdef LINUX_SYSINFO_UNIT 6889#ifdef LINUX_SYSINFO_UNIT
6889 units = si.mem_unit; 6890 units = si.mem_unit;
6890#else 6891#else