swap_cache_alloc_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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's MPOL_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:

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