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