[Crash-utility] [PATCH] Enhance the "kmem -i" option to properly display the statistics of CACHED

Lianbo Jiang lijiang at redhat.com
Tue Feb 14 14:37:08 UTC 2023


The "kmem -i" option may output the bogus statistics of CACHED, which
might be observed when some extreme situations occur in kernel, such as
OOM, disk IO errors, etc.

The following result of calculation may be a negative value, refer to
the dump_kmeminfo():
  page_cache_size = nr_file_pages - swapper_space_nrpages - buffer_pages;

As a result, the negative value will be converted to unsigned long
integer, eventually it overflows and gets a big integer.

  crash> kmem -i
                   PAGES        TOTAL      PERCENTAGE
      TOTAL MEM  255314511     973.9 GB         ----
           FREE   533574         2 GB    0% of TOTAL MEM
           USED  254780937     971.9 GB   99% of TOTAL MEM
         SHARED     1713       6.7 MB    0% of TOTAL MEM
        BUFFERS      374       1.5 MB    0% of TOTAL MEM
         CACHED     -114  70368744177664 GB  72251060080% of TOTAL MEM
                    ^^^^  ^^^^^^^^^^^^^^     ^^^^^^^^^^^^
         ...

Let's normalize it to zero to fix such corner cases.

Reported-by: Buland Kumar Singh <bsingh at redhat.com>
Signed-off-by: Lianbo Jiang <lijiang at redhat.com>
---
 memory.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/memory.c b/memory.c
index e0742c1bd3a4..860a3a978a4d 100644
--- a/memory.c
+++ b/memory.c
@@ -8615,6 +8615,8 @@ dump_kmeminfo(void)
 		page_cache_size = 0;
 
 
+	if (page_cache_size < 0)
+		page_cache_size = 0;
         pct = (page_cache_size * 100)/totalram_pages;
         fprintf(fp, "%13s  %7ld  %11s  %3ld%% of TOTAL MEM\n", 
 		"CACHED", page_cache_size, 
-- 
2.37.1



More information about the Crash-utility mailing list