blob: ffff1439076a51af81c83e91602c9bfd08bed308 [file] [log] [blame]
Joonsoo Kim16a7ade2014-12-12 16:56:07 -08001page owner: Tracking about who allocated each page
2-----------------------------------------------------------
3
4* Introduction
5
6page owner is for the tracking about who allocated each page.
7It can be used to debug memory leak or to find a memory hogger.
8When allocation happens, information about allocation such as call stack
9and order of pages is stored into certain storage for each page.
10When we need to know about status of all pages, we can get and analyze
11this information.
12
13Although we already have tracepoint for tracing page allocation/free,
14using it for analyzing who allocate each page is rather complex. We need
15to enlarge the trace buffer for preventing overlapping until userspace
16program launched. And, launched program continually dump out the trace
17buffer for later analysis and it would change system behviour with more
18possibility rather than just keeping it in memory, so bad for debugging.
19
20page owner can also be used for various purposes. For example, accurate
21fragmentation statistics can be obtained through gfp flag information of
22each page. It is already implemented and activated if page owner is
23enabled. Other usages are more than welcome.
24
25page owner is disabled in default. So, if you'd like to use it, you need
26to add "page_owner=on" into your boot cmdline. If the kernel is built
27with page owner and page owner is disabled in runtime due to no enabling
28boot option, runtime overhead is marginal. If disabled in runtime, it
29doesn't require memory to store owner information, so there is no runtime
30memory overhead. And, page owner inserts just two unlikely branches into
Vlastimil Babka7dd80b82016-03-15 14:56:12 -070031the page allocator hotpath and if not enabled, then allocation is done
32like as the kernel without page owner. These two unlikely branches should
33not affect to allocation performance, especially if the static keys jump
34label patching functionality is available. Following is the kernel's code
35size change due to this facility.
Joonsoo Kim16a7ade2014-12-12 16:56:07 -080036
37- Without page owner
38 text data bss dec hex filename
39 40662 1493 644 42799 a72f mm/page_alloc.o
40
41- With page owner
42 text data bss dec hex filename
43 40892 1493 644 43029 a815 mm/page_alloc.o
44 1427 24 8 1459 5b3 mm/page_ext.o
45 2722 50 0 2772 ad4 mm/page_owner.o
46
47Although, roughly, 4 KB code is added in total, page_alloc.o increase by
48230 bytes and only half of it is in hotpath. Building the kernel with
49page owner and turning it on if needed would be great option to debug
50kernel memory problem.
51
52There is one notice that is caused by implementation detail. page owner
53stores information into the memory from struct page extension. This memory
54is initialized some time later than that page allocator starts in sparse
55memory system, so, until initialization, many pages can be allocated and
56they would have no owner information. To fix it up, these early allocated
57pages are investigated and marked as allocated in initialization phase.
58Although it doesn't mean that they have the right owner information,
59at least, we can tell whether the page is allocated or not,
60more accurately. On 2GB memory x86-64 VM box, 13343 early allocated pages
61are catched and marked, although they are mostly allocated from struct
62page extension feature. Anyway, after that, no page is left in
63un-tracking state.
64
65* Usage
66
671) Build user-space helper
68 cd tools/vm
69 make page_owner_sort
70
712) Enable page owner
72 Add "page_owner=on" to boot cmdline.
73
743) Do the job what you want to debug
75
764) Analyze information from page owner
77 cat /sys/kernel/debug/page_owner > page_owner_full.txt
78 grep -v ^PFN page_owner_full.txt > page_owner.txt
79 ./page_owner_sort page_owner.txt sorted_page_owner.txt
80
81 See the result about who allocated each page
82 in the sorted_page_owner.txt.