page owner: Tracking about who allocated each page¶
Introduction¶
page owner is for the tracking about who allocated each page.It can be used to debug memory leak or to find a memory hogger.When allocation happens, information about allocation such as call stackand order of pages is stored into certain storage for each page.When we need to know about status of all pages, we can get and analyzethis information.
Although we already have tracepoint for tracing page allocation/free,using it for analyzing who allocate each page is rather complex. We needto enlarge the trace buffer for preventing overlapping until userspaceprogram launched. And, launched program continually dump out the tracebuffer for later analysis and it would change system behviour with morepossibility rather than just keeping it in memory, so bad for debugging.
page owner can also be used for various purposes. For example, accuratefragmentation statistics can be obtained through gfp flag information ofeach page. It is already implemented and activated if page owner isenabled. Other usages are more than welcome.
page owner is disabled in default. So, if you’d like to use it, you needto add “page_owner=on” into your boot cmdline. If the kernel is builtwith page owner and page owner is disabled in runtime due to no enablingboot option, runtime overhead is marginal. If disabled in runtime, itdoesn’t require memory to store owner information, so there is no runtimememory overhead. And, page owner inserts just two unlikely branches intothe page allocator hotpath and if not enabled, then allocation is donelike as the kernel without page owner. These two unlikely branches shouldnot affect to allocation performance, especially if the static keys jumplabel patching functionality is available. Following is the kernel’s codesize change due to this facility.
Without page owner:
text data bss dec hex filename40662 1493 644 42799 a72f mm/page_alloc.o
With page owner:
text data bss dec hex filename40892 1493 644 43029 a815 mm/page_alloc.o1427 24 8 1459 5b3 mm/page_ext.o2722 50 0 2772 ad4 mm/page_owner.o
Although, roughly, 4 KB code is added in total, page_alloc.o increase by230 bytes and only half of it is in hotpath. Building the kernel withpage owner and turning it on if needed would be great option to debugkernel memory problem.
There is one notice that is caused by implementation detail. page ownerstores information into the memory from struct page extension. This memoryis initialized some time later than that page allocator starts in sparsememory system, so, until initialization, many pages can be allocated andthey would have no owner information. To fix it up, these early allocatedpages are investigated and marked as allocated in initialization phase.Although it doesn’t mean that they have the right owner information,at least, we can tell whether the page is allocated or not,more accurately. On 2GB memory x86-64 VM box, 13343 early allocated pagesare catched and marked, although they are mostly allocated from structpage extension feature. Anyway, after that, no page is left inun-tracking state.
Usage¶
Build user-space helper:
cd tools/vmmake page_owner_sort
Enable page owner: add “page_owner=on” to boot cmdline.
Do the job what you want to debug
Analyze information from page owner:
cat /sys/kernel/debug/page_owner > page_owner_full.txt./page_owner_sort page_owner_full.txt sorted_page_owner.txt
See the result about who allocated each pagein the
sorted_page_owner.txt.