wb_get_lookup(9)
π wb_get_lookup(9) β from the Kernel API Manual, bestie
okay so picture this: you're deep in the kernel, you've got a bdi, you've got a memcg_css, and you need the wb that goes with them. that's literally this whole page. welcome π«Ά
β¨ NAME β¨
wb_get_lookup β get wb for a given memcg π
πΈ SYNOPSIS πΈ
struct bdi_writeback * wb_get_lookup (struct backing_dev_info *bdi ,
struct cgroup_subsys_state *memcg_css );
π ARGUMENTS π
bdiβ the target bdi. that's the one, the main character of the arg list π«memcg_cssβ thecgroup_subsys_stateof the target memcg. and listen, it must have positive ref β that's not a suggestion, that's the vibe check β
π¦ DESCRIPTION π¦
So the whole point: try to get the wb for memcg_css on bdi. and bestie, the returned wb? its refcount has been incremented. so you're holding a reference, act accordingly π
This function uses css_get on memcg_css, and because of that it expects its refcnt to be positive on invocation. IOW β and this is the part people get wrong π β rcu_read_lock protection on memcg_css isn't enough. nope. not it. you gotta try_get it before calling this function. fr fr. π
A wb is keyed by its associated memcg. and here's why that slay: as blkcg implicitly enables memcg on the default hierarchy, the memcg association is guaranteed to be more specific β equal to, or a descendant of, the associated blkcg β and thus it can identify both the memcg and blkcg associations. one key, two identities. iconic π
Now the plot twist π: the blkcg associated with a memcg may change, because blkcg gets enabled and disabled closer to root in the hierarchy. so to keep things honest, each wb keeps track of both the memcg and blkcg associated with it, and verifies the blkcg on each lookup. and on mismatch? the existing wb is discarded and a new one is created. out with the old, in with the new, no cap π
β οΈ quick reminder before you go: positive ref onmemcg_cssat call time,try_getit first.rcu_read_lockalone is not the move. don't do it bestie π
π§ SEE ALSO π§
- Kernel file
./mm/backing-dev.c wb_get_create(9)wb_memcg_offline(9)wb_blkcg_offline(9)bdi_get_by_id(9)
go read those too, iykyk πβ¨
and that's the whole page, bestie! this lil gem lives in ./mm and is dated October 2026 β so like, from the future, which is very main character of it. study up, pass it on, and don't forget the try_get. mwah πππ₯
π¦ 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