Magic Buffers and io_uring Registered Buffers

Hacker News Top Tools

Summary

The article explores using mmap to create a magic ring buffer where two contiguous virtual memory ranges map the same physical memory, and tests its compatibility with io_uring's registered buffers, finding that it works as expected.

No content available
Original Article
View Cached Full Text

Cached at: 06/18/26, 05:47 AM

# Magic Buffers and io_uring Registered Buffers – Some Assembly Required Source: [https://www.mindfruit.co.uk/posts/2025/10/magic-buffers-and-io-uring-write-fixed/](https://www.mindfruit.co.uk/posts/2025/10/magic-buffers-and-io-uring-write-fixed/) There’s a really cool little`mmap`gadget that maps the same underlying memory region into two contiguous virtual memory address ranges\. When you write past the end of the first mapped region, the remaining bytes end up in the second mapped region \(*and*at the start of the first one\)\. Fabien Giesen calls this a “[Magic Ring Buffer](https://fgiesen.wordpress.com/2012/07/21/the-magic-ring-buffer/)”, which is good enough for me\. I wondered whether the virtual memory contortions would survive contact with IO Uring’s registered buffers\. It turns out \(spoiler alert\) that they do, and it’s virtual memory all the way down\. I wrote a little test application, and have published it on my Github with some more comments[here](https://github.com/michael-g/mgkdb/tree/master/iou)\. Essentially, what the app does is: 1. Constructs a Magic Buffer \(using my`MgCircularBuffer`implementation[here](https://github.com/michael-g/mgkdb/blob/master/io/src/MgCircularBuffer.cpp), I know … it’s not circular\) 2. Uses`io\_uring\_register\_buffers`to register the buffer’s “double extent” with the kernel 3. Writes a kdb IPC message across the “seam” in the magic buffer 4. Uses`io\_uring\_prep\_write\_fixed`to send the message to a couple of connected KDB instances It works as expected\.

Similar Articles

Exploring automatic Buffer Management with io_uring

Lobsters Hottest

The article details the implementation of automatic buffer management using io_uring's buffer rings in UringMachine, a Ruby gem for asynchronous I/O. It explains how buffer rings enable efficient multishot read/recv operations by allowing the kernel to use application-provided buffers.

Premature Optimization is Fun Sometimes

Lobsters Hottest

A blog post exploring the optimization of a ring buffer data structure for storing ping timestamps, discussing tagged unions, bitfields, and struct padding to reduce memory footprint.

Epoll vs. Io_uring in Linux

Hacker News Top

A technical comparison of epoll and io_uring in Linux, explaining their architectures and performance characteristics for asynchronous I/O.