swap_cache_get_folio(9)
π 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
entryis 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:
swap_cache_has_folio(9)swap_cache_get_shadow(9)__swap_cache_add_check(9)__swap_cache_add_folio(9)__swap_cache_del_folio(9)swap_cache_del_folio(9)__swap_cache_replace_folio(9)swap_cache_alloc_folio(9)swap_update_readahead(9)swapin_sync(9)swap_cluster_readahead(9)swap_vma_readahead(9)swapin_readahead(9)
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
- 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