blob: 68fa75247488b1b3a0fa21a9f90b755fcf12069a [file] [log] [blame]
Changbin Du3cdd8682018-02-17 13:39:43 +08001============================
2Subsystem Trace Points: kmem
3============================
Mel Gorman8fbb3982009-09-21 17:02:49 -07004
Randy Dunlap2ec91ee2009-12-21 14:37:23 -08005The kmem tracing system captures events related to object and page allocation
6within the kernel. Broadly speaking there are five major subheadings.
Mel Gorman8fbb3982009-09-21 17:02:49 -07007
Changbin Du3cdd8682018-02-17 13:39:43 +08008 - Slab allocation of small objects of unknown type (kmalloc)
9 - Slab allocation of small objects of known type
10 - Page allocation
11 - Per-CPU Allocator Activity
12 - External Fragmentation
Mel Gorman8fbb3982009-09-21 17:02:49 -070013
Randy Dunlap2ec91ee2009-12-21 14:37:23 -080014This document describes what each of the tracepoints is and why they
Mel Gorman8fbb3982009-09-21 17:02:49 -070015might be useful.
16
171. Slab allocation of small objects of unknown type
18===================================================
Changbin Du3cdd8682018-02-17 13:39:43 +080019::
20
21 kmalloc call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s
22 kmalloc_node call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d
23 kfree call_site=%lx ptr=%p
Mel Gorman8fbb3982009-09-21 17:02:49 -070024
25Heavy activity for these events may indicate that a specific cache is
26justified, particularly if kmalloc slab pages are getting significantly
27internal fragmented as a result of the allocation pattern. By correlating
28kmalloc with kfree, it may be possible to identify memory leaks and where
29the allocation sites were.
30
31
322. Slab allocation of small objects of known type
33=================================================
Changbin Du3cdd8682018-02-17 13:39:43 +080034::
35
36 kmem_cache_alloc call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s
37 kmem_cache_alloc_node call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d
38 kmem_cache_free call_site=%lx ptr=%p
Mel Gorman8fbb3982009-09-21 17:02:49 -070039
40These events are similar in usage to the kmalloc-related events except that
41it is likely easier to pin the event down to a specific cache. At the time
42of writing, no information is available on what slab is being allocated from,
Randy Dunlap2ec91ee2009-12-21 14:37:23 -080043but the call_site can usually be used to extrapolate that information.
Mel Gorman8fbb3982009-09-21 17:02:49 -070044
453. Page allocation
46==================
Changbin Du3cdd8682018-02-17 13:39:43 +080047::
48
49 mm_page_alloc page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s
50 mm_page_alloc_zone_locked page=%p pfn=%lu order=%u migratetype=%d cpu=%d percpu_refill=%d
51 mm_page_free page=%p pfn=%lu order=%d
52 mm_page_free_batched page=%p pfn=%lu order=%d cold=%d
Mel Gorman8fbb3982009-09-21 17:02:49 -070053
54These four events deal with page allocation and freeing. mm_page_alloc is
55a simple indicator of page allocator activity. Pages may be allocated from
56the per-CPU allocator (high performance) or the buddy allocator.
57
58If pages are allocated directly from the buddy allocator, the
59mm_page_alloc_zone_locked event is triggered. This event is important as high
60amounts of activity imply high activity on the zone->lock. Taking this lock
61impairs performance by disabling interrupts, dirtying cache lines between
62CPUs and serialising many CPUs.
63
Konstantin Khlebnikovb413d482012-01-10 15:07:09 -080064When a page is freed directly by the caller, the only mm_page_free event
Mel Gorman8fbb3982009-09-21 17:02:49 -070065is triggered. Significant amounts of activity here could indicate that the
66callers should be batching their activities.
67
Konstantin Khlebnikovb413d482012-01-10 15:07:09 -080068When pages are freed in batch, the also mm_page_free_batched is triggered.
69Broadly speaking, pages are taken off the LRU lock in bulk and
70freed in batch with a page list. Significant amounts of activity here could
Mel Gorman8fbb3982009-09-21 17:02:49 -070071indicate that the system is under memory pressure and can also indicate
Hugh Dickins15b44732020-12-15 14:21:31 -080072contention on the lruvec->lru_lock.
Mel Gorman8fbb3982009-09-21 17:02:49 -070073
744. Per-CPU Allocator Activity
75=============================
Changbin Du3cdd8682018-02-17 13:39:43 +080076::
77
78 mm_page_alloc_zone_locked page=%p pfn=%lu order=%u migratetype=%d cpu=%d percpu_refill=%d
79 mm_page_pcpu_drain page=%p pfn=%lu order=%d cpu=%d migratetype=%d
Mel Gorman8fbb3982009-09-21 17:02:49 -070080
81In front of the page allocator is a per-cpu page allocator. It exists only
82for order-0 pages, reduces contention on the zone->lock and reduces the
83amount of writing on struct page.
84
85When a per-CPU list is empty or pages of the wrong type are allocated,
86the zone->lock will be taken once and the per-CPU list refilled. The event
87triggered is mm_page_alloc_zone_locked for each page allocated with the
88event indicating whether it is for a percpu_refill or not.
89
90When the per-CPU list is too full, a number of pages are freed, each one
91which triggers a mm_page_pcpu_drain event.
92
Randy Dunlap2ec91ee2009-12-21 14:37:23 -080093The individual nature of the events is so that pages can be tracked
Mel Gorman8fbb3982009-09-21 17:02:49 -070094between allocation and freeing. A number of drain or refill pages that occur
Randy Dunlap2ec91ee2009-12-21 14:37:23 -080095consecutively imply the zone->lock being taken once. Large amounts of per-CPU
Mel Gorman8fbb3982009-09-21 17:02:49 -070096refills and drains could imply an imbalance between CPUs where too much work
97is being concentrated in one place. It could also indicate that the per-CPU
98lists should be a larger size. Finally, large amounts of refills on one CPU
99and drains on another could be a factor in causing large amounts of cache
100line bounces due to writes between CPUs and worth investigating if pages
101can be allocated and freed on the same CPU through some algorithm change.
102
1035. External Fragmentation
104=========================
Changbin Du3cdd8682018-02-17 13:39:43 +0800105::
106
107 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
Mel Gorman8fbb3982009-09-21 17:02:49 -0700108
109External fragmentation affects whether a high-order allocation will be
110successful or not. For some types of hardware, this is important although
111it is avoided where possible. If the system is using huge pages and needs
112to be able to resize the pool over the lifetime of the system, this value
113is important.
114
115Large numbers of this event implies that memory is fragmenting and
116high-order allocations will start failing at some time in the future. One
Randy Dunlap2ec91ee2009-12-21 14:37:23 -0800117means of reducing the occurrence of this event is to increase the size of
Mel Gorman8fbb3982009-09-21 17:02:49 -0700118min_free_kbytes in increments of 3*pageblock_size*nr_online_nodes where
119pageblock_size is usually the size of the default hugepage size.