ww_mutex_lock(9)
π ww_mutex_lock β the girlies' guide to grabbing the w/w mutex β¨
okay so this is from the Kernel API Manual, section 9 (kernel interfaces, iykyk), and bestie, we're about to learn how to take a w/w mutex the correct way. no cap. π
β¨ NAME β¨
ww_mutex_lock β acquire the w/w mutex. that's it. that's the whole vibe. π
π¦ SYNOPSIS π¦
int ww_mutex_lock (struct ww_mutex *lock , struct ww_acquire_ctx *ctx );
πΈ ARGUMENTS πΈ
lockβ the mutex to be acquired. the thing you want. your main character mutex. πctxβ w/w acquire context, orNULLto acquire only a single lock. yeah,NULLis totally valid here β it literally just means "one lock only, no group chat." π«Ά
π DESCRIPTION π
Lock the w/w mutex exclusively for this task. nobody else gets in. periodt. π₯
Deadlocks within a given w/w class of locks are detected and handled with the wait/die algorithm. so like, if the lock isn't immediately available, this function will either:
- sleep until it is (that's the wait case π΄), or
- select the current context for backing off by returning
-EDEADLK(that's the die case π).
Trying to acquire the same lock with the same context twice is also detected and signalled by returning -EALREADY. happens to the best of us, ngl. π
Returns 0 if the mutex was successfully acquired. slay. β¨
π§ the die case, explained (because it's giving complications)
In the die case the caller must release all currently held w/w mutexes for the given context, and then wait for this contending lock to be available by calling ww_mutex_lock_slow.
Alternatively, callers can opt to not acquire this lock and proceed with trying to acquire further w/w mutexes β e.g. when scanning through lru lists trying to free resources. sometimes you just gotta let it go and move on, bestie. π¦
β οΈ rules, rules, rules (do NOT skip these, fr fr)
- The mutex must later on be released by the same task that acquired it. no passing it off to your friend. π―
- The task may not exit without first unlocking the mutex.
- Kernel memory where the mutex resides must not be freed with the mutex still locked.
- The mutex must first be initialized (or statically defined) before it can be locked.
memset-ing the mutex to 0 is not allowed. like, don't. π- The mutex must be of the same w/w lock class as was used to initialize the acquire context. it's giving "matching set energy." π
A mutex acquired with this function must be released with ww_mutex_unlock. that's the whole point of the cycle, okay?? π
π SEE ALSO π
- Kernel file
./include/linux/ww_mutex.h ww_mutex_init(9)ww_acquire_init(9)ww_acquire_done(9)ww_acquire_fini(9)ww_mutex_lock_interruptible(9)ww_mutex_lock_slow(9)ww_mutex_lock_slow_interruptible(9)ww_mutex_is_locked(9)
all the friends in the same friend group, honestly. go read them. π
and that's the tea! π this iconic little page lives at ./include/linux, dated October 2026, and it's literally called ww_mutex_lock(9) β ok bye, love you, lock responsibly! π
πβ¨
π¦ 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