Hi kazu:


1. I found that vmlinux of kernel-6.1 did not have symbol nr_swapper_spaces but only have swapper_spaces

Also check in GKI vmlinux, can not find nr_swapper_spaces

It may have some problem in symbol of nr_swapper_spaces


2. I think that crash tools will check nr_swapper_spaces first and then check *swapper_spaces, swaper_space[] last.

so first check nr_swapper_spaces not found, crash tool can use *swapper_spaces to enhance compatibility.

The patch i send can resolve this situation which nr_swapper_spaces symbols can not found.


Thanks!

Best Regards


From: HAGIO KAZUHITO(萩尾 一仁) <k-hagio-ab@nec.com>
Sent: Thursday, November 30, 2023 4:24:06 PM
To: 薛国伦; devel@lists.crash-utility.osci.io
Cc: Lianbo Jiang
Subject: [External Mail]Re: [Crash-utility] [BUG FIXED]fix bug of CACHED in kmem -i show memory
 
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给misec@xiaomi.com进行反馈

On 2023/11/29 22:17, 薛国伦 wrote:
> 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

Hmm, it looks like this issue was already fixed by [1].

[1]
https://github.com/crash-utility/crash/commit/333df037bc72aa81faf0904aaea29d43be2c724d

"nr_swapper_spaces" is not present in your kernel?

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4b3ef9daa4fc0bba742a79faecb17fdaaead083b
+struct address_space *swapper_spaces[MAX_SWAPFILES];
+static unsigned int nr_swapper_spaces[MAX_SWAPFILES];

These were introduced together..

Thanks,
Kazu

>
> 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!******/#