From: Craig Small Date: Wed, 16 Jun 2021 10:29:03 +0000 (+1000) Subject: free: option to show memory commit limits X-Git-Tag: v4.0.0~183 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=16734d580eb779654e626f3b41a98992fc0d557d;p=procps-ng free: option to show memory commit limits This commit is largely the userland only changes found in !73 added by Jens Låås (@jelaas) References: procps-ng/procps!73 --- diff --git a/NEWS b/NEWS index a0e80099..79b80441 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ procps-ng-NEXT --------------- * Rename pwait to pidwait + * free: Add committed line option merge #25 * library: renamed to libproc-2 and reset to 0:0:0 * library: add support for accessing smaps_rollup issue #112, #201 * pkill: Check for lt- variants of program name issue #192 diff --git a/free.1 b/free.1 index b0b21c65..e755c80f 100644 --- a/free.1 +++ b/free.1 @@ -2,7 +2,7 @@ .\" This page Copyright (C) 1993 Matt Welsh, mdw@sunsite.unc.edu. .\" Long options where added at April 15th, 2011. .\" Freely distributable under the terms of the GPL -.TH FREE 1 "2018-05-31" "procps-ng" "User Commands" +.TH FREE 1 "2020-06-16" "procps-ng" "User Commands" .SH NAME free \- Display amount of free and used memory in the system .SH SYNOPSIS @@ -124,6 +124,11 @@ of 1024). \fB\-t\fR, \fB\-\-total\fR Display a line showing the column totals. .TP +\fB\-v\fR, \fB\-\-committed\fR +Display a line showing the memory commit limit and amount of committed/uncommitted +memory. The \fBtotal\fR column on this line will display the memory commit +limit. This line is relevant if memory overcommit is disabled. +.TP \fB\-\-help\fR Print help. .TP diff --git a/free.c b/free.c index 6e7f9466..db0a0876 100644 --- a/free.c +++ b/free.c @@ -54,6 +54,7 @@ #define FREE_SI (1 << 5) #define FREE_REPEAT (1 << 6) #define FREE_REPEATCOUNT (1 << 7) +#define FREE_COMMITTED (1 << 8) struct commandline_arguments { int exponent; /* demanded in kilos, magas... */ @@ -88,6 +89,7 @@ static void __attribute__ ((__noreturn__)) fputs(_(" --si use powers of 1000 not 1024\n"), out); fputs(_(" -l, --lohi show detailed low and high memory statistics\n"), out); fputs(_(" -t, --total show total for RAM + swap\n"), out); + fputs(_(" -v, --committed show committed memory and commit limit\n"), out); fputs(_(" -s N, --seconds N repeat printing every N seconds\n"), out); fputs(_(" -c N, --count N repeat printing N times, then exit\n"), out); fputs(_(" -w, --wide wide output\n"), out); @@ -209,6 +211,7 @@ int main(int argc, char **argv) { "si", no_argument, NULL, SI_OPTION }, { "lohi", no_argument, NULL, 'l' }, { "total", no_argument, NULL, 't' }, + { "committed", no_argument, NULL, 'v' }, { "seconds", required_argument, NULL, 's' }, { "count", required_argument, NULL, 'c' }, { "wide", no_argument, NULL, 'w' }, @@ -230,7 +233,7 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); - while ((c = getopt_long(argc, argv, "bkmghltc:ws:V", longopts, NULL)) != -1) + while ((c = getopt_long(argc, argv, "bkmghltvc:ws:V", longopts, NULL)) != -1) switch (c) { case 'b': check_unit_set(&unit_set); @@ -293,6 +296,9 @@ int main(int argc, char **argv) case 't': flags |= FREE_TOTAL; break; + case 'v': + flags |= FREE_COMMITTED; + break; case 's': flags |= FREE_REPEAT; errno = 0; @@ -392,6 +398,16 @@ int main(int argc, char **argv) MEMINFO_GET(mem_info, MEMINFO_SWAP_FREE, ul_int), flags, args)); printf("\n"); } + if (flags & FREE_COMMITTED) { + printf("%-9s", _("Comm:")); + printf("%11s", scale_size(MEMINFO_GET(mem_info, MEMINFO_MEM_COMMIT_LIMIT, ul_int), flags, args)); + printf(" %11s", scale_size(MEMINFO_GET(mem_info, MEMINFO_MEM_COMMITTED_AS, ul_int), flags, args)); + printf(" %11s", scale_size( + MEMINFO_GET(mem_info, MEMINFO_MEM_COMMIT_LIMIT, ul_int) - + MEMINFO_GET(mem_info, MEMINFO_MEM_COMMITTED_AS, ul_int), flags, args)); + printf("\n"); + } + fflush(stdout); if (flags & FREE_REPEATCOUNT) { args.repeat_counter--;