diff options
| author | Dmitry Antipov <dmantipov@yandex.ru> | 2014-07-10 16:33:35 +0400 |
|---|---|---|
| committer | Dmitry Antipov <dmantipov@yandex.ru> | 2014-07-10 16:33:35 +0400 |
| commit | 9242810cd3bb14056dde937fc9ad39fc49261dfd (patch) | |
| tree | abd85cf5087ecbb123c3a511d78244fc9d069482 /src/alloc.c | |
| parent | 80fb41cd90467782f4cfb21074aaa4f95308985e (diff) | |
| download | emacs-9242810cd3bb14056dde937fc9ad39fc49261dfd.tar.gz | |
* configure.ac: Check whether sys/sysinfo.h provides
Linux 'sysinfo' function and 'struct sysinfo' type.
* src/alloc.c (Fmemory_info): New function.
* lisp/files.el (warn-maybe-out-of-memory): New function.
(find-file-noselect): Use it.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/alloc.c b/src/alloc.c index 6eb2e756ed1..c535e836397 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -49,6 +49,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <verify.h> #include <execinfo.h> /* For backtrace. */ +#ifdef HAVE_LINUX_SYSINFO +#include <sys/sysinfo.h> +#endif + #if (defined ENABLE_CHECKING \ && defined HAVE_VALGRIND_VALGRIND_H \ && !defined USE_VALGRIND) @@ -6865,7 +6869,33 @@ gc_sweep (void) check_string_bytes (!noninteractive); } - +DEFUN ("memory-info", Fmemory_info, Smemory_info, 0, 0, 0, + doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP). +All values are in Kbytes. If there is no swap space, last two +values are zero. If the system is not supported, return nil. */) + (void) +{ +#ifdef HAVE_LINUX_SYSINFO + struct sysinfo si; + uintmax_t units; + + if (sysinfo (&si)) + emacs_abort (); +#ifdef LINUX_SYSINFO_UNIT + units = si.mem_unit; +#else + units = 1; +#endif + return list4i ((uintmax_t) si.totalram * units / 1024, + (uintmax_t) si.freeram * units / 1024, + (uintmax_t) si.totalswap * units / 1024, + (uintmax_t) si.freeswap * units / 1024); +#else /* not HAVE_LINUX_SYSINFO */ + /* FIXME: add more systems. */ + return Qnil; +#endif /* HAVE_LINUX_SYSINFO */ +} + /* Debugging aids. */ DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0, @@ -7204,6 +7234,7 @@ The time is in seconds as a floating point value. */); defsubr (&Spurecopy); defsubr (&Sgarbage_collect); defsubr (&Smemory_limit); + defsubr (&Smemory_info); defsubr (&Smemory_use_counts); defsubr (&Ssuspicious_object); |
