waitqueue_active(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– NAME πŸ’–

okay so this is waitqueue_active(9), straight out of the Kernel API Manual, and it’s here to locklessly test for waiters on the queue. That’s the whole name vibe, bestie. ✨


✨ SYNOPSIS ✨

int waitqueue_active (struct wait_queue_head *wq_head );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • wq_head β€” the waitqueue to test for waiters. That’s it, that’s the argument. 🫢

πŸ’… DESCRIPTION πŸ’…

It returns true if the wait list is not empty. That’s the behavior, no cap. πŸ‘‘


⚠️ NOTE ⚠️

this function is lockless and requires care, incorrect usage _will_ lead to sporadic and non-obvious failure. πŸ’€

Use either while holding wait_queue_head::lock or when used for wakeups with an extra smp_mb like:

            CPU0 - waker                    CPU1 - waiter

                                            for (;;) {
            cond = true;                     prepare_to_wait(wq_head, wait, state);
            smp_mb;                         // smp_mb from set_current_state
            if (waitqueue_active(wq_head))         if (cond)
              wake_up(wq_head);                      break;
                                              schedule;
                                            }
                                            finish_wait(wq_head, wait);

Because without the explicit smp_mb it's possible for the waitqueue_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.

Also note that this 'optimization' trades a spin_lock for an smp_mb, which (when the lock is uncontended) are of roughly equal cost.


🌈 SEE ALSO 🌈

Kernel file ./include/linux/wait.h

okay bestie, that’s the whole page β€” source/version: ./include/linux, date: October 2026, page: waitqueue_active(9) β€” byeee, go check your wait list πŸ’–πŸ‘‹

πŸ“¦ where this page comes from