raw_atomic_fetch_sub(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME

okay so bestie, welcome to the raw_atomic_fetch_sub(9) page from the Kernel API Manual β€” this is the one about atomic subtract with full ordering ✨. It’s giving β€œI do math on shared memory and I do it safely” energy, and honestly? Iconic.

✨ SYNOPSIS

int raw_atomic_fetch_sub (int i , atomic_t *v );

πŸŽ€ ARGUMENTS

  • i β€” an int value to subtract. This is the amount you’re taking off, bestie πŸ’…
  • v β€” pointer to atomic_t. This is the atomic thing getting updated, no cap.

🌸 DESCRIPTION

Atomically updates v to (v - i) with full ordering. Translation: the subtract happens as one atomic operation, and the full ordering is there too β€” so this function is not playing around with memory ordering. Periodt.

It’s safe to use in noinstr code; prefer atomic_fetch_sub elsewhere. So yes, she’s the raw/under-the-hood option, and regular atomic_fetch_sub is the one you should reach for outside that special noinstr situation. Iykyk 🫢

Vibe check: noinstr safe? Yes. Should you use this everywhere instead of atomic_fetch_sub? No bestie β€” the page literally says prefer atomic_fetch_sub elsewhere. πŸ’€

πŸ’– RETURN

The original value of v β€” like, the value it had before the subtraction, not the new one. That’s the whole point, and she ate. πŸ”₯

πŸ¦‹ SEE ALSO

Kernel file: ./include/linux/atomic/atomic-arch-fallback.h

Not me listing the entire atomic extended family, but she did πŸ’€ Here’s the full guest list:

okay signing off from the <pink>./include/linux/atomic</pink> corner of the kernel, October 2026 edition, for raw_atomic_fetch_sub(9) β€” source/version and date noted, mwah bestie, go subtract atomically and stay hydrated πŸ«ΆπŸ’–βœ¨

πŸ“¦ where this page comes from