Blame view

Documentation/vm/page_owner.rst 3.74 KB
f227e04e9   Mike Rapoport   docs/vm: page_own...
1
2
3
  .. _page_owner:
  
  ==================================================
16a7ade8a   Joonsoo Kim   Documentation: ad...
4
  page owner: Tracking about who allocated each page
f227e04e9   Mike Rapoport   docs/vm: page_own...
5
  ==================================================
16a7ade8a   Joonsoo Kim   Documentation: ad...
6

f227e04e9   Mike Rapoport   docs/vm: page_own...
7
8
  Introduction
  ============
16a7ade8a   Joonsoo Kim   Documentation: ad...
9
10
11
12
13
14
15
16
17
18
19
20
  
  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 stack
  and 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 analyze
  this information.
  
  Although we already have tracepoint for tracing page allocation/free,
  using it for analyzing who allocate each page is rather complex. We need
  to enlarge the trace buffer for preventing overlapping until userspace
  program launched. And, launched program continually dump out the trace
94ebdd28f   Colin Ian King   docs/vm: trivial ...
21
  buffer for later analysis and it would change system behaviour with more
16a7ade8a   Joonsoo Kim   Documentation: ad...
22
23
24
25
26
27
28
29
30
31
32
33
34
  possibility rather than just keeping it in memory, so bad for debugging.
  
  page owner can also be used for various purposes. For example, accurate
  fragmentation statistics can be obtained through gfp flag information of
  each page. It is already implemented and activated if page owner is
  enabled. Other usages are more than welcome.
  
  page owner is disabled in default. So, if you'd like to use it, you need
  to add "page_owner=on" into your boot cmdline. If the kernel is built
  with page owner and page owner is disabled in runtime due to no enabling
  boot option, runtime overhead is marginal. If disabled in runtime, it
  doesn't require memory to store owner information, so there is no runtime
  memory overhead. And, page owner inserts just two unlikely branches into
7dd80b8af   Vlastimil Babka   mm, page_owner: c...
35
36
37
38
39
  the page allocator hotpath and if not enabled, then allocation is done
  like as the kernel without page owner. These two unlikely branches should
  not affect to allocation performance, especially if the static keys jump
  label patching functionality is available. Following is the kernel's code
  size change due to this facility.
16a7ade8a   Joonsoo Kim   Documentation: ad...
40

f227e04e9   Mike Rapoport   docs/vm: page_own...
41
  - Without page owner::
16a7ade8a   Joonsoo Kim   Documentation: ad...
42
     text    data     bss     dec     hex filename
fd0328e37   Liam Mark   UPSTREAM: mm/page...
43
     48392   2333     644   51369    c8a9 mm/page_alloc.o
f227e04e9   Mike Rapoport   docs/vm: page_own...
44
45
  
  - With page owner::
16a7ade8a   Joonsoo Kim   Documentation: ad...
46

16a7ade8a   Joonsoo Kim   Documentation: ad...
47
     text    data     bss     dec     hex filename
fd0328e37   Liam Mark   UPSTREAM: mm/page...
48
49
50
     48800   2445     644   51889    cab1 mm/page_alloc.o
     6574     108      29    6711    1a37 mm/page_owner.o
     1025       8       8    1041     411 mm/page_ext.o
16a7ade8a   Joonsoo Kim   Documentation: ad...
51

fd0328e37   Liam Mark   UPSTREAM: mm/page...
52
53
  Although, roughly, 8 KB code is added in total, page_alloc.o increase by
  520 bytes and less than half of it is in hotpath. Building the kernel with
16a7ade8a   Joonsoo Kim   Documentation: ad...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  page owner and turning it on if needed would be great option to debug
  kernel memory problem.
  
  There is one notice that is caused by implementation detail. page owner
  stores information into the memory from struct page extension. This memory
  is initialized some time later than that page allocator starts in sparse
  memory system, so, until initialization, many pages can be allocated and
  they would have no owner information. To fix it up, these early allocated
  pages 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 pages
  are catched and marked, although they are mostly allocated from struct
  page extension feature. Anyway, after that, no page is left in
  un-tracking state.
f227e04e9   Mike Rapoport   docs/vm: page_own...
69
70
71
72
  Usage
  =====
  
  1) Build user-space helper::
16a7ade8a   Joonsoo Kim   Documentation: ad...
73

16a7ade8a   Joonsoo Kim   Documentation: ad...
74
75
  	cd tools/vm
  	make page_owner_sort
f227e04e9   Mike Rapoport   docs/vm: page_own...
76
  2) Enable page owner: add "page_owner=on" to boot cmdline.
16a7ade8a   Joonsoo Kim   Documentation: ad...
77
78
  
  3) Do the job what you want to debug
f227e04e9   Mike Rapoport   docs/vm: page_own...
79
  4) Analyze information from page owner::
16a7ade8a   Joonsoo Kim   Documentation: ad...
80
  	cat /sys/kernel/debug/page_owner > page_owner_full.txt
5b94ce2fc   Changhee Han   tools/vm/page_own...
81
  	./page_owner_sort page_owner_full.txt sorted_page_owner.txt
16a7ade8a   Joonsoo Kim   Documentation: ad...
82

f227e04e9   Mike Rapoport   docs/vm: page_own...
83
84
     See the result about who allocated each page
     in the ``sorted_page_owner.txt``.