From: Jim Warner Date: Thu, 17 Jul 2014 18:13:13 +0000 (-0500) Subject: top: exploit new kb_main_available, make Jaromir happy X-Git-Tag: v3.3.10~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d310a18fc2391ba06f3531aff020c97057c0ed3c;p=procps-ng top: exploit new kb_main_available, make Jaromir happy This patch will trade a former pessimistic calculation of free physical memory for a more optimistic one that uses the newly added kb_main_available library export. But in case one might wish to return to the old former method, there's a new #define that was made available. [ the new calculation will affect graphing mode only ] Reference(s): http://www.freelists.org/post/procps/systemd-support-to-library,9 Signed-off-by: Jim Warner --- diff --git a/top/top.1 b/top/top.1 index 85d8fc8c..de51725f 100644 --- a/top/top.1 +++ b/top/top.1 @@ -470,14 +470,21 @@ with the `E' \*(CI. As a default, Line 1 reflects \*(MP, classified as: .nf - total, used, free and buffers + total, free, used and buff/cache .fi Line 2 reflects mostly \*(MV, classified as: .nf - total, used, free and cached (which is \*(MP) + total, free, used and avail (which is \*(MP) .fi +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. + In the alternate memory display modes, two abbreviated summary lines are shown consisting of these elements: .nf @@ -489,9 +496,10 @@ are shown consisting of these elements: Where: a) is the percentage used; b) is the total available; and c) is one of two visual graphs of those representations. -In the case of \*(MP, the percentage includes the sum of \fBused\fR, \fBbuffers\fR -and \fBcached\fR memory noted above. -The `Mem' graph itself is divided between \fBused\fR then \fBbuffers\fR and \fBcached\fR combined. +In the case of \*(MP, the percentage represents the \fBtotal\fR minus the estimated +\fBavail\fR noted above. +The `Mem' graph itself is divided between \fBused\fR the any remaining memory not +otherwise accounted for by \fBavail\fR. \*(XT 4b. SUMMARY AREA Commands and the `m' command for additional information on that special 4-way toggle. diff --git a/top/top.c b/top/top.c index 9094fafc..207ea5be 100644 --- a/top/top.c +++ b/top/top.c @@ -5216,7 +5216,7 @@ numa_nope: // and prT macro might replace space at buf[8] with: ------> + char buf[10]; // MEMORY_lines_fmt provides for 8+1 bytes } buftab[8]; - unsigned long kb_main_my_used; + unsigned long kb_main_my_used, kb_main_my_misc; if (!scaletab[0].label) { scaletab[0].label = N_txt(AMT_kilobyte_txt); @@ -5226,7 +5226,8 @@ numa_nope: scaletab[4].label = N_txt(AMT_petabyte_txt); scaletab[5].label = N_txt(AMT_exxabyte_txt); } - kb_main_my_used = kb_main_used - kb_main_buffers - kb_main_cached; + kb_main_my_misc = kb_main_buffers + kb_main_cached; + kb_main_my_used = kb_main_used - kb_main_my_misc; if (w->rc.graph_mems) { static struct { @@ -5238,7 +5239,11 @@ numa_nope: char used[SMLBUFSIZ], util[SMLBUFSIZ], dual[MEDBUFSIZ]; int ix = w->rc.graph_mems - 1; float pct_used = (float)kb_main_my_used * (100.0 / (float)kb_main_total), - pct_misc = (float)(kb_main_buffers + kb_main_cached) * (100.0 / (float)kb_main_total), +#ifdef MEMGRAPH_OLD + pct_misc = (float)kb_main_my_misc * (100.0 / (float)kb_main_total), +#else + pct_misc = (float)(kb_main_total - kb_main_available - kb_main_my_used) * (100.0 / (float)kb_main_total), +#endif pct_swap = kb_swap_total ? (float)kb_swap_used * (100.0 / (float)kb_swap_total) : 0; snprintf(used, sizeof(used), gtab[ix].used, (int)((pct_used * Graph_adj) + .5), gtab[ix].type); snprintf(util, sizeof(util), gtab[ix].misc, (int)((pct_misc * Graph_adj) + .5), gtab[ix].type); @@ -5250,9 +5255,9 @@ numa_nope: , scT(label), N_txt(WORD_abv_swp_txt), pct_swap, bfT(1), Graph_len +2, Graph_len +2, util)); } else { prT(bfT(0), mkM(total)); prT(bfT(1), mkM(free)); - prT(bfT(2), mkM(my_used)); prT(bfT(3), mkM(buffers)); + prT(bfT(2), mkM(my_used)); prT(bfT(3), mkM(my_misc)); prT(bfT(4), mkS(total)); prT(bfT(5), mkS(free)); - prT(bfT(6), mkS(used)); prT(bfT(7), mkM(cached)); + prT(bfT(6), mkS(used)); prT(bfT(7), mkM(available)); show_special(0, fmtmk(N_unq(MEMORY_lines_fmt) , scT(label), N_txt(WORD_abv_mem_txt), bfT(0), bfT(1), bfT(2), bfT(3) , scT(label), N_txt(WORD_abv_swp_txt), bfT(4), bfT(5), bfT(6), bfT(7) diff --git a/top/top.h b/top/top.h index 263de6c2..391da51d 100644 --- a/top/top.h +++ b/top/top.h @@ -41,6 +41,7 @@ //#define INSP_OFFDEMO /* disable demo screens, issue msg instead */ //#define INSP_SAVEBUF /* preserve 'Insp_buf' contents in a file */ //#define INSP_SLIDE_1 /* when scrolling left/right don't move 8 */ +//#define MEMGRAPH_OLD /* don't use 'available' when graphing Mem */ //#define OFF_HST_HASH /* use BOTH qsort+bsrch vs. hashing scheme */ //#define OFF_NUMASKIP /* do NOT skip numa nodes if discontinuous */ //#define OFF_SCROLLBK /* disable tty emulators scrollback buffer */ @@ -658,6 +659,9 @@ typedef struct WIN_t { #if defined(TERMIOS_ONLY) # warning 'TERMIOS_ONLY' disables input recall and makes man doc incorrect #endif +#if defined(MEMGRAPH_OLD) +# warning 'MEMGRAPH_OLD' will make the man document Section 2c. misleading +#endif /*###### Some Prototypes (ha!) #########################################*/ diff --git a/top/top_nls.c b/top/top_nls.c index eed01310..8edc5b0b 100644 --- a/top/top_nls.c +++ b/top/top_nls.c @@ -637,8 +637,8 @@ static void build_uniq_nlstab (void) { "%#5.1f ~2us,~3%#5.1f ~2sy,~3%#5.1f ~2ni,~3%#5.1f ~2id,~3%#5.1f ~2wa,~3%#5.1f ~2hi,~3%#5.1f ~2si,~3%#5.1f ~2st~3\n"); Uniq_nlstab[MEMORY_lines_fmt] = _("" - "%s %s:~3 %9.9s~2total,~3 %9.9s~2free,~3 %9.9s~2used,~3 %9.9s~2buffers~3\n" - "%s %s:~3 %9.9s~2total,~3 %9.9s~2free,~3 %9.9s~2used.~3 %9.9s~2cached %s~3\n"); + "%s %s:~3 %9.9s~2total,~3 %9.9s~2free,~3 %9.9s~2used,~3 %9.9s~2buff/cache~3\n" + "%s %s:~3 %9.9s~2total,~3 %9.9s~2free,~3 %9.9s~2used.~3 %9.9s~2avail %s~3\n"); Uniq_nlstab[INSP_hdrsels_fmt] = _("" "Inspection~2 Pause at: pid ~1%d~6 running ~1%s~6 as user ~1%s~6\n"