VM_MAP_LOCK(9)

πŸ’– VM_MAP_LOCK β€” vm_map locking macros πŸ’–

okay bestie, sit DOWN, because we're talking about vm_map_lock and its whole friend group β€” and yes, this is from the Kernel Developer's Manual, section 9, so you already know it's giving big-kid kernel energy. 🧚✨

The squad is: vm_map_lock, vm_map_unlock, vm_map_lock_read, vm_map_unlock_read, vm_map_trylock, vm_map_trylock_read, vm_map_lock_upgrade, vm_map_lock_downgrade β€” the vm_map locking macros. Eight little icons. All of them. Periodt. πŸ‘‘


✨ SYNOPSIS ✨

first things first, you gotta bring in the essentials, no skipping:

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

then it's just:

void
vm_map_lock(vm_map_t map);

void
vm_map_unlock(vm_map_t map);

void
vm_map_lock_read(vm_map_t map);

void
vm_map_unlock_read(vm_map_t map);

int
vm_map_trylock(vm_map_t map);

int
vm_map_trylock_read(vm_map_t map);

int
vm_map_lock_upgrade(vm_map_t map);

int
vm_map_lock_downgrade(vm_map_t map);

look at that. gorgeous. no notes. πŸ’…


🌸 DESCRIPTION 🌸

so here's the tea on each one, bestie, one by one:

  • vm_map_lock() β€” this macro grabs an exclusive lock on map. it's the main character lock, nobody else gets in while it's held. 🫢
  • vm_map_unlock() β€” releases that exclusive lock on map. bye babe, thanks for coming. πŸ’–
  • vm_map_lock_read() β€” this one gets a read-lock on map. like, you can look, but don't touch. πŸ‘€
  • vm_map_unlock_read() β€” releases the read-lock on map. lookin' time is over. πŸŽ€
  • vm_map_trylock() β€” tries to snag an exclusive lock on map, but it's not gonna wait around for it. if the lock can't be acquired immediately it returns FALSE; otherwise it returns TRUE with the lock acquired. lowkey impatient, highkey efficient. 😌
  • vm_map_trylock_read() β€” same vibe but for a read-lock on map. returns FALSE if the lock can't be acquired immediately; otherwise returns TRUE with the lock acquired. no waiting, no begging. ✨
  • vm_map_lock_upgrade() β€” attempts to atomically upgrade a read-lock on map to an exclusive lock. glow-up but make it atomic. πŸ¦‹
  • vm_map_lock_downgrade() β€” attempts to downgrade an exclusive lock on map to a read-lock. sometimes you just gotta step back and let the read-locks breathe. 🌈

πŸ› οΈ IMPLEMENTATION NOTES πŸ› οΈ

as of right now, bestie, all of these locking macros implement their locks as sleep locks. every single one. that's the whole note. fr fr. πŸ’€


πŸ‘€ SEE ALSO πŸ‘€

  • vm_map(9) β€” go read it, it's the source material, iykyk. πŸ“š

πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Bruce M Simpson <bms@spc.org>. king behavior, honestly. 🫑


aaaand that's the whole page, bestie!! this one came from Debian, dated July 19, 2003 β€” vintage but still slaying. go lock your maps responsibly, mwah πŸ’‹πŸ’–βœ¨

πŸ“¦ where this page comes from