summaryrefslogtreecommitdiff
path: root/include/trace/events/ksm.h
blob: e728647b5d268ef7fa79a81972ff25a913b783e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM ksm

#if !defined(_TRACE_KSM_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_KSM_H

#include <linux/tracepoint.h>

/**
 * ksm_scan_template - called for start / stop scan
 *
 * @seq:		sequence number of scan
 * @rmap_entries:	actual number of rmap entries
 *
 * Allows to trace the start / stop of a ksm scan.
 */
DECLARE_EVENT_CLASS(ksm_scan_template,

	TP_PROTO(int seq, u32 rmap_entries),

	TP_ARGS(seq, rmap_entries),

	TP_STRUCT__entry(
		__field(int,	seq)
		__field(u32,	rmap_entries)
	),

	TP_fast_assign(
		__entry->seq		= seq;
		__entry->rmap_entries	= rmap_entries;
	),

	TP_printk("seq %d rmap size %d",
			__entry->seq, __entry->rmap_entries)
);

/**
 * ksm_start_scan - called after a new ksm scan is started
 *
 * @seq:		sequence number of scan
 * @rmap_entries:	actual number of rmap entries
 *
 * Allows to trace the start of a ksm scan.
 */
DEFINE_EVENT(ksm_scan_template, ksm_start_scan,

	TP_PROTO(int seq, u32 rmap_entries),

	TP_ARGS(seq, rmap_entries)
);

/**
 * ksm_stop_scan - called after a new ksm scan has completed
 *
 * @seq:		sequence number of scan
 * @rmap_entries:	actual number of rmap entries
 *
 * Allows to trace the completion of a ksm scan.
 */
DEFINE_EVENT(ksm_scan_template, ksm_stop_scan,

	TP_PROTO(int seq, u32 rmap_entries),

	TP_ARGS(seq, rmap_entries)
);

/**
 * ksm_enter - called after a new process has been added / removed from ksm
 *
 * @mm:			address of the mm object of the process
 *
 * Allows to trace the when a process has been added or removed from ksm.
 */
DECLARE_EVENT_CLASS(ksm_enter_exit_template,

	TP_PROTO(void *mm),

	TP_ARGS(mm),

	TP_STRUCT__entry(
		__field(void *,		mm)
	),

	TP_fast_assign(
		__entry->mm	= mm;
	),

	TP_printk("mm %p", __entry->mm)
);

/**
 * ksm_enter - called after a new process has been added to ksm
 *
 * @mm:			address of the mm object of the process
 *
 * Allows to trace the when a process has been added to ksm.
 */
DEFINE_EVENT(ksm_enter_exit_template, ksm_enter,

	TP_PROTO(void *mm),

	TP_ARGS(mm)
);

/**
 * ksm_exit - called after a new process has been removed from ksm
 *
 * @mm:			address of the mm object of the process
 *
 * Allows to trace the when a process has been removed from ksm.
 */
DEFINE_EVENT(ksm_enter_exit_template, ksm_exit,

	TP_PROTO(void *mm),

	TP_ARGS(mm)
);

/**
 * ksm_merge_one_page - called after a page has been merged
 *
 * @pfn:		page frame number of ksm page
 * @rmap_item:		address of rmap_item  object
 * @mm:			address of the process mm struct
 * @err:		success
 *
 * Allows to trace the ksm merging of individual pages.
 */
TRACE_EVENT(ksm_merge_one_page,

	TP_PROTO(unsigned long pfn, void *rmap_item, void *mm, int err),

	TP_ARGS(pfn, rmap_item, mm, err),

	TP_STRUCT__entry(
		__field(unsigned long,	pfn)
		__field(void *,		rmap_item)
		__field(void *,		mm)
		__field(int,		err)
	),

	TP_fast_assign(
		__entry->pfn		= pfn;
		__entry->rmap_item	= rmap_item;
		__entry->mm		= mm;
		__entry->err		= err;
	),

	TP_printk("ksm pfn %lu rmap_item %p mm %p error %d",
			__entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
);

/**
 * ksm_merge_with_ksm_page - called after a page has been merged with a ksm page
 *
 * @ksm_page:		address ksm page
 * @pfn:		page frame number of ksm page
 * @rmap_item:		address of rmap_item  object
 * @mm:			address of the mm object of the process
 * @err:		success
 *
 * Allows to trace the merging of a page with a ksm page.
 */
TRACE_EVENT(ksm_merge_with_ksm_page,

	TP_PROTO(void *ksm_page, unsigned long pfn, void *rmap_item, void *mm, int err),

	TP_ARGS(ksm_page, pfn, rmap_item, mm, err),

	TP_STRUCT__entry(
		__field(void *,		ksm_page)
		__field(unsigned long,	pfn)
		__field(void *,		rmap_item)
		__field(void *,		mm)
		__field(int,		err)
	),

	TP_fast_assign(
		__entry->ksm_page	= ksm_page;
		__entry->pfn		= pfn;
		__entry->rmap_item	= rmap_item;
		__entry->mm		= mm;
		__entry->err		= err;
	),

	TP_printk("%spfn %lu rmap_item %p mm %p error %d",
		  (__entry->ksm_page ? "ksm " : ""),
		  __entry->pfn, __entry->rmap_item, __entry->mm, __entry->err)
);

/**
 * ksm_remove_ksm_page - called after a ksm page has been removed
 *
 * @pfn:		page frame number of ksm page
 *
 * Allows to trace the removing of stable ksm pages.
 */
TRACE_EVENT(ksm_remove_ksm_page,

	TP_PROTO(unsigned long pfn),

	TP_ARGS(pfn),

	TP_STRUCT__entry(
		__field(unsigned long, pfn)
	),

	TP_fast_assign(
		__entry->pfn = pfn;
	),

	TP_printk("pfn %lu", __entry->pfn)
);

/**
 * ksm_remove_rmap_item - called after a rmap_item has been removed from the
 *                        stable tree
 *
 * @pfn:		page frame number of ksm page
 * @rmap_item:		address of rmap_item  object
 * @mm:			address of the process mm struct
 *
 * Allows to trace the removal of pages from the stable tree list.
 */
TRACE_EVENT(ksm_remove_rmap_item,

	TP_PROTO(unsigned long pfn, void *rmap_item, void *mm),

	TP_ARGS(pfn, rmap_item, mm),

	TP_STRUCT__entry(
		__field(unsigned long,	pfn)
		__field(void *,		rmap_item)
		__field(void *,		mm)
	),

	TP_fast_assign(
		__entry->pfn		= pfn;
		__entry->rmap_item	= rmap_item;
		__entry->mm		= mm;
	),

	TP_printk("pfn %lu rmap_item %p mm %p",
			__entry->pfn, __entry->rmap_item, __entry->mm)
);

/**
 * ksm_advisor - called after the advisor has run
 *
 * @scan_time:		scan time in seconds
 * @pages_to_scan:	new pages_to_scan value
 * @cpu_percent:	cpu usage in percent
 *
 * Allows to trace the ksm advisor.
 */
TRACE_EVENT(ksm_advisor,

	TP_PROTO(s64 scan_time, unsigned long pages_to_scan,
		 unsigned int cpu_percent),

	TP_ARGS(scan_time, pages_to_scan, cpu_percent),

	TP_STRUCT__entry(
		__field(s64,		scan_time)
		__field(unsigned long,	pages_to_scan)
		__field(unsigned int,	cpu_percent)
	),

	TP_fast_assign(
		__entry->scan_time	= scan_time;
		__entry->pages_to_scan	= pages_to_scan;
		__entry->cpu_percent	= cpu_percent;
	),

	TP_printk("ksm scan time %lld pages_to_scan %lu cpu percent %u",
			__entry->scan_time, __entry->pages_to_scan,
			__entry->cpu_percent)
);

#endif /* _TRACE_KSM_H */

/* This part must be outside protection */
#include <trace/define_trace.h>