# HG changeset patch # User Natanael Copa # Date 1397812587 0 # Node ID 10089b66b66e866c14db6d9ca5f70322d2f4f637 # Parent 8d4f74d331352d6e8799052d80180d14ff0238b7 physmem: use sysinfo if _SC_PHYS_PAGES unavailable * 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 diff -r 8d4f74d33135 -r 10089b66b66e ChangeLog --- a/ChangeLog Fri Apr 18 22:29:55 2014 -0700 +++ b/ChangeLog Fri Apr 18 09:16:27 2014 +0000 @@ -1,3 +1,11 @@ +2014-04-18 Natanael Copa + + 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 exclude: port to strict C99 diff -r 8d4f74d33135 -r 10089b66b66e lib/physmem.c --- a/lib/physmem.c Fri Apr 18 22:29:55 2014 -0700 +++ b/lib/physmem.c Fri Apr 18 09:16:27 2014 +0000 @@ -32,8 +32,11 @@ # include #endif -#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H +#if HAVE_SYS_SYSINFO_H # include +#endif + +#if HAVE_MACHINE_HAL_SYSINFO_H # include #endif @@ -90,6 +93,14 @@ } #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 @@ } #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; diff -r 8d4f74d33135 -r 10089b66b66e m4/physmem.m4 --- a/m4/physmem.m4 Fri Apr 18 22:29:55 2014 -0700 +++ b/m4/physmem.m4 Fri Apr 18 09:16:27 2014 +0000 @@ -40,6 +40,7 @@ #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 ]]) AC_REQUIRE([gl_SYS__SYSTEM_CONFIGURATION]) ])