Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tracing: Simplify the max length test when using the filtering temp buffer

When filtering trace events, a temp buffer is used because the extra copy
from the temp buffer into the ring buffer is still faster than the direct
write into the ring buffer followed by a discard if the filter does not
match.

But the data that can be stored in the temp buffer is a PAGE_SIZE minus the
ring buffer event header. The calculation of that header size is complex,
but using the helper macro "struct_size()" can simplify it.

Link: https://lore.kernel.org/stable/CAHk-=whKbJkuVmzb0hD3N6q7veprUrSpiBHRxVY=AffWZPtxmg@mail.gmail.com/

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

+3 -1
+3 -1
kernel/trace/trace.c
··· 2735 2735 (trace_file->flags & (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED)) && 2736 2736 (entry = this_cpu_read(trace_buffered_event))) { 2737 2737 /* Try to use the per cpu buffer first */ 2738 + int max_len = PAGE_SIZE - struct_size(entry, array, 1); 2739 + 2738 2740 val = this_cpu_inc_return(trace_buffered_event_cnt); 2739 - if ((len < (PAGE_SIZE - sizeof(*entry) - sizeof(entry->array[0]))) && val == 1) { 2741 + if (val == 1 && likely(len <= max_len)) { 2740 2742 trace_event_setup(entry, type, trace_ctx); 2741 2743 entry->array[0] = len; 2742 2744 return entry;