blob: a91da69f153ad0c859997356d53db6548006db7c [file] [log] [blame]
Frederic Weisbecker36994e52008-12-29 13:42:23 -08001/*
2 * Memory allocator tracing
3 *
4 * Copyright (C) 2008 Eduard - Gabriel Munteanu
5 * Copyright (C) 2008 Pekka Enberg <penberg@cs.helsinki.fi>
6 * Copyright (C) 2008 Frederic Weisbecker <fweisbec@gmail.com>
7 */
8
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +02009#include <linux/tracepoint.h>
Ingo Molnarc826e3c2009-03-23 16:14:13 +010010#include <linux/seq_file.h>
11#include <linux/debugfs.h>
12#include <linux/dcache.h>
13#include <linux/fs.h>
14
Zhaolei02af61b2009-04-10 14:26:18 +080015#include <linux/kmemtrace.h>
Frederic Weisbecker36994e52008-12-29 13:42:23 -080016
Frederic Weisbecker36994e52008-12-29 13:42:23 -080017#include "trace_output.h"
Ingo Molnarc826e3c2009-03-23 16:14:13 +010018#include "trace.h"
Frederic Weisbecker36994e52008-12-29 13:42:23 -080019
20/* Select an alternative, minimalistic output than the original one */
21#define TRACE_KMEM_OPT_MINIMAL 0x1
22
23static struct tracer_opt kmem_opts[] = {
24 /* Default disable the minimalistic output */
25 { TRACER_OPT(kmem_minimalistic, TRACE_KMEM_OPT_MINIMAL) },
26 { }
27};
28
29static struct tracer_flags kmem_tracer_flags = {
Ingo Molnarc826e3c2009-03-23 16:14:13 +010030 .val = 0,
31 .opts = kmem_opts
Frederic Weisbecker36994e52008-12-29 13:42:23 -080032};
33
Frederic Weisbecker36994e52008-12-29 13:42:23 -080034static struct trace_array *kmemtrace_array;
35
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020036/* Trace allocations */
37static inline void kmemtrace_alloc(enum kmemtrace_type_id type_id,
38 unsigned long call_site,
39 const void *ptr,
40 size_t bytes_req,
41 size_t bytes_alloc,
42 gfp_t gfp_flags,
43 int node)
44{
Tom Zanussie1112b42009-03-31 00:48:49 -050045 struct ftrace_event_call *call = &event_kmem_alloc;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020046 struct trace_array *tr = kmemtrace_array;
Ingo Molnarc826e3c2009-03-23 16:14:13 +010047 struct kmemtrace_alloc_entry *entry;
48 struct ring_buffer_event *event;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020049
50 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
51 if (!event)
52 return;
Ingo Molnarc826e3c2009-03-23 16:14:13 +010053
54 entry = ring_buffer_event_data(event);
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020055 tracing_generic_entry_update(&entry->ent, 0, 0);
56
Ingo Molnarc826e3c2009-03-23 16:14:13 +010057 entry->ent.type = TRACE_KMEM_ALLOC;
58 entry->type_id = type_id;
59 entry->call_site = call_site;
60 entry->ptr = ptr;
61 entry->bytes_req = bytes_req;
62 entry->bytes_alloc = bytes_alloc;
63 entry->gfp_flags = gfp_flags;
64 entry->node = node;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020065
Tom Zanussieb02ce02009-04-08 03:15:54 -050066 if (!filter_check_discard(call, entry, tr->buffer, event))
67 ring_buffer_unlock_commit(tr->buffer, event);
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020068
69 trace_wake_up();
70}
71
72static inline void kmemtrace_free(enum kmemtrace_type_id type_id,
73 unsigned long call_site,
74 const void *ptr)
75{
Tom Zanussie1112b42009-03-31 00:48:49 -050076 struct ftrace_event_call *call = &event_kmem_free;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020077 struct trace_array *tr = kmemtrace_array;
Ingo Molnarc826e3c2009-03-23 16:14:13 +010078 struct kmemtrace_free_entry *entry;
79 struct ring_buffer_event *event;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020080
81 event = ring_buffer_lock_reserve(tr->buffer, sizeof(*entry));
82 if (!event)
83 return;
84 entry = ring_buffer_event_data(event);
85 tracing_generic_entry_update(&entry->ent, 0, 0);
86
Ingo Molnarc826e3c2009-03-23 16:14:13 +010087 entry->ent.type = TRACE_KMEM_FREE;
88 entry->type_id = type_id;
89 entry->call_site = call_site;
90 entry->ptr = ptr;
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020091
Tom Zanussieb02ce02009-04-08 03:15:54 -050092 if (!filter_check_discard(call, entry, tr->buffer, event))
93 ring_buffer_unlock_commit(tr->buffer, event);
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +020094
95 trace_wake_up();
96}
97
98static void kmemtrace_kmalloc(unsigned long call_site,
99 const void *ptr,
100 size_t bytes_req,
101 size_t bytes_alloc,
102 gfp_t gfp_flags)
103{
104 kmemtrace_alloc(KMEMTRACE_TYPE_KMALLOC, call_site, ptr,
105 bytes_req, bytes_alloc, gfp_flags, -1);
106}
107
108static void kmemtrace_kmem_cache_alloc(unsigned long call_site,
109 const void *ptr,
110 size_t bytes_req,
111 size_t bytes_alloc,
112 gfp_t gfp_flags)
113{
114 kmemtrace_alloc(KMEMTRACE_TYPE_CACHE, call_site, ptr,
115 bytes_req, bytes_alloc, gfp_flags, -1);
116}
117
118static void kmemtrace_kmalloc_node(unsigned long call_site,
119 const void *ptr,
120 size_t bytes_req,
121 size_t bytes_alloc,
122 gfp_t gfp_flags,
123 int node)
124{
125 kmemtrace_alloc(KMEMTRACE_TYPE_KMALLOC, call_site, ptr,
126 bytes_req, bytes_alloc, gfp_flags, node);
127}
128
129static void kmemtrace_kmem_cache_alloc_node(unsigned long call_site,
130 const void *ptr,
131 size_t bytes_req,
132 size_t bytes_alloc,
133 gfp_t gfp_flags,
134 int node)
135{
136 kmemtrace_alloc(KMEMTRACE_TYPE_CACHE, call_site, ptr,
137 bytes_req, bytes_alloc, gfp_flags, node);
138}
139
140static void kmemtrace_kfree(unsigned long call_site, const void *ptr)
141{
142 kmemtrace_free(KMEMTRACE_TYPE_KMALLOC, call_site, ptr);
143}
144
145static void kmemtrace_kmem_cache_free(unsigned long call_site, const void *ptr)
146{
147 kmemtrace_free(KMEMTRACE_TYPE_CACHE, call_site, ptr);
148}
149
150static int kmemtrace_start_probes(void)
151{
152 int err;
153
154 err = register_trace_kmalloc(kmemtrace_kmalloc);
155 if (err)
156 return err;
157 err = register_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc);
158 if (err)
159 return err;
160 err = register_trace_kmalloc_node(kmemtrace_kmalloc_node);
161 if (err)
162 return err;
163 err = register_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node);
164 if (err)
165 return err;
166 err = register_trace_kfree(kmemtrace_kfree);
167 if (err)
168 return err;
169 err = register_trace_kmem_cache_free(kmemtrace_kmem_cache_free);
170
171 return err;
172}
173
174static void kmemtrace_stop_probes(void)
175{
176 unregister_trace_kmalloc(kmemtrace_kmalloc);
177 unregister_trace_kmem_cache_alloc(kmemtrace_kmem_cache_alloc);
178 unregister_trace_kmalloc_node(kmemtrace_kmalloc_node);
179 unregister_trace_kmem_cache_alloc_node(kmemtrace_kmem_cache_alloc_node);
180 unregister_trace_kfree(kmemtrace_kfree);
181 unregister_trace_kmem_cache_free(kmemtrace_kmem_cache_free);
182}
183
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800184static int kmem_trace_init(struct trace_array *tr)
185{
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800186 kmemtrace_array = tr;
187
Steven Rostedt76f0d072009-09-04 12:12:39 -0400188 tracing_reset_online_cpus(tr);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800189
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +0200190 kmemtrace_start_probes();
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800191
192 return 0;
193}
194
195static void kmem_trace_reset(struct trace_array *tr)
196{
Eduard - Gabriel Munteanuca2b84cb2009-03-23 15:12:24 +0200197 kmemtrace_stop_probes();
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800198}
199
200static void kmemtrace_headers(struct seq_file *s)
201{
202 /* Don't need headers for the original kmemtrace output */
203 if (!(kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL))
204 return;
205
206 seq_printf(s, "#\n");
207 seq_printf(s, "# ALLOC TYPE REQ GIVEN FLAGS "
208 " POINTER NODE CALLER\n");
209 seq_printf(s, "# FREE | | | | "
210 " | | | |\n");
211 seq_printf(s, "# |\n\n");
212}
213
214/*
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200215 * The following functions give the original output from kmemtrace,
216 * plus the origin CPU, since reordering occurs in-kernel now.
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800217 */
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200218
219#define KMEMTRACE_USER_ALLOC 0
220#define KMEMTRACE_USER_FREE 1
221
222struct kmemtrace_user_event {
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100223 u8 event_id;
224 u8 type_id;
225 u16 event_size;
226 u32 cpu;
227 u64 timestamp;
228 unsigned long call_site;
229 unsigned long ptr;
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200230};
231
232struct kmemtrace_user_event_alloc {
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100233 size_t bytes_req;
234 size_t bytes_alloc;
235 unsigned gfp_flags;
236 int node;
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200237};
238
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800239static enum print_line_t
Li Zefan80098c22009-07-06 16:15:04 +0800240kmemtrace_print_alloc(struct trace_iterator *iter, int flags)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800241{
242 struct trace_seq *s = &iter->seq;
Li Zefanddc16372009-07-03 17:34:24 +0800243 struct kmemtrace_alloc_entry *entry;
244 int ret;
245
246 trace_assign_type(entry, iter->ent);
247
248 ret = trace_seq_printf(s, "type_id %d call_site %pF ptr %lu "
249 "bytes_req %lu bytes_alloc %lu gfp_flags %lu node %d\n",
250 entry->type_id, (void *)entry->call_site, (unsigned long)entry->ptr,
251 (unsigned long)entry->bytes_req, (unsigned long)entry->bytes_alloc,
252 (unsigned long)entry->gfp_flags, entry->node);
253
254 if (!ret)
255 return TRACE_TYPE_PARTIAL_LINE;
256 return TRACE_TYPE_HANDLED;
257}
258
259static enum print_line_t
Li Zefan80098c22009-07-06 16:15:04 +0800260kmemtrace_print_free(struct trace_iterator *iter, int flags)
Li Zefanddc16372009-07-03 17:34:24 +0800261{
262 struct trace_seq *s = &iter->seq;
263 struct kmemtrace_free_entry *entry;
264 int ret;
265
266 trace_assign_type(entry, iter->ent);
267
268 ret = trace_seq_printf(s, "type_id %d call_site %pF ptr %lu\n",
269 entry->type_id, (void *)entry->call_site,
270 (unsigned long)entry->ptr);
271
272 if (!ret)
273 return TRACE_TYPE_PARTIAL_LINE;
274 return TRACE_TYPE_HANDLED;
275}
276
277static enum print_line_t
Li Zefan80098c22009-07-06 16:15:04 +0800278kmemtrace_print_alloc_user(struct trace_iterator *iter, int flags)
Li Zefanddc16372009-07-03 17:34:24 +0800279{
280 struct trace_seq *s = &iter->seq;
281 struct kmemtrace_alloc_entry *entry;
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200282 struct kmemtrace_user_event *ev;
Li Zefanddc16372009-07-03 17:34:24 +0800283 struct kmemtrace_user_event_alloc *ev_alloc;
284
285 trace_assign_type(entry, iter->ent);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800286
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200287 ev = trace_seq_reserve(s, sizeof(*ev));
288 if (!ev)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800289 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100290
291 ev->event_id = KMEMTRACE_USER_ALLOC;
292 ev->type_id = entry->type_id;
293 ev->event_size = sizeof(*ev) + sizeof(*ev_alloc);
294 ev->cpu = iter->cpu;
295 ev->timestamp = iter->ts;
296 ev->call_site = entry->call_site;
297 ev->ptr = (unsigned long)entry->ptr;
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200298
299 ev_alloc = trace_seq_reserve(s, sizeof(*ev_alloc));
300 if (!ev_alloc)
301 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100302
303 ev_alloc->bytes_req = entry->bytes_req;
304 ev_alloc->bytes_alloc = entry->bytes_alloc;
305 ev_alloc->gfp_flags = entry->gfp_flags;
306 ev_alloc->node = entry->node;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800307
308 return TRACE_TYPE_HANDLED;
309}
310
311static enum print_line_t
Li Zefan80098c22009-07-06 16:15:04 +0800312kmemtrace_print_free_user(struct trace_iterator *iter, int flags)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800313{
314 struct trace_seq *s = &iter->seq;
Li Zefanddc16372009-07-03 17:34:24 +0800315 struct kmemtrace_free_entry *entry;
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200316 struct kmemtrace_user_event *ev;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800317
Li Zefanddc16372009-07-03 17:34:24 +0800318 trace_assign_type(entry, iter->ent);
319
Eduard - Gabriel Munteanu42af9052009-03-23 15:12:26 +0200320 ev = trace_seq_reserve(s, sizeof(*ev));
321 if (!ev)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800322 return TRACE_TYPE_PARTIAL_LINE;
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100323
324 ev->event_id = KMEMTRACE_USER_FREE;
325 ev->type_id = entry->type_id;
326 ev->event_size = sizeof(*ev);
327 ev->cpu = iter->cpu;
328 ev->timestamp = iter->ts;
329 ev->call_site = entry->call_site;
330 ev->ptr = (unsigned long)entry->ptr;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800331
332 return TRACE_TYPE_HANDLED;
333}
334
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800335/* The two other following provide a more minimalistic output */
336static enum print_line_t
Li Zefanddc16372009-07-03 17:34:24 +0800337kmemtrace_print_alloc_compress(struct trace_iterator *iter)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800338{
Li Zefanddc16372009-07-03 17:34:24 +0800339 struct kmemtrace_alloc_entry *entry;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800340 struct trace_seq *s = &iter->seq;
341 int ret;
342
Li Zefanddc16372009-07-03 17:34:24 +0800343 trace_assign_type(entry, iter->ent);
344
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800345 /* Alloc entry */
346 ret = trace_seq_printf(s, " + ");
347 if (!ret)
348 return TRACE_TYPE_PARTIAL_LINE;
349
350 /* Type */
351 switch (entry->type_id) {
352 case KMEMTRACE_TYPE_KMALLOC:
353 ret = trace_seq_printf(s, "K ");
354 break;
355 case KMEMTRACE_TYPE_CACHE:
356 ret = trace_seq_printf(s, "C ");
357 break;
358 case KMEMTRACE_TYPE_PAGES:
359 ret = trace_seq_printf(s, "P ");
360 break;
361 default:
362 ret = trace_seq_printf(s, "? ");
363 }
364
365 if (!ret)
366 return TRACE_TYPE_PARTIAL_LINE;
367
368 /* Requested */
Randy Dunlapecf441b2009-01-29 13:49:45 -0800369 ret = trace_seq_printf(s, "%4zu ", entry->bytes_req);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800370 if (!ret)
371 return TRACE_TYPE_PARTIAL_LINE;
372
373 /* Allocated */
Randy Dunlapecf441b2009-01-29 13:49:45 -0800374 ret = trace_seq_printf(s, "%4zu ", entry->bytes_alloc);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800375 if (!ret)
376 return TRACE_TYPE_PARTIAL_LINE;
377
378 /* Flags
379 * TODO: would be better to see the name of the GFP flag names
380 */
381 ret = trace_seq_printf(s, "%08x ", entry->gfp_flags);
382 if (!ret)
383 return TRACE_TYPE_PARTIAL_LINE;
384
385 /* Pointer to allocated */
386 ret = trace_seq_printf(s, "0x%tx ", (ptrdiff_t)entry->ptr);
387 if (!ret)
388 return TRACE_TYPE_PARTIAL_LINE;
389
Frederic Weisbecker6a167c62009-07-09 04:46:30 +0200390 /* Node and call site*/
391 ret = trace_seq_printf(s, "%4d %pf\n", entry->node,
392 (void *)entry->call_site);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800393 if (!ret)
394 return TRACE_TYPE_PARTIAL_LINE;
395
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800396 return TRACE_TYPE_HANDLED;
397}
398
399static enum print_line_t
Li Zefanddc16372009-07-03 17:34:24 +0800400kmemtrace_print_free_compress(struct trace_iterator *iter)
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800401{
Li Zefanddc16372009-07-03 17:34:24 +0800402 struct kmemtrace_free_entry *entry;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800403 struct trace_seq *s = &iter->seq;
404 int ret;
405
Li Zefanddc16372009-07-03 17:34:24 +0800406 trace_assign_type(entry, iter->ent);
407
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800408 /* Free entry */
409 ret = trace_seq_printf(s, " - ");
410 if (!ret)
411 return TRACE_TYPE_PARTIAL_LINE;
412
413 /* Type */
414 switch (entry->type_id) {
415 case KMEMTRACE_TYPE_KMALLOC:
416 ret = trace_seq_printf(s, "K ");
417 break;
418 case KMEMTRACE_TYPE_CACHE:
419 ret = trace_seq_printf(s, "C ");
420 break;
421 case KMEMTRACE_TYPE_PAGES:
422 ret = trace_seq_printf(s, "P ");
423 break;
424 default:
425 ret = trace_seq_printf(s, "? ");
426 }
427
428 if (!ret)
429 return TRACE_TYPE_PARTIAL_LINE;
430
431 /* Skip requested/allocated/flags */
432 ret = trace_seq_printf(s, " ");
433 if (!ret)
434 return TRACE_TYPE_PARTIAL_LINE;
435
436 /* Pointer to allocated */
437 ret = trace_seq_printf(s, "0x%tx ", (ptrdiff_t)entry->ptr);
438 if (!ret)
439 return TRACE_TYPE_PARTIAL_LINE;
440
Frederic Weisbecker6a167c62009-07-09 04:46:30 +0200441 /* Skip node and print call site*/
442 ret = trace_seq_printf(s, " %pf\n", (void *)entry->call_site);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800443 if (!ret)
444 return TRACE_TYPE_PARTIAL_LINE;
445
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800446 return TRACE_TYPE_HANDLED;
447}
448
449static enum print_line_t kmemtrace_print_line(struct trace_iterator *iter)
450{
451 struct trace_entry *entry = iter->ent;
452
Li Zefanddc16372009-07-03 17:34:24 +0800453 if (!(kmem_tracer_flags.val & TRACE_KMEM_OPT_MINIMAL))
454 return TRACE_TYPE_UNHANDLED;
455
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800456 switch (entry->type) {
Li Zefanddc16372009-07-03 17:34:24 +0800457 case TRACE_KMEM_ALLOC:
458 return kmemtrace_print_alloc_compress(iter);
459 case TRACE_KMEM_FREE:
460 return kmemtrace_print_free_compress(iter);
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800461 default:
462 return TRACE_TYPE_UNHANDLED;
463 }
464}
465
Li Zefanddc16372009-07-03 17:34:24 +0800466static struct trace_event kmem_trace_alloc = {
467 .type = TRACE_KMEM_ALLOC,
Li Zefan80098c22009-07-06 16:15:04 +0800468 .trace = kmemtrace_print_alloc,
469 .binary = kmemtrace_print_alloc_user,
Li Zefanddc16372009-07-03 17:34:24 +0800470};
471
472static struct trace_event kmem_trace_free = {
473 .type = TRACE_KMEM_FREE,
Li Zefan80098c22009-07-06 16:15:04 +0800474 .trace = kmemtrace_print_free,
475 .binary = kmemtrace_print_free_user,
Li Zefanddc16372009-07-03 17:34:24 +0800476};
477
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800478static struct tracer kmem_tracer __read_mostly = {
Ingo Molnarc826e3c2009-03-23 16:14:13 +0100479 .name = "kmemtrace",
480 .init = kmem_trace_init,
481 .reset = kmem_trace_reset,
482 .print_line = kmemtrace_print_line,
483 .print_header = kmemtrace_headers,
484 .flags = &kmem_tracer_flags
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800485};
486
Ingo Molnar3e806802009-01-06 10:16:35 +0100487void kmemtrace_init(void)
488{
489 /* earliest opportunity to start kmem tracing */
490}
491
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800492static int __init init_kmem_tracer(void)
493{
Li Zefanddc16372009-07-03 17:34:24 +0800494 if (!register_ftrace_event(&kmem_trace_alloc)) {
495 pr_warning("Warning: could not register kmem events\n");
496 return 1;
497 }
498
499 if (!register_ftrace_event(&kmem_trace_free)) {
500 pr_warning("Warning: could not register kmem events\n");
501 return 1;
502 }
503
Paul Mundtf9ac5a62009-09-28 16:55:40 +0900504 if (register_tracer(&kmem_tracer) != 0) {
Li Zefanddc16372009-07-03 17:34:24 +0800505 pr_warning("Warning: could not register the kmem tracer\n");
506 return 1;
507 }
508
509 return 0;
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800510}
Frederic Weisbecker36994e52008-12-29 13:42:23 -0800511device_initcall(init_kmem_tracer);