内存调试:如何在Linux中的用户空间/内核空间中获取锁定的页面信息

时间:2019-03-04 13:27:42

标签: memory-management memory-leaks linux-kernel embedded-linux

有什么方法可以在Linux的用户空间/内核空间中获取锁定页面(虚拟内存页面)信息。

我想知道以下细节: 谁锁定了页面? 多少页被锁定? 锁定页面的进程名称?

也请让我知道内核空间以及用户空间中的内存调试技术。

1 个答案:

答案 0 :(得分:1)

For each page in memory the is flag assigned to it, Virtual memory page is locked using mlock, mlockall() etc API, it assigned the VM_LOCKED flag to page.

Two options to know the locked pages detail:

  1. Use cat /sys/kernel/debug/page_owner >> page_owner.txt To enable debug: kernel menuconfig PAGE_OWNER=y add "page_owner=on" to boot cmdline. cat /sys/kernel/debug/page_owner >> page_owner.txt

  2. In linux source code type: /tool/vm/page-types.c, then compile it and iterate through all pid entries in /proc/ and use the following option for application: ./test -p $PID -L >> test_output.txt. It will give you all page details with flags, then you can find locked pages in memory.