---
help.c | 4 +++-
memory.c | 17 ++++++++++++++---
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/help.c b/help.c
index ffc8aeb..0f1508d 100644
--- a/help.c
+++ b/help.c
@@ -5541,7 +5541,7 @@ NULL
char *help_kmem[] = {
"kmem",
"kernel memory",
-"[-f|-F|-p|-c|-C|-i|-s|-S|-v|-V|-n|-z|-o|-h|-k] [slab] [[-P] address]\n"
+"[-f|-F|-p|-c|-C|-i|-s|-S|-v|-V|-n|-z|-o|-h|-k|-r] [slab] [[-P] address]\n"
" [-g [flags]] [-I slab[,slab]]",
" This command displays information about the use of kernel memory.\n",
" -f displays the contents of the system free memory headers.",
@@ -5576,6 +5576,8 @@ char *help_kmem[] = {
" caused by misuse of compound pages (e.g. free with wrong
order).",
" When an error is found, the compound order will be shown as -1.",
" Only works when -p is used without an address.",
+" -r only print used pages (i.e. the page count is not zero).",
+" Only works when -p is used without an address.",
" flags when used with -g, translates all bits in this hexadecimal page",
" structure flags value into its enumerator values.",
" slab when used with -s or -S, limits the command to only the slab
cache",
diff --git a/memory.c b/memory.c
index 43ceff7..a1ef59a 100644
--- a/memory.c
+++ b/memory.c
@@ -4425,6 +4425,7 @@ get_task_mem_usage(ulong task, struct task_mem_usage *tm)
#define SLAB_BITFIELD (ADDRESS_SPECIFIED << 25)
#define VERIFY_COMPOUND_PAGES (1 << 0)
+#define SKIP_FREE_PAGES (1 << 1)
#define GET_ALL \
(GET_SHARED_PAGES|GET_TOTALRAM_PAGES|GET_BUFFERS_PAGES|GET_SLAB_PAGES)
@@ -4436,7 +4437,7 @@ cmd_kmem(void)
int c;
int sflag, Sflag, pflag, fflag, Fflag, vflag, zflag, oflag, gflag;
int nflag, cflag, Cflag, iflag, lflag, Lflag, Pflag, Vflag, hflag;
- int kflag;
+ int kflag, rflag;
struct meminfo meminfo;
ulonglong value[MAXARGS];
char buf[BUFSIZE];
@@ -4446,12 +4447,12 @@ cmd_kmem(void)
spec_addr = 0;
sflag = Sflag = pflag = fflag = Fflag = Pflag = zflag = oflag = 0;
vflag = Cflag = cflag = iflag = nflag = lflag = Lflag = Vflag = 0;
- gflag = hflag = kflag = 0;
+ gflag = hflag = kflag = rflag = 0;
escape = FALSE;
BZERO(&meminfo, sizeof(struct meminfo));
BZERO(&value[0], sizeof(ulonglong)*MAXARGS);
- while ((c = getopt(argcnt, args, "gI:sSFfpkvczCinl:L:PVoh")) != EOF) {
+ while ((c = getopt(argcnt, args, "gI:sSFfpkrvczCinl:L:PVoh")) != EOF)
{
switch(c)
{
case 'V':
@@ -4560,6 +4561,10 @@ cmd_kmem(void)
kflag = 1;
break;
+ case 'r':
+ rflag = 1;
+ break;
+
default:
argerrs++;
break;
@@ -4730,6 +4735,8 @@ cmd_kmem(void)
if (pflag == 1) {
if (kflag)
meminfo.extra_flags |= VERIFY_COMPOUND_PAGES;
+ if (rflag)
+ meminfo.extra_flags |= SKIP_FREE_PAGES;
dump_mem_map(&meminfo);
}
@@ -5228,6 +5235,8 @@ dump_mem_map_SPARSEMEM(struct meminfo *mi)
if (SIZE(page_flags) == 4)
flags &= 0xffffffff;
count = UINT(pcache + OFFSET(page_count));
+ if (!count && (mi->extra_flags & SKIP_FREE_PAGES))
+ continue;
switch (mi->flags)
{
@@ -5677,6 +5686,8 @@ dump_mem_map(struct meminfo *mi)
if (SIZE(page_flags) == 4)
flags &= 0xffffffff;
count = UINT(pcache + OFFSET(page_count));
+ if (!count && (mi->extra_flags & SKIP_FREE_PAGES))
+ continue;
switch (mi->flags)
{
--
2.2.0.rc0.207.ga3a616c