preempt_disable_nested(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… preempt_disable_nested(9) πŸ’…

okay bestie, buckle up, this one's from the Kernel API Manual and it's honestly kinda iconic once you get what it's doing πŸŽ€


✨ NAME ✨

preempt_disable_nested β€” disables preemption inside a section that's already normally preempt-disabled. yes, nested. yes, that's the whole point. slay 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

preempt_disable_nested

that's it. no arguments, no drama, just vibes ✨


πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜• β€” you use this for code that needs preemption protection inside a critical section that's already implicitly preemption-disabled on kernels that are not PREEMPT_RT enabled. and how does that happen, you ask? by, like, things such as:

  • holding a spinlock/rwlock πŸ”’
  • soft interrupt context ⚑
  • regular interrupt handlers πŸ›ŽοΈ

now on PREEMPT_RT enabled kernels, things are different, and this is the part where it gets spicy 🌢️ β€” spinlock/rwlock held sections, soft interrupt context, and regular interrupt handlers are preemptible and only prevent migration. so preempt_disable_nested steps in and makes sure preemption is actually disabled for the cases that need CPU local serialization, even on PREEMPT_RT. and for non-PREEMPT_RT kernels? it's literally a NOP. no cap, it just sits there looking pretty πŸ’€

the use cases are code sequences that are not serialized by a particular lock instance, like:

  • seqcount write side critical sections where the seqcount isn't associated to a particular lock and therefore the automatic protection mechanism doesn't work 🚫. this is what prevents a live lock against a preempting high priority reader. very main character energy of it, honestly πŸ‘‘
  • RMW per CPU variable updates like vmstat πŸ“Š

🌈 SEE ALSO 🌈


bestie reminder: this only exists so CPU local serialization actually holds up on PREEMPT_RT. don't go thinking it does anything extra on the non-PREEMPT_RT side β€” it's a NOP there, periodt πŸ’…

and that's the whole page, mwah πŸ’‹ β€” this cutie lives in ./include/linux, it's dated October 2026, and it's brought to you by the preempt_disable_nested(9) era of the kernel docs. go forth and nest your preempt disables responsibly, ily πŸ§šπŸ’œ

πŸ“¦ where this page comes from