page_owner.txt 3.7 KB

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