内核开启page owner debug宏:
CONFIG_PAGE_OWNER=y
CONFIG_PAGE_OWNER_SLIM=y
dts配置page_owner=on或者部分可通过fastboot oem append-cmdline page_owner=on来打开。
page owner信息可通过下面方法来查看:
cat /sys/kernel/debug/page_owner
它可以用来调试内存泄漏或查找内存占用,跟踪每个页面的分配者,将堆栈和页面顺序存储在每个页面的特定存储中。
log如下:
Page allocated via order 1, mask 0x15240(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC)
PFN 474986 type Unmovable Block 463 type Unmovable Flags 0x10200(slab|head)
get_page_from_freelist+0xef8/0x1034
__alloc_pages_nodemask+0x13c/0xce0
new_slab+0x100/0x4b0
___slab_alloc.constprop.27+0x264/0x358
__slab_alloc.isra.21.constprop.26+0x5c/0x90
kmem_cache_alloc+0xdc/0x2b4
selinux_inode_alloc_security+0x3c/0x88
security_inode_alloc+0x44/0x50
inode_init_always+0xa4/0x17c
alloc_inode+0x40/0x9c
new_inode_pseudo+0x20/0x5c
new_inode+0x28/0x44
proc_pid_make_inode+0x2c/0xc0
proc_fd_instantiate+0x34/0xa8
proc_fill_cache+0xb0/0x168
proc_readfd_common+0x1f0/0x238
通过调用次数来帮助对内存泄漏问题的分析,其他参数需要待研究。