wb_get_lookup(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 β€” the cgroup_subsys_state of 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 on memcg_css at call time, try_get it first. rcu_read_lock alone is not the move. don't do it bestie 😭

🧚 SEE ALSO 🧚

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