truncate_setsize(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 (generally i_rwsem, but like, e.g. xfs uses 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:

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