Commit 64565911cdb57c2f512a9715b985b5617402cc67
1 parent
4722dc52a8
Exists in
master
and in
7 other branches
block: make blktrace use per-cpu buffers for message notes
Currently it uses a single static char array, but that risks being corrupted when multiple users issue message notes at the same time. Make the buffers dynamically allocated when the trace is setup and make them per-cpu instead. The default max message size of 1k is also very large, the interface is mainly for small text notes. So shrink it to 128 bytes. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Showing 2 changed files with 14 additions and 4 deletions Side-by-side Diff
block/blktrace.c
... | ... | @@ -79,13 +79,16 @@ |
79 | 79 | { |
80 | 80 | int n; |
81 | 81 | va_list args; |
82 | - static char bt_msg_buf[BLK_TN_MAX_MSG]; | |
82 | + char *buf; | |
83 | 83 | |
84 | + preempt_disable(); | |
85 | + buf = per_cpu_ptr(bt->msg_data, smp_processor_id()); | |
84 | 86 | va_start(args, fmt); |
85 | - n = vscnprintf(bt_msg_buf, BLK_TN_MAX_MSG, fmt, args); | |
87 | + n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args); | |
86 | 88 | va_end(args); |
87 | 89 | |
88 | - trace_note(bt, 0, BLK_TN_MESSAGE, bt_msg_buf, n); | |
90 | + trace_note(bt, 0, BLK_TN_MESSAGE, buf, n); | |
91 | + preempt_enable(); | |
89 | 92 | } |
90 | 93 | EXPORT_SYMBOL_GPL(__trace_note_message); |
91 | 94 | |
... | ... | @@ -246,6 +249,7 @@ |
246 | 249 | debugfs_remove(bt->dropped_file); |
247 | 250 | blk_remove_tree(bt->dir); |
248 | 251 | free_percpu(bt->sequence); |
252 | + free_percpu(bt->msg_data); | |
249 | 253 | kfree(bt); |
250 | 254 | } |
251 | 255 | |
... | ... | @@ -360,6 +364,10 @@ |
360 | 364 | if (!bt->sequence) |
361 | 365 | goto err; |
362 | 366 | |
367 | + bt->msg_data = __alloc_percpu(BLK_TN_MAX_MSG); | |
368 | + if (!bt->msg_data) | |
369 | + goto err; | |
370 | + | |
363 | 371 | ret = -ENOENT; |
364 | 372 | dir = blk_create_tree(buts->name); |
365 | 373 | if (!dir) |
... | ... | @@ -406,6 +414,7 @@ |
406 | 414 | if (bt->dropped_file) |
407 | 415 | debugfs_remove(bt->dropped_file); |
408 | 416 | free_percpu(bt->sequence); |
417 | + free_percpu(bt->msg_data); | |
409 | 418 | if (bt->rchan) |
410 | 419 | relay_close(bt->rchan); |
411 | 420 | kfree(bt); |
include/linux/blktrace_api.h
... | ... | @@ -121,6 +121,7 @@ |
121 | 121 | int trace_state; |
122 | 122 | struct rchan *rchan; |
123 | 123 | unsigned long *sequence; |
124 | + unsigned char *msg_data; | |
124 | 125 | u16 act_mask; |
125 | 126 | u64 start_lba; |
126 | 127 | u64 end_lba; |
... | ... | @@ -172,7 +173,7 @@ |
172 | 173 | if (unlikely(bt)) \ |
173 | 174 | __trace_note_message(bt, fmt, ##__VA_ARGS__); \ |
174 | 175 | } while (0) |
175 | -#define BLK_TN_MAX_MSG 1024 | |
176 | +#define BLK_TN_MAX_MSG 128 | |
176 | 177 | |
177 | 178 | /** |
178 | 179 | * blk_add_trace_rq - Add a trace for a request oriented action |