futex_proxy_trylock_atomic(9)
π futex_proxy_trylock_atomic(9) π
okay so bestie, welcome to the kernel API manual β this one lives in section 9 (the kernel developer zone, iykyk) and it's literally called futex_proxy_trylock_atomic. yes that's a mouthful. no we're not renaming it. it's iconic and we respect it π«Ά
β¨ NAME β¨
futex_proxy_trylock_atomic β Attempt an atomic lock for the top waiter
like... it tries to grab the lock for the top waiter, atomically. that's the whole vibe check. π
πΈ SYNOPSIS πΈ
int futex_proxy_trylock_atomic (u32 __user *pifutex , struct
futex_hash_bucket *hb1 , struct futex_hash_bucket *hb2 , union futex_key
*key1 , union futex_key *key2 , struct futex_pi_state **ps , struct
task_struct **exiting , int set_waiters );
look at all those parameters. main character energy fr fr. π
π¦ ARGUMENTS π¦
pifutexβ the user address of the to futex. yep, "the to futex" β that's the wording, we're keeping it, don't come for me πhb1β the from futex hash bucket, and it must be locked by the caller. not optional. it's giving "you had one job" πhb2β the to futex hash bucket, which also must be locked by the caller. same energy.key1β the from futex key ποΈkey2β the to futex key ποΈpsβ address to store thepi_statepointer. it's a pointer to a pointer, we love a double pointer moment β¨exitingβ Pointer to store the task pointer of the owner task which is in the middle of exiting. lowkey dramatic but okay πset_waitersβ force setting theFUTEX_WAITERSbit (1) or not (0). binary queen. either you're setting it or you're not π
π DESCRIPTION π
So the whole point: Try and get the lock on behalf of the top waiter if we can do it atomically. Wake the top waiter if we succeed. literally "I gotchu bestie, here's the lock, go off π".
If the caller specified set_waiters, then it directs futex_lock_pi_atomic to force setting the FUTEX_WAITERS bit. just passing along the instruction, no cap. π―
And hb1 and hb2 must be held by the caller. like, both of them. held. by you. before you call this. π
Now the important bit, pay attention: exiting is only set when the return value is -EBUSY. If so, this holds a refcount on the exiting task on return and the caller needs to drop it after waiting for the exit to complete. so if you see -EBUSY, don't just walk away β you're holding a refcount, and you gotta drop it once the exit finishes. it's giving responsibility π
π₯ RETURN π₯
0β failed to acquire the lock atomically; π no lock for you>0β acquired the lock, return value is vpid of thetop_waiterπ slay<0β error π
π SEE ALSO π
Kernel file ./kernel/futex/requeue.c β plus all these besties:
requeue_futex(9)requeue_pi_wake_futex(9)futex_requeue(9)handle_early_requeue_pi_wakeup(9)futex_wait_requeue_pi(9)
go read them. iykyk π§
β οΈ friendly reminder bestie:hb1andhb2must be locked by the caller, and if you get-EBUSYback you are holding a refcount on the exiting task. drop it after waiting for the exit to complete or the vibes will be rancid. fr fr.
and that's the page!! brought to you by ./kernel/futex, dated October 2026 β mwah, ily, go lock something atomically πβ¨π
π¦ 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