VNODE_PAGER_SETSIZE(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… VNODE_PAGER_SETSIZE(9) β€” like, the kernel dev manual page, bestie

okay so picture this: you're deep in kernel-land, and the VM system has no idea your file just changed size. rude. that's literally what vnode_pager_setsize is for ✨


🌸 NAME 🌸

vnode_pager_setsize β€” the function that tells the VM system "hey bestie, the file size changed" πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>

void
vnode_pager_setsize(struct vnode *vp, vm_ooffset_t nsize);

πŸ¦‹ DESCRIPTION πŸ¦‹

vnode_pager_setsize lets the VM system know that a file's size changed, and it updates both the object size and the vnode pager size of the vm object in vp to match nsize. so iconic of it 🫢

now the serious part, no cap: if you get a page fault on the object mapping with an offset that's past the new object size, that fault results in SIGBUS. literally not the vibe. πŸ’€

when the file size shrinks, the pages between the old EOF and the new EOF get removed from the object queue. and if the new EOF you passed in nsize isn't aligned to a page boundary? then the partial-page area starting beyond the EOF gets zeroed out and marked invalid β€” but only if that page actually exists resident. yes, there's a vibe check involved 🧚

also important: if the vnode vp doesn't have a VM object allocated, calling this function is a no-op. nothing happens. it simply said "not today" πŸ™ˆ

this function must be used inside file system code to implement truncation, if your file system allocates vm objects for vnodes. periodt. πŸ‘‘


πŸ”’ LOCKS πŸ”’

the vnode should be exclusively locked on entry, and it will still be locked on exit. it's giving "you had one job and you kept it" energy πŸ’…


🌈 SEE ALSO 🌈


⭐ HISTORY ⭐

the vnode_pager_setsize manual page first appeared in FreeBSD 14. a whole era πŸ”₯


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Ka Ho Ng <khng@FreeBSD.org>. thank you for your service 🫑 πŸ’œ


fr fr, keep that vnode locked and your pages aligned, bestie β€” the VM system is watching 😭

okay that's the whole thing, mwah πŸ’– this was Debian, dated April 8, 2021, and yes that's the same VNODE_PAGER_SETSIZE(9) we started with β€” slay, go update some file sizes ✨🌷

πŸ“¦ where this page comes from