lru_cache_drain_for_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 NAME β€” lru_cache_drain_for_folio(9) from the Kernel API Manual 🌸

okay bestie, this page is literally about lru_cache_drain_for_folio β€” and its whole thing is: drain LRU caches if the caches might hold folio references. πŸ’…βœ¨


✨ SYNOPSIS ✨

void lru_cache_drain_for_folio (const struct folio *folio , unsigned int
extra_refs , enum lru_cache_drained *drained );

🫢 ARGUMENTS 🫢

  • folio β€” the folio. πŸ¦‹
  • extra_refs β€” extra folio references held by the caller. πŸ’–
  • drained β€” drain status for batch folio processing. πŸŽ€

πŸ’… DESCRIPTION πŸ’…

okay so the mission is: drain LRU caches if the caches might hold folio references. πŸ‘‘ It starts with a local LRU cache drain, and then β€” if local draining was insufficient β€” it drains LRU caches on all CPUs. that's the escalation arc, no cap. πŸ”₯

Now the detection part: this function detects LRU cache references by comparing the folio refcount with the sum of the expected folio refcount + extra references held by the caller. πŸ” literally comparing refcounts, that's the vibe.

⚠️ and bestie, do not come for PG_lru here: we cannot rely on PG_lru to reliably detect all LRU cache references. there are rare scenarios β€” concurrent folio (un)mapping) β€” where this function might miss detecting LRU cache references. πŸ’€ keep that in mind, fr fr.

If drained is not NULL, the function will avoid re-draining LRU caches when processing multiple folios in a row. πŸŽ€ in that case, the variable drained points at must be initialized to LRU_CACHE_NOT_DRAINED before the first invocation by the caller. do not skip the setup, bestie β€” that's the whole point. 🫢


🌈 SEE ALSO 🌈

Kernel file ./mm/folio.c:


πŸ’‹ mwah! this cutie came from the source ./mm, dated October 2026, and it's literally the lru_cache_drain_for_folio(9) page. periodt. πŸ’…πŸŒΈ

πŸ“¦ where this page comes from