ring-buffer/tracing: Allow ring buffer to have bigger sub buffers
Subsystems (5)
Steven Rostedt
maintainercover ring-buffer/tracing: Allow ring buffer to have bigger sub buffers
Note, this has been on my todo list since the ring buffer was created back in 2008.
Tzvetomir last worked on this in 2020 and I need to finally get it in.
His last series was:
https://lore.kernel.org/linux-trace-devel/[email protected]/
With the description of:
Currently the size of one sub buffer page is global for all buffers and it is hard coded to one system page. The patch set introduces configurable ring buffer sub page size, per ring buffer. A new user space interface is introduced, which allows to change the sub page size of the ftrace buffer, per ftrace instance.
I'm pulling in his patches mostly untouched, except that I had to tweak a few things to forward port them.
The issues I found I added as the last 7 patches to the series, and then I added documentation and a selftest.
Basically, events to the tracing subsystem are limited to just under a PAGE_SIZE, as the ring buffer is split into "sub buffers" of one page size, and an event can not be bigger than a sub buffer. This allows users to change the size of a sub buffer by the order:
echo 3 > /sys/kernel/tracing/buffer_subbuf_order
Will make each sub buffer a size of 8 pages, allowing events to be almost as big as 8 pages in size (sub buffers do have meta data on them as well, keeping an event from reaching the same size as a sub buffer).
Steven Rostedt (Google) (9):
ring-buffer: Clear pages on error in ring_buffer_subbuf_order_set() failure
ring-buffer: Do no swap cpu buffers if order is different
ring-buffer: Make sure the spare sub buffer used for reads has same size
tracing: Update snapshot order along with main buffer order
tracing: Stop the tracing while changing the ring buffer subbuf size
ring-buffer: Keep the same size when updating the order
ring-buffer: Just update the subbuffers when changing their allocation order
ring-buffer: Add documentation on the buffer_subbuf_order file ringbuffer/selftest: Add basic selftest to test chaning subbuf order
Tzvetomir Stoyanov (VMware) (5):
ring-buffer: Refactor ring buffer implementation
ring-buffer: Page size per ring buffer
ring-buffer: Add interface for configuring trace sub buffer size
ring-buffer: Set new size of the ring buffer sub page
ring-buffer: Read and write to ring buffers with custom sub buffer size
----
Documentation/trace/ftrace.rst | 27 ++ include/linux/ring_buffer.h | 17 +- kernel/trace/ring_buffer.c | 406 ++++++++++++++++----- kernel/trace/ring_buffer_benchmark.c | 10 +- kernel/trace/trace.c | 143 +++++++- kernel/trace/trace.h | 1 + kernel/trace/trace_events.c | 59 ++- .../ftrace/test.d/00basic/ringbuffer_order.tc | 46 +++ 8 files changed, 588 insertions(+), 121 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc
Steven Rostedt
maintainerPATCH 1/14 ring-buffer: Refactor ring buffer implementation
From: "Tzvetomir Stoyanov (VMware)" <[email protected]>
In order to introduce sub-buffer size per ring buffer, some internal refactoring is needed. As ring_buffer_print_page_header() will depend on the trace_buffer structure, it is moved after the structure definition.
--- kernel/trace/ring_buffer.c | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-)
kernel/trace/ring_buffer.c +30 -30
@@ -381,36 +381,6 @@ static inline bool test_time_stamp(u64 delta)/* Events may have a timestamp attached to them */ #define BUF_MAX_EVENT_SIZE (BUF_MAX_DATA_SIZE - RB_LEN_TIME_EXTEND) -int ring_buffer_print_page_header (struct trace_seq *s) -{ -struct buffer_data_page field; - -trace_seq_printf (s,"\tfield: u64 timestamp;\t" -"offset:0;\tsize:%u;\tsigned:%u;\n" , - (unsigned int )sizeof (field.time_stamp), - (unsigned int )is_signed_type (u64)); - -trace_seq_printf (s,"\tfield: local_t commit;\t" -"offset:%u;\tsize:%u;\tsigned:%u;\n" , - (unsigned int )offsetof(typeof (field ), commit), - (unsigned int )sizeof (field.commit), - (unsigned int )is_signed_type (long)); - -trace_seq_printf (s,"\tfield: int overwrite;\t" -"offset:%u;\tsize:%u;\tsigned:%u;\n" , - (unsigned int )offsetof(typeof (field ), commit), -1 , - (unsigned int )is_signed_type (long)); - -trace_seq_printf (s,"\tfield: char data;\t" -"offset:%u;\tsize:%u;\tsigned:%u;\n" , - (unsigned int )offsetof(typeof (field ), data), - (unsigned int )BUF_PAGE_SIZE , - (unsigned int )is_signed_type (char)); - -return !trace_seq_has_overflowed (s); -} -struct rb_irq_work {struct irq_work work;wait_queue_head_t waiters;
@@ -576,6 +546,36 @@ struct ring_buffer_iter {int missed_events; }; +int ring_buffer_print_page_header (struct trace_seq *s) +{ +struct buffer_data_page field; + +trace_seq_printf (s,"\tfield: u64 timestamp;\t" +"offset:0;\tsize:%u;\tsigned:%u;\n" , + (unsigned int )sizeof (field.time_stamp), + (unsigned int )is_signed_type (u64)); + +trace_seq_printf (s,"\tfield: local_t commit;\t" +"offset:%u;\tsize:%u;\tsigned:%u;\n" , + (unsigned int )offsetof(typeof (field ), commit), + (unsigned int )sizeof (field.commit), + (unsigned int )is_signed_type (long)); + +trace_seq_printf (s,"\tfield: int overwrite;\t" +"offset:%u;\tsize:%u;\tsigned:%u;\n" , + (unsigned int )offsetof(typeof (field ), commit), +1 , + (unsigned int )is_signed_type (long)); + +trace_seq_printf (s,"\tfield: char data;\t" +"offset:%u;\tsize:%u;\tsigned:%u;\n" , + (unsigned int )offsetof(typeof (field ), data), + (unsigned int )BUF_PAGE_SIZE , + (unsigned int )is_signed_type (char)); + +return !trace_seq_has_overflowed (s); +} +#ifdef RB_TIME_32 /*
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 2/14 ring-buffer: Page size per ring buffer
In reply to Steven RostedtFrom: "Tzvetomir Stoyanov (VMware)" <[email protected]>
Currently the size of one sub buffer page is global for all buffers and it is hard coded to one system page. In order to introduce configurable ring buffer sub page size, the internal logic should be refactored to work with sub page size per ring buffer.
--- include/linux/ring_buffer.h | 2 +- kernel/trace/ring_buffer.c | 65 +++++++++++++++++++------------------ kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 1 + kernel/trace/trace_events.c | 59 +++++++++++++++++++++++++-------- 5 files changed, 82 insertions(+), 47 deletions(-)
include/linux/ring_buffer.h +1 -1
@@ -200,7 +200,7 @@ int ring_buffer_read_page(struct trace_buffer *buffer, void **data_page,struct trace_seq ;int ring_buffer_print_entry_header (struct trace_seq *s); -int ring_buffer_print_page_header (struct trace_seq *s); +int ring_buffer_print_page_header (struct trace_buffer *buffer,struct trace_seq *s);enum ring_buffer_flags {RB_FL_OVERWRITE =1 <<0 ,
kernel/trace/ring_buffer.c +34 -31
218 lines not on this page · raw message
kernel/trace/trace.c +1 -1
@@ -5012,7 +5012,7 @@ static int tracing_release(struct inode *inode, struct file *file)return 0 ; } -static int tracing_release_generic_tr (struct inode *inode,struct file *file) +int tracing_release_generic_tr (struct inode *inode,struct file *file) {struct trace_array *tr = inode->i_private;
kernel/trace/trace.h +1 -0
@@ -616,6 +616,7 @@ void tracing_reset_all_online_cpus(void);void tracing_reset_all_online_cpus_unlocked (void );int tracing_open_generic (struct inode *inode,struct file *filp);int tracing_open_generic_tr (struct inode *inode,struct file *filp); +int tracing_release_generic_tr (struct inode *inode,struct file *file);int tracing_open_file_tr (struct inode *inode,struct file *filp);int tracing_release_file_tr (struct inode *inode,struct file *filp);bool tracing_is_disabled (void );
kernel/trace/trace_events.c +45 -14
88 lines not on this page · raw message
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 3/14 ring-buffer: Add interface for configuring trace sub buffer size
In reply to Steven RostedtFrom: "Tzvetomir Stoyanov (VMware)" <[email protected]>
The trace ring buffer sub page size can be configured, per trace instance. A new ftrace file "buffer_subbuf_order" is added to get and set the size of the ring buffer sub page for current trace instance. The size must be an order of system page size, that's why the new interface works with system page order, instead of absolute page size:
0 means the ring buffer sub page is equal to 1 system page and so forth:
0 - 1 system page
1 - 2 system pages
2 - 4 system pages
...
The ring buffer sub page size is limited between 1 and 128 system pages. The default value is 1 system page.
New ring buffer APIs are introduced:
ring_buffer_subbuf_order_set() ring_buffer_subbuf_order_get() ring_buffer_subbuf_size_get()
--- include/linux/ring_buffer.h | 4 ++ kernel/trace/ring_buffer.c | 73 +++++++++++++++++++++++++++++++++++++ kernel/trace/trace.c | 48 ++++++++++++++++++++++++ 3 files changed, 125 insertions(+)
include/linux/ring_buffer.h +4 -0
@@ -202,6 +202,10 @@ struct trace_seq;int ring_buffer_print_entry_header (struct trace_seq *s);int ring_buffer_print_page_header (struct trace_buffer *buffer,struct trace_seq *s); +int ring_buffer_subbuf_order_get (struct trace_buffer *buffer); +int ring_buffer_subbuf_order_set (struct trace_buffer *buffer,int order); +int ring_buffer_subbuf_size_get (struct trace_buffer *buffer); +enum ring_buffer_flags {RB_FL_OVERWRITE =1 <<0 , };
kernel/trace/ring_buffer.c +73 -0
85 lines not on this page · raw message
kernel/trace/trace.c +48 -0
60 lines not on this page · raw message
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 4/14 ring-buffer: Set new size of the ring buffer sub page
In reply to Steven RostedtFrom: "Tzvetomir Stoyanov (VMware)" <[email protected]>
There are two approaches when changing the size of the ring buffer sub page:
1. Destroying all pages and allocating new pages with the new size.
2. Allocating new pages, copying the content of the old pages before destroying them.
The first approach is easier, it is selected in the proposed implementation. Changing the ring buffer sub page size is supposed to not happen frequently. Usually, that size should be set only once, when the buffer is not in use yet and is supposed to be empty.
--- kernel/trace/ring_buffer.c | 80 ++++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-)
kernel/trace/ring_buffer.c +73 -7
@@ -331,6 +331,7 @@ struct buffer_page {unsigned read;/* index for next read */ local_t entries;/* entries on this page */ unsigned long real_end;/* real end of data */ +unsigned order;/* order of the page */ struct buffer_data_page *page;/* Actual data page */ };
@@ -361,7 +362,7 @@ static __always_inline unsigned int rb_page_commit(struct buffer_page *bpage)static void free_buffer_page (struct buffer_page *bpage) { -free_page ((unsigned long )bpage->page); +free_pages ((unsigned long )bpage->page, bpage->order);kfree (bpage); }
@@ -1655,10 +1656,12 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,list_add (&bpage->list, pages); - page =alloc_pages_node (cpu_to_node (cpu_buffer->cpu), mflags,0 ); + page =alloc_pages_node (cpu_to_node (cpu_buffer->cpu), mflags, + cpu_buffer->buffer->subbuf_order);if (!page) goto free_pages; bpage->page =page_address (page); + bpage->order = cpu_buffer->buffer->subbuf_order;rb_init_page (bpage->page);if (user_thread &&fatal_signal_pending (current))
@@ -1737,7 +1740,8 @@ rb_allocate_cpu_buffer(struct trace_buffer *buffer, long nr_pages, int cpu)rb_check_bpage (cpu_buffer, bpage); cpu_buffer->reader_page = bpage; - page =alloc_pages_node (cpu_to_node (cpu),GFP_KERNEL ,0 ); + + page =alloc_pages_node (cpu_to_node (cpu),GFP_KERNEL , cpu_buffer->buffer->subbuf_order);if (!page) goto fail_free_reader; bpage->page =page_address (page);
@@ -1819,6 +1823,7 @@ struct trace_buffer *__ring_buffer_alloc(unsigned long size, unsigned flags, goto fail_free_buffer;/* Default buffer page size - one system page */ + buffer->subbuf_order =0 ; buffer->subbuf_size =PAGE_SIZE -BUF_PAGE_HDR_SIZE ;/* Max payload is buffer page size - header (8bytes) */
@@ -5636,8 +5641,8 @@ void *ring_buffer_alloc_read_page(struct trace_buffer *buffer, int cpu)if (bpage) goto out; - page =alloc_pages_node (cpu_to_node (cpu), -GFP_KERNEL | __GFP_NORETRY,0 ); + page =alloc_pages_node (cpu_to_node (cpu),GFP_KERNEL | __GFP_NORETRY, + cpu_buffer->buffer->subbuf_order);if (!page)return ERR_PTR (-ENOMEM );
@@ -5686,7 +5691,7 @@ void ring_buffer_free_read_page(struct trace_buffer *buffer, int cpu, void *datalocal_irq_restore (flags); out: -free_page ((unsigned long )bpage); +free_pages ((unsigned long )bpage, buffer->subbuf_order); }EXPORT_SYMBOL_GPL (ring_buffer_free_read_page);
@@ -5946,7 +5951,13 @@ EXPORT_SYMBOL_GPL(ring_buffer_subbuf_order_get);*/ int ring_buffer_subbuf_order_set (struct trace_buffer *buffer,int order) { +struct ring_buffer_per_cpu **cpu_buffers; +int old_order, old_size; +int nr_pages;int psize; +int bsize; +int err; +int cpu;if (!buffer || order <0 )return -EINVAL ;
@@ -5958,12 +5969,67 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)if (psize <=BUF_PAGE_HDR_SIZE )return -EINVAL ; + bsize =sizeof (void *) * buffer->cpus; + cpu_buffers =kzalloc (bsize,GFP_KERNEL ); +if (!cpu_buffers) +return -ENOMEM ; + + old_order = buffer->subbuf_order; + old_size = buffer->subbuf_size; + +/* prevent another thread from changing buffer sizes */ +mutex_lock (&buffer->mutex); +atomic_inc (&buffer->record_disabled); + +/* Make sure all commits have finished */ +synchronize_rcu (); + buffer->subbuf_order = order; buffer->subbuf_size = psize -BUF_PAGE_HDR_SIZE ; -/* Todo: reset the buffer with the new page size */ +/* Make sure all new buffers are allocated, before deleting the old ones */ +for_each_buffer_cpu (buffer, cpu) { +if (!cpumask_test_cpu (cpu, buffer->cpumask)) +continue ; + + nr_pages = buffer->buffers[cpu]->nr_pages; + cpu_buffers[cpu] =rb_allocate_cpu_buffer (buffer, nr_pages, cpu); +if (!cpu_buffers[cpu]) { + err = -ENOMEM ; + goto error; + } + } + +for_each_buffer_cpu (buffer, cpu) { +if (!cpumask_test_cpu (cpu, buffer->cpumask)) +continue ; + +rb_free_cpu_buffer (buffer->buffers[cpu]); + buffer->buffers[cpu] = cpu_buffers[cpu]; + } + +atomic_dec (&buffer->record_disabled); +mutex_unlock (&buffer->mutex); + +kfree (cpu_buffers);return 0 ; + +error: + buffer->subbuf_order = old_order; + buffer->subbuf_size = old_size; + +atomic_dec (&buffer->record_disabled); +mutex_unlock (&buffer->mutex); + +for_each_buffer_cpu (buffer, cpu) { +if (!cpu_buffers[cpu]) +continue ; +kfree (cpu_buffers[cpu]); + } +kfree (cpu_buffers); + +return err; }EXPORT_SYMBOL_GPL (ring_buffer_subbuf_order_set);
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 5/14 ring-buffer: Read and write to ring buffers with custom sub buffer size
In reply to Steven RostedtFrom: "Tzvetomir Stoyanov (VMware)" <[email protected]>
As the size of the ring sub buffer page can be changed dynamically, the logic that reads and writes to the buffer should be fixed to take that into account. Some internal ring buffer APIs are changed:
ring_buffer_alloc_read_page() ring_buffer_free_read_page()
ring_buffer_read_page()
A new API is introduced:
ring_buffer_read_page_data()
--- include/linux/ring_buffer.h | 11 ++-- kernel/trace/ring_buffer.c | 75 ++++++++++++++++++++-------- kernel/trace/ring_buffer_benchmark.c | 10 ++-- kernel/trace/trace.c | 34 +++++++------ 4 files changed, 89 insertions(+), 41 deletions(-)
include/linux/ring_buffer.h +8 -3
@@ -192,10 +192,15 @@ bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer);size_t ring_buffer_nr_pages (struct trace_buffer *buffer,int cpu);size_t ring_buffer_nr_dirty_pages (struct trace_buffer *buffer,int cpu); -void *ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu); -void ring_buffer_free_read_page (struct trace_buffer *buffer,int cpu,void *data); -int ring_buffer_read_page (struct trace_buffer *buffer,void **data_page, +struct buffer_data_read_page ; +struct buffer_data_read_page * +ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu); +void ring_buffer_free_read_page (struct trace_buffer *buffer,int cpu, +struct buffer_data_read_page *page); +int ring_buffer_read_page (struct trace_buffer *buffer, +struct buffer_data_read_page *data_page,size_t len,int cpu,int full); +void *ring_buffer_read_page_data (struct buffer_data_read_page *page);struct trace_seq ;
kernel/trace/ring_buffer.c +55 -20
173 lines not on this page · raw message
kernel/trace/ring_buffer_benchmark.c +6 -4
@@ -104,10 +104,11 @@ static enum event_status read_event(int cpu)static enum event_status read_page (int cpu) { +struct buffer_data_read_page *bpage;struct ring_buffer_event *event;struct rb_page *rpage;unsigned long commit; -void *bpage; +int page_size;int *entry;int ret;int inc;
@@ -117,14 +118,15 @@ static enum event_status read_page(int cpu)if (IS_ERR (bpage))return EVENT_DROPPED ; - ret =ring_buffer_read_page (buffer, &bpage,PAGE_SIZE , cpu,1 ); + page_size =ring_buffer_subbuf_size_get (buffer); + ret =ring_buffer_read_page (buffer, bpage, page_size, cpu,1 );if (ret >=0 ) { - rpage = bpage; + rpage =ring_buffer_read_page_data (bpage);/* The commit may have missed event flags set, clear them */ commit =local_read (&rpage->commit) &0xfffff ;for (i =0 ; i < commit && !test_error ; i += inc) { -if (i >= (PAGE_SIZE - offsetof(struct rb_page , data))) { +if (i >= (page_size - offsetof(struct rb_page , data))) {TEST_ERROR ();break ; }
kernel/trace/trace.c +20 -14
@@ -8271,6 +8271,8 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, {struct ftrace_buffer_info *info = filp->private_data;struct trace_iterator *iter = &info->iter; +void *trace_data; +int page_size;ssize_t ret =0 ;ssize_t size;
@@ -8282,6 +8284,8 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,return -EBUSY ;#endif + page_size =ring_buffer_subbuf_size_get (iter->array_buffer->buffer); +if (!info->spare) { info->spare =ring_buffer_alloc_read_page (iter->array_buffer->buffer, iter->cpu_file);
@@ -8296,13 +8300,13 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,return ret;/* Do we have previous read data to read? */ -if (info->read <PAGE_SIZE ) +if (info->read < page_size) goto read; again:trace_access_lock (iter->cpu_file); ret =ring_buffer_read_page (iter->array_buffer->buffer, - &info->spare, + info->spare, count, iter->cpu_file,0 );trace_access_unlock (iter->cpu_file);
@@ -8323,11 +8327,11 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, info->read =0 ; read: - size =PAGE_SIZE - info->read; + size = page_size - info->read;if (size > count) size = count; - - ret =copy_to_user (ubuf, info->spare + info->read, size); + trace_data =ring_buffer_read_page_data (info->spare); + ret =copy_to_user (ubuf, trace_data + info->read, size);if (ret == size)return -EFAULT ;
@@ -8438,6 +8442,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, .spd_release = buffer_spd_release, };struct buffer_ref *ref; +int page_size;int entries, i;ssize_t ret =0 ;
@@ -8446,13 +8451,14 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,return -EBUSY ;#endif -if (*ppos & (PAGE_SIZE -1 )) + page_size =ring_buffer_subbuf_size_get (iter->array_buffer->buffer); +if (*ppos & (page_size -1 ))return -EINVAL ; -if (len & (PAGE_SIZE -1 )) { -if (len <PAGE_SIZE ) +if (len & (page_size -1 )) { +if (len < page_size)return -EINVAL ; - len &=PAGE_MASK ; + len &= (~(page_size -1 )); }if (splice_grow_spd (pipe, &spd))
@@ -8462,7 +8468,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,trace_access_lock (iter->cpu_file); entries =ring_buffer_entries_cpu (iter->array_buffer->buffer, iter->cpu_file); -for (i =0 ; i < spd.nr_pages_max && len && entries; i++, len -=PAGE_SIZE ) { +for (i =0 ; i < spd.nr_pages_max && len && entries; i++, len -= page_size) {struct page *page;int r;
@@ -8483,7 +8489,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos, } ref->cpu = iter->cpu_file; - r =ring_buffer_read_page (ref->buffer, &ref->page, + r =ring_buffer_read_page (ref->buffer, ref->page, len, iter->cpu_file,1 );if (r <0 ) { ring_buffer_free_read_page(ref->buffer, ref->cpu,
@@ -8492,14 +8498,14 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,break ; } - page =virt_to_page (ref->page); + page =virt_to_page (ring_buffer_read_page_data (ref->page)); spd.pages[i] = page; - spd.partial[i].len =PAGE_SIZE ; + spd.partial[i].len = page_size; spd.partial[i].offset =0 ; spd.partial[i].private = (unsigned long )ref; spd.nr_pages++; - *ppos +=PAGE_SIZE ; + *ppos += page_size; entries =ring_buffer_entries_cpu (iter->array_buffer->buffer, iter->cpu_file); }
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 6/14 ring-buffer: Clear pages on error in ring_buffer_subbuf_order_set() failure
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
On failure to allocate ring buffer pages, the pointer to the CPU buffer pages is freed, but the pages that were allocated previously were not. Make sure they are freed too.
--- kernel/trace/ring_buffer.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/ring_buffer.c +1 -0
@@ -6060,6 +6060,7 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)for_each_buffer_cpu (buffer, cpu) {if (!cpu_buffers[cpu])continue ; +rb_free_cpu_buffer (cpu_buffers[cpu]);kfree (cpu_buffers[cpu]); }kfree (cpu_buffers);
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 7/14 ring-buffer: Do no swap cpu buffers if order is different
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
As all the subbuffer order (subbuffer sizes) must be the same throughout the ring buffer, check the order of the buffers that are doing a CPU buffer swap in ring_buffer_swap_cpu() to make sure they are the same.
If the are not the same, then fail to do the swap, otherwise the ring buffer will think the CPU buffer has a specific subbuffer size when it does not.
--- kernel/trace/ring_buffer.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/ring_buffer.c +3 -0
@@ -5550,6 +5550,9 @@ int ring_buffer_swap_cpu(struct trace_buffer *buffer_a,if (cpu_buffer_a->nr_pages != cpu_buffer_b->nr_pages) goto out; +if (buffer_a->subbuf_order != buffer_b->subbuf_order) + goto out; + ret = -EAGAIN ;if (atomic_read (&buffer_a->record_disabled))
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 8/14 ring-buffer: Make sure the spare sub buffer used for reads has same size
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Now that the ring buffer specifies the size of its sub buffers, they all need to be the same size. When doing a read, a swap is done with a spare page. Make sure they are the same size before doing the swap, otherwise the read will fail.
--- kernel/trace/trace.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
kernel/trace/trace.c +11 -0
@@ -7567,6 +7567,7 @@ struct ftrace_buffer_info {struct trace_iterator iter;void *spare;unsigned int spare_cpu; +unsigned int spare_size;unsigned int read; };
@@ -8286,6 +8287,15 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, page_size =ring_buffer_subbuf_size_get (iter->array_buffer->buffer); +/* Make sure the spare matches the current sub buffer size */ +if (info->spare) { +if (page_size != info->spare_size) { +ring_buffer_free_read_page (iter->array_buffer->buffer, + info->spare_cpu, info->spare); + info->spare =NULL ; + } + } +if (!info->spare) { info->spare =ring_buffer_alloc_read_page (iter->array_buffer->buffer, iter->cpu_file);
@@ -8294,6 +8304,7 @@ tracing_buffers_read(struct file *filp, char __user *ubuf, info->spare =NULL ; }else { info->spare_cpu = iter->cpu_file; + info->spare_size = page_size; } }if (!info->spare)
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 9/14 tracing: Update snapshot order along with main buffer order
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
When updating the order of the sub buffers for the main buffer, make sure that if the snapshot buffer exists, that it gets its order updated as well.
--- kernel/trace/trace.c | 45 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
kernel/trace/trace.c +43 -2
@@ -1263,10 +1263,17 @@ static void set_buffer_entries(struct array_buffer *buf, unsigned long val);int tracing_alloc_snapshot_instance (struct trace_array *tr) { +int order;int ret;if (!tr->allocated_snapshot) { +/* Make the snapshot buffer have the same order as main buffer */ + order =ring_buffer_subbuf_order_get (tr->array_buffer.buffer); + ret =ring_buffer_subbuf_order_set (tr->max_buffer.buffer, order); +if (ret <0 ) +return ret; +/* allocate spare buffer */ ret =resize_buffer_duplicate_size (&tr->max_buffer, &tr->array_buffer,RING_BUFFER_ALL_CPUS );
@@ -1286,6 +1293,7 @@ static void free_snapshot(struct trace_array *tr)* The max_tr ring buffer has some state (e.g. ring->clock) and * we want preserve it. */ +ring_buffer_subbuf_order_set (tr->max_buffer.buffer,0 );ring_buffer_resize (tr->max_buffer.buffer,1 ,RING_BUFFER_ALL_CPUS );set_buffer_entries (&tr->max_buffer,1 );tracing_reset_online_cpus (&tr->max_buffer);
@@ -9378,6 +9386,7 @@ buffer_order_write(struct file *filp, const char __user *ubuf, {struct trace_array *tr = filp->private_data;unsigned long val; +int old_order;int ret; ret =kstrtoul_from_user (ubuf, cnt,10 , &val);
@@ -9388,12 +9397,44 @@ buffer_order_write(struct file *filp, const char __user *ubuf,if (val <0 || val >7 )return -EINVAL ; + old_order =ring_buffer_subbuf_order_get (tr->array_buffer.buffer); +if (old_order == val) +return 0 ; + ret =ring_buffer_subbuf_order_set (tr->array_buffer.buffer, val);if (ret) -return ret; +return 0 ; - (*ppos)++; +#ifdef CONFIG_TRACER_MAX_TRACE +if (!tr->allocated_snapshot) + goto out_max; + + ret =ring_buffer_subbuf_order_set (tr->max_buffer.buffer, val); +if (ret) { +/* Put back the old order */ + cnt =ring_buffer_subbuf_order_set (tr->array_buffer.buffer, old_order); +if (WARN_ON_ONCE (cnt)) { +/* +* AARGH! We are left with different orders! +* The max buffer is our "snapshot" buffer. +* When a tracer needs a snapshot (one of the +* latency tracers), it swaps the max buffer +* with the saved snap shot. We succeeded to +* update the order of the main buffer, but failed to +* update the order of the max buffer. But when we tried +* to reset the main buffer to the original size, we +* failed there too. This is very unlikely to +* happen, but if it does, warn and kill all +* tracing. +*/ + tracing_disabled =1 ; + } +return ret; + } + out_max: +#endif + (*ppos)++;return cnt; }
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 10/14 tracing: Stop the tracing while changing the ring buffer subbuf size
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Because the main buffer and the snapshot buffer need to be the same for some tracers, otherwise it will fail and disable all tracing, the tracers need to be stopped while updating the sub buffer sizes so that the tracers see the main and snapshot buffers with the same sub buffer size.
--- kernel/trace/trace.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
kernel/trace/trace.c +10 -3
@@ -9397,13 +9397,16 @@ buffer_order_write(struct file *filp, const char __user *ubuf,if (val <0 || val >7 )return -EINVAL ; +/* Do not allow tracing while changing the order of the ring buffer */ +tracing_stop_tr (tr); + old_order =ring_buffer_subbuf_order_get (tr->array_buffer.buffer);if (old_order == val) -return 0 ; + goto out; ret =ring_buffer_subbuf_order_set (tr->array_buffer.buffer, val);if (ret) -return 0 ; + goto out;#ifdef CONFIG_TRACER_MAX_TRACE
@@ -9430,11 +9433,15 @@ buffer_order_write(struct file *filp, const char __user *ubuf,*/ tracing_disabled = 1; } -return ret; + goto out; } out_max: #endif (*ppos)++; + out: +if (ret) + cnt = ret; +tracing_start_tr (tr);return cnt; }
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 11/14 ring-buffer: Keep the same size when updating the order
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The function ring_buffer_subbuf_order_set() just updated the sub-buffers to the new size, but this also changes the size of the buffer in doing so. As the size is determined by nr_pages * subbuf_size. If the subbuf_size is increased without decreasing the nr_pages, this causes the total size of the buffer to increase.
This broke the latency tracers as the snapshot needs to be the same size as the main buffer. The size of the snapshot buffer is only expanded when needed, and because the order is still the same, the size becomes out of sync with the main buffer, as the main buffer increased in size without the tracing system knowing.
Calculate the nr_pages to allocate with the new subbuf_size to be buffer_size / new_subbuf_size.
--- kernel/trace/ring_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/trace/ring_buffer.c +4 -1
@@ -6030,7 +6030,10 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)if (!cpumask_test_cpu (cpu, buffer->cpumask))continue ; - nr_pages = buffer->buffers[cpu]->nr_pages; +/* Update the number of pages to match the new size */ + nr_pages = old_size * buffer->buffers[cpu]->nr_pages; + nr_pages =DIV_ROUND_UP (nr_pages, buffer->subbuf_size); + cpu_buffers[cpu] =rb_allocate_cpu_buffer (buffer, nr_pages, cpu);if (!cpu_buffers[cpu]) { err = -ENOMEM ;
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 12/14 ring-buffer: Just update the subbuffers when changing their allocation order
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
The ring_buffer_subbuf_order_set() was creating ring_buffer_per_cpu cpu_buffers with the new subbuffers with the updated order, and if they all successfully were created, then they the ring_buffer's per_cpu buffers would be freed and replaced by them.
The problem is that the freed per_cpu buffers contains state that would be lost. Running the following commands:
1. # echo 3 > /sys/kernel/tracing/buffer_subbuf_order
2. # echo 0 > /sys/kernel/tracing/tracing_cpumask
3. # echo 1 > /sys/kernel/tracing/snapshot
4. # echo ff > /sys/kernel/tracing/tracing_cpumask
5. # echo test > /sys/kernel/tracing/trace_marker
Would result in:
-bash: echo: write error: Bad file descriptor
That's because the state of the per_cpu buffers of the snapshot buffer is lost when the order is changed (the order of a freed snapshot buffer goes to 0 to save memory, and when the snapshot buffer is allocated again, it goes back to what the main buffer is).
In operation 2, the snapshot buffers were set to "disable" (as all the ring buffers CPUs were disabled).
In operation 3, the snapshot is allocated and a call to ring_buffer_subbuf_order_set() replaced the per_cpu buffers losing the "record_disable" count.
When it was enabled again, the atomic_dec(&cpu_buffer->record_disable) was decrementing a zero, setting it to -1. Writing 1 into the snapshot would swap the snapshot buffer with the main buffer, so now the main buffer is "disabled", and nothing can write to the ring buffer anymore.
Instead of creating new per_cpu buffers and losing the state of the old buffers, basically do what the resize does and just allocate new subbuf pages into the new_pages link list of the per_cpu buffer and if they all succeed, then replace the old sub buffers with the new ones. This keeps the per_cpu buffer descriptor in tact and by doing so, keeps its state.
--- kernel/trace/ring_buffer.c | 82 +++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 14 deletions(-)
kernel/trace/ring_buffer.c +68 -14
@@ -5989,7 +5989,8 @@ EXPORT_SYMBOL_GPL(ring_buffer_subbuf_order_get);*/ int ring_buffer_subbuf_order_set (struct trace_buffer *buffer,int order) { -struct ring_buffer_per_cpu **cpu_buffers; +struct ring_buffer_per_cpu *cpu_buffer; +struct buffer_page *bpage, *tmp;int old_order, old_size;int nr_pages;int psize;
@@ -6008,9 +6009,6 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)return -EINVAL ; bsize =sizeof (void *) * buffer->cpus; - cpu_buffers =kzalloc (bsize,GFP_KERNEL ); -if (!cpu_buffers) -return -ENOMEM ; old_order = buffer->subbuf_order; old_size = buffer->subbuf_size;
@@ -6027,33 +6025,85 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)/* Make sure all new buffers are allocated, before deleting the old ones */ for_each_buffer_cpu (buffer, cpu) { +if (!cpumask_test_cpu (cpu, buffer->cpumask))continue ; + cpu_buffer = buffer->buffers[cpu]; +/* Update the number of pages to match the new size */ nr_pages = old_size * buffer->buffers[cpu]->nr_pages; nr_pages =DIV_ROUND_UP (nr_pages, buffer->subbuf_size); - cpu_buffers[cpu] =rb_allocate_cpu_buffer (buffer, nr_pages, cpu); -if (!cpu_buffers[cpu]) { +/* we need a minimum of two pages */ +if (nr_pages <2 ) + nr_pages =2 ; + + cpu_buffer->nr_pages_to_update = nr_pages; + +/* Include the reader page */ + nr_pages++; + +/* Allocate the new size buffer */ +INIT_LIST_HEAD (&cpu_buffer->new_pages); +if (__rb_allocate_pages (cpu_buffer, nr_pages, + &cpu_buffer->new_pages)) { +/* not enough memory for new pages */ err = -ENOMEM ; goto error; } }for_each_buffer_cpu (buffer, cpu) { +if (!cpumask_test_cpu (cpu, buffer->cpumask))continue ; -rb_free_cpu_buffer (buffer->buffers[cpu]); - buffer->buffers[cpu] = cpu_buffers[cpu]; + cpu_buffer = buffer->buffers[cpu]; + +/* Clear the head bit to make the link list normal to read */ +rb_head_page_deactivate (cpu_buffer); + +/* Now walk the list and free all the old sub buffers */ +list_for_each_entry_safe (bpage, tmp, cpu_buffer->pages, list) { +list_del_init (&bpage->list); +free_buffer_page (bpage); + } +/* The above loop stopped an the last page needing to be freed */ + bpage = list_entry(cpu_buffer->pages, struct buffer_page, list); +free_buffer_page (bpage); + +/* Free the current reader page */ +free_buffer_page (cpu_buffer->reader_page); + +/* One page was allocated for the reader page */ + cpu_buffer->reader_page =list_entry (cpu_buffer->new_pages.next, + struct buffer_page, list); +list_del_init (&cpu_buffer->reader_page->list); + +/* The cpu_buffer pages are a link list with no head */ + cpu_buffer->pages = cpu_buffer->new_pages.next; + cpu_buffer->new_pages.next->prev = cpu_buffer->new_pages.prev; + cpu_buffer->new_pages.prev->next = cpu_buffer->new_pages.next; + +/* Clear the new_pages list */ +INIT_LIST_HEAD (&cpu_buffer->new_pages); + + cpu_buffer->head_page + = list_entry(cpu_buffer->pages, struct buffer_page, list); + cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page; + + cpu_buffer->nr_pages = cpu_buffer->nr_pages_to_update; + cpu_buffer->nr_pages_to_update =0 ; + +rb_head_page_activate (cpu_buffer); + +rb_check_pages (cpu_buffer); }atomic_dec (&buffer->record_disabled);mutex_unlock (&buffer->mutex); -kfree (cpu_buffers); -return 0 ; error:
@@ -6064,12 +6114,16 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)mutex_unlock (&buffer->mutex);for_each_buffer_cpu (buffer, cpu) { -if (!cpu_buffers[cpu]) + cpu_buffer = buffer->buffers[cpu]; + +if (!cpu_buffer->nr_pages_to_update)continue ; -rb_free_cpu_buffer (cpu_buffers[cpu]); -kfree (cpu_buffers[cpu]); + +list_for_each_entry_safe (bpage, tmp, &cpu_buffer->new_pages, list) { +list_del_init (&bpage->list); +free_buffer_page (bpage); + } } -kfree (cpu_buffers);return err; }
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 13/14 ring-buffer: Add documentation on the buffer_subbuf_order file
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add to the documentation how to use the buffer_subbuf_order file to change the size and how it affects what events can be added to the ring buffer.
--- Documentation/trace/ftrace.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
Documentation/trace/ftrace.rst +27 -0
@@ -203,6 +203,33 @@ of ftrace. Here is a list of some of the key files: This displays the total combined size of all the trace buffers. + buffer_subbuf_order: + + This sets or displays the sub buffer page size order. The ring buffer + is broken up into several same size "sub buffers". An event can not be + bigger than the size of the sub buffer. Normally, the sub buffer is + the size of the architecture's page (4K on x86). The sub buffer also + contains meta data at the start which also limits the size of an event. + That means when the sub buffer is a page size, no event can be larger + than the page size minus the sub buffer meta data. + + The buffer_subbuf_order allows the user to change the size of the sub + buffer. As the sub buffer is a set of pages by the power of 2, thus + the sub buffer total size is defined by the order: + + order size + ---- ---- + 0 PAGE_SIZE + 1 PAGE_SIZE * 2 + 2 PAGE_SIZE * 4 + 3 PAGE_SIZE * 8 + + Changing the order will change the sub buffer size allowing for events + to be larger than the page size. + + Note: When changing the order, tracing is stopped and any data in the + ring buffer and the snapshot buffer will be discarded. + free_buffer: If a process is performing tracing, and the ring buffer should be
Signature · 1 line
2.42.0
Steven Rostedt
maintainerPATCH 14/14 ringbuffer/selftest: Add basic selftest to test chaning subbuf order
In reply to Steven RostedtFrom: "Steven Rostedt (Google)" <[email protected]>
Add a self test that will write into the trace buffer with differ trace sub buffer order sizes.
--- .../ftrace/test.d/00basic/ringbuffer_order.tc | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc
tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc new file +46 -0
@@ -0,0 +1,46 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Change the ringbuffer size +# requires: buffer_subbuf_order +# flags: instance + +get_buffer_data_size() { + sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page +} + +a="1234567890" + +make_str() { + cnt=$1 + s="" + while [ $cnt -gt 10 ]; do + s="${s}${a}" + cnt=$((cnt-10)) + done + while [ $cnt -gt 0 ]; do + s="${s}X" + cnt=$((cnt-1)) + done + echo -n $s +} + +test_buffer() { + + size=`get_buffer_data_size` + + str=`make_str $size` + + echo $str > trace_marker + + grep -q $a trace +} + +ORIG=`cat buffer_subbuf_order` + +for a in `seq 0 4`; do + echo 0 > buffer_subbuf_order + test_buffer +done + +echo $ORIG > buffer_subbuf_order +
Signature · 1 line
2.42.0
Mathieu Desnoyers
reviewerOn 2023-12-09 22:54, Steven Rostedt wrote:
[...]
Quoted 11 lines
Basically, events to the tracing subsystem are limited to just under a
PAGE_SIZE, as the ring buffer is split into "sub buffers" of one page size, and an event can not be bigger than a sub buffer. This allows users to change the size of a sub buffer by the order:echo 3 >
/sys/kernel/tracing/buffer_subbuf_orderWill make each sub buffer a size of 8 pages, allowing events to be almost as big as 8 pages in size (sub buffers do have meta data on them as well, keeping an event from reaching the same size as a sub buffer).
Specifying the "order" of subbuffer size as a power of two of number of pages is a poor UX choice for a user-facing ABI.
I would recommend allowing the user to specify the size in bytes, and internally bump to size to the next power of 2, with a minimum of PAGE_SIZE.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
reviewerRe: [PATCH 14/14] ringbuffer/selftest: Add basic selftest to test chaning subbuf order
In reply to Steven RostedtOn 2023-12-09 22:54, Steven Rostedt wrote:
[...]
Quoted 19 lines
tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc new file +19
-0+get_buffer_data_size() { + sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page +} + +a="1234567890" + +make_str() { + cnt=$1 + s="" + while [ $cnt -gt 10 ]; do + s="${s}${a}" + cnt=$((cnt-10)) + done + while [ $cnt -gt 0 ]; do + s="${s}X" + cnt=$((cnt-1)) + done + echo -n $s +}
tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc line 35
Quoted 10 lines
tools/testing/selftests/ftrace/test.d/00basic/ringbuffer_order.tc new file +10
-0+ +test_buffer() { + + size=`get_buffer_data_size` + + str=`make_str $size` + + echo $str > trace_marker + + grep -q $a trace
This test has no clue if the record was truncated or not.
It basically repeats the string
"1234567890" until it fills the subbuffer size and pads with XXXX as needed as trace marker payload, but the grep looks for the "1234567890" pattern only.
The test should be extended to validate whether the trace marker payload was truncated or not, otherwise it is of limited value.
Thanks,
Mathieu
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Mathieu Desnoyers
reviewerRe: [PATCH 13/14] ring-buffer: Add documentation on the buffer_subbuf_order file
In reply to Steven RostedtOn 2023-12-09 22:54, Steven Rostedt wrote:
[...]
Documentation/trace/ftrace.rst of ftrace. Here is a list of some of the key files: · line 214
Quoted 9 lines
Documentation/trace/ftrace.rst +9
-0+ buffer_subbuf_order: + + This sets or displays the sub buffer page size order. The ring buffer + is broken up into several same size "sub buffers". An event can not be + bigger than the size of the sub buffer. Normally, the sub buffer is + the size of the architecture's page (4K on x86). The sub buffer also + contains meta data at the start which also limits the size of an event. + That means when the sub buffer is a page size, no event can be larger + than the page size minus the sub buffer meta data.
The fact that the user ABI documentation for this tracer parameter needs to dig into details about architecture page size is a good indicator that this ABI is not at the abstraction level it should be (pages vs bytes).
Thanks,
Mathieu
Quoted 21 lines
Documentation/trace/ftrace.rst +18
-0+ + The buffer_subbuf_order allows the user to change the size of the sub + buffer. As the sub buffer is a set of pages by the power of 2, thus + the sub buffer total size is defined by the order: + + order size + ---- ---- + 0 PAGE_SIZE + 1 PAGE_SIZE * 2 + 2 PAGE_SIZE * 4 + 3 PAGE_SIZE * 8 + + Changing the order will change the sub buffer size allowing for events + to be larger than the page size. + + Note: When changing the order, tracing is stopped and any data in the + ring buffer and the snapshot buffer will be discarded. + free_buffer: If a process is performing tracing, and the ring buffer should be
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com
Steven Rostedt
maintainerQuoted 14 lines · On Sun, 10 Dec 2023 09:17:44 -0500 Mathieu Desnoyers…
On 2023-12-09 22:54, Steven Rostedt wrote:
[...]Quoted 11 lines
Basically, events to the tracing subsystem are limited to just under a
PAGE_SIZE, as the ring buffer is split into "sub buffers" of one page size, and an event can not be bigger than a sub buffer. This allows users to change the size of a sub buffer by the order:echo 3 >
/sys/kernel/tracing/buffer_subbuf_orderWill make each sub buffer a size of 8 pages, allowing events to be almost as big as 8 pages in size (sub buffers do have meta data on them as well, keeping an event from reaching the same size as a sub buffer).
Quoted 6 lines
Specifying the "order" of subbuffer size as a power of two of number of pages is a poor UX choice for a user-facing ABI.
I would recommend allowing the user to specify the size in bytes, and internally bump to size to the next power of 2, with a minimum of
PAGE_SIZE.
Thanks. I actually agree with you and thought about doing just that, but decided to not make those changes and send out these patches with the given API first. I wanted to see if you would comment on this ;-) You did not disappoint!
I was thinking of keeping the same kind of interface as we have with the buffer size "buffer_size_kb", and have it be "buffer_subbuf_size_kb", where you specify the minimum size in kilobytes and it creates it, and the subbuf may end up being bigger than specified (as that's more a implementation detail).
Now that you called it out, I will add a patch to convert that as such. But will keep the current patches in for historical reasons.
-- Steve
Steven Rostedt
maintainerRe: [PATCH 14/14] ringbuffer/selftest: Add basic selftest to test chaning subbuf order
In reply to Mathieu DesnoyersQuoted 10 lines · On Sun, 10 Dec 2023 09:26:13 -0500 Mathieu Desnoyers…
This test has no clue if the record was truncated or not.
It basically repeats the string
"1234567890" until it fills the subbuffer size and pads with XXXX as needed as trace marker payload, but the grep looks for the "1234567890" pattern only.
The test should be extended to validate whether the trace marker payload was truncated or not, otherwise it is of limited value.
It can be, but for now it's just testing to make sure it doesn't crash. I ran out of time, and if someone else wants to extend this, go ahead. Currently, my testing has been just manual observations. I threw this in just to have some kind of smoke test applied.
I agree with the API changes, and will update that. But given that this has been two years and never applied, is because nobody has the time to work on this. The reason I'm pushing for this now, is because Kent hit the limit in his work. Knowing that he would not have hit this limit if these patches were applied, I feel more urgency on getting them in. But this is all on my own time, not part of my Employer (hence why I'm working on the weekend).
-- Steve