swap_vma_readahead(9)
๐ swap_vma_readahead โ kernel API manual, bestie edition
okay so welcome to swap_vma_readahead(9), the lil function that goes "hmm what if we need these pages soon" and justโฆ grabs them. iconic behavior tbh. ๐ฆ
โจ NAME โจ
swap_vma_readahead โ swap in pages in hope we need them soon ๐
like, manifesting pages into memory. the audacity. the vision. ๐ฎ
๐ธ SYNOPSIS ๐ธ
struct folio * swap_vma_readahead (swp_entry_t targ_entry , gfp_t
gfp_mask , struct mempolicy *mpol , pgoff_t targ_ilx , struct vm_fault
*vmf );
she returns a struct folio *, she takes five whole arguments, she's booked and busy ๐
๐ ARGUMENTS ๐
targ_entryโ the swap entry of the targeted memory. like, the actual thing we're going after ๐ฏgfp_maskโ memory allocation flags. the vibes for how we allocate โจmpolโ the NUMA memory allocation policy to be applied. NUMA said "let me handle this" ๐targ_ilxโ the NUMA interleave index, and heads up bestie, it's for use only whenMPOL_INTERLEAVEโ don't be using it otherwise ๐vmfโ fault information. the lore. the context. ๐
๐ฆ DESCRIPTION ๐ฆ
So what she does: she returns the struct folio for entry and addr, after queueing swapin. โจ
This is the primitive swap readahead code, no cap. We simply read in a few pages whose virtual addresses are around the fault address in the same vma. that's it. that's the whole bit. surrounding pages, same vma, grab a few, hope for the best ๐ซถ
heads up bestie ๐ โ the caller must hold readmmap_lockifvmf->vmais not NULL. like, mandatory. non-negotiable. do not skip this step fr fr.
๐ 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_cache_alloc_folio(9)swap_update_readahead(9)swapin_sync(9)swap_cluster_readahead(9)swapin_readahead(9)
๐ธ okay that's the whole page, ily, go read some swap cache code ๐
sign-off era: this one lives in ./mm, dated October 2026, and it's swap_vma_readahead(9) โ that's a wrap bestie ๐โจ๐ซถ
๐ฆ 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