[Crash-utility] [BUG FIXED]fix bug of CACHED in kmem -i show memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi lianbo:


I have a bug fixed need to merge to crash-utility which patch in attachment.


It can obviously see that kmem -i show memory info of system.
But CACHED have wrong output for add up size of cached memory.

The reason of this bug is:
newest kernel version use "struct address_space *swapper_spaces[MAX_SWAPFILES]"
instead of "struct address_space swapper_spaces[MAX_SWAPFILES]" in old kernel.
this change bring into kernel after kernel 4.11.0

So newest version need to readmem twice, first is address of one struct address_space
second is value of struct address_space.

This bug fix patch add twice readmem when read swapper_spaces struct, it can accurately
read nrpage in struct address_space. And i found that definition of struct address_space swapper_spaces
change in kernel 4.11.0, so i make kernel version compatible for this change.

fix before:
crash> kmem -i
                 PAGES        TOTAL      PERCENTAGE
    TOTAL MEM  2854115      10.9 GB         ----
         FREE   169699     662.9 MB    5% of TOTAL MEM
         USED  2684416      10.2 GB   94% of TOTAL MEM
       SHARED   891094       3.4 GB   31% of TOTAL MEM
      BUFFERS      329       1.3 MB    0% of TOTAL MEM
       CACHED  873327085626  3331478.4 GB  30598875% of TOTAL MEM
         SLAB   230128     898.9 MB    8% of TOTAL MEM

fix after:
crash> kmem -i
                 PAGES        TOTAL      PERCENTAGE
    TOTAL MEM  2854115      10.9 GB         ----
         FREE   169699     662.9 MB    5% of TOTAL MEM
         USED  2684416      10.2 GB   94% of TOTAL MEM
       SHARED   891094       3.4 GB   31% of TOTAL MEM
      BUFFERS      329       1.3 MB    0% of TOTAL MEM
       CACHED  1729018       6.6 GB   60% of TOTAL MEM
         SLAB   230128     898.9 MB    8% of TOTAL MEM



Thanks
Best Regards
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it!******/#
From cada55e284d3e7c2a9feb9eae6bb59f1816eb8da Mon Sep 17 00:00:00 2001
From: xueguolun <xueguolun@xxxxxxxxxx>
Date: Wed, 29 Nov 2023 17:36:32 +0800
Subject: [PATCH] [kmem]fix bug of CACHED in kmem -i show memory

It can obviously see that kmem -i show memory info of system.
But CACHED have wrong output for add up size of cached memory.

The reason of this bug is:
newest kernel version use "struct address_space *swapper_spaces[MAX_SWAPFILES]"
instead of "struct address_space swapper_spaces[MAX_SWAPFILES]" in old kernel.

So newest version need to readmem twice, first is address of one struct address_space
second is value of struct address_space

fix before:
crash> kmem -i
                 PAGES        TOTAL      PERCENTAGE
    TOTAL MEM  2854115      10.9 GB         ----
         FREE   169699     662.9 MB    5% of TOTAL MEM
         USED  2684416      10.2 GB   94% of TOTAL MEM
       SHARED   891094       3.4 GB   31% of TOTAL MEM
      BUFFERS      329       1.3 MB    0% of TOTAL MEM
       CACHED  873327085626  3331478.4 GB  30598875% of TOTAL MEM
         SLAB   230128     898.9 MB    8% of TOTAL MEM

fix after:
crash> kmem -i
                 PAGES        TOTAL      PERCENTAGE
    TOTAL MEM  2854115      10.9 GB         ----
         FREE   169699     662.9 MB    5% of TOTAL MEM
         USED  2684416      10.2 GB   94% of TOTAL MEM
       SHARED   891094       3.4 GB   31% of TOTAL MEM
      BUFFERS      329       1.3 MB    0% of TOTAL MEM
       CACHED  1729018       6.6 GB   60% of TOTAL MEM
         SLAB   230128     898.9 MB    8% of TOTAL MEM

Signed-off-by: xueguolun <xueguolun@xxxxxxxxxx>
---
 memory.c | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/memory.c b/memory.c
index 791194a..a14e8d3 100644
--- a/memory.c
+++ b/memory.c
@@ -8479,6 +8479,7 @@ dump_kmeminfo(void)
         ulong freehighmem_pages;
         ulong totallowmem_pages;
         ulong freelowmem_pages;
+        ulong address_space_ptr;
 	ulong allowed;
 	long committed;
 	ulong overcommit_kbytes = 0;
@@ -8649,11 +8650,26 @@ dump_kmeminfo(void)
 		} else if (symbol_exists("swapper_spaces") &&
 		    (len = get_array_length("swapper_spaces", NULL, 0))) {
 			for (i = 0; i < len; i++) {
-		    		if (!readmem(symbol_value("swapper_spaces") + 
-				    i * SIZE(address_space), KVADDR, 
-		    		    swapper_space, SIZE(address_space), 
-				    "swapper_space", RETURN_ON_ERROR))
-					break;
+
+                                if (THIS_KERNEL_VERSION < LINUX(4,11,0)) {
+		    		        if (!readmem(symbol_value("swapper_spaces") +
+				        i * SIZE(address_space), KVADDR,
+		    		        swapper_space, SIZE(address_space),
+				        "swapper_space", RETURN_ON_ERROR))
+					        break;
+                                } else {
+                                        if (!readmem(symbol_value("swapper_spaces") +
+                                        i * sizeof(unsigned long), KVADDR,
+                                        &address_space_ptr, sizeof(unsigned long),
+                                        "swapper_space ptr", RETURN_ON_ERROR))
+                                                break;
+
+                                        if (address_space_ptr > 0 && !readmem(address_space_ptr,
+                                        KVADDR, swapper_space, SIZE(address_space),
+                                        "swapper_space", RETURN_ON_ERROR))
+                                                break;
+                                }
+
 				swapper_space_nrpages += ULONG(swapper_space + 
 					OFFSET(address_space_nrpages));
 			}
-- 
2.43.0

--
Crash-utility mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxxxxxx
https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/
Contribution Guidelines: https://github.com/crash-utility/crash/wiki

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux