ring_buffer_read_page(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« 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 from ring_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 πŸ‘‘


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