VM_PAGE_BUSY(9)
π VM_PAGE_BUSY(9) β Kernel Developer's Manual π
okay so bestie, welcome to the VM_PAGE_BUSY(9) page from the Kernel Developerβs Manual π this whole thing is about protecting page identity changes and page content references, and itβs lowkey a whole vibe.
β¨ NAME β¨
vm_page_busied, vm_page_busy_downgrade, vm_page_busy_sleep, vm_page_sbusied, vm_page_sunbusy, vm_page_trysbusy, vm_page_tryxbusy, vm_page_xbusied, vm_page_xunbusy, vm_page_assert_sbusied, vm_page_assert_unbusied, vm_page_assert_xbusied β protect page identity changes and page content references π
π¦ SYNOPSIS π¦
the includes and signatures, served exactly as written, no cap:
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_page.h>
int
vm_page_busied(vm_page_t m);
void
vm_page_busy_downgrade(vm_page_t m);
bool
vm_page_busy_sleep(vm_page_t m, const char *msg, int allocflags);
int
vm_page_sbusied(vm_page_t m);
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_xunbusy(vm_page_t m);
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 π₯
so page identity is usually protected by higher level locks like vm_object locks and vm page locks. but 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 energy, honestly.
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 β¨
π big rule energy: 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. periodt.
okay now the function tea, one by one:
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()β checks the busy state of the pagemand puts the invoking thread to sleep if the page is busy. the VM object for the page must be locked. theallocflagsparameter must be either0, in which case the function will sleep if the page is busied, orVM_ALLOC_IGN_SBUSY, in which case the function will sleep only if the page is exclusively busied. a return value oftrueindicates that the invoking thread was put to sleep and that the object was unlocked. a return value offalseindicates that the invoking thread did not sleep and the object remains locked. the parametermsgis a string describing the sleep condition for userland tools.vm_page_busied()β the shared-mode line as printed: returns non-zero if the current thread busiedmin shared mode. returns zero otherwise.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_xunbusy()β exclusive unbusiesm. assertions on the busy state allow kernels compiled withoptions INVARIANTSandoptions INVARIANT_SUPPORTto panic if they are not respected.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 π
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 whole page, bestie π this one came from Debian, dated November 11, 2021, and its manual handle is VM_PAGE_BUSY(9) β slay and stay correctly busied β¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2013 EMC Corp
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms