STRUCT FUTEX_Q(9)
π struct futex_q(9)
okay bestie, buckle up β this is a page from the Kernel API Manual, and it's about struct futex_q, which is the hashed futex queue entry, one per waiting task. literally one for every task that's waiting. iconic behavior tbh π
β¨ NAME β¨
struct futex_q β the hashed futex queue entry, one per waiting task π¦
π§ SYNOPSIS π§
struct futex_q {
struct plist_node list;
struct task_struct *task;
spinlock_t *lock_ptr;
futex_wake_fn *wake;
void *wake_data;
union futex_key key;
struct futex_pi_state *pi_state;
struct rt_mutex_waiter *rt_waiter;
union futex_key *requeue_pi_key;
u32 bitset;
atomic_t requeue_state;
struct futex_private_hash *drop_fph;
#ifdef CONFIG_PREEMPT_RT;
struct rcuwait requeue_wait;
#endif;
};
like, that's the whole shape of it. every field accounted for, no notes π
πΈ Members πΈ
okay so here's the cast of characters, one by one, no skips:
listβ priority-sorted list of tasks waiting on this futex. yes, sorted, it's giving organized queen energy πtaskβ the task waiting on the futex. the main character of this entry ngllock_ptrβ the hash bucket lock πwakeβ the wake handler for this queuewake_dataβ data associated with the wake handler. it's the handler's little plus-one π«Άkeyβ the key the futex is hashed onpi_stateβ optional priority inheritance state. optional! it's giving only if you're that girl β¨rt_waiterβrt_waiterstorage for use withrequeue_pirequeue_pi_keyβ therequeue_pitarget futex keybitsetβ bitset for the optional bitmasked wakeuprequeue_stateβ State field forfutex_requeue_pidrop_fphβ Waiter should drop the extra private hash reference when setrequeue_waitβ RCU wait forfutex_requeue_pi(RT only) β³
π Description π
so like, why does this even exist? We use this hashed waitqueue, instead of a normal wait_queue_entry_t, so we can wake only the relevant ones (hashed queues may be shared). lowkey a flex, but a necessary one β no cap π
A futex_q has a woken state, just like tasks have TASK_RUNNING. It is considered woken when:
plist_node_empty(q->list) || q->lock_ptr == 0
and the order of wakeup is always to make the first condition true, then the second. don't flip them, bestie, that's the whole ritual π―οΈ
PI futexes are typically woken before they are removed from the hash list via the rt_mutex code. see futex_unqueue_pi. π¦
π₯ SEE ALSO π₯
Kernel file ./kernel/futex/futex.h futex_match(9), futex_queue(9), struct futex_vector(9) β go read those next, iykyk π
okay that's the whole page, mwah π this one lives in ./kernel/futex, dated October 2026 β shoutout to that directory for keeping it real, and to the Kernel API Manual for the hosting gig πβ¨
π¦ 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