VM_PAGE_AFLAG(9)

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

πŸ’… VM_PAGE_AFLAG(9) β€” the kernel dev manual, but make it make sense

okay so bestie, welcome to VM_PAGE_AFLAG(9) β€” this is one of those kernel developer manual pages, and honestly? it's a little gem. it's all about flipping the atomic flags on a page, and no, that's not a metaphor, we're literally talking about memory pages here 🧚


✨ NAME ✨

vm_page_aflag_clear, vm_page_aflag_set, vm_page_reference β€” change page atomic flags

like, the whole trio's job is touching the atomic flags on a page. that's it. that's the vibe. πŸŽ€


🌸 SYNOPSIS 🌸

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

void
vm_page_aflag_clear(vm_page_t m, uint8_t bits);

void
vm_page_aflag_set(vm_page_t m, uint8_t bits);

void
vm_page_reference(vm_page_t m);

look at those includes, they're iconic. keep them in that order, mwah πŸ’‹


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie:

  • vm_page_aflag_clear() atomically clears the specified bits on the page's aflags. poof. gone. ✨
  • vm_page_aflag_set() atomically sets the specified bits on the page's aflags. boom. set. ✨

and then there's vm_page_reference(m), which is literally just the same thing as:

vm_page_aflag_set(m, PGA_REFERENCED);

fr fr, it's the exact same call. and it's the recommended way to mark the page as referenced from third-party kernel modules β€” so if you're writing a module and you need to do this, use vm_page_reference(m) and don't be out here doing it the long way, iykyk 😌

k now here's the part that's genuinely slay: these functions neither block nor require any locks to be held around the calls for correctness. no lock gymnastics, no waiting around. they just do the thing. periodt. πŸ’…

πŸ“ the function arguments

  • m β€” the page whose aflags are getting updated. the main character, obviously πŸ‘‘
  • bits β€” the bits that are set or cleared on the page's flags. the little sparkles you're sprinkling on ✨

🌈 the aflags you can set or clear

  • PGA_REFERENCED β€” this bit may be set to indicate that the page has been recently accessed. for instance, pmap(9) sets this bit to reflect the accessed attribute of the page mapping, which is typically updated by the processor's memory management unit on the page access. so like, the MMU snitches on the page and pmap(9) marks the receipt πŸ™ˆ
  • PGA_WRITEABLE β€” a writeable mapping for the page may exist. that's it, that's the whole description, don't come for me 🫢
heads up bestie: both PGA_REFERENCED and PGA_WRITEABLE bits are only valid for the managed pages. so if you're out here flipping these on unmanaged pages, that's not it. check yourself before you wreck yourself πŸ’€

πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Chad David <davidc@acns.ab.ca>. give it up for Chad, he wrote the whole thing and we're grateful 🫢


πŸŽ€ the cute sign-off πŸŽ€

so this whole page came from the Debian crew, dated August 31, 2011, and it's the VM_PAGE_AFLAG(9) kernel developer's manual. ancient? kinda. still serving? absolutely. go forth and set some aflags, bestie, you're gonna do amazing πŸ’–πŸ₯°πŸŒΈ

πŸ“¦ where this page comes from