]> granicus.if.org Git - procps-ng/commitdiff
library: MemAvailable fallback now uses /proc/meminfo
authorJaromir Capik <jcapik@redhat.com>
Tue, 29 Jul 2014 18:56:20 +0000 (20:56 +0200)
committerJaromir Capik <jcapik@redhat.com>
Thu, 31 Jul 2014 13:10:42 +0000 (15:10 +0200)
Taking the values from /proc/vmstat was unnecessary
and prone to race conditions.

proc/libprocps.sym
proc/sysinfo.c
proc/sysinfo.h

index 8b2bab52cdf8efc7d24e59732e346048c89c0392..77a658ba25b5e9f1cfa6a5cefdfd7564d9a02226 100644 (file)
@@ -33,8 +33,6 @@ global:
        kb_main_shared;
        kb_main_total;
        kb_main_used;
-       kb_slab_reclaimable;
-       kb_slab_unreclaimable;
        kb_swap_free;
        kb_swap_total;
        kb_swap_used;
index 7ffcb8706bd37d58e42adae02dc23393411136fa..f1cc52ccc72dda9de220dab4b4bd25214a4f93dd 100644 (file)
@@ -610,8 +610,15 @@ static unsigned long kb_anon_pages;
 static unsigned long kb_bounce;
 static unsigned long kb_commit_limit;
 static unsigned long kb_nfs_unstable;
-unsigned long kb_slab_reclaimable;
-unsigned long kb_slab_unreclaimable;
+// seen on 2.6.18
+static unsigned long kb_min_free;
+// 2.6.19+
+static unsigned long kb_slab_reclaimable;
+static unsigned long kb_slab_unreclaimable;
+// 2.6.27+
+static unsigned long kb_active_file;
+static unsigned long kb_inactive_file;
+
 
 void meminfo(void){
   char namebuf[16]; /* big enough to hold any row name */
@@ -621,6 +628,7 @@ void meminfo(void){
   char *tail;
   static const mem_table_struct mem_table[] = {
   {"Active",       &kb_active},       // important
+  {"Active(file)", &kb_active_file},
   {"AnonPages",    &kb_anon_pages},
   {"Bounce",       &kb_bounce},
   {"Buffers",      &kb_main_buffers}, // important
@@ -635,6 +643,7 @@ void meminfo(void){
   {"Inact_laundry",&kb_inact_laundry},
   {"Inact_target", &kb_inact_target},
   {"Inactive",     &kb_inactive},     // important
+  {"Inactive(file)",&kb_inactive_file},
   {"LowFree",      &kb_low_free},
   {"LowTotal",     &kb_low_total},
   {"Mapped",       &kb_mapped},       // kB version of vmstat nr_mapped
@@ -701,16 +710,17 @@ nextline:
     if (linux_version_code < LINUX_VERSION(2, 6, 27))
       kb_main_available = kb_main_free;
     else {
-      vminfo();
-      watermark_low = vm_min_free * 5 / 4; /* should be equal to sum of all 'low' fields in /proc/zoneinfo */
+      FILE_TO_BUF(VM_MIN_FREE_FILE, vm_min_free_fd);
+      kb_min_free = (unsigned long) strtoull(buf,&tail,10);
+
+      watermark_low = kb_min_free * 5 / 4; /* should be equal to sum of all 'low' fields in /proc/zoneinfo */
 
-      mem_available = (signed long)vm_nr_free_pages + vm_nr_inactive_file + vm_nr_active_file
-      - MIN((vm_nr_inactive_file + vm_nr_active_file) / 2, watermark_low)
-      + vm_nr_slab_reclaimable - MIN(vm_nr_slab_reclaimable / 2, watermark_low)
-      - watermark_low;
+      mem_available = (signed long)kb_main_free - watermark_low
+      + kb_inactive_file + kb_active_file - MIN((kb_inactive_file + kb_active_file) / 2, watermark_low)
+      + kb_slab_reclaimable - MIN(kb_slab_reclaimable / 2, watermark_low);
 
       if (mem_available < 0) mem_available = 0;
-      kb_main_available = (unsigned long)((unsigned long long)mem_available * page_bytes / 1024ull);
+      kb_main_available = (unsigned long)mem_available;
     }
   }
 }
@@ -741,7 +751,6 @@ unsigned long vm_nr_slab_unreclaimable;// 2.6.19+ kernels
 unsigned long vm_nr_active_file;       // 2.6.27+ kernels
 unsigned long vm_nr_inactive_file;     // 2.6.27+ kernels
 unsigned long vm_nr_free_pages;        // 2.6.21+ kernels
-unsigned long vm_min_free;             // calculated from /proc/sys/vm/min_free_kbytes
 unsigned long vm_pgpgin;             // kB disk reads  (same as 1st num on /proc/stat page line)
 unsigned long vm_pgpgout;            // kB disk writes (same as 2nd num on /proc/stat page line)
 unsigned long vm_pswpin;             // swap reads     (same as 1st num on /proc/stat swap line)
@@ -893,9 +902,6 @@ nextline:
                 + vm_pgscan_kswapd_dma + vm_pgscan_kswapd_high + vm_pgscan_kswapd_normal;
   if(!vm_pgsteal)
     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 / page_bytes);
 }
 
 ///////////////////////////////////////////////////////////////////////
index 69518d8423b1a6597bf7f5c7e798dd687cc5781a..adb0519182d37747a06021b464ee171c9b4478a9 100644 (file)
@@ -55,9 +55,6 @@ extern unsigned long kb_dirty;
 extern unsigned long kb_inactive;
 extern unsigned long kb_mapped;
 extern unsigned long kb_pagetables;
-// seen on 2.6.24-rc6-git12
-extern unsigned long kb_slab_reclaimable;
-extern unsigned long kb_slab_unreclaimable;
 
 #define BUFFSIZE (64*1024)
 typedef unsigned long long jiff;
@@ -82,7 +79,6 @@ extern unsigned long vm_nr_slab_unreclaimable;
 extern unsigned long vm_nr_active_file;
 extern unsigned long vm_nr_inactive_file;
 extern unsigned long vm_nr_free_pages;
-extern unsigned long vm_min_free;
 extern unsigned long vm_pgpgin;
 extern unsigned long vm_pgpgout;
 extern unsigned long vm_pswpin;