swap_cache_alloc_folio(9)
π swap_cache_alloc_folio β the kernel API manual, but make it cute
okay so bestie, welcome to section 9 of the Kernel API Manual, and today's main character is swap_cache_alloc_folio π
β¨ NAME β¨
swap_cache_alloc_folio β literally allocating a folio for a swapped-out slot in the swap cache π¦
πΈ SYNOPSIS πΈ
struct folio * swap_cache_alloc_folio (swp_entry_t targ_entry , gfp_t
gfp , unsigned long orders , struct vm_fault *vmf , struct mempolicy
*mpol , pgoff_t ilx );
like, six arguments, no cap. she's high maintenance but she's worth it π
π«Ά ARGUMENTS π«Ά
targ_entryβ the swap entry that points at the target slot. this is the one you're shopping for β¨gfpβ the memory allocation flags. the vibe settings for how we allocate, basically.ordersβ the allocation orders. must be non-zero, fr fr, zero is not it πvmfβ the fault information. all the deets about the fault that brought us here.mpolβ the NUMA memory allocation policy to be applied. yes we're being picky about where the memory lives πilxβ the NUMA interleave index. only for use when it'sMPOL_INTERLEAVE, iykyk.
π DESCRIPTION π
so what she does: she allocates a folio in the swap cache for one swap slot. typically this happens before doing IO β think swap in, or zswap writeback π
the swap slot that targ_entry points at must have a non-zero swap count, meaning it's actually swapped out. that's the vibe check it has to pass β
π₯ CONTEXT π₯
the caller has to protect the swap device β either with a reference count or with locks. no freelancing, bestie, protect your device π€
β RETURN β
- she returns the folio if the allocation succeeded and the folio is chillin' in the swap cache π
- she returns an error code if it failed β because of a race, OOM, or invalid arguments. and yes, invalid arguments is a real one, so mind your
ordersπ
π¦ SEE ALSO π¦
kernel file ./mm/swap_state.c and honestly the whole friend group:
swap_cache_get_folio(9)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_update_readahead(9)swapin_sync(9)swap_cluster_readahead(9)swap_vma_readahead(9)swapin_readahead(9)
like, the entire swap cache friend group showed up to the group chat ππ
and that's the page!! sourced from ./mm, dated October 2026 β mwah, go read your swap cache code bestie, slay π§ββοΈππ«
π¦ 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