xref: /linux/include/trace/events/ksm.h (revision 45d8b572fac3aa8b49d53c946b3685eaf78a2824)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM ksm
4 
5 #if !defined(_TRACE_KSM_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_KSM_H
7 
8 #include <linux/tracepoint.h>
9 
10 /**
11  * ksm_scan_template - called for start / stop scan
12  *
13  * @seq:		sequence number of scan
14  * @rmap_entries:	actual number of rmap entries
15  *
16  * Allows to trace the start / stop of a ksm scan.
17  */
18 DECLARE_EVENT_CLASS(ksm_scan_template,
19 
20 	TP_PROTO(int seq, u32 rmap_entries),
21 
22 	TP_ARGS(seq, rmap_entries),
23 
24 	TP_STRUCT__entry(
25 		__field(int,	seq)
26 		__field(u32,	rmap_entries)
27 	),
28 
29 	TP_fast_assign(
30 		__entry->seq		= seq;
31 		__entry->rmap_entries	= rmap_entries;
32 	),
33 
34 	TP_printk("seq %d rmap size %d",
35 			__entry->seq, __entry->rmap_entries)
36 );
37 
38 /**
39  * ksm_start_scan - called after a new ksm scan is started
40  *
41  * @seq:		sequence number of scan
42  * @rmap_entries:	actual number of rmap entries
43  *
44  * Allows to trace the start of a ksm scan.
45  */
46 DEFINE_EVENT(ksm_scan_template, ksm_start_scan,
47 
48 	TP_PROTO(int seq, u32 rmap_entries),
49 
50 	TP_ARGS(seq, rmap_entries)
51 );
52 
53 /**
54  * ksm_stop_scan - called after a new ksm scan has completed
55  *
56  * @seq:		sequence number of scan
57  * @rmap_entries:	actual number of rmap entries
58  *
59  * Allows to trace the completion of a ksm scan.
60  */
61 DEFINE_EVENT(ksm_scan_template, ksm_stop_scan,
62 
63 	TP_PROTO(int seq, u32 rmap_entries),
64 
65 	TP_ARGS(seq, rmap_entries)
66 );
67 
68 /**
69  * ksm_enter - called after a new process has been added / removed from ksm
70  *
71  * @mm:			address of the mm object of the process
72  *
73  * Allows to trace the when a process has been added or removed from ksm.
74  */
75 DECLARE_EVENT_CLASS(ksm_enter_exit_template,
76 
77 	TP_PROTO(void *mm),
78 
79 	TP_ARGS(mm),
80 
81 	TP_STRUCT__entry(
82 		__field(void *,		mm)
83 	),
84 
85 	TP_fast_assign(
86 		__entry->mm	= mm;
87 	),
88 
89 	TP_printk("mm %p", __entry->mm)
90 );
91 
92 /**
93  * ksm_enter - called after a new process has been added to ksm
94  *
95  * @mm:			address of the mm object of the process
96  *
97  * Allows to trace the when a process has been added to ksm.
98  */
99 DEFINE_EVENT(ksm_enter_exit_template, ksm_enter,
100 
101 	TP_PROTO(void *mm),
102 
103 	TP_ARGS(mm)
104 );
105 
106 /**
107  * ksm_exit - called after a new process has been removed from ksm
108  *
109  * @mm:			address of the mm object of the process
110  *
111  * Allows to trace the when a process has been removed from ksm.
112  */
113 DEFINE_EVENT(ksm_enter_exit_template, ksm_exit,
114 
115 	TP_PROTO(void *mm),
116 
117 	TP_ARGS(mm)
118 );
119 
120 /**
121  * ksm_merge_one_page - called after a page has been merged
122  *
123  * @pfn:		page frame number of ksm page
124  * @rmap_item:		address of rmap_item  object
125  * @mm:			address of the process mm struct
126  * @err:		success
127  *
128  * Allows to trace the ksm merging of individual pages.
129  */
130 TRACE_EVENT(ksm_merge_one_page,
131 
132 	TP_PROTO(unsigned long pfn, void *rmap_item, void *mm, int err),
133 
134 	TP_ARGS(pfn, rmap_item, mm, err),
135 
136 	TP_STRUCT__entry(
137 		__field(unsigned long,	pfn)
138 		__field(void *,		rmap_item)
139 		__field(void *,		mm)
140 		__field(int,		err)
141 	),
142 
143 	TP_fast_assign(
144 		__entry->pfn		= pfn;
145 		__entry->rmap_item	= rmap_item;
146 		__entry->mm		= mm;
147 		__entry->err		= err;
148 	),
149 
150 	TP_printk("ksm pfn %lu rmap_item %p mm %p error %d",
151 			__entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
152 );
153 
154 /**
155  * ksm_merge_with_ksm_page - called after a page has been merged with a ksm page
156  *
157  * @ksm_page:		address ksm page
158  * @pfn:		page frame number of ksm page
159  * @rmap_item:		address of rmap_item  object
160  * @mm:			address of the mm object of the process
161  * @err:		success
162  *
163  * Allows to trace the merging of a page with a ksm page.
164  */
165 TRACE_EVENT(ksm_merge_with_ksm_page,
166 
167 	TP_PROTO(void *ksm_page, unsigned long pfn, void *rmap_item, void *mm, int err),
168 
169 	TP_ARGS(ksm_page, pfn, rmap_item, mm, err),
170 
171 	TP_STRUCT__entry(
172 		__field(void *,		ksm_page)
173 		__field(unsigned long,	pfn)
174 		__field(void *,		rmap_item)
175 		__field(void *,		mm)
176 		__field(int,		err)
177 	),
178 
179 	TP_fast_assign(
180 		__entry->ksm_page	= ksm_page;
181 		__entry->pfn		= pfn;
182 		__entry->rmap_item	= rmap_item;
183 		__entry->mm		= mm;
184 		__entry->err		= err;
185 	),
186 
187 	TP_printk("%spfn %lu rmap_item %p mm %p error %d",
188 		  (__entry->ksm_page ? "ksm " : ""),
189 		  __entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
190 );
191 
192 /**
193  * ksm_remove_ksm_page - called after a ksm page has been removed
194  *
195  * @pfn:		page frame number of ksm page
196  *
197  * Allows to trace the removing of stable ksm pages.
198  */
199 TRACE_EVENT(ksm_remove_ksm_page,
200 
201 	TP_PROTO(unsigned long pfn),
202 
203 	TP_ARGS(pfn),
204 
205 	TP_STRUCT__entry(
206 		__field(unsigned long, pfn)
207 	),
208 
209 	TP_fast_assign(
210 		__entry->pfn = pfn;
211 	),
212 
213 	TP_printk("pfn %lu", __entry->pfn)
214 );
215 
216 /**
217  * ksm_remove_rmap_item - called after a rmap_item has been removed from the
218  *                        stable tree
219  *
220  * @pfn:		page frame number of ksm page
221  * @rmap_item:		address of rmap_item  object
222  * @mm:			address of the process mm struct
223  *
224  * Allows to trace the removal of pages from the stable tree list.
225  */
226 TRACE_EVENT(ksm_remove_rmap_item,
227 
228 	TP_PROTO(unsigned long pfn, void *rmap_item, void *mm),
229 
230 	TP_ARGS(pfn, rmap_item, mm),
231 
232 	TP_STRUCT__entry(
233 		__field(unsigned long,	pfn)
234 		__field(void *,		rmap_item)
235 		__field(void *,		mm)
236 	),
237 
238 	TP_fast_assign(
239 		__entry->pfn		= pfn;
240 		__entry->rmap_item	= rmap_item;
241 		__entry->mm		= mm;
242 	),
243 
244 	TP_printk("pfn %lu rmap_item %p mm %p",
245 			__entry->pfn, __entry->rmap_item, __entry->mm)
246 );
247 
248 /**
249  * ksm_advisor - called after the advisor has run
250  *
251  * @scan_time:		scan time in seconds
252  * @pages_to_scan:	new pages_to_scan value
253  * @cpu_percent:	cpu usage in percent
254  *
255  * Allows to trace the ksm advisor.
256  */
257 TRACE_EVENT(ksm_advisor,
258 
259 	TP_PROTO(s64 scan_time, unsigned long pages_to_scan,
260 		 unsigned int cpu_percent),
261 
262 	TP_ARGS(scan_time, pages_to_scan, cpu_percent),
263 
264 	TP_STRUCT__entry(
265 		__field(s64,		scan_time)
266 		__field(unsigned long,	pages_to_scan)
267 		__field(unsigned int,	cpu_percent)
268 	),
269 
270 	TP_fast_assign(
271 		__entry->scan_time	= scan_time;
272 		__entry->pages_to_scan	= pages_to_scan;
273 		__entry->cpu_percent	= cpu_percent;
274 	),
275 
276 	TP_printk("ksm scan time %lld pages_to_scan %lu cpu percent %u",
277 			__entry->scan_time, __entry->pages_to_scan,
278 			__entry->cpu_percent)
279 );
280 
281 #endif /* _TRACE_KSM_H */
282 
283 /* This part must be outside protection */
284 #include <trace/define_trace.h>
285