VM_PAGE_BITS(9)
π¦ VM_PAGE_BITS(9) π¦
okay so bestie, this is a page straight outta the Kernel Developer's Manual, section 9, and it's all about the β¨clean bitsβ¨ and the πdirty bitsπ on memory pages. come sit with me, we're doing kernel memory management today and it's giving very much main character energy.
πΈ 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 β literally just here to manage page clean and dirty bits π
β¨ SYNOPSIS β¨
okay so first you gotta pull in the fits, like so:
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
and then here's the whole squad, signatures and all, no cap:
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);
π DESCRIPTION π
π vm_page_bits()
vm_page_bits() does the math and hands you the bits that represent the DEV_BSIZE range of bytes sitting between base and size. the vibe check here: that byte range is expected to live inside a single page, so don't go wild. and if size is zero? no bits will be set. none. zero. nada. π«Ά
π§ vm_page_set_validclean()
vm_page_set_validclean() flags the byte range between base and size as valid and clean at the same time β multitasking icon. that range is expected to be DEV_BSIZE aligned and no larger than PAGE_SIZE. if it's not properly aligned tho, any unaligned chunks of the DEV_BSIZE blocks at the beginning and end of the range get zeroed. π
also, little plot twist: if base is zero and size is one page, the modified bit in the page map is cleared, and on top of that the VPO_NOSYNC flag is cleared too. two-for-one.
π vm_page_clear_dirty()
vm_page_clear_dirty() clears the dirty bits within a page, in the range between base and size. the bits representing that range? calculated by calling vm_page_bits(). it's a whole ecosystem, they support each other. π
π vm_page_set_invalid()
vm_page_set_invalid() clears the bits in both the valid and dirty flags that represent the DEV_BSIZE blocks between base and size in the page. those bits come from calling vm_page_bits() β yes, again, obsessed with that function. and as well as clearing the bits within the page, the generation number within the object holding the page gets incremented. glow up for the generation number β¨
π vm_page_zero_invalid()
vm_page_zero_invalid() zeroes out all the blocks within the page that are currently flagged as invalid. and if setvalid is TRUE, then all of the valid bits within the page get set. boom.
but fr fr, in some cases β NFS being the example β the valid bits cannot be set, because they need to maintain cache consistency. so don't come for it.
π¦ vm_page_is_valid()
vm_page_is_valid() checks whether all of the DEV_BSIZE blocks between base and size of the page are valid. it returns an int, bestie.
here's the sneaky part: if size is zero and the page is entirely invalid, vm_page_is_valid() will return TRUE. in all other cases, a size of zero will return FALSE. so that one specific combo is the exception, don't get it twisted. π
π
vm_page_test_dirty()
vm_page_test_dirty() checks if a page has been modified via any of its physical maps, and if it has, it flags the entire page as dirty. to actually modify the dirty bits, vm_page_dirty() is called. tag team. π«Ά
π₯ vm_page_dirty()
vm_page_dirty() flags the entire page as dirty. but heads up: it's expected that the page is not currently on the cache queue. respect the queue bestie.
πΈ vm_page_undirty()
vm_page_undirty() clears all of the dirty bits in a page. total clean slate, fresh start, new semester energy. π
β NOTES β
none of these functions are allowed to block. not a single one. no blocking, no waiting around, they gotta keep it moving. periodt.
π AUTHORS π
this manual page was written by Chad David <davidc@acns.ab.ca>. thank you for your service king π
and that's the whole page babes π this one came from Debian, dated December 1, 2001 β yeah she's an elder but she still ate, and she's still VM_PAGE_BITS(9) down to the very last line. mwah π
β¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (C) 2001 Chad David <davidc@acns.ab.ca>. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms