diff --git a/free.1 b/free.1 index 85efef88..a4665ea9 100644 --- a/free.1 +++ b/free.1 @@ -33,6 +33,14 @@ Memory used by kernel buffers (Buffers in /proc/meminfo) .TP \fBcached\fR 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 .TP \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 terabytes and columns might not be aligned with header. .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 Display the result .I count diff --git a/free.c b/free.c index d95feaa8..e6ea043d 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_AVAILABLE (1 << 8) struct commandline_arguments { 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(_(" -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(_(" -a, --available show available memory\n"), out); fputs(USAGE_SEPARATOR, out); fputs(_(" --help display this help and exit\n"), out); fputs(USAGE_VERSION, out); @@ -213,6 +215,7 @@ int main(int argc, char **argv) { "total", no_argument, NULL, 't' }, { "seconds", required_argument, NULL, 's' }, { "count", required_argument, NULL, 'c' }, + { "available", no_argument, NULL, 'a' }, { "help", no_argument, NULL, HELP_OPTION }, { "version", no_argument, NULL, 'V' }, { NULL, 0, NULL, 0 } @@ -231,7 +234,7 @@ int main(int argc, char **argv) textdomain(PACKAGE); 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) { case 'b': args.exponent = 1; @@ -281,6 +284,9 @@ int main(int argc, char **argv) error(EXIT_FAILURE, ERANGE, _("failed to parse count argument: '%s'"), optarg); break; + case 'a': + flags |= FREE_AVAILABLE; + break; case HELP_OPTION: usage(stdout); case 'V': @@ -296,7 +302,9 @@ int main(int argc, char **argv) /* Translation Hint: You can use 9 character words in * the header, and the words need to be right align to * 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(" %10s", scale_size(kb_main_total, 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_buffers, 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"); /* * Print low vs. high information, if the user requested it. diff --git a/proc/libprocps.sym b/proc/libprocps.sym index d4f692ee..b86175ff 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -26,6 +26,7 @@ global: kb_inactive; kb_low_free; kb_low_total; + kb_main_available; kb_main_buffers; kb_main_cached; kb_main_free; diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 85fb0a43..e3e2ca5b 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -573,6 +573,7 @@ unsigned long kb_high_free; unsigned long kb_high_total; unsigned long kb_low_free; unsigned long kb_low_total; +unsigned long kb_main_available; /* 2.4.xx era */ unsigned long kb_active; unsigned long kb_inact_laundry; @@ -629,6 +630,7 @@ void meminfo(void){ {"LowFree", &kb_low_free}, {"LowTotal", &kb_low_total}, {"Mapped", &kb_mapped}, // kB version of vmstat nr_mapped + {"MemAvailable", &kb_main_available}, // important {"MemFree", &kb_main_free}, // important {"MemTotal", &kb_main_total}, // important {"NFS_Unstable", &kb_nfs_unstable}, diff --git a/proc/sysinfo.h b/proc/sysinfo.h index 22916319..2ec7954a 100644 --- a/proc/sysinfo.h +++ b/proc/sysinfo.h @@ -34,6 +34,7 @@ extern unsigned long kb_high_free; extern unsigned long kb_high_total; extern unsigned long kb_low_free; extern unsigned long kb_low_total; +extern unsigned long kb_main_available; /* 2.4.xx era */ extern unsigned long kb_active; extern unsigned long kb_inact_laundry; // grrr...