free: support for MemAvailable
This commit adds a new switch -a/--available that appends a new column called 'available' to the output. The column displays an estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the 'cached' or 'free' 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.
This commit is contained in:
parent
e751606fcc
commit
ba6396f886
12
free.1
12
free.1
@ -33,6 +33,14 @@ Memory used by kernel buffers (Buffers in /proc/meminfo)
|
|||||||
.TP
|
.TP
|
||||||
\fBcached\fR
|
\fBcached\fR
|
||||||
Memory used by the page cache (Cached in /proc/meminfo)
|
Memory used by the page cache (Cached in /proc/meminfo)
|
||||||
|
.TP
|
||||||
|
\fBavailable\fR
|
||||||
|
Estimation of how much memory is available for starting
|
||||||
|
new applications, without swapping. Unlike the data
|
||||||
|
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)
|
||||||
.SH OPTIONS
|
.SH OPTIONS
|
||||||
.TP
|
.TP
|
||||||
\fB\-b\fR, \fB\-\-bytes\fR
|
\fB\-b\fR, \fB\-\-bytes\fR
|
||||||
@ -65,6 +73,10 @@ display the units of print out. Following units are used.
|
|||||||
If unit is missing, and you have petabyte of RAM or swap, the number is in
|
If unit is missing, and you have petabyte of RAM or swap, the number is in
|
||||||
terabytes and columns might not be aligned with header.
|
terabytes and columns might not be aligned with header.
|
||||||
.TP
|
.TP
|
||||||
|
\fB\-a\fR, \fB\-\-available\fR
|
||||||
|
Display the estimation of memory available for starting new applications,
|
||||||
|
without swapping. This switch makes the output wider than 80 characters.
|
||||||
|
.TP
|
||||||
\fB\-c\fR, \fB\-\-count\fR \fIcount\fR
|
\fB\-c\fR, \fB\-\-count\fR \fIcount\fR
|
||||||
Display the result
|
Display the result
|
||||||
.I count
|
.I count
|
||||||
|
13
free.c
13
free.c
@ -54,6 +54,7 @@
|
|||||||
#define FREE_SI (1 << 5)
|
#define FREE_SI (1 << 5)
|
||||||
#define FREE_REPEAT (1 << 6)
|
#define FREE_REPEAT (1 << 6)
|
||||||
#define FREE_REPEATCOUNT (1 << 7)
|
#define FREE_REPEATCOUNT (1 << 7)
|
||||||
|
#define FREE_AVAILABLE (1 << 8)
|
||||||
|
|
||||||
struct commandline_arguments {
|
struct commandline_arguments {
|
||||||
int exponent; /* demanded in kilos, magas... */
|
int exponent; /* demanded in kilos, magas... */
|
||||||
@ -85,6 +86,7 @@ static void __attribute__ ((__noreturn__))
|
|||||||
fputs(_(" -t, --total show total for RAM + swap\n"), out);
|
fputs(_(" -t, --total show total for RAM + swap\n"), out);
|
||||||
fputs(_(" -s N, --seconds N repeat printing every N seconds\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(_(" -c N, --count N repeat printing N times, then exit\n"), out);
|
||||||
|
fputs(_(" -a, --available show available memory\n"), out);
|
||||||
fputs(USAGE_SEPARATOR, out);
|
fputs(USAGE_SEPARATOR, out);
|
||||||
fputs(_(" --help display this help and exit\n"), out);
|
fputs(_(" --help display this help and exit\n"), out);
|
||||||
fputs(USAGE_VERSION, out);
|
fputs(USAGE_VERSION, out);
|
||||||
@ -213,6 +215,7 @@ int main(int argc, char **argv)
|
|||||||
{ "total", no_argument, NULL, 't' },
|
{ "total", no_argument, NULL, 't' },
|
||||||
{ "seconds", required_argument, NULL, 's' },
|
{ "seconds", required_argument, NULL, 's' },
|
||||||
{ "count", required_argument, NULL, 'c' },
|
{ "count", required_argument, NULL, 'c' },
|
||||||
|
{ "available", no_argument, NULL, 'a' },
|
||||||
{ "help", no_argument, NULL, HELP_OPTION },
|
{ "help", no_argument, NULL, HELP_OPTION },
|
||||||
{ "version", no_argument, NULL, 'V' },
|
{ "version", no_argument, NULL, 'V' },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
@ -231,7 +234,7 @@ int main(int argc, char **argv)
|
|||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
atexit(close_stdout);
|
atexit(close_stdout);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "bkmghlotc:s:V", longopts, NULL)) != -1)
|
while ((c = getopt_long(argc, argv, "bkmghlotc:as:V", longopts, NULL)) != -1)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
case 'b':
|
||||||
args.exponent = 1;
|
args.exponent = 1;
|
||||||
@ -281,6 +284,9 @@ int main(int argc, char **argv)
|
|||||||
error(EXIT_FAILURE, ERANGE,
|
error(EXIT_FAILURE, ERANGE,
|
||||||
_("failed to parse count argument: '%s'"), optarg);
|
_("failed to parse count argument: '%s'"), optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'a':
|
||||||
|
flags |= FREE_AVAILABLE;
|
||||||
|
break;
|
||||||
case HELP_OPTION:
|
case HELP_OPTION:
|
||||||
usage(stdout);
|
usage(stdout);
|
||||||
case 'V':
|
case 'V':
|
||||||
@ -296,7 +302,9 @@ int main(int argc, char **argv)
|
|||||||
/* Translation Hint: You can use 9 character words in
|
/* Translation Hint: You can use 9 character words in
|
||||||
* the header, and the words need to be right align to
|
* the header, and the words need to be right align to
|
||||||
* beginning of a number. */
|
* beginning of a number. */
|
||||||
printf("%s\n", _(" total used free shared buffers cached"));
|
printf(_(" total used free shared buffers cached"));
|
||||||
|
if (flags & FREE_AVAILABLE) printf(_(" available"));
|
||||||
|
printf("\n");
|
||||||
printf("%-7s", _("Mem:"));
|
printf("%-7s", _("Mem:"));
|
||||||
printf(" %10s", scale_size(kb_main_total, flags, args));
|
printf(" %10s", scale_size(kb_main_total, flags, args));
|
||||||
printf(" %10s", scale_size(kb_main_used, flags, args));
|
printf(" %10s", scale_size(kb_main_used, flags, args));
|
||||||
@ -304,6 +312,7 @@ int main(int argc, char **argv)
|
|||||||
printf(" %10s", scale_size(kb_main_shared, flags, args));
|
printf(" %10s", scale_size(kb_main_shared, flags, args));
|
||||||
printf(" %10s", scale_size(kb_main_buffers, flags, args));
|
printf(" %10s", scale_size(kb_main_buffers, flags, args));
|
||||||
printf(" %10s", scale_size(kb_main_cached, flags, args));
|
printf(" %10s", scale_size(kb_main_cached, flags, args));
|
||||||
|
if (flags & FREE_AVAILABLE) printf(" %10s", scale_size(kb_main_available, flags, args));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
/*
|
/*
|
||||||
* Print low vs. high information, if the user requested it.
|
* Print low vs. high information, if the user requested it.
|
||||||
|
@ -26,6 +26,7 @@ global:
|
|||||||
kb_inactive;
|
kb_inactive;
|
||||||
kb_low_free;
|
kb_low_free;
|
||||||
kb_low_total;
|
kb_low_total;
|
||||||
|
kb_main_available;
|
||||||
kb_main_buffers;
|
kb_main_buffers;
|
||||||
kb_main_cached;
|
kb_main_cached;
|
||||||
kb_main_free;
|
kb_main_free;
|
||||||
|
@ -573,6 +573,7 @@ unsigned long kb_high_free;
|
|||||||
unsigned long kb_high_total;
|
unsigned long kb_high_total;
|
||||||
unsigned long kb_low_free;
|
unsigned long kb_low_free;
|
||||||
unsigned long kb_low_total;
|
unsigned long kb_low_total;
|
||||||
|
unsigned long kb_main_available;
|
||||||
/* 2.4.xx era */
|
/* 2.4.xx era */
|
||||||
unsigned long kb_active;
|
unsigned long kb_active;
|
||||||
unsigned long kb_inact_laundry;
|
unsigned long kb_inact_laundry;
|
||||||
@ -629,6 +630,7 @@ void meminfo(void){
|
|||||||
{"LowFree", &kb_low_free},
|
{"LowFree", &kb_low_free},
|
||||||
{"LowTotal", &kb_low_total},
|
{"LowTotal", &kb_low_total},
|
||||||
{"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped
|
{"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped
|
||||||
|
{"MemAvailable", &kb_main_available}, // important
|
||||||
{"MemFree", &kb_main_free}, // important
|
{"MemFree", &kb_main_free}, // important
|
||||||
{"MemTotal", &kb_main_total}, // important
|
{"MemTotal", &kb_main_total}, // important
|
||||||
{"NFS_Unstable", &kb_nfs_unstable},
|
{"NFS_Unstable", &kb_nfs_unstable},
|
||||||
|
@ -34,6 +34,7 @@ extern unsigned long kb_high_free;
|
|||||||
extern unsigned long kb_high_total;
|
extern unsigned long kb_high_total;
|
||||||
extern unsigned long kb_low_free;
|
extern unsigned long kb_low_free;
|
||||||
extern unsigned long kb_low_total;
|
extern unsigned long kb_low_total;
|
||||||
|
extern unsigned long kb_main_available;
|
||||||
/* 2.4.xx era */
|
/* 2.4.xx era */
|
||||||
extern unsigned long kb_active;
|
extern unsigned long kb_active;
|
||||||
extern unsigned long kb_inact_laundry; // grrr...
|
extern unsigned long kb_inact_laundry; // grrr...
|
||||||
|
Loading…
Reference in New Issue
Block a user