Skip to content

Commit

Permalink
Fix for "kmem -i" option to not print invalid values for CACHED
Browse files Browse the repository at this point in the history
The "kmem -i" option may output a bogus statistics for 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 is printed as big integers.

  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 with an info message to fix such cornor cases.

Reported-by: Buland Kumar Singh <bsingh@redhat.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
  • Loading branch information
lian-bo authored and k-hagio committed Feb 15, 2023
1 parent c64a827 commit 277da34
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions memory.c
Expand Up @@ -8615,6 +8615,11 @@ dump_kmeminfo(void)
page_cache_size = 0;


if (page_cache_size < 0) {
error(INFO, "page_cache_size went negative (%ld), setting to 0\n",
page_cache_size);
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,
Expand Down

0 comments on commit 277da34

Please sign in to comment.