Zero-Copy Pages in Rust: Or How I Learned To Stop Worrying And Love Lifetimes

April 16, 2026
A child appears stressed and frustrated while seated in a library, holding their head.
Photo by Mikhail Nilov on Pexels

What the post says

A new deep-dive explains how to build zero-copy pages in Rust to avoid needless memcpy()s between disk, kernel and a database’s buffer pool. It has been reported that the technique can make a huge difference in throughput when working sets no longer fit in CPU caches — who wouldn’t want to shave off those wasted cycles? The write-up walks through the classic database stack, points out the two painful copy boundaries (OS and between buffer pool and upper layers), and sets up why eliding copies matters for high‑performance engines.

How it works in Rust

The author shows a practical path: use direct I/O (O_DIRECT) to bypass the page cache and then make sure your user-space pages meet the kernel’s alignment and size rules. In Rust that’s solved with #[repr(align(4096))] on page buffers and performing page-aligned, 4 KiB I/O. Lifetimes are the quiet hero here — Rust’s borrowing rules let you hand out references to pages without making fresh copies, keeping safety and performance both intact. There’s also code: the post links to a repository so you can poke under the hood and try it yourself.

Caveats and the big picture

It’s not magic. The kernel can still force a bounce buffer (swiotlb) on 32‑bit DMA or in some confidential‑computing VMs, reintroducing copies — so be careful where you deploy this. The post also nods to the old Linus rant about direct I/O (he’s not a fan of naïve database tricks), and notes that while many modern databases use O_DIRECT, others like Postgres are more conservative. Allegedly, when done right this pattern meaningfully reduces CPU churn under load; the code and examples make it easier to test that claim in your environment. In short: fewer memcpys, more throughput — and yes, Rust lifetimes suddenly look a lot less scary.

Sources: redixhumayun.github.io, Lobsters