events-kmem.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ============================
  2. Subsystem Trace Points: kmem
  3. ============================
  4. The kmem tracing system captures events related to object and page allocation
  5. within the kernel. Broadly speaking there are five major subheadings.
  6. - Slab allocation of small objects of unknown type (kmalloc)
  7. - Slab allocation of small objects of known type
  8. - Page allocation
  9. - Per-CPU Allocator Activity
  10. - External Fragmentation
  11. This document describes what each of the tracepoints is and why they
  12. might be useful.
  13. 1. Slab allocation of small objects of unknown type
  14. ===================================================
  15. ::
  16. kmalloc call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s
  17. kmalloc_node call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d
  18. kfree call_site=%lx ptr=%p
  19. Heavy activity for these events may indicate that a specific cache is
  20. justified, particularly if kmalloc slab pages are getting significantly
  21. internal fragmented as a result of the allocation pattern. By correlating
  22. kmalloc with kfree, it may be possible to identify memory leaks and where
  23. the allocation sites were.
  24. 2. Slab allocation of small objects of known type
  25. =================================================
  26. ::
  27. kmem_cache_alloc call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s
  28. kmem_cache_alloc_node call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d
  29. kmem_cache_free call_site=%lx ptr=%p
  30. These events are similar in usage to the kmalloc-related events except that
  31. it is likely easier to pin the event down to a specific cache. At the time
  32. of writing, no information is available on what slab is being allocated from,
  33. but the call_site can usually be used to extrapolate that information.
  34. 3. Page allocation
  35. ==================
  36. ::
  37. mm_page_alloc page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s
  38. mm_page_alloc_zone_locked page=%p pfn=%lu order=%u migratetype=%d cpu=%d percpu_refill=%d
  39. mm_page_free page=%p pfn=%lu order=%d
  40. mm_page_free_batched page=%p pfn=%lu order=%d cold=%d
  41. These four events deal with page allocation and freeing. mm_page_alloc is
  42. a simple indicator of page allocator activity. Pages may be allocated from
  43. the per-CPU allocator (high performance) or the buddy allocator.
  44. If pages are allocated directly from the buddy allocator, the
  45. mm_page_alloc_zone_locked event is triggered. This event is important as high
  46. amounts of activity imply high activity on the zone->lock. Taking this lock
  47. impairs performance by disabling interrupts, dirtying cache lines between
  48. CPUs and serialising many CPUs.
  49. When a page is freed directly by the caller, the only mm_page_free event
  50. is triggered. Significant amounts of activity here could indicate that the
  51. callers should be batching their activities.
  52. When pages are freed in batch, the also mm_page_free_batched is triggered.
  53. Broadly speaking, pages are taken off the LRU lock in bulk and
  54. freed in batch with a page list. Significant amounts of activity here could
  55. indicate that the system is under memory pressure and can also indicate
  56. contention on the zone->lru_lock.
  57. 4. Per-CPU Allocator Activity
  58. =============================
  59. ::
  60. mm_page_alloc_zone_locked page=%p pfn=%lu order=%u migratetype=%d cpu=%d percpu_refill=%d
  61. mm_page_pcpu_drain page=%p pfn=%lu order=%d cpu=%d migratetype=%d
  62. In front of the page allocator is a per-cpu page allocator. It exists only
  63. for order-0 pages, reduces contention on the zone->lock and reduces the
  64. amount of writing on struct page.
  65. When a per-CPU list is empty or pages of the wrong type are allocated,
  66. the zone->lock will be taken once and the per-CPU list refilled. The event
  67. triggered is mm_page_alloc_zone_locked for each page allocated with the
  68. event indicating whether it is for a percpu_refill or not.
  69. When the per-CPU list is too full, a number of pages are freed, each one
  70. which triggers a mm_page_pcpu_drain event.
  71. The individual nature of the events is so that pages can be tracked
  72. between allocation and freeing. A number of drain or refill pages that occur
  73. consecutively imply the zone->lock being taken once. Large amounts of per-CPU
  74. refills and drains could imply an imbalance between CPUs where too much work
  75. is being concentrated in one place. It could also indicate that the per-CPU
  76. lists should be a larger size. Finally, large amounts of refills on one CPU
  77. and drains on another could be a factor in causing large amounts of cache
  78. line bounces due to writes between CPUs and worth investigating if pages
  79. can be allocated and freed on the same CPU through some algorithm change.
  80. 5. External Fragmentation
  81. =========================
  82. ::
  83. mm_page_alloc_extfrag page=%p pfn=%lu alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d
  84. External fragmentation affects whether a high-order allocation will be
  85. successful or not. For some types of hardware, this is important although
  86. it is avoided where possible. If the system is using huge pages and needs
  87. to be able to resize the pool over the lifetime of the system, this value
  88. is important.
  89. Large numbers of this event implies that memory is fragmenting and
  90. high-order allocations will start failing at some time in the future. One
  91. means of reducing the occurrence of this event is to increase the size of
  92. min_free_kbytes in increments of 3*pageblock_size*nr_online_nodes where
  93. pageblock_size is usually the size of the default hugepage size.