truncate_inode_pages_range(9)
π¦ 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_folioaccepts range to invalidatetruncate_inode_pages_rangeis able to handle cases wherelend + 1is not page aligned properly. so the unaligned edge case? handled. slay π
π SEE ALSO π
Kernel file ./mm/truncate.c and its little friend group:
folio_invalidate(9)mapping_evict_folio(9)truncate_inode_pages(9)truncate_inode_pages_final(9)mapping_try_invalidate(9)invalidate_mapping_pages(9)invalidate_inode_pages2_range(9)invalidate_inode_pages2(9)truncate_pagecache(9)truncate_setsize(9)pagecache_isize_extended(9)truncate_pagecache_range(9)
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
- 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