]> Savannah Git Hosting - gnulib.git/commitdiff
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
authorNatanael Copa <ncopa@alpinelinux.org>
Fri, 18 Apr 2014 09:16:27 +0000 (09:16 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 19 Apr 2014 11:34:49 +0000 (12:34 +0100)
* lib/physmem.c (physmem_total): Some systems like musl libc do not
(yet) support _SC_PHYS_PAGES.  Use the linux syscall sysinfo as fallback
if _SC_PHYS_PAGES or _SC_PAGESIZE fails.
(physmem_available): Likewise for _SC_AVPHYS_PAGES.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
ChangeLog
lib/physmem.c
m4/physmem.m4

index 5d38d8288970476e2d74ff3456ea2f03cf7c2617..5f29475e9ea2b0ec06e6d7eb229f2355e209c8cf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-04-18  Natanael Copa  <ncopa@alpinelinux.org>
+
+       physmem: use sysinfo on linux-gnu if _SC_PHYS_PAGES unavailable
+       * lib/physmem.c (physmem_total): Some systems like musl libc don't yet
+       support _SC_PHYS_PAGES.  Use the linux syscall sysinfo as fallback
+       if _SC_PHYS_PAGES or _SC_PAGESIZE fails.
+       (physmem_available): Likewise for _SC_AVPHYS_PAGES.
+
 2014-04-18  Paul Eggert  <eggert@cs.ucla.edu>
 
        exclude: port to strict C99
index 7a67fb3ffdd64209eec5e8f0232858ef7f1d3780..d0989aa84ece5a05d8bee477df415517bbb0dc10 100644 (file)
 # include <sys/sysmp.h>
 #endif
 
-#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H
+#if HAVE_SYS_SYSINFO_H
 # include <sys/sysinfo.h>
+#endif
+
+#if HAVE_MACHINE_HAL_SYSINFO_H
 # include <machine/hal_sysinfo.h>
 #endif
 
@@ -90,6 +93,14 @@ physmem_total (void)
   }
 #endif
 
+#if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT
+  { /* This works on linux.  */
+    struct sysinfo si;
+    if (sysinfo(&si) == 0)
+      return (double) si.totalram * si.mem_unit;
+  }
+#endif
+
 #if HAVE_PSTAT_GETSTATIC
   { /* This works on hpux11.  */
     struct pst_static pss;
@@ -194,6 +205,14 @@ physmem_available (void)
   }
 #endif
 
+#if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT
+  { /* This works on linux.  */
+    struct sysinfo si;
+    if (sysinfo(&si) == 0)
+      return ((double) si.freeram + si.bufferram) * si.mem_unit;
+  }
+#endif
+
 #if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
   { /* This works on hpux11.  */
     struct pst_static pss;
index ff3d268e3b3e08afa6809ff2292d14db54a60804..a1179eb33f697477d27d96bf3ed8ac725e30473e 100644 (file)
@@ -40,6 +40,7 @@ AC_DEFUN([gl_PHYSMEM],
      #endif
     ])
 
-  AC_CHECK_FUNCS([pstat_getstatic pstat_getdynamic sysmp getsysinfo sysctl table])
+  AC_CHECK_FUNCS([pstat_getstatic pstat_getdynamic sysmp getsysinfo sysctl table sysinfo])
+  AC_CHECK_MEMBERS([struct sysinfo.mem_unit],,, [[#include <sys/sysinfo.h>]])
   AC_REQUIRE([gl_SYS__SYSTEM_CONFIGURATION])
 ])