swap_vma_readahead(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… 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 when MPOL_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 read mmap_lock if vmf->vma is 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:


๐ŸŒธ 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