truncate_setsize(9)
π truncate_setsize(9) β like, the Kernel API Manual page you actually wanna read
okay bestie, gather round π«Ά this one lives in the Kernel API Manual section 9 and it's giving "small function, big responsibilities." let's go β¨
πΈ NAME πΈ
truncate_setsize β updates the inode and the pagecache when your file gets a brand-new size, no cap π
π SYNOPSIS π
void truncate_setsize (struct inode *inode , loff_t newsize );
literally that's it. two args. void return. she's tidy π
π¦ ARGUMENTS π¦
inodeβ the inode. yes. that's the whole description. iconic of the kernel docs honestly πnewsizeβ the new file size, bestie. the fresh number. the glow-up measurement πβ¨
π₯ DESCRIPTION π₯
okay so here's the tea β truncate_setsize updates i_size and does pagecache truncation (if necessary) to newsize. like, it sets the size AND cleans up the pagecache to match β but only if necessary, she's not out here doing extra work for no reason π
the way that it'll typically be called from the filesystem's setattr function when ATTR_SIZE is passed in π― so if you're deep in filesystem code and you see ATTR_SIZE show up, yeah, this is probably the vibe you're heading toward.
β οΈ big important caveat, pls do not skip: you must call it with a lock that serializes truncates and writes (generallyi_rwsem, but like, e.g.xfsuses a different lock β everyone's got their own thing π). and you gotta call it before all filesystem-specific block truncation has been performed. order matters, bestie. do not come in here out of order, that's not the move π
π§ SEE ALSO π§
bestie you are gonna be SO well-read after this list, it's literally a whole syllabus πβ¨ Kernel file ./mm/truncate.c and all her friends:
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_pagecache(9)pagecache_isize_extended(9)truncate_pagecache_range(9)
like, go read them. all of them. i'll wait π
π and that's the whole page!! sourced from ./mm, dated October 2026, filed under truncate_setsize(9) β mwah, love that for us ππ
π¦ 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