VM_PAGE_BUSY(9)
π VM_PAGE_BUSY(9) π
okay bestie, welcome to the Kernel Developer's Manual section 9, page VM_PAGE_BUSY β this is the page about protecting page identity changes and page content references. yes it's giving very serious kernel business and yes i'm gonna make it make sense. π¦
β¨ NAME β¨
vm_page_busied, vm_page_busy_downgrade, vm_page_busy_sleep, vm_page_sbusied, vm_page_sbusy, vm_page_sleep_if_busy, vm_page_sunbusy, vm_page_trysbusy, vm_page_tryxbusy, vm_page_xbusied, vm_page_xbusy, vm_page_xunbusy, vm_page_assert_sbusied, vm_page_assert_unbusied, vm_page_assert_xbusied β protect page identity changes and page content references π
β¨ SYNOPSIS β¨
like, the incantations first. copy these EXACTLY, no cap:
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
then the whole squad of functions:
int
vm_page_busied(vm_page_t m);
void
vm_page_busy_downgrade(vm_page_t m);
void
vm_page_busy_sleep(vm_page_t m, const char *msg);
int
vm_page_sbusied(vm_page_t m);
void
vm_page_sbusy(vm_page_t m);
int
vm_page_sleep_if_busy(vm_page_t m, const char *msg);
void
vm_page_sunbusy(vm_page_t m);
int
vm_page_trysbusy(vm_page_t m);
int
vm_page_tryxbusy(vm_page_t m);
int
vm_page_xbusied(vm_page_t m);
void
vm_page_xbusy(vm_page_t m);
void
vm_page_xunbusy(vm_page_t m);
and the three assertion girlies need these kernel options to even exist:
options INVARIANTS
options INVARIANT_SUPPORT
void
vm_page_assert_sbusied(vm_page_t m);
void
vm_page_assert_unbusied(vm_page_t m);
void
vm_page_assert_xbusied(vm_page_t m);
β¨ DESCRIPTION β¨
okay so. Page identity is usually protected by higher level locks like vm_object locks and vm page locks. normally that's the vibe. π
BUT β and this is the plot twist β sometimes it is not possible to hold such locks for the time necessary to complete the identity change. in that case, the page can be exclusively busied by a thread which needs to own the identity for a certain amount of time. main character thread energy only. π
In other situations, threads do not need to change the identity of the page but they want to prevent other threads from changing the identity themselves. For example, when a thread wants to access or update page contents without a lock held, the page is shared busied.
π¨ THE RULE, bestie, do not skip this one: Before busying a page thevm_objectlock must be held. The same rule applies when a page is unbusied. This makes thevm_objectlock a real busy interlock.
now let's go function by function, no skipping, i love a complete list π
vm_page_busied()β returns non-zero if the current thread busiedmin either exclusive or shared mode. Returns zero otherwise.vm_page_busy_downgrade()β must be used to downgrademfrom an exclusive busy state to a shared busy state.vm_page_busy_sleep()β puts the invoking thread to sleep using the appropriate waitchannels for the busy mechanism. The parametermsgis a string describing the sleep condition for userland tools. π΄vm_page_busied()β returns non-zero if the current thread busiedmin shared mode. Returns zero otherwise.vm_page_sbusy()β shared busiesm.vm_page_sleep_if_busy()β puts the invoking thread to sleep, using the appropriate waitchannels for the busy mechanism, ifm.is busied in either exclusive or shared mode. If the invoking thread slept a non-zero value is returned, otherwise0is returned. The parametermsgis a string describing the sleep condition for userland tools.vm_page_sunbusy()β shared unbusiesm.vm_page_trysbusy()β attempts to shared busym. If the operation cannot immediately succeedvm_page_trysbusy()returns0, otherwise a non-zero value is returned.vm_page_tryxbusy()β attempts to exclusive busym. If the operation cannot immediately succeedvm_page_tryxbusy()returns0, otherwise a non-zero value is returned.vm_page_xbusied()β returns non-zero if the current thread busiedmin exclusive mode. Returns zero otherwise.vm_page_xbusy()β exclusive busiesm.vm_page_xunbusy()β exclusive unbusiesm. Assertions on the busy state allow kernels compiled withoptions INVARIANTSandoptions INVARIANT_SUPPORTto panic if they are not respected. π
and now the assertion trio, the ones that will absolutely call you out:
vm_page_assert_sbusied()β panics ifmis not shared busied.vm_page_assert_unbusied()β panics ifmis not unbusied.vm_page_assert_xbusied()β panics ifmis not exclusive busied.
π SEE ALSO π
go read these next, i promise they're worth it π«Ά
vm_page_aflag(9)vm_page_alloc(9)vm_page_deactivate(9)vm_page_free(9)vm_page_grab(9)vm_page_insert(9)vm_page_lookup(9)vm_page_rename(9)VOP_GETPAGES(9)
and that's the page, bestie!! this one came out of Debian, dated August 07, 2013 β yeah it's a classic, it's been slaying in the Kernel Developer's Manual since forever, mwah πβ¨ go busy a page responsibly, and remember: hold that vm_object lock. periodt. π
π¦ 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) 2013 EMC Corp
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms