truncate_inode_pages_range(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ truncate_inode_pages_range(9) β€” the Kernel API Manual glow-up πŸ¦‹

okay so bestie, welcome to truncate_inode_pages_range(9) from the Kernel API Manual ✨ this one's all about yeeting a whole range of pages out of the page cache, and honestly it's giving main character energy. let's get into it πŸ’…


🌸 NAME 🌸

truncate_inode_pages_range β€” truncate range of pages specified by start & end byte offsets πŸŽ€


✨ SYNOPSIS ✨

void truncate_inode_pages_range (struct address_space *mapping , loff_t lstart , uoff_t lend );

like, that's the whole signature, no notes πŸ’–


🫢 ARGUMENTS 🫢

  • mapping β€” the mapping to truncate. this is the thing we're literally doing surgery on πŸ”₯
  • lstart β€” offset from which to truncate. where the carnage begins ⭐
  • lend β€” offset to which to truncate (inclusive). where it ends β€” and yes bestie, inclusive means inclusive, don't come for me πŸ™ˆ

πŸ‘‘ DESCRIPTION πŸ‘‘

Truncate the page cache, removing the pages that are between specified offsets (and zeroing out partial pages if lstart or lend + 1 is not page aligned). so we're not just deleting, we're cleaning up the edges too, iykyk 🧚

Truncate takes two passes β€” the first pass is nonblocking. It will not block on page locks and it will not block on writeback. The second pass will wait. The whole point is to prevent as much IO as possible in the affected region. The first pass will remove most pages, so the search cost of the second pass is low. like, first pass does the heavy lifting so the second pass can just vibe through the leftovers πŸ’€βœ¨

We pass down the cache-hot hint to the page freeing code. Even if the mapping is large, it is probably the case that the final pages are the most recently touched, and freeing happens in ascending file offset order. so yeah, we're telling the freeing code "these ones are still warm, handle accordingly" πŸ“

Note that since ->invalidate_folio accepts range to invalidate truncate_inode_pages_range is able to handle cases where lend + 1 is not page aligned properly. so the unaligned edge case? handled. slay πŸ’…

🌈 SEE ALSO 🌈

Kernel file ./mm/truncate.c and its little friend group:


and that's the whole page, bestie 🫢 this gem lives in ./mm and it's dated October 2026 β€” so go forth, truncate responsibly, and remember: two passes, no cap πŸ’œπŸ’«

πŸ“¦ where this page comes from