swap_cache_get_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… swap_cache_get_folio β€” like, the kernel API manual, bestie ✨

okay so this is a page straight out of the Kernel API Manual (swap_cache_get_folio(9), section 9, we love a numbered section) and it's literally the cheat sheet for looking up a folio in the swap cache. tiny page, big main character energy πŸŽ€


🌸 NAME 🌸

swap_cache_get_folio β€” looks up a folio in the swap cache. that's it, that's the whole vibe πŸ¦‹


✨ SYNOPSIS ✨

struct folio * swap_cache_get_folio (swp_entry_t entry );

copy it exactly like that, no cap πŸ™ˆ


πŸ“ ARGUMENTS πŸ“

  • entry β€” the swap entry you're using for the lookup. that's the key you're searching with πŸ”‘

πŸ’– DESCRIPTION πŸ’–

so when a folio is found, it comes back to you unlocked and with its refcount increased. yes, you read that right β€” unlocked. do not assume it's ready to use, bestie 😭 (more on that in RETURN).


πŸ‘‘ CONTEXT πŸ‘‘

this is the part where you gotta do your homework, fr fr:

  • the caller must make sure entry is valid, and
  • the caller must protect the swap device with a reference count or locks.
like, this isn't optional. handle your business before you call in πŸ’…

πŸ”₯ RETURN πŸ”₯

  • on success: the found folio πŸ’–
  • otherwise: NULL πŸ’€

and here's the part that gets people every single time: the caller must lock and check if the folio still matches the swap entry before use (e.g. with folio_matches_swap_entry). the folio you got might not be the folio anymore β€” vibe check it first, ngl 🧚


🌈 SEE ALSO 🌈

Kernel file ./mm/swap_state.c, plus the whole friend group:


alright bestie, that's the page 🫢 it lives in ./mm, it's dated October 2026, and it's filed under swap_cache_get_folio(9). go get that folio (unlocked, refcount bumped, and checked β€” periodt) β­πŸ’œ

πŸ“¦ where this page comes from