]> granicus.if.org Git - procps-ng/commitdiff
library: tweak newly added MemAvailable fall-back code
authorJim Warner <james.warner@comcast.net>
Thu, 17 Jul 2014 16:11:11 +0000 (11:11 -0500)
committerJaromir Capik <jcapik@redhat.com>
Fri, 18 Jul 2014 18:49:57 +0000 (20:49 +0200)
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 <james.warner@comcast.net>
proc/libprocps.sym
proc/sysinfo.c
proc/sysinfo.h

index b86175ff93713ae303b2ab2e4e207a4f91868121..77a658ba25b5e9f1cfa6a5cefdfd7564d9a02226 100644 (file)
@@ -44,6 +44,7 @@ global:
        open_psdb;
        open_psdb_message;
        openproc;
+       page_bytes;
        pretty_print_signals;
        print_uptime;
        procps_version;
index f6cc1628147aed2c4ad5a47b316f85f46e644181..e493e794b93e754eeb26c183bb7305e72639ad1b 100644 (file)
@@ -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);
 }
 
 ///////////////////////////////////////////////////////////////////////
index fcfd0f456394dfb712bf382b993f2047910e762b..5847b6714b28d4d2d0a6c80895ea1847a4f7955d 100644 (file)
@@ -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