From e4f0b4ebf3eaa1bda9a0315ec7b113c73a510dd4 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 17 Jul 2014 11:11:11 -0500 Subject: [PATCH] library: tweak newly added MemAvailable fall-back code This commit just ensures recalculation of some amounts for iterative processes, like top. It also trades some repeated runtime calls to sysconf for a one time cost. Reference(s): http://www.freelists.org/post/procps/systemd-support-to-library,7 . fall-back calculations commit b779855cf15d68f9038ff1809db18c0788e9ae70 Signed-off-by: Jim Warner --- proc/libprocps.sym | 1 + proc/sysinfo.c | 7 +++++-- proc/sysinfo.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/proc/libprocps.sym b/proc/libprocps.sym index b86175ff..77a658ba 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -44,6 +44,7 @@ global: open_psdb; open_psdb_message; openproc; + page_bytes; pretty_print_signals; print_uptime; procps_version; diff --git a/proc/sysinfo.c b/proc/sysinfo.c index f6cc1628..e493e794 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -37,6 +37,7 @@ #endif long smp_num_cpus; /* number of CPUs */ +long page_bytes; /* this architecture's page size */ #define BAD_OPEN_MESSAGE \ "Error: /proc must be mounted\n" \ @@ -277,6 +278,7 @@ static void init_libproc(void){ init_Linux_version(); /* Must be called before we check code */ cpuinfo(); + page_bytes = sysconf(_SC_PAGESIZE); #ifdef __linux__ if(linux_version_code > LINUX_VERSION(2, 4, 0)){ @@ -661,6 +663,7 @@ void meminfo(void){ FILE_TO_BUF(MEMINFO_FILE,meminfo_fd); kb_inactive = ~0UL; + kb_low_total = kb_main_available = 0; head = buf; for(;;){ @@ -704,7 +707,7 @@ nextline: - watermark_low; if (mem_available < 0) mem_available = 0; - kb_main_available = (unsigned long)((unsigned long long)mem_available * sysconf(_SC_PAGESIZE) / 1024ull); + kb_main_available = (unsigned long)((unsigned long long)mem_available * page_bytes / 1024ull); } } @@ -888,7 +891,7 @@ nextline: vm_pgsteal = vm_pgsteal_dma + vm_pgsteal_high + vm_pgsteal_normal; FILE_TO_BUF(VM_MIN_FREE_FILE, vm_min_free_fd); - vm_min_free = (unsigned long) (strtoull(buf,&tail,10) * 1024ull / sysconf(_SC_PAGESIZE)); + vm_min_free = (unsigned long) (strtoull(buf,&tail,10) * 1024ull / page_bytes); } /////////////////////////////////////////////////////////////////////// diff --git a/proc/sysinfo.h b/proc/sysinfo.h index fcfd0f45..5847b671 100644 --- a/proc/sysinfo.h +++ b/proc/sysinfo.h @@ -9,6 +9,7 @@ EXTERN_C_BEGIN extern unsigned long long Hertz; /* clock tick frequency */ extern long smp_num_cpus; /* number of CPUs */ extern int have_privs; /* boolean, true if setuid or similar */ +extern long page_bytes; /* this architecture's bytes per page */ #if 0 #define JT double