ww_mutex_lock_interruptible(9)
π ww_mutex_lock_interruptible β Kernel API Manual β¨
okay so bestie, welcome to the ww_mutex_lock_interruptible page from the Kernel API Manual ππ this one is all about grabbing a w/w mutex the interruptible way, and honestly it's giving "polite but firm" energy. let's get into it π
β¨ SYNOPSIS β¨
int ww_mutex_lock_interruptible (struct ww_mutex *lock , struct
ww_acquire_ctx *ctx );
that's the whole signature, no cap π«Ά
πΈ ARGUMENTS πΈ
lockβ the mutex to be acquired π like, the actual thing you're trying to get your hands onctxβ the w/w acquire context π« the vibe-check context that keeps the whole w/w thing coordinated
π DESCRIPTION π
Lock the w/w mutex exclusively for this task. exclusive, bestie, meaning it's yours and nobody else's while you hold it π
Deadlocks within a given w/w class of locks are detected and handled with the wait/die algorithm π€ and yes that's as dramatic as it sounds:
- if the lock isn't immediately available, this function will either sleep until it is (the wait case) π΄
- or it selects the current context for backing off by returning
-EDEADLK(the die case) π
Trying to acquire the same lock with the same context twice is also detected, and it gets signalled by returning -EALREADY π like, you already have it, girl.
Returns 0 if the mutex was successfully acquired π And if a signal arrives while waiting for the lock, then this function returns -EINTR β‘οΈ (that's the "interruptible" part of the whole deal, iykyk).
β οΈ 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_interruptible. 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).
π¦ the rules of ownership π¦
okay this part is important so listen up fr fr:
- The mutex must later on be released by the same task that acquired it. no passing it off to your friend, bestie π«Ά
- The task may not exit without first unlocking the mutex. like, you can't just dip πββοΈ
- Also, kernel memory where the mutex resides must not be freed with the mutex still locked. nope. not allowed. π₯
- The mutex must first be initialized (or statically defined) before it can be locked.
memset-ing the mutex to0is not allowed π«π ββοΈ (that's an absolute no)- The mutex must be of the same w/w lock class as was used to initialize the acquire context. matching vibes only β¨
π
And a mutex acquired with this function must be released with ww_mutex_unlock.
π SEE ALSO π
Kernel file ./include/linux/ww_mutex.h and all these iconic little functions:
ww_mutex_init(9)ww_acquire_init(9)ww_acquire_done(9)ww_acquire_fini(9)ww_mutex_lock(9)ww_mutex_lock_slow(9)ww_mutex_lock_slow_interruptible(9)ww_mutex_is_locked(9)
and that's the page!! πβ¨
this whole thing lives in ./include/linux π, and the version/date situation is October 2026 β so like, future girly vibes, we love to see it π¦π mwah, go forth and 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