preempt_disable_nested(9)
π 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:
seqcountwrite side critical sections where theseqcountisn'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 πRMWper CPU variable updates likevmstatπ
π SEE ALSO π
- Kernel file
./include/linux/preempt.hποΈ interrupt_context_level(9)preempt_enable_nested(9)β the lil sibling that undoes the vibe π«Ά
bestie reminder: this only exists so CPU local serialization actually holds up onPREEMPT_RT. don't go thinking it does anything extra on the non-PREEMPT_RTside β it's aNOPthere, 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms