xref: /linux/include/trace/events/kmem.h (revision be709d48329a500621d2a05835283150ae137b45)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM kmem
4 
5 #if !defined(_TRACE_KMEM_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_KMEM_H
7 
8 #include <linux/types.h>
9 #include <linux/tracepoint.h>
10 #include <trace/events/mmflags.h>
11 
12 DECLARE_EVENT_CLASS(kmem_alloc,
13 
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 
38 	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s",
39 		__entry->call_site,
40 		__entry->ptr,
41 		__entry->bytes_req,
42 		__entry->bytes_alloc,
43 		show_gfp_flags(__entry->gfp_flags))
44 );
45 
46 DEFINE_EVENT(kmem_alloc, kmalloc,
47 
48 	TP_PROTO(unsigned long call_site, const void *ptr,
49 		 size_t bytes_req, size_t bytes_alloc, gfp_t gfp_flags),
50 
51 	TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags)
52 );
53 
54 DEFINE_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 
62 DECLARE_EVENT_CLASS(kmem_alloc_node,
63 
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 
91 	TP_printk("call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s node=%d",
92 		__entry->call_site,
93 		__entry->ptr,
94 		__entry->bytes_req,
95 		__entry->bytes_alloc,
96 		show_gfp_flags(__entry->gfp_flags),
97 		__entry->node)
98 );
99 
100 DEFINE_EVENT(kmem_alloc_node, kmalloc_node,
101 
102 	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),
105 
106 	TP_ARGS(call_site, ptr, bytes_req, bytes_alloc, gfp_flags, node)
107 );
108 
109 DEFINE_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 
118 DECLARE_EVENT_CLASS(kmem_free,
119 
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 
134 	TP_printk("call_site=%lx ptr=%p", __entry->call_site, __entry->ptr)
135 );
136 
137 DEFINE_EVENT(kmem_free, kfree,
138 
139 	TP_PROTO(unsigned long call_site, const void *ptr),
140 
141 	TP_ARGS(call_site, ptr)
142 );
143 
144 DEFINE_EVENT(kmem_free, kmem_cache_free,
145 
146 	TP_PROTO(unsigned long call_site, const void *ptr),
147 
148 	TP_ARGS(call_site, ptr)
149 );
150 
151 TRACE_EVENT(mm_page_free,
152 
153 	TP_PROTO(struct page *page, unsigned int order),
154 
155 	TP_ARGS(page, order),
156 
157 	TP_STRUCT__entry(
158 		__field(	unsigned long,	pfn		)
159 		__field(	unsigned int,	order		)
160 	),
161 
162 	TP_fast_assign(
163 		__entry->pfn		= page_to_pfn(page);
164 		__entry->order		= order;
165 	),
166 
167 	TP_printk("page=%p pfn=%lu order=%d",
168 			pfn_to_page(__entry->pfn),
169 			__entry->pfn,
170 			__entry->order)
171 );
172 
173 TRACE_EVENT(mm_page_free_batched,
174 
175 	TP_PROTO(struct page *page),
176 
177 	TP_ARGS(page),
178 
179 	TP_STRUCT__entry(
180 		__field(	unsigned long,	pfn		)
181 	),
182 
183 	TP_fast_assign(
184 		__entry->pfn		= page_to_pfn(page);
185 	),
186 
187 	TP_printk("page=%p pfn=%lu order=0",
188 			pfn_to_page(__entry->pfn),
189 			__entry->pfn)
190 );
191 
192 TRACE_EVENT(mm_page_alloc,
193 
194 	TP_PROTO(struct page *page, unsigned int order,
195 			gfp_t gfp_flags, int migratetype),
196 
197 	TP_ARGS(page, order, gfp_flags, migratetype),
198 
199 	TP_STRUCT__entry(
200 		__field(	unsigned long,	pfn		)
201 		__field(	unsigned int,	order		)
202 		__field(	gfp_t,		gfp_flags	)
203 		__field(	int,		migratetype	)
204 	),
205 
206 	TP_fast_assign(
207 		__entry->pfn		= page ? page_to_pfn(page) : -1UL;
208 		__entry->order		= order;
209 		__entry->gfp_flags	= gfp_flags;
210 		__entry->migratetype	= migratetype;
211 	),
212 
213 	TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s",
214 		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
215 		__entry->pfn != -1UL ? __entry->pfn : 0,
216 		__entry->order,
217 		__entry->migratetype,
218 		show_gfp_flags(__entry->gfp_flags))
219 );
220 
221 DECLARE_EVENT_CLASS(mm_page,
222 
223 	TP_PROTO(struct page *page, unsigned int order, int migratetype),
224 
225 	TP_ARGS(page, order, migratetype),
226 
227 	TP_STRUCT__entry(
228 		__field(	unsigned long,	pfn		)
229 		__field(	unsigned int,	order		)
230 		__field(	int,		migratetype	)
231 	),
232 
233 	TP_fast_assign(
234 		__entry->pfn		= page ? page_to_pfn(page) : -1UL;
235 		__entry->order		= order;
236 		__entry->migratetype	= migratetype;
237 	),
238 
239 	TP_printk("page=%p pfn=%lu order=%u migratetype=%d percpu_refill=%d",
240 		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
241 		__entry->pfn != -1UL ? __entry->pfn : 0,
242 		__entry->order,
243 		__entry->migratetype,
244 		__entry->order == 0)
245 );
246 
247 DEFINE_EVENT(mm_page, mm_page_alloc_zone_locked,
248 
249 	TP_PROTO(struct page *page, unsigned int order, int migratetype),
250 
251 	TP_ARGS(page, order, migratetype)
252 );
253 
254 TRACE_EVENT(mm_page_pcpu_drain,
255 
256 	TP_PROTO(struct page *page, unsigned int order, int migratetype),
257 
258 	TP_ARGS(page, order, migratetype),
259 
260 	TP_STRUCT__entry(
261 		__field(	unsigned long,	pfn		)
262 		__field(	unsigned int,	order		)
263 		__field(	int,		migratetype	)
264 	),
265 
266 	TP_fast_assign(
267 		__entry->pfn		= page ? page_to_pfn(page) : -1UL;
268 		__entry->order		= order;
269 		__entry->migratetype	= migratetype;
270 	),
271 
272 	TP_printk("page=%p pfn=%lu order=%d migratetype=%d",
273 		pfn_to_page(__entry->pfn), __entry->pfn,
274 		__entry->order, __entry->migratetype)
275 );
276 
277 TRACE_EVENT(mm_page_alloc_extfrag,
278 
279 	TP_PROTO(struct page *page,
280 		int alloc_order, int fallback_order,
281 		int alloc_migratetype, int fallback_migratetype),
282 
283 	TP_ARGS(page,
284 		alloc_order, fallback_order,
285 		alloc_migratetype, fallback_migratetype),
286 
287 	TP_STRUCT__entry(
288 		__field(	unsigned long,	pfn			)
289 		__field(	int,		alloc_order		)
290 		__field(	int,		fallback_order		)
291 		__field(	int,		alloc_migratetype	)
292 		__field(	int,		fallback_migratetype	)
293 		__field(	int,		change_ownership	)
294 	),
295 
296 	TP_fast_assign(
297 		__entry->pfn			= page_to_pfn(page);
298 		__entry->alloc_order		= alloc_order;
299 		__entry->fallback_order		= fallback_order;
300 		__entry->alloc_migratetype	= alloc_migratetype;
301 		__entry->fallback_migratetype	= fallback_migratetype;
302 		__entry->change_ownership	= (alloc_migratetype ==
303 					get_pageblock_migratetype(page));
304 	),
305 
306 	TP_printk("page=%p pfn=%lu alloc_order=%d fallback_order=%d pageblock_order=%d alloc_migratetype=%d fallback_migratetype=%d fragmenting=%d change_ownership=%d",
307 		pfn_to_page(__entry->pfn),
308 		__entry->pfn,
309 		__entry->alloc_order,
310 		__entry->fallback_order,
311 		pageblock_order,
312 		__entry->alloc_migratetype,
313 		__entry->fallback_migratetype,
314 		__entry->fallback_order < pageblock_order,
315 		__entry->change_ownership)
316 );
317 
318 #endif /* _TRACE_KMEM_H */
319 
320 /* This part must be outside protection */
321 #include <trace/define_trace.h>
322