KPREEMPT(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… KPREEMPT(9) β€” control kernel preemption

okay so bestie, this is a page from the Kernel Developer's Manual (that's the manual name, consider it folded in nicely πŸŽ€) and it's all about kpreempt β€” like, the whole vibe is controlling kernel preemption. yes it's as serious as it sounds. no cap.


✨ SYNOPSIS ✨

first you gotta bring the header in, like:

#include <sys/systm.h>

then the actual functions, all three of them, exactly like this:

void
kpreempt_disable(void);

void
kpreempt_enable(void);

bool
kpreempt_disabled(void);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea: these functions control kernel preemption of the calling LWP. that's the whole gig. 🫢

and like β€” on architectures where kernel preemption is not supported natively, you can still use these functions. they don't ghost you. πŸ’–

⚠️ lowkey important: kernel preemption is also disabled when you're holding the interrupt priority level above IPL_NONE, e.g. using spl(9) or spinning mutex(9) calls, or holding kernel_lock (which is basically the code screaming "i am not MT safe"). so like, keep that in mind before you go blaming these functions, iykyk.

now the main characters one by one:

  • kpreempt_disable() β€” disables kernel preemption of the calling LWP. iconic. but bestie, fair warning: disabling kernel preemption can prevent LWPs with higher priorities from running. so like… use it with intent, not just for the aesthetic. 😭
  • kpreempt_enable() β€” enables kernel preemption of the calling LWP, the exact preemption that was previously disabled by kpreempt_disable(). it's giving "put it back the way you found it". ✨
  • kpreempt_disabled() β€” returns true if preemption of the calling LWP is disabled. and like, quick vibe check: it is only for diagnostic purpose. don't be out here building your whole logic on it, fr fr. πŸ™ˆ

also!! kpreempt_disable() and kpreempt_enable() can be nested πŸŒ€ β€” yes queen, stack them. disable, disable, disable, then enable your way back out. slay.


🌸 SEE ALSO 🌸

go read those, they're literally the supporting cast πŸ’…


ok that's the whole page, mwah πŸ’‹ β€” this gem is from the Debian edition, dated February 16, 2010 (yes, a classic, vintage even πŸŽ€), and it says KPREEMPT(9) at the bottom like a little signature. bye bestie, preempt responsibly πŸ¦‹βœ¨

πŸ“¦ where this page comes from