ww_acquire_init(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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:


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