crash/SOURCES/0074-Fix-for-kmem-i-option-to-not-print-invalid-values-fo.patch
2023-09-27 12:47:33 +00:00

57 lines
1.9 KiB
Diff

From b13a2f3c2885bc638d1e413ef9e7c59a8ec8f81d Mon Sep 17 00:00:00 2001
From: Lianbo Jiang <lijiang@redhat.com>
Date: Tue, 14 Feb 2023 22:37:08 +0800
Subject: [PATCH 74/89] Fix for "kmem -i" option to not print invalid values
for CACHED
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>
---
memory.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/memory.c b/memory.c
index e0742c1bd3a4..d9cd616f19de 100644
--- a/memory.c
+++ b/memory.c
@@ -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,
--
2.37.1