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
This commit is contained in:
Craig Small 2021-06-16 20:29:03 +10:00
parent 9bebdf2ab3
commit 16734d580e
3 changed files with 24 additions and 2 deletions

1
NEWS
View File

@ -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

7
free.1
View File

@ -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

18
free.c
View File

@ -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--;