ring_buffer_read_page(9)
π« NAME π«
ring_buffer_read_page β the function that yanks a whole page out of the ring buffer and consumes it, no take-backs π«Ά
This lil guy lives in the Kernel API Manual, section 9. Yeah bestie, we're in the kernel now β bring snacks π
β¨ SYNOPSIS β¨
int ring_buffer_read_page (struct trace_buffer *buffer , struct
buffer_data_read_page *data_page , size_t len , int cpu , int full );
That's the whole signature, character for character, don't @ me π
π ARGUMENTS π
bufferβ the buffer we're extracting from. the main character of this whole operation, honestly πdata_pageβ the page you're gonna use, and it must be one allocated fromring_buffer_alloc_read_page. no substitutions, no randoms πlenβ how much you want to extract πΈcpuβ the cpu of the buffer you're extracting from π¦fullβ should the extraction only happen when the page is full? that's the vibe check right there β
π DESCRIPTION π
okay so here's the tea β β this function pulls out a page from the ring buffer and consumes it. Like, it's gone. eaten. ate and left no crumbs π₯
data_page seriously has to be the address of the variable that was returned from ring_buffer_alloc_read_page. Not a copy, not a cousin of it β the address of the variable itself. Why? because the page might be used to swap with a page in the ring buffer, and if you passed something else it would not slay π
for example, literally right here:
rpage = ring_buffer_alloc_read_page(buffer, cpu);
if (IS_ERR(rpage))
return PTR_ERR(rpage);
ret = ring_buffer_read_page(buffer, rpage, len, cpu, 0);
if (ret >= 0)
process_page(ring_buffer_read_page_data(rpage), ret);
ring_buffer_free_read_page(buffer, cpu, rpage);
see how rpage gets passed in? yeah. that's the whole point π«Ά
when full is set, the function will not return true unless the writer is off the reader page. like, it's picky and it's valid for being picky β¨
π NOTE π
it is up to the calling functions to handle sleeps and wakeups, fr fr π the ring buffer can be used anywhere in the kernel, so it can not blindly call wake_up. the layer that uses the ring buffer must be responsible for that. that's on you bestie, not on the buffer π
β RETURN β
>=0β data has been transferred! π it returns the offset of consumed data.<0β no data has been transferred π nothing happened, no page for you.
π¦ SEE ALSO π¦
Kernel file ./kernel/trace/ring_buffer.c β and the whole extended friend group π
ring_buffer_event_length(9)ring_buffer_event_data(9)rb_page_capacity(9)rb_subbuf_capacity(9)rb_subbuf_max_data_size(9)rb_subbuf_start(9)ring_buffer_event_time_stamp(9)ring_buffer_nr_dirty_pages(9)ring_buffer_wake_waiters(9)ring_buffer_wait(9)ring_buffer_poll_wait(9)rb_check_pages(9)rb_validate_buffer(9)__ring_buffer_alloc(9)__ring_buffer_alloc_range(9)__ring_buffer_alloc_remote(9)ring_buffer_free(9)ring_buffer_resize(9)rb_update_event(9)ring_buffer_nest_start(9)ring_buffer_nest_end(9)ring_buffer_unlock_commit(9)ring_buffer_lock_reserve(9)ring_buffer_discard_commit(9)ring_buffer_write(9)ring_buffer_record_disable(9)ring_buffer_record_enable(9)ring_buffer_record_off(9)ring_buffer_record_on(9)ring_buffer_record_is_on(9)ring_buffer_record_is_set_on(9)ring_buffer_record_is_on_cpu(9)ring_buffer_record_disable_cpu(9)ring_buffer_record_enable_cpu(9)ring_buffer_oldest_event_ts(9)ring_buffer_bytes_cpu(9)ring_buffer_entries_cpu(9)ring_buffer_overrun_cpu(9)ring_buffer_commit_overrun_cpu(9)ring_buffer_dropped_events_cpu(9)ring_buffer_read_events_cpu(9)ring_buffer_entries(9)ring_buffer_overruns(9)ring_buffer_iter_reset(9)ring_buffer_iter_empty(9)ring_buffer_peek(9)ring_buffer_iter_peek(9)ring_buffer_consume(9)ring_buffer_read_start(9)ring_buffer_read_finish(9)ring_buffer_iter_advance(9)ring_buffer_size(9)ring_buffer_max_event_size(9)ring_buffer_reset_cpu(9)ring_buffer_reset_online_cpus(9)ring_buffer_reset(9)ring_buffer_empty(9)ring_buffer_empty_cpu(9)ring_buffer_swap_cpu(9)ring_buffer_alloc_read_page(9)ring_buffer_free_read_page(9)ring_buffer_read_page_data(9)ring_buffer_read_page_size(9)ring_buffer_subbuf_size_get(9)ring_buffer_subbuf_order_get(9)ring_buffer_subbuf_order_set(9)
okay that's the whole page, no cap π this beauty ships out of ./kernel/trace, dated October 2026, and it's manual page ring_buffer_read_page(9) from the Kernel API Manual. go read a ring buffer, bestie β you're gonna eat πΈβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms