ww_acquire_init(9)
β¨ ww_acquire_init β¨
okay so bestie, welcome to the kernel API manual (Kernel API Manual, that's the series, iykyk) β this one's ww_acquire_init, and it's literally the opening move for wound/wait mutexes. let's go π
π NAME π
ww_acquire_init β initialize a w/w acquire context
like, it sets up your whole acquire-context situation so you can grab a bunch of those w/w mutexes without the kernel having a whole meltdown π«Ά
πΈ SYNOPSIS πΈ
void ww_acquire_init (struct ww_acquire_ctx *ctx , struct ww_class *ww_class );
π¦ ARGUMENTS π¦
ctxβ the w/w acquire context you're initializing. this is the thing getting its glow-up β¨ww_classβ the w/w class of the context. the family it belongs to, fr fr
π DESCRIPTION π
so what it actually does: it initializes a context so you can acquire multiple mutexes of the given w/w class. iconic behavior, no cap π
the way context-based w/w mutex acquiring works? you can do it in any order whatsoever within a given lock class. literally any order. and if a deadlock happens anyway, it gets detected and handled with the wait/die logic. the kernel's got you π«‘
now the strict part, bestie, pay attention π
Mixing context-based w/w mutex acquiring with single w/w mutex locking can result in undetected deadlocks, and is therefore forbidden. π«
and also:
Mixing different contexts for the same w/w class when acquiring mutexes can also result in undetected deadlocks, so that's also forbidden. π«π«
both flavors of abuse get caught if you enable CONFIG_PROVE_LOCKING β that's your vibe check for lock abuse, and it will clock you π
the good news? nesting acquire contexts for _different_ w/w classes is possible β just subject to the usual locking rules between different lock classes. so like, nesting is fine across classes, not within one. got it? π§
and a little housekeeping rule, because of course there is one:
an acquire context must be released with ww_acquire_fini by the same task, before the memory is freed. π
the manual also recommends allocating the context itself on the stack. stack-allocated contexts are the main character here, honestly π
π₯ SEE ALSO π₯
kernel file ./include/linux/ww_mutex.h, plus the whole friend group:
ww_mutex_init(9)ww_acquire_done(9)ww_acquire_fini(9)ww_mutex_lock(9)ww_mutex_lock_interruptible(9)ww_mutex_lock_slow(9)ww_mutex_lock_slow_interruptible(9)ww_mutex_is_locked(9)
that's the whole page, bestie β and before you go, the β¨ official receipt β¨: this one lives in ./include/linux (that's the source, the whole version sitch) and it's dated October 2026. slay, go init your context, and don't forget to ww_acquire_fini on the way out ππ
π¦ 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