From 9242810cd3bb14056dde937fc9ad39fc49261dfd Mon Sep 17 00:00:00 2001
From: Dmitry Antipov
Date: Thu, 10 Jul 2014 16:33:35 +0400
Subject: * 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.
---
src/alloc.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
(limited to 'src/alloc.c')
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 . */
#include
#include /* For backtrace. */
+#ifdef HAVE_LINUX_SYSINFO
+#include
+#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);
--
cgit v1.2.1