]> granicus.if.org Git - procps-ng/commitdiff
library: evolve MenAvailable algorithm on older kernel
authorJim Warner <james.warner@comcast.net>
Sat, 19 Jul 2014 09:44:44 +0000 (04:44 -0500)
committerJaromir Capik <jcapik@redhat.com>
Mon, 21 Jul 2014 14:17:52 +0000 (16:17 +0200)
Let's not report zero for kb_main_available when older
kernels don't have MemAvailable. Instead, if we simply
duplicate the 'free' amount we can avoid all ancillary
problems, such as those involving top's graphing mode.

Reference(s):
http://www.freelists.org/post/procps/kb-main-available-etc,3

Signed-off-by: Jim Warner <james.warner@comcast.net>
free.1
proc/sysinfo.c
top/top.1

diff --git a/free.1 b/free.1
index 1b40f8d067ca340765a4a11f36c21b71ceb6d308..a2bac2610ebd7b313e0cebc3ea0e221b388110c8 100644 (file)
--- a/free.1
+++ b/free.1
@@ -41,7 +41,7 @@ provided by the \fBcached\fR or \fBfree\fR fields,
 this field takes into account page cache and also that
 not all reclaimable memory slabs will be reclaimed
 due to items being in use (MemAvailable in /proc/meminfo, available on
-kernels 3.14, emulated on kernels 2.6.27+, displayed as zero if not available)
+kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as \fBfree\fR)
 .SH OPTIONS
 .TP
 \fB\-b\fR, \fB\-\-bytes\fR
index e493e794b93e754eeb26c183bb7305e72639ad1b..c9b3241bc5ca27e29bd6694f0b4d36546126afa2 100644 (file)
@@ -697,17 +697,21 @@ nextline:
   kb_main_used = kb_main_total - kb_main_free;
 
   /* zero? might need fallback for 2.6.27 <= kernel <? 3.14 */
-  if (!kb_main_available && linux_version_code >= 20627) {
-    vminfo();
-    watermark_low = vm_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;
-
-    if (mem_available < 0) mem_available = 0;
-    kb_main_available = (unsigned long)((unsigned long long)mem_available * page_bytes / 1024ull);
+  if (!kb_main_available) {
+    if (linux_version_code < 20627)
+      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 */
+
+      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;
+
+      if (mem_available < 0) mem_available = 0;
+      kb_main_available = (unsigned long)((unsigned long long)mem_available * page_bytes / 1024ull);
+    }
   }
 }
 
index 08096654ef9cb5c046b235b594b976dda3b93853..75f6ab51632b5bae447f31e260247e9120caa239 100644 (file)
--- a/top/top.1
+++ b/top/top.1
@@ -482,8 +482,8 @@ The \fBavail\fR number on line 2 is an estimation of \*(MP available for
 starting new applications, without swapping.
 Unlike the \fBfree\fR field, it attempts to account for readily reclaimable
 page cache and memory slabs.
-It is available on kernels 3.14, emulated on kernels 2.6.27+ and displayed
-as zero otherwise.
+It is available on kernels 3.14, emulated on kernels 2.6.27+, otherwise
+the same as \fBfree\fR.
 
 In the alternate memory display modes, two abbreviated summary lines
 are shown consisting of these elements: