atomic_sub_return(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… atomic_sub_return(9) β€” Kernel API Manual, but make it make sense

okay so bestie, welcome to atomic_sub_return(9), your new fave little kernel function from the Kernel API Manual. she's small, she's atomic, she has full ordering, and she's about to subtract a number from your atomic_t like it's nothing. slay.


✨ NAME ✨

atomic_sub_return β€” atomic subtract with full ordering. that's it, that's the whole vibe. subtracting that also returns, no cap. πŸŽ€


🌸 SYNOPSIS 🌸

int atomic_sub_return (int i , atomic_t *v );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • i β€” the int value you're subtracting. the amount going bye-bye. πŸ’¨
  • v β€” a pointer to the atomic_t you're messing with. this is the main character.

πŸ’œ DESCRIPTION πŸ’œ

so here's the tea: she atomically updates v to (v - i) with full ordering. atomically means nobody else can sneak in halfway through and see a cursed in-between state β€” it all happens as one glamorous unit. ✨ and full ordering means the memory ordering is strict, not vibes-only.

okay so this one matters: it's unsafe to use in noinstr code. if you're living in noinstr land, use raw_atomic_sub_return there instead. fr fr, do not test this. πŸ’€

πŸ‘‘ RETURN πŸ‘‘

the updated value of v. like, after the subtraction. the new number. the fresh look. 🫢


🌈 SEE ALSO 🌈

the kernel file this lives in is ./include/linux/atomic/atomic-instrumented.h β€” and honestly the friend group here is huge, so buckle up, we're naming everyone at the party:

and now the 64-bit girlies, atomic64_ edition:

and finally the atomic_long_ crew, the long-distance icons:


okay that's the whole squad 🫢 and before you go β€” this page came from the kernel file ./include/linux/atomic, dated October 2026, under the atomic_sub_return(9) tag. mwah, bye bestie πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from