✨ From vibe coding to vibe deployment. UBOS MCP turns ideas into infra with one message.

Learn more
Andrii Bidochko
  • Updated: January 19, 2026
  • 7 min read

Rust Read_once and Write_once: Memory Safety and Programming News

READ_ONCE() and WRITE_ONCE() are Linux‑kernel macros that force a single, non‑optimised read or write to a memory location, while Rust developers are debating whether to create analogous macros or simply rely on the language’s Atomic types for safe, lock‑free concurrency.

What the LWN discussion revealed

The Linux Weekly News (LWN) published a detailed thread on January 9 2026 about the future of READ_ONCE() and WRITE_ONCE() in the kernel’s emerging Rust codebase. The conversation highlighted three core questions:

  • Do we need Rust‑specific equivalents of these macros?
  • Can the existing Atomic crate express the same guarantees more clearly?
  • What are the broader implications for kernel developers who must juggle C and Rust APIs?

Below we break down the technical background, the community’s arguments, and why this debate matters for anyone building low‑level, memory‑safe software.

Background: READ_ONCE() and WRITE_ONCE() in the Linux kernel

These macros live in include/asm-generic/rwonce.h and were introduced in Linux 3.18 (2014). Their purpose is two‑fold:

  1. Volatile access: Prevent the compiler from merging, re‑ordering, or eliminating the read/write.
  2. Atomicity guarantee: Ensure that a concurrent read sees either the value before or after a write, never a torn intermediate state.

Importantly, the macros do not impose memory‑ordering barriers; they only stop the compiler from performing optimisations that could break lock‑less algorithms. This makes them a lightweight tool for high‑performance code that cannot afford the overhead of full memory fences.

Why Rust developers care about READ_ONCE/WRITE_ONCE

Rust’s core promise is memory safety without a garbage collector. When the kernel started accepting Rust modules, developers expected the language’s strong type system and Atomic primitives to replace many of the C‑only tricks. The key motivations are:

  • Explicit intent: Rust’s AtomicU32::load(Ordering::Relaxed) makes the programmer’s intention crystal clear, whereas READ_ONCE() is a “band‑aid” that hides intent behind a macro.
  • Safety guarantees: The Rust compiler enforces that atomic types cannot be accessed without the proper API, reducing the risk of data races.
  • Cross‑language consistency: As more kernel code moves to Rust, having a single, well‑documented concurrency model simplifies onboarding for new contributors.

Community debate: Rust‑specific macros vs. the Atomic crate

When Alice Ryhl submitted a patch series adding READ_ONCE() and WRITE_ONCE() for Rust, the response was mixed. Gary Guo and Boqun Feng argued that the Atomic crate already provides the needed guarantees, and that introducing duplicate macros would muddy the API surface.

Key points raised by the community

Concern Proposed Solution
Semantic ambiguity of READ_ONCE/WRITE_ONCE Prefer Atomic::load(Relaxed) to make atomicity explicit.
Potential for duplicated code paths (C vs. Rust) Standardise on Rust’s atomic API and deprecate macro wrappers.
Performance overhead concerns Relaxed atomics have negligible overhead on modern CPUs; they are cheaper than full fences.

The consensus leaned toward using the Atomic crate, citing clearer intent, better tooling support, and alignment with the Linux Kernel Memory Model (LKMM).

Technical comparison: C macros vs. Rust atomics

Below is a side‑by‑side look at how the two approaches behave on typical architectures (x86‑64, ARMv8, RISC‑V).

  • Compiler guarantees: READ_ONCE() relies on volatile casts; Rust atomics are built into the language semantics.
  • Ordering control: C macros provide no ordering; Rust atomics let you choose Relaxed, Acquire, Release, or SeqCst.
  • Portability: On architectures lacking native atomic instructions, Rust disables the corresponding Atomic type, forcing developers to handle the limitation explicitly. The C macros silently fall back to volatile accesses, which may be unsafe.
  • Debugging support: Rust’s type system surfaces misuse at compile time; C macros can hide bugs until runtime.

Implications for kernel developers and Rust adoption

Choosing Rust’s atomic API over macro wrappers has ripple effects across the kernel ecosystem:

  1. Codebase divergence: C and Rust sections will use different primitives, requiring developers to be fluent in both.
  2. Documentation overhaul: Existing C code that assumes plain writes are atomic will need to be audited and possibly replaced with WRITE_ONCE() or proper atomics.
  3. Tooling improvements: Static analysis tools like KCSAN can more easily detect missing atomic annotations when Rust code follows a strict API.
  4. Performance tuning: Relaxed atomics often compile down to a single load/store, matching the performance of volatile reads while providing stronger guarantees.

In practice, this means that future kernel contributors will likely see a hybrid model: C code continues to use READ_ONCE()/WRITE_ONCE() for legacy paths, while new Rust modules adopt the Atomic crate.

Quote highlights from the LWN thread

“The problem of READ_ONCE() and WRITE_ONCE() is that the semantics is complicated. Sometimes they are used for atomicity, sometimes they are used for preventing data race.” – Boqun Feng

“Using the Atomic crate allows developers to specify more precisely which guarantees an operation needs, making the expectations of the code more clear.” – Gary Guo

These statements capture the core tension: clarity versus convenience. The kernel community is leaning toward clarity, which aligns with Rust’s philosophy.

Read the full discussion on LWN

For a comprehensive view of the arguments, see the original LWN article that documents the patch series, community feedback, and the final decision.

Explore related resources on UBOS

While the kernel debate focuses on low‑level concurrency, many developers are also building higher‑level AI‑driven services that benefit from Rust’s safety guarantees. UBOS offers a suite of tools and templates that can accelerate your projects:

If you’re looking for ready‑made AI applications that already embody safe concurrency patterns, the UBOS Template Marketplace offers dozens of examples. A few that align closely with kernel‑level concepts include:

Conclusion: A clear path forward for safe kernel concurrency

The LWN discussion makes it evident that the Linux kernel community values clarity, safety, and future‑proofing over short‑term convenience. By favouring Rust’s Atomic crate, developers gain:

  • Explicit memory‑ordering semantics.
  • Compile‑time checks that prevent accidental data races.
  • Better alignment with the Linux Kernel Memory Model.

For teams building both kernel‑level components and high‑performance AI services, embracing Rust’s atomic primitives now will pay dividends in maintainability and performance.

Ready to experiment with safe concurrency in your own projects? Start with a UBOS template today and see how Rust’s guarantees can simplify your codebase.


Andrii Bidochko

CTO UBOS

Andrii Bidochko is an AI entrepreneur and researcher focused on AI agents, reinforcement learning, and autonomous systems. He writes about the technologies shaping the future of machine intelligence, from frontier models and agent architectures to real-world AI applications.

Sign up for our newsletter

Stay up to date with the roadmap progress, announcements and exclusive discounts feel free to sign up with your email.

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.