page_owner.rst 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .. _page_owner:
  2. ==================================================
  3. page owner: Tracking about who allocated each page
  4. ==================================================
  5. Introduction
  6. ============
  7. page owner is for the tracking about who allocated each page.
  8. It can be used to debug memory leak or to find a memory hogger.
  9. When allocation happens, information about allocation such as call stack
  10. and order of pages is stored into certain storage for each page.
  11. When we need to know about status of all pages, we can get and analyze
  12. this information.
  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 behaviour with more
  18. possibility rather than just keeping it in memory, so bad for debugging.
  19. page owner can also be used for various purposes. For example, accurate
  20. fragmentation statistics can be obtained through gfp flag information of
  21. each page. It is already implemented and activated if page owner is
  22. enabled. Other usages are more than welcome.
  23. page owner is disabled in default. So, if you'd like to use it, you need
  24. to add "page_owner=on" into your boot cmdline. If the kernel is built
  25. with page owner and page owner is disabled in runtime due to no enabling
  26. boot option, runtime overhead is marginal. If disabled in runtime, it
  27. doesn't require memory to store owner information, so there is no runtime
  28. memory overhead. And, page owner inserts just two unlikely branches into
  29. the page allocator hotpath and if not enabled, then allocation is done
  30. like as the kernel without page owner. These two unlikely branches should
  31. not affect to allocation performance, especially if the static keys jump
  32. label patching functionality is available. Following is the kernel's code
  33. size change due to this facility.
  34. - Without page owner::
  35. text data bss dec hex filename
  36. 48392 2333 644 51369 c8a9 mm/page_alloc.o
  37. - With page owner::
  38. text data bss dec hex filename
  39. 48800 2445 644 51889 cab1 mm/page_alloc.o
  40. 6662 108 29 6799 1a8f mm/page_owner.o
  41. 1025 8 8 1041 411 mm/page_ext.o
  42. Although, roughly, 8 KB code is added in total, page_alloc.o increase by
  43. 520 bytes and less than half of it is in hotpath. Building the kernel with
  44. page owner and turning it on if needed would be great option to debug
  45. kernel memory problem.
  46. There is one notice that is caused by implementation detail. page owner
  47. stores information into the memory from struct page extension. This memory
  48. is initialized some time later than that page allocator starts in sparse
  49. memory system, so, until initialization, many pages can be allocated and
  50. they would have no owner information. To fix it up, these early allocated
  51. pages are investigated and marked as allocated in initialization phase.
  52. Although it doesn't mean that they have the right owner information,
  53. at least, we can tell whether the page is allocated or not,
  54. more accurately. On 2GB memory x86-64 VM box, 13343 early allocated pages
  55. are catched and marked, although they are mostly allocated from struct
  56. page extension feature. Anyway, after that, no page is left in
  57. un-tracking state.
  58. Usage
  59. =====
  60. 1) Build user-space helper::
  61. cd tools/vm
  62. make page_owner_sort
  63. 2) Enable page owner: add "page_owner=on" to boot cmdline.
  64. 3) Do the job what you want to debug
  65. 4) Analyze information from page owner::
  66. cat /sys/kernel/debug/page_owner > page_owner_full.txt
  67. ./page_owner_sort page_owner_full.txt sorted_page_owner.txt
  68. See the result about who allocated each page
  69. in the ``sorted_page_owner.txt``.