linux debugfs 使用

四 23 五月 2024 | tags: Linux

内核配置

确保内核配置选项中启用了debugfs支持(CONFIG_DEBUG_FS=y)并重新编译内核

挂载debugfs文件系统

mount -t debugfs none /sys/kernel/debug

kernel_page_tables

确保内核配置选项中启用了如下配置:

CONFIG_GENERIC_PTDUMP=y
CONFIG_PTDUMP_CORE=y
CONFIG_PTDUMP_DEBUGFS=y

对应的代码文件 arch/arm64/mm/ptdump.c,命令:

#cat /sys/kernel/debug/kernel_page_tables
---[ Linear Mapping start ]---
0xffff000000000000-0xffff6e0000000000         110T PGD
0xffff6e0000000000-0xffff6e77c0000000         479G PUD
0xffff6e77c0000000-0xffff6e77c0210000        2112K PTE       RW NX SHD AF            UXN    MEM/NORMAL-TAGGED
//...
0xffff6e8130000000-0xffff6e8140000000         256M PMD
0xffff6e8140000000-0xffff6f0000000000         507G PUD
0xffff6f0000000000-0xffff800000000000          17T PGD
---[ Linear Mapping end ]---
---[ Modules start ]---
0xffff800000000000-0xffff800008000000         128M PMD
---[ Modules end ]---
---[ vmalloc() area ]---
0xffff800008000000-0xffff800008004000          16K PTE       RW NX SHD AF            UXN    MEM/NORMAL-TAGGED
0xffff800008004000-0xffff800008005000           4K PTE
//...
0xfffffbffeffc4000-0xfffffbffeffd0000          48K PTE       RW NX SHD AF            UXN    MEM/NORMAL
0xfffffbffeffd0000-0xfffffbffeffe2000          72K PTE
0xfffffbffeffe2000-0xfffffbffeffee000          48K PTE       RW NX SHD AF            UXN    MEM/NORMAL
0xfffffbffeffee000-0xfffffbfff0000000          72K PTE
---[ vmalloc() end ]---
0xfffffbfff0000000-0xfffffbfffda00000         218M PMD
0xfffffbfffda00000-0xfffffbfffdbf9000        2020K PTE
---[ Fixmap start ]---
0xfffffbfffdbf9000-0xfffffbfffdbfa000           4K PTE
0xfffffbfffdbfa000-0xfffffbfffdbfd000          12K PTE       ro x  SHD AF            UXN    MEM/NORMAL
0xfffffbfffdbfd000-0xfffffbfffdbfe000           4K PTE       ro NX SHD AF            UXN    MEM/NORMAL
0xfffffbfffdbfe000-0xfffffbfffdbff000           4K PTE
0xfffffbfffdbff000-0xfffffbfffdc00000           4K PTE       RW NX SHD AF            UXN    DEVICE/nGnRE
0xfffffbfffdc00000-0xfffffbfffde00000           2M PMD       ro NX SHD AF        BLK UXN    MEM/NORMAL
0xfffffbfffde00000-0xfffffbfffe000000           2M PMD
---[ Fixmap end ]---
0xfffffbfffe000000-0xfffffbfffe800000           8M PMD
---[ PCI I/O start ]---
0xfffffbfffe800000-0xfffffbffff800000          16M PMD
---[ PCI I/O end ]---
0xfffffbffff800000-0xfffffc0000000000           8M PMD
---[ vmemmap start ]---
0xfffffc0000000000-0xfffffd8000000000        1536G PGD
0xfffffd8000000000-0xfffffdb9c0000000         231G PUD
0xfffffdb9c0000000-0xfffffdb9df000000         496M PMD
0xfffffdb9df000000-0xfffffdb9e1000000          32M PMD       RW NX SHD AF        BLK UXN    MEM/NORMAL
0xfffffdb9e1000000-0xfffffdb9ff000000         480M PMD
0xfffffdb9ff000000-0xfffffdba04c00000          92M PMD       RW NX SHD AF        BLK UXN    MEM/NORMAL
0xfffffdba04c00000-0xfffffdba40000000         948M PMD
0xfffffdba40000000-0xfffffe0000000000         279G PUD
---[ vmemmap end ]---
0xfffffe0000000000-0x0000000000000000           2T PGD

memblock

对应的代码文件 mm/memblock.c, 开启CONFIG_DEBUG_FS 就会有命令:

# cat /sys/kernel/debug/memblock/memory
   0: 0x0000000080000000..0x00000000f89fffff
   1: 0x00000000f8a00000..0x00000000f8dfffff
   2: 0x00000000f8e00000..0x00000000f8ffffff
   3: 0x0000000880000000..0x00000009efffffff
# cat /sys/kernel/debug/memblock/reserved
   0: 0x0000000080210000..0x000000008239efff
   1: 0x00000000823a4000..0x00000000823affff
   2: 0x0000000087fffa00..0x0000000087ffffcf
   3: 0x00000000efb83000..0x00000000efb8607f
   4: 0x00000000f4a00000..0x00000000f89fffff
   5: 0x00000000f8e00000..0x00000000f8ffffff
   6: 0x00000009dba00000..0x00000009e41fffff
   7: 0x00000009e4230000..0x00000009e6ffffff
   8: 0x00000009e7015500..0x00000009e7015a07
   9: 0x00000009e7015a40..0x00000009e7015fc7
  10: 0x00000009e7017f80..0x00000009e701b08f
  11: 0x00000009e701b0c0..0x00000009e701b11f
  12: 0x00000009e701b140..0x00000009e701b34f
  13: 0x00000009e701b380..0x00000009e701b49f
  14: 0x00000009e701b4c0..0x00000009e701b51f
  15: 0x00000009e701b540..0x00000009e701b547
  16: 0x00000009e701b580..0x00000009e701b771
  17: 0x00000009e701b780..0x00000009e701b971
  18: 0x00000009e701b980..0x00000009e701db07
  19: 0x00000009e701db28..0x00000009e701db56
  20: 0x00000009e701db58..0x00000009e702fffb
  21: 0x00000009e7030000..0x00000009efffffff

Comments !