truncate_pagecache(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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 β€” the inode. 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:


πŸ’« 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