folio_dup_swap(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… folio_dup_swap(9)

okay so this is a page straight out of the Kernel API Manual, bestie β€” it's called folio_dup_swap(9) and honestly? it's giving "small helper, big responsibility." let's get into it ✨


🌸 NAME

folio_dup_swap β€” bump up the swap count on the swap entries of a folio. that's the whole vibe. no cap πŸ’…


πŸŽ€ SYNOPSIS

int folio_dup_swap (struct folio *folio , struct page *page );

like, yes, it returns an int, and yes, it takes exactly those two things. copy it exactly, bestie, don't get creative 🫢


πŸ¦‹ ARGUMENTS

  • folio β€” the folio that has swap entries bounded to it. this is the main character of the whole operation πŸ‘‘
  • page β€” if this isn't NULL, then we only increase the swap count of this specific page. if it is NULL, we're doing the whole folio. iykyk ✨

🌈 DESCRIPTION

okay so here's the tea πŸ“ β€” this one typically gets called when the folio is unmapped and its swap entry is stepping in to take its place.

swap entries allocated to a folio start out with count == 0 and they're pinned by the swap cache. and here's the sneaky part: that swap cache pin doesn't increase the swap count. nope. it just sits there.

so this helper comes in and sets the initial count == 1, then keeps increasing the count as the folio gets unmapped and swap entries that reference the slots are generated to replace the folio. that's literally the entire job. slay 🌟


πŸ”₯ CONTEXT

the caller must make sure the folio is locked and in the swap cache. this isn't optional, bestie β€” it's the price of admission πŸ’€


πŸ’€ NOTE

the caller also has to ensure there is no raced call to swap_put_entries_direct on its swap entry before this helper returns β€” otherwise the swap count may underflow. and that is a bad time. like, genuinely. 😭

please take this seriously fr fr πŸ™ˆ


🧚 SEE ALSO

kernel file ./mm/swapfile.c, plus the whole friend group:


and that's the whole page, bestie!! this lil icon was brought to you by ./mm, dated October 2026, and it's folio_dup_swap(9) forever and always πŸ’–πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from