swap_cluster_readahead(9)
π swap_cluster_readahead β Kernel API Manual, section 9 π
okay bestie, gather round, because this one is literally the "manifesting your swap-ins" function and I'm obsessed β¨
πΈ NAME πΈ
swap_cluster_readahead β swap in pages in hope we need them soon π (yes, that's the actual energy, the kernel is out here hoping, and honestly? relatable.)
π¦ SYNOPSIS π¦
struct folio * swap_cluster_readahead (swp_entry_t entry , gfp_t
gfp_mask , struct mempolicy *mpol , pgoff_t ilx );
like, it returns a struct folio * pointer, and it takes four things. we'll get to each one, don't worry π«Ά
β ARGUMENTS β
entryβ the swap entry of this memory. it's the thing we're trying to bring back, iykyk π₯gfp_maskβ the memory allocation flags. your whole "how am I allowed to allocate" vibe check.mpolβ the NUMA memory allocation policy that gets applied. NUMA said "let me cook" πilxβ the NUMA interleave index, for use only when it'sMPOL_INTERLEAVE. not any other time, bestie, that's the rule π
β¨ DESCRIPTION β¨
So what does it actually do? It returns the struct folio for entry and addr, after queueing swapin. π
It's the primitive swap readahead code. "Primitive" here is not a read, it's literally just describing the approach β and the approach is: we simply read an aligned block of (1 << page_cluster) entries in the swap area. One big aligned chomp of swap π
Why this method? Because it doesn't cost us any seek time. Zero. None. Slay π
And we also make sure to queue the 'original' request together with the readahead ones... π§
no cap, this is the humble little workhorse of speculative swapping: read a whole aligned cluster because it's basically free, and hope the neighbours come in handy π
π NOTE π
It is intentional that the same NUMA policy and interleave index are used for every page of the readahead. Why? Because neighbouring pages on swap are fairly likely to have been swapped out from the same node. So like, same node, same policy, same ilx, every single page β main character consistency, periodt π₯
π SEE ALSO π
Kernel file ./mm/swap_state.c β and honestly the whole swap_cache & swapin 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_vma_readahead(9)swapin_readahead(9)
okay that's the whole page, you ate that π
and for the record: this lil' gem lives in ./mm, it's dated October 2026, and it's section 9 of the Kernel API Manual. go forth and readahead responsibly, 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