VM_PAGE_BITS(9)
π« vm_page_bits π«
okay so bestie, this is the VM_PAGE_BITS(9) manual page β Kernel Developer's Manual energy fr fr, and it's literally all about managing page clean and dirty bits β¨ it's giving low-level filesystem realness, and i'm obsessed π«Ά
π NAME π
vm_page_bits, vm_page_set_validclean, vm_page_clear_dirty, vm_page_set_invalid, vm_page_zero_invalid, vm_page_is_valid, vm_page_test_dirty, vm_page_dirty, vm_page_undirty β manage page clean and dirty bits, periodt π
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
int
vm_page_bits(int base, int size);
void
vm_page_set_validclean(vm_page_t m, int base, int size);
void
vm_page_clear_dirty(vm_page_t m, int base, int size);
void
vm_page_set_invalid(vm_page_t m, int base, int size);
void
vm_page_zero_invalid(vm_page_t m, boolean_t setvalid);
int
vm_page_is_valid(vm_page_t m, int base, int size);
void
vm_page_test_dirty(vm_page_t m);
void
vm_page_dirty(vm_page_t m);
void
vm_page_undirty(vm_page_t m);
like, these are the includes you need first π no cap, don't skip them π
π¦ DESCRIPTION π¦
okay so let's break these down one by one, bestie β each function is iconic in its own way πΈ
vm_page_bits()β calculates the bits representing theDEV_BSIZErange of bytes betweenbaseandsize. the byte range is supposed to be within a single page, and ifsizeis zero, no bits get set. that's it, that's the function πvm_page_set_validclean()β flags the byte range betweenbaseandsizeas<green>valid</green>and<mint>clean</mint>. the range is expected to beDEV_BSIZEaligned and no larger thanPAGE_SIZE. heads up tho π if it's not properly aligned, any unaligned chunks of theDEV_BSIZEblocks at the beginning and end of the range get zeroed.
alsooo β if base is zero and size is one page, the modified bit in the page map is cleared, and the VPO_NOSYNC flag is cleared too. two for one, slay π
vm_page_clear_dirty()β clears the dirty bits within a page in the range betweenbaseandsize. the bits representing the range are calculated by callingvm_page_bits(). so it's giving teamwork, love that for them π«Άvm_page_set_invalid()β clears the bits in both the valid and dirty flags representing theDEV_BSIZEblocks betweenbaseandsizein the page. the bits are calculated by callingvm_page_bits(). and as well as clearing the bits within the page, the generation number within the object holding the page gets incremented. main character energy, fr fr πvm_page_zero_invalid()β zeroes all of the blocks within the page that are currently flagged as invalid. ifsetvalidisTRUE, all of the valid bits within the page are set. easy peasy β¨
ngl in some cases β like NFS β the valid bits can't be set, because cache consistency has to be maintained π§ so like, it's not always a free-for-all, iykyk.
vm_page_is_valid()β checks to determine if all of theDEV_BSIZEblocks betweenbaseandsizeof the page are valid. lowkey a little quirky with the edge case: ifsizeis zero and the page is entirely invalid,vm_page_is_valid()will returnTRUE. in all other cases, asizeof zero will returnFALSE. so watch out for that πvm_page_test_dirty()β checks if a page has been modified via any of its physical maps, and if so, flags the entire page as dirty.vm_page_dirty()is called to modify the dirty bits. detective work but make it kernel πvm_page_dirty()β flags the entire page as dirty. it's expected that the page is not currently on the cache queue. like, don't do that, okay? πvm_page_undirty()β clears all of the dirty bits in a page. clean slate, fresh start, we love a reset π¦
π NOTES π
none of these functions are allowed to block. like, at all. blocking is not the vibe here, periodt π
π AUTHORS π
this manual page was written by Chad David <davidc@acns.ab.ca>. slay, Chad π
and that's the whole manual, bestie! this page is from the Debian distribution, dated December 1, 2001 π so yeah, it's a little vintage but the facts are still facts π
β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms