summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorVincent Donnefort <vdonnefort@google.com>2026-09-11 20:39:37 +0100
committerSteven Rostedt <rostedt@goodmis.org>2026-10-15 18:31:09 -0400
commit20d432b4454b54f32afaaa1b0ac336078c3b6be7 (patch)
tree2db2badc2a3e96b849890254f5c76ecfa1e0add7 /include/linux
parent8acb31975a55e5cf3efc36750dad5d0788ff8bb7 (diff)
downloadlinux-20d432b4454b54f32afaaa1b0ac336078c3b6be7.tar.gz
linux-20d432b4454b54f32afaaa1b0ac336078c3b6be7.zip
ring-buffer: Unify ring buffer minimum page calculations
The codebase scatters hardcoded minimum page limits across multiple places. Introduce RING_BUFFER_MIN_NR_PAGES and rb_calculate_nr_pages() to formalize the requirement of two pages in a ring buffer. Link: https://patch.msgid.link/20260911193937.602202-4-vdonnefort@google.com Signed-off-by: Vincent Donnefort <vdonnefort@google.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/ring_buffer.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index eac3e9080c3c..e4370064273e 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -99,6 +99,13 @@ struct trace_buffer *__ring_buffer_alloc_range(unsigned long size, unsigned flag
void *ring_buffer_meta_scratch(struct trace_buffer *buffer, unsigned int *size);
/*
+ * A minimum of 2 pages ensures we can always swap a page out of the ring
+ * buffer. This does not account for the reader page or any other page
+ * containing meta data used by static ring buffers.
+ */
+#define RING_BUFFER_MIN_NR_PAGES 2UL
+
+/*
* Because the ring buffer is generic, if other users of the ring buffer get
* traced by ftrace, it can produce lockdep warnings. We need to keep each
* ring buffer's lock class separate.
@@ -287,7 +294,7 @@ static inline struct ring_buffer_desc *__first_ring_buffer_desc(struct trace_buf
static inline unsigned long __calc_nr_pages_ring_buffer_desc(size_t size)
{
/* Takes into account the reader page */
- return max(DIV_ROUND_UP(size, PAGE_SIZE - BUF_PAGE_HDR_SIZE), 2UL) + 1;
+ return max(DIV_ROUND_UP(size, PAGE_SIZE - BUF_PAGE_HDR_SIZE), RING_BUFFER_MIN_NR_PAGES) + 1;
}
static inline size_t trace_buffer_desc_size(size_t buffer_size, unsigned int nr_cpus)