1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM kmem
5 #if !defined(_TRACE_KMEM_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/types.h>
9 #include <linux/tracepoint.h>
10 #include <trace/events/mmflags.h>
12 TRACE_EVENT(kmem_cache_alloc
,
14 TP_PROTO(unsigned long call_site
,
20 TP_ARGS(call_site
, ptr
, s
, gfp_flags
, node
),
23 __field( unsigned long, call_site
)
24 __field( const void *, ptr
)
25 __field( size_t, bytes_req
)
26 __field( size_t, bytes_alloc
)
27 __field( unsigned long, gfp_flags
)
29 __field( bool, accounted
)
33 __entry
->call_site
= call_site
;
35 __entry
->bytes_req
= s
->object_size
;
36 __entry
->bytes_alloc
= s
->size
;
37 __entry
->gfp_flags
= (__force
unsigned long)gfp_flags
;
39 __entry
->accounted
= IS_ENABLED(CONFIG_MEMCG
) ?
40 ((gfp_flags
& __GFP_ACCOUNT
) ||
41 (s
->flags
& SLAB_ACCOUNT
)) : false;
44 TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d accounted=%s",
45 (void *)__entry
->call_site
,
49 show_gfp_flags(__entry
->gfp_flags
),
51 __entry
->accounted
? "true" : "false")
56 TP_PROTO(unsigned long call_site
,
63 TP_ARGS(call_site
, ptr
, bytes_req
, bytes_alloc
, gfp_flags
, node
),
66 __field( unsigned long, call_site
)
67 __field( const void *, ptr
)
68 __field( size_t, bytes_req
)
69 __field( size_t, bytes_alloc
)
70 __field( unsigned long, gfp_flags
)
75 __entry
->call_site
= call_site
;
77 __entry
->bytes_req
= bytes_req
;
78 __entry
->bytes_alloc
= bytes_alloc
;
79 __entry
->gfp_flags
= (__force
unsigned long)gfp_flags
;
83 TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d accounted=%s",
84 (void *)__entry
->call_site
,
88 show_gfp_flags(__entry
->gfp_flags
),
90 (IS_ENABLED(CONFIG_MEMCG
) &&
91 (__entry
->gfp_flags
& (__force
unsigned long)__GFP_ACCOUNT
)) ? "true" : "false")
96 TP_PROTO(unsigned long call_site
, const void *ptr
),
98 TP_ARGS(call_site
, ptr
),
101 __field( unsigned long, call_site
)
102 __field( const void *, ptr
)
106 __entry
->call_site
= call_site
;
110 TP_printk("call_site=%pS ptr=%p",
111 (void *)__entry
->call_site
, __entry
->ptr
)
114 TRACE_EVENT(kmem_cache_free
,
116 TP_PROTO(unsigned long call_site
, const void *ptr
, const struct kmem_cache
*s
),
118 TP_ARGS(call_site
, ptr
, s
),
121 __field( unsigned long, call_site
)
122 __field( const void *, ptr
)
123 __string( name
, s
->name
)
127 __entry
->call_site
= call_site
;
132 TP_printk("call_site=%pS ptr=%p name=%s",
133 (void *)__entry
->call_site
, __entry
->ptr
, __get_str(name
))
136 TRACE_EVENT(mm_page_free
,
138 TP_PROTO(struct page
*page
, unsigned int order
),
140 TP_ARGS(page
, order
),
143 __field( unsigned long, pfn
)
144 __field( unsigned int, order
)
148 __entry
->pfn
= page_to_pfn(page
);
149 __entry
->order
= order
;
152 TP_printk("page=%p pfn=0x%lx order=%d",
153 pfn_to_page(__entry
->pfn
),
158 TRACE_EVENT(mm_page_free_batched
,
160 TP_PROTO(struct page
*page
),
165 __field( unsigned long, pfn
)
169 __entry
->pfn
= page_to_pfn(page
);
172 TP_printk("page=%p pfn=0x%lx order=0",
173 pfn_to_page(__entry
->pfn
),
177 TRACE_EVENT(mm_page_alloc
,
179 TP_PROTO(struct page
*page
, unsigned int order
,
180 gfp_t gfp_flags
, int migratetype
),
182 TP_ARGS(page
, order
, gfp_flags
, migratetype
),
185 __field( unsigned long, pfn
)
186 __field( unsigned int, order
)
187 __field( unsigned long, gfp_flags
)
188 __field( int, migratetype
)
192 __entry
->pfn
= page
? page_to_pfn(page
) : -1UL;
193 __entry
->order
= order
;
194 __entry
->gfp_flags
= (__force
unsigned long)gfp_flags
;
195 __entry
->migratetype
= migratetype
;
198 TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s",
199 __entry
->pfn
!= -1UL ? pfn_to_page(__entry
->pfn
) : NULL
,
200 __entry
->pfn
!= -1UL ? __entry
->pfn
: 0,
202 __entry
->migratetype
,
203 show_gfp_flags(__entry
->gfp_flags
))
206 DECLARE_EVENT_CLASS(mm_page
,
208 TP_PROTO(struct page
*page
, unsigned int order
, int migratetype
,
211 TP_ARGS(page
, order
, migratetype
, percpu_refill
),
214 __field( unsigned long, pfn
)
215 __field( unsigned int, order
)
216 __field( int, migratetype
)
217 __field( int, percpu_refill
)
221 __entry
->pfn
= page
? page_to_pfn(page
) : -1UL;
222 __entry
->order
= order
;
223 __entry
->migratetype
= migratetype
;
224 __entry
->percpu_refill
= percpu_refill
;
227 TP_printk("page=%p pfn=0x%lx order=%u migratetype=%d percpu_refill=%d",
228 __entry
->pfn
!= -1UL ? pfn_to_page(__entry
->pfn
) : NULL
,
229 __entry
->pfn
!= -1UL ? __entry
->pfn
: 0,
231 __entry
->migratetype
,
232 __entry
->percpu_refill
)
235 DEFINE_EVENT(mm_page
, mm_page_alloc_zone_locked
,
237 TP_PROTO(struct page
*page
, unsigned int order
, int migratetype
,
240 TP_ARGS(page
, order
, migratetype
, percpu_refill
)
243 TRACE_EVENT(mm_page_pcpu_drain
,
245 TP_PROTO(struct page
*page
, unsigned int order
, int migratetype
),
247 TP_ARGS(page
, order
, migratetype
),
250 __field( unsigned long, pfn
)
251 __field( unsigned int, order
)
252 __field( int, migratetype
)
256 __entry
->pfn
= page
? page_to_pfn(page
) : -1UL;
257 __entry
->order
= order
;
258 __entry
->migratetype
= migratetype
;
261 TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d",
262 pfn_to_page(__entry
->pfn
), __entry
->pfn
,
263 __entry
->order
, __entry
->migratetype
)
266 TRACE_EVENT(mm_page_alloc_extfrag
,
268 TP_PROTO(struct page
*page
,
269 int alloc_order
, int fallback_order
,
270 int alloc_migratetype
, int fallback_migratetype
),
273 alloc_order
, fallback_order
,
274 alloc_migratetype
, fallback_migratetype
),
277 __field( unsigned long, pfn
)
278 __field( int, alloc_order
)
279 __field( int, fallback_order
)
280 __field( int, alloc_migratetype
)
281 __field( int, fallback_migratetype
)
282 __field( int, change_ownership
)
286 __entry
->pfn
= page_to_pfn(page
);
287 __entry
->alloc_order
= alloc_order
;
288 __entry
->fallback_order
= fallback_order
;
289 __entry
->alloc_migratetype
= alloc_migratetype
;
290 __entry
->fallback_migratetype
= fallback_migratetype
;
291 __entry
->change_ownership
= (alloc_migratetype
==
292 get_pageblock_migratetype(page
));
295 TP_printk("page=%p pfn=0x%lx alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d",
296 pfn_to_page(__entry
->pfn
),
298 __entry
->alloc_order
,
299 __entry
->fallback_order
,
301 __entry
->alloc_migratetype
,
302 __entry
->fallback_migratetype
,
303 __entry
->fallback_order
< pageblock_order
,
304 __entry
->change_ownership
)
307 TRACE_EVENT(mm_alloc_contig_migrate_range_info
,
309 TP_PROTO(unsigned long start
,
311 unsigned long nr_migrated
,
312 unsigned long nr_reclaimed
,
313 unsigned long nr_mapped
,
316 TP_ARGS(start
, end
, nr_migrated
, nr_reclaimed
, nr_mapped
, migratetype
),
319 __field(unsigned long, start
)
320 __field(unsigned long, end
)
321 __field(unsigned long, nr_migrated
)
322 __field(unsigned long, nr_reclaimed
)
323 __field(unsigned long, nr_mapped
)
324 __field(int, migratetype
)
328 __entry
->start
= start
;
330 __entry
->nr_migrated
= nr_migrated
;
331 __entry
->nr_reclaimed
= nr_reclaimed
;
332 __entry
->nr_mapped
= nr_mapped
;
333 __entry
->migratetype
= migratetype
;
336 TP_printk("start=0x%lx end=0x%lx migratetype=%d nr_migrated=%lu nr_reclaimed=%lu nr_mapped=%lu",
339 __entry
->migratetype
,
340 __entry
->nr_migrated
,
341 __entry
->nr_reclaimed
,
346 * Required for uniquely and securely identifying mm in rss_stat tracepoint.
348 #ifndef __PTR_TO_HASHVAL
349 static unsigned int __maybe_unused
mm_ptr_to_hash(const void *ptr
)
352 unsigned long hashval
;
354 ret
= ptr_to_hashval(ptr
, &hashval
);
358 /* The hashed value is only 32-bit */
359 return (unsigned int)hashval
;
361 #define __PTR_TO_HASHVAL
364 #define TRACE_MM_PAGES \
373 #define EM(a) TRACE_DEFINE_ENUM(a);
374 #define EMe(a) TRACE_DEFINE_ENUM(a);
381 #define EM(a) { a, #a },
382 #define EMe(a) { a, #a }
384 TRACE_EVENT(rss_stat
,
386 TP_PROTO(struct mm_struct
*mm
,
392 __field(unsigned int, mm_id
)
393 __field(unsigned int, curr
)
399 __entry
->mm_id
= mm_ptr_to_hash(mm
);
400 __entry
->curr
= !!(current
->mm
== mm
);
401 __entry
->member
= member
;
402 __entry
->size
= (percpu_counter_sum_positive(&mm
->rss_stat
[member
])
406 TP_printk("mm_id=%u curr=%d type=%s size=%ldB",
409 __print_symbolic(__entry
->member
, TRACE_MM_PAGES
),
412 #endif /* _TRACE_KMEM_H */
414 /* This part must be outside protection */
415 #include <trace/define_trace.h>