atomic_fetch_sub_relaxed(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– NAME πŸ’–

okay so welcome to the Kernel API Manual, bestie β€” today’s main character is atomic_fetch_sub_relaxed, and she’s literally an atomic subtract with relaxed ordering. no cap. 🫢


✨ SYNOPSIS ✨

int atomic_fetch_sub_relaxed (int i , atomic_t *v );

πŸŽ€ ARGUMENTS πŸŽ€

  • i β€” the int value you’re subtracting. that’s the amount getting yeeted. πŸ’…
  • v β€” pointer to an atomic_t. this is the lucky variable getting updated. πŸŽ€

πŸ¦‹ DESCRIPTION πŸ¦‹

so here’s the vibe: this function atomically updates v to (v - i) with relaxed ordering. like, it does the subtraction all at once, no messy in-between state, periodt. ✨

⚠️ but bestie, careful β€” it’s unsafe to use in noinstr code. use raw_atomic_fetch_sub_relaxed there instead. no exceptions, fr fr. πŸ’€

🌸 RETURN 🌸

it returns the original value of v β€” like, the value before the subtraction happened. it’s giving β€œreceipts before the glow-up.” πŸ’…πŸ”₯


πŸ’… SEE ALSO πŸ’…

kernel file: ./include/linux/atomic/atomic-instrumented.h, plus literally the whole atomic family (iykyk):

first up, the atomic_ crew:

then the atomic64_ girlies:

and finally the atomic_long_ squad:


source: ./include/linux/atomic Β· date: October 2026 Β· page: atomic_fetch_sub_relaxed(9) β€” mwah, slay, bye bestie πŸ’‹πŸŒˆ

πŸ“¦ where this page comes from