Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Documentation: add new page_owner document

page owner is for the tracking about who allocated each page. This
document explains what is the page owner feature and what is the merit of
it. And, simple HOW-TO is also explained. See the document for detailed
information.

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Dave Hansen <dave@sr71.net>
Cc: Michal Nazarewicz <mina86@mina86.com>
Cc: Jungsoo Son <jungsoo.son@lge.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Joonsoo Kim and committed by
Linus Torvalds
16a7ade8 61cf5feb

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