truncate_pagecache(9)
β¨ truncate_pagecache β the Kernel API Manual tea βπ
Okay so bestie, welcome to the Kernel API Manual entry for truncate_pagecache(9), and honestly? This one is a whole vibe. It's the function that unmaps and removes pagecache that has been truncated. Iconic behavior, no cap. π
β¨ SYNOPSIS β¨
void truncate_pagecache (struct inode *inode , loff_t newsize );
That's it. That's the whole signature. Short, sweet, and it will absolutely ruin your day if you call it wrong. π«Ά
πΈ ARGUMENTS πΈ
inodeβ theinode. Yeah bestie, it's literally just an inode. That's the whole description. Go off I guess. πnewsizeβ the new file size. This is the size you're shrinking (or, like, resizing) down to. Main character energy. π
π DESCRIPTION π
So here's the situation. The inode's new i_size must already be written before truncate_pagecache is called. Like, before. Not after. Before. The function is not out here doing that for you, it's not your assistant, it's your colleague. π
This function should typically be called before the filesystem releases resources associated with the freed range β for example, before it deallocates blocks. The way that this matters is honestly so real: doing it in that order means pagecache will always stay logically coherent with the on-disk format. Slay. π
And because of that ordering, the filesystem doesn't have to deal with cursed situations β like writepage being called for a page that has already had its underlying blocks deallocated. Nobody wants that. That's a vibe check failure of the highest order. π
ngl, get the ordering wrong here and you're in for a bad time. Write i_size first, truncate the pagecache second, release resources third. Periodt. β
π¦ SEE ALSO π¦
Kernel file ./mm/truncate.c, plus all these besties right here:
folio_invalidate(9)mapping_evict_folio(9)truncate_inode_pages_range(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_setsize(9)pagecache_isize_extended(9)truncate_pagecache_range(9)
π« and that's the whole page, bestie π«
This little gem lives in the source ./mm, and the version stamp on it is October 2026 for truncate_pagecache(9). Go forth, truncate responsibly, and remember: i_size first. Always. ππ§π
π¦ 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