blob: ddc8c944f417a6f4a5310c22b6a3e183fe4cd56c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Li Zefand0b6e042009-07-13 10:33:21 +08002#undef TRACE_SYSTEM
3#define TRACE_SYSTEM kmem
4
Steven Rostedtea20d922009-04-10 08:54:16 -04005#if !defined(_TRACE_KMEM_H) || defined(TRACE_HEADER_MULTI_READ)
Zhaolei02af61b2009-04-10 14:26:18 +08006#define _TRACE_KMEM_H
Eduard - Gabriel Munteanub9ce08c2008-08-10 20:14:03 +03007
8#include <linux/types.h>
Zhaoleifc182a42009-04-10 14:27:38 +08009#include <linux/tracepoint.h>
Vlastimil Babka420adbe92016-03-15 14:55:52 -070010#include <trace/events/mmflags.h>
Steven Rostedt62ba1802009-05-15 16:16:30 -040011
Li Zefan53d04222009-11-26 15:04:10 +080012DECLARE_EVENT_CLASS(kmem_alloc,
Steven Rostedtea20d922009-04-10 08:54:16 -040013
14 TP_PROTO(unsigned long call_site,
15 const void *ptr,
16 size_t bytes_req,
17 size_t bytes_alloc,
18 gfp_t gfp_flags),
19
20 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags),
21
22 TP_STRUCT__entry(
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( gfp_t, gfp_flags )
28 ),
29
30 TP_fast_assign(
31 __entry->call_site = call_site;
32 __entry->ptr = ptr;
33 __entry->bytes_req = bytes_req;
34 __entry->bytes_alloc = bytes_alloc;
35 __entry->gfp_flags = gfp_flags;
36 ),
37
Changbin Duf7d63162019-09-14 18:32:15 +080038 TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
39 (void *)__entry->call_site,
Steven Rostedtea20d922009-04-10 08:54:16 -040040 __entry->ptr,
41 __entry->bytes_req,
42 __entry->bytes_alloc,
Steven Rostedt62ba1802009-05-15 16:16:30 -040043 show_gfp_flags(__entry->gfp_flags))
Steven Rostedtea20d922009-04-10 08:54:16 -040044);
45
Li Zefan53d04222009-11-26 15:04:10 +080046DEFINE_EVENT(kmem_alloc, kmalloc,
Steven Rostedtea20d922009-04-10 08:54:16 -040047
Li Zefan53d04222009-11-26 15:04:10 +080048 TP_PROTO(unsigned long call_site, const void *ptr,
49 size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
Steven Rostedtea20d922009-04-10 08:54:16 -040050
Li Zefan53d04222009-11-26 15:04:10 +080051 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags)
Steven Rostedtea20d922009-04-10 08:54:16 -040052);
53
Li Zefan53d04222009-11-26 15:04:10 +080054DEFINE_EVENT(kmem_alloc, kmem_cache_alloc,
55
56 TP_PROTO(unsigned long call_site, const void *ptr,
57 size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
58
59 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags)
60);
61
62DECLARE_EVENT_CLASS(kmem_alloc_node,
Steven Rostedtea20d922009-04-10 08:54:16 -040063
64 TP_PROTO(unsigned long call_site,
65 const void *ptr,
66 size_t bytes_req,
67 size_t bytes_alloc,
68 gfp_t gfp_flags,
69 int node),
70
71 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node),
72
73 TP_STRUCT__entry(
74 __field( unsigned long, call_site )
75 __field( const void *, ptr )
76 __field( size_t, bytes_req )
77 __field( size_t, bytes_alloc )
78 __field( gfp_t, gfp_flags )
79 __field( int, node )
80 ),
81
82 TP_fast_assign(
83 __entry->call_site = call_site;
84 __entry->ptr = ptr;
85 __entry->bytes_req = bytes_req;
86 __entry->bytes_alloc = bytes_alloc;
87 __entry->gfp_flags = gfp_flags;
88 __entry->node = node;
89 ),
90
Junyong Sun7e168b92020-01-30 22:13:48 -080091 TP_printk("call_site=%pS ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
92 (void *)__entry->call_site,
Steven Rostedtea20d922009-04-10 08:54:16 -040093 __entry->ptr,
94 __entry->bytes_req,
95 __entry->bytes_alloc,
Steven Rostedt62ba1802009-05-15 16:16:30 -040096 show_gfp_flags(__entry->gfp_flags),
Steven Rostedtea20d922009-04-10 08:54:16 -040097 __entry->node)
98);
99
Li Zefan53d04222009-11-26 15:04:10 +0800100DEFINE_EVENT(kmem_alloc_node, kmalloc_node,
Steven Rostedtea20d922009-04-10 08:54:16 -0400101
Li Zefan53d04222009-11-26 15:04:10 +0800102 TP_PROTO(unsigned long call_site, const void *ptr,
103 size_t bytes_req, size_t bytes_alloc,
104 gfp_t gfp_flags, int node),
Steven Rostedtea20d922009-04-10 08:54:16 -0400105
Li Zefan53d04222009-11-26 15:04:10 +0800106 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
Steven Rostedtea20d922009-04-10 08:54:16 -0400107);
108
Li Zefan53d04222009-11-26 15:04:10 +0800109DEFINE_EVENT(kmem_alloc_node, kmem_cache_alloc_node,
110
111 TP_PROTO(unsigned long call_site, const void *ptr,
112 size_t bytes_req, size_t bytes_alloc,
113 gfp_t gfp_flags, int node),
114
115 TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
116);
117
Jacob Wen3544de8e2021-02-24 12:00:55 -0800118TRACE_EVENT(kfree,
Steven Rostedtea20d922009-04-10 08:54:16 -0400119
120 TP_PROTO(unsigned long call_site, const void *ptr),
121
122 TP_ARGS(call_site, ptr),
123
124 TP_STRUCT__entry(
125 __field( unsigned long, call_site )
126 __field( const void *, ptr )
127 ),
128
129 TP_fast_assign(
130 __entry->call_site = call_site;
131 __entry->ptr = ptr;
132 ),
133
Changbin Duf7d63162019-09-14 18:32:15 +0800134 TP_printk("call_site=%pS ptr=%p",
135 (void *)__entry->call_site, __entry->ptr)
Steven Rostedtea20d922009-04-10 08:54:16 -0400136);
137
Jacob Wen3544de8e2021-02-24 12:00:55 -0800138TRACE_EVENT(kmem_cache_free,
Steven Rostedtea20d922009-04-10 08:54:16 -0400139
Jacob Wen3544de8e2021-02-24 12:00:55 -0800140 TP_PROTO(unsigned long call_site, const void *ptr, const char *name),
Steven Rostedtea20d922009-04-10 08:54:16 -0400141
Jacob Wen3544de8e2021-02-24 12:00:55 -0800142 TP_ARGS(call_site, ptr, name),
Steven Rostedtea20d922009-04-10 08:54:16 -0400143
Jacob Wen3544de8e2021-02-24 12:00:55 -0800144 TP_STRUCT__entry(
145 __field( unsigned long, call_site )
146 __field( const void *, ptr )
Steven Rostedt (VMware)d8145672021-02-25 12:49:58 -0500147 __string( name, name )
Jacob Wen3544de8e2021-02-24 12:00:55 -0800148 ),
Steven Rostedtea20d922009-04-10 08:54:16 -0400149
Jacob Wen3544de8e2021-02-24 12:00:55 -0800150 TP_fast_assign(
151 __entry->call_site = call_site;
152 __entry->ptr = ptr;
Steven Rostedt (VMware)d8145672021-02-25 12:49:58 -0500153 __assign_str(name, name);
Jacob Wen3544de8e2021-02-24 12:00:55 -0800154 ),
Steven Rostedtea20d922009-04-10 08:54:16 -0400155
Jacob Wen3544de8e2021-02-24 12:00:55 -0800156 TP_printk("call_site=%pS ptr=%p name=%s",
Steven Rostedt (VMware)d8145672021-02-25 12:49:58 -0500157 (void *)__entry->call_site, __entry->ptr, __get_str(name))
Steven Rostedtea20d922009-04-10 08:54:16 -0400158);
Mel Gorman4b4f2782009-09-21 17:02:41 -0700159
Steven Rostedt (Red Hat)633f6f52016-02-19 13:59:54 -0500160TRACE_EVENT(mm_page_free,
Mel Gorman4b4f2782009-09-21 17:02:41 -0700161
162 TP_PROTO(struct page *page, unsigned int order),
163
164 TP_ARGS(page, order),
165
166 TP_STRUCT__entry(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900167 __field( unsigned long, pfn )
Mel Gorman4b4f2782009-09-21 17:02:41 -0700168 __field( unsigned int, order )
169 ),
170
171 TP_fast_assign(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900172 __entry->pfn = page_to_pfn(page);
Mel Gorman4b4f2782009-09-21 17:02:41 -0700173 __entry->order = order;
174 ),
175
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700176 TP_printk("page=%p pfn=0x%lx order=%d",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900177 pfn_to_page(__entry->pfn),
178 __entry->pfn,
Mel Gorman4b4f2782009-09-21 17:02:41 -0700179 __entry->order)
180);
181
Konstantin Khlebnikovb413d482012-01-10 15:07:09 -0800182TRACE_EVENT(mm_page_free_batched,
Mel Gorman4b4f2782009-09-21 17:02:41 -0700183
Mel Gorman2d4894b2017-11-15 17:37:59 -0800184 TP_PROTO(struct page *page),
Mel Gorman4b4f2782009-09-21 17:02:41 -0700185
Mel Gorman2d4894b2017-11-15 17:37:59 -0800186 TP_ARGS(page),
Mel Gorman4b4f2782009-09-21 17:02:41 -0700187
188 TP_STRUCT__entry(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900189 __field( unsigned long, pfn )
Mel Gorman4b4f2782009-09-21 17:02:41 -0700190 ),
191
192 TP_fast_assign(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900193 __entry->pfn = page_to_pfn(page);
Mel Gorman4b4f2782009-09-21 17:02:41 -0700194 ),
195
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700196 TP_printk("page=%p pfn=0x%lx order=0",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900197 pfn_to_page(__entry->pfn),
Mel Gorman2d4894b2017-11-15 17:37:59 -0800198 __entry->pfn)
Mel Gorman4b4f2782009-09-21 17:02:41 -0700199);
200
201TRACE_EVENT(mm_page_alloc,
202
203 TP_PROTO(struct page *page, unsigned int order,
204 gfp_t gfp_flags, int migratetype),
205
206 TP_ARGS(page, order, gfp_flags, migratetype),
207
208 TP_STRUCT__entry(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900209 __field( unsigned long, pfn )
Mel Gorman4b4f2782009-09-21 17:02:41 -0700210 __field( unsigned int, order )
211 __field( gfp_t, gfp_flags )
212 __field( int, migratetype )
213 ),
214
215 TP_fast_assign(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900216 __entry->pfn = page ? page_to_pfn(page) : -1UL;
Mel Gorman4b4f2782009-09-21 17:02:41 -0700217 __entry->order = order;
218 __entry->gfp_flags = gfp_flags;
219 __entry->migratetype = migratetype;
220 ),
221
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700222 TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900223 __entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
224 __entry->pfn != -1UL ? __entry->pfn : 0,
Mel Gorman4b4f2782009-09-21 17:02:41 -0700225 __entry->order,
226 __entry->migratetype,
227 show_gfp_flags(__entry->gfp_flags))
228);
229
Li Zefan53d04222009-11-26 15:04:10 +0800230DECLARE_EVENT_CLASS(mm_page,
Mel Gorman0d3d0622009-09-21 17:02:44 -0700231
232 TP_PROTO(struct page *page, unsigned int order, int migratetype),
233
234 TP_ARGS(page, order, migratetype),
235
236 TP_STRUCT__entry(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900237 __field( unsigned long, pfn )
Mel Gorman0d3d0622009-09-21 17:02:44 -0700238 __field( unsigned int, order )
239 __field( int, migratetype )
240 ),
241
242 TP_fast_assign(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900243 __entry->pfn = page ? page_to_pfn(page) : -1UL;
Mel Gorman0d3d0622009-09-21 17:02:44 -0700244 __entry->order = order;
245 __entry->migratetype = migratetype;
246 ),
247
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700248 TP_printk("page=%p pfn=0x%lx order=%u migratetype=%d percpu_refill=%d",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900249 __entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
250 __entry->pfn != -1UL ? __entry->pfn : 0,
Mel Gorman0d3d0622009-09-21 17:02:44 -0700251 __entry->order,
252 __entry->migratetype,
253 __entry->order == 0)
254);
255
Li Zefan53d04222009-11-26 15:04:10 +0800256DEFINE_EVENT(mm_page, mm_page_alloc_zone_locked,
Mel Gorman0d3d0622009-09-21 17:02:44 -0700257
Li Zefan53d04222009-11-26 15:04:10 +0800258 TP_PROTO(struct page *page, unsigned int order, int migratetype),
259
260 TP_ARGS(page, order, migratetype)
261);
262
Steven Rostedt (Red Hat)633f6f52016-02-19 13:59:54 -0500263TRACE_EVENT(mm_page_pcpu_drain,
Li Zefan53d04222009-11-26 15:04:10 +0800264
265 TP_PROTO(struct page *page, unsigned int order, int migratetype),
Mel Gorman0d3d0622009-09-21 17:02:44 -0700266
267 TP_ARGS(page, order, migratetype),
268
Shreyas B. Prabhu649b8de2015-05-28 15:44:22 -0700269 TP_STRUCT__entry(
270 __field( unsigned long, pfn )
271 __field( unsigned int, order )
272 __field( int, migratetype )
273 ),
274
275 TP_fast_assign(
276 __entry->pfn = page ? page_to_pfn(page) : -1UL;
277 __entry->order = order;
278 __entry->migratetype = migratetype;
279 ),
280
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700281 TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900282 pfn_to_page(__entry->pfn), __entry->pfn,
Li Zefan53d04222009-11-26 15:04:10 +0800283 __entry->order, __entry->migratetype)
Mel Gorman0d3d0622009-09-21 17:02:44 -0700284);
285
Mel Gormane0fff1b2009-09-21 17:02:42 -0700286TRACE_EVENT(mm_page_alloc_extfrag,
287
288 TP_PROTO(struct page *page,
KOSAKI Motohiro52c8f6a2013-11-12 15:08:19 -0800289 int alloc_order, int fallback_order,
Vlastimil Babka99592d52015-02-11 15:28:15 -0800290 int alloc_migratetype, int fallback_migratetype),
Mel Gormane0fff1b2009-09-21 17:02:42 -0700291
292 TP_ARGS(page,
293 alloc_order, fallback_order,
Vlastimil Babka99592d52015-02-11 15:28:15 -0800294 alloc_migratetype, fallback_migratetype),
Mel Gormane0fff1b2009-09-21 17:02:42 -0700295
296 TP_STRUCT__entry(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900297 __field( unsigned long, pfn )
Mel Gormane0fff1b2009-09-21 17:02:42 -0700298 __field( int, alloc_order )
299 __field( int, fallback_order )
300 __field( int, alloc_migratetype )
301 __field( int, fallback_migratetype )
Srivatsa S. Bhatf92310c2013-09-11 14:20:36 -0700302 __field( int, change_ownership )
Mel Gormane0fff1b2009-09-21 17:02:42 -0700303 ),
304
305 TP_fast_assign(
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900306 __entry->pfn = page_to_pfn(page);
Mel Gormane0fff1b2009-09-21 17:02:42 -0700307 __entry->alloc_order = alloc_order;
308 __entry->fallback_order = fallback_order;
309 __entry->alloc_migratetype = alloc_migratetype;
310 __entry->fallback_migratetype = fallback_migratetype;
Vlastimil Babka99592d52015-02-11 15:28:15 -0800311 __entry->change_ownership = (alloc_migratetype ==
312 get_pageblock_migratetype(page));
Mel Gormane0fff1b2009-09-21 17:02:42 -0700313 ),
314
Vincent Whitchurch53d884a2021-06-28 19:40:08 -0700315 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",
Namhyung Kim9fdd8a82015-04-06 14:36:09 +0900316 pfn_to_page(__entry->pfn),
317 __entry->pfn,
Mel Gormane0fff1b2009-09-21 17:02:42 -0700318 __entry->alloc_order,
319 __entry->fallback_order,
320 pageblock_order,
321 __entry->alloc_migratetype,
322 __entry->fallback_migratetype,
323 __entry->fallback_order < pageblock_order,
Srivatsa S. Bhatf92310c2013-09-11 14:20:36 -0700324 __entry->change_ownership)
Mel Gormane0fff1b2009-09-21 17:02:42 -0700325);
326
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800327/*
328 * Required for uniquely and securely identifying mm in rss_stat tracepoint.
329 */
330#ifndef __PTR_TO_HASHVAL
331static unsigned int __maybe_unused mm_ptr_to_hash(const void *ptr)
332{
333 int ret;
334 unsigned long hashval;
335
336 ret = ptr_to_hashval(ptr, &hashval);
337 if (ret)
338 return 0;
339
340 /* The hashed value is only 32-bit */
341 return (unsigned int)hashval;
342}
343#define __PTR_TO_HASHVAL
344#endif
345
Ovidiu Panaitf9001102021-04-29 22:57:26 -0700346#define TRACE_MM_PAGES \
347 EM(MM_FILEPAGES) \
348 EM(MM_ANONPAGES) \
349 EM(MM_SWAPENTS) \
350 EMe(MM_SHMEMPAGES)
351
352#undef EM
353#undef EMe
354
355#define EM(a) TRACE_DEFINE_ENUM(a);
356#define EMe(a) TRACE_DEFINE_ENUM(a);
357
358TRACE_MM_PAGES
359
360#undef EM
361#undef EMe
362
363#define EM(a) { a, #a },
364#define EMe(a) { a, #a }
365
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800366TRACE_EVENT(rss_stat,
367
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800368 TP_PROTO(struct mm_struct *mm,
369 int member,
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800370 long count),
371
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800372 TP_ARGS(mm, member, count),
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800373
374 TP_STRUCT__entry(
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800375 __field(unsigned int, mm_id)
376 __field(unsigned int, curr)
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800377 __field(int, member)
378 __field(long, size)
379 ),
380
381 TP_fast_assign(
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800382 __entry->mm_id = mm_ptr_to_hash(mm);
383 __entry->curr = !!(current->mm == mm);
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800384 __entry->member = member;
385 __entry->size = (count << PAGE_SHIFT);
386 ),
387
Ovidiu Panaitf9001102021-04-29 22:57:26 -0700388 TP_printk("mm_id=%u curr=%d type=%s size=%ldB",
Joel Fernandes (Google)e4dcad22019-11-30 17:50:33 -0800389 __entry->mm_id,
390 __entry->curr,
Ovidiu Panaitf9001102021-04-29 22:57:26 -0700391 __print_symbolic(__entry->member, TRACE_MM_PAGES),
Joel Fernandes (Google)b3d14112019-11-30 17:50:30 -0800392 __entry->size)
393 );
Steven Rostedta8d154b2009-04-10 09:36:00 -0400394#endif /* _TRACE_KMEM_H */
Steven Rostedtea20d922009-04-10 08:54:16 -0400395
Steven Rostedta8d154b2009-04-10 09:36:00 -0400396/* This part must be outside protection */
397#include <trace/define_trace.h>