swait_active(9)
okay so bestie, welcome to swait_active(9) from the Kernel API Manual β this one's a tiny little lockless vibe check for waitqueues, and she's giving main character energy: small, iconic, and not to be underestimated π
β¨
π NAME π
swait_active - - locklessly test for waiters on the queue
β¨ SYNOPSIS β¨
int swait_active (struct swait_queue_head *wq );
π ARGUMENTS π
wqβ the waitqueue to test for waiters π«Ά
π¦ DESCRIPTION π¦
returns true if the wait list is not empty. lowkey that's the whole plot, and honestly? obsessed β¨
π NOTE π
okay bestie, this function is lockless and requires care β like, incorrect usage _will_ lead to sporadic and non-obvious failure. no cap, fr fr, do not treat this like a cute little shortcut without reading the fine print π iykyk
NOTE2: this function has the same above implications as regular waitqueues.
Use either while holding swait_queue_head::lock or when used for wakeups with an extra smp_mb like:
CPU0 - waker CPU1 - waiter
for (;;) { cond = true;
prepare_to_swait_exclusive(wq_head, wait, state); smp_mb;
// smp_mb from set_current_state if (swait_active(wq_head)) if
(cond) wake_up(wq_head); break; schedule; }
finish_swait(wq_head, wait);
Because without the explicit smp_mb it's possible for the swait_active load to get hoisted over the cond store such that we'll observe an empty wait list while the waiter might not observe cond. This, in turn, can trigger missing wakeups. missing wakeups are not a slay, periodt π
Also note that this 'optimization' trades a spin_lock for an smp_mb, which (when the lock is uncontended) are of roughly equal cost. ngl, that's the trade-off, bestie π
π SEE ALSO π
Kernel file ./include/linux/swait.h β plus swq_has_sleeper(9), swait_event_idle_exclusive(9), and swait_event_idle_timeout_exclusive(9) π¦ iykyk, go read those too.
that's the whole page, bestie π«Ά source path/version: ./include/linux, dated October 2026, and the page itself is swait_active(9) β periodt πβ¨
π¦ 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