VM_MAP_WIRE(9)

✨ VM_MAP_WIRE β€” kernel dev manual, section 9 ✨

okay bestie, welcome to the kernel developer's manual for VM_MAP_WIRE πŸ’… this is the page about managing page wiring inside a virtual memory map, and yes it's giving very serious grown-up energy, but we're gonna get through it together 🫢


🌸 NAME 🌸

vm_map_wire, vm_map_unwire β€” manage page wiring within a virtual memory map πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

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

int
vm_map_wire(vm_map_t map, vm_offset_t start, vm_offset_t end,
    int flags);

int
vm_map_unwire(vm_map_t map, vm_offset_t start, vm_offset_t end,
    int flags);

like, there they are. two little functions. iconic behavior honestly πŸ¦‹


✨ DESCRIPTION ✨

okay so. vm_map_wire() is the function in charge of wiring pages in the range between start and end inside the map map. and what does "wiring" even mean, you ask? it means those pages get locked into physical memory πŸ”’ and they may not be paged out for as long as their wire count stays above zero. no cap. they're staying put.

vm_map_unwire() does the corresponding unwire operation β€” it's the undo button, the "okay you can go now bestie" of the pair πŸ™ˆ

the flags argument is a bit mask, and it's made up of the following flags:

  • If the VM_MAP_WIRE_USER flag is set, the function operates within user address space πŸ‘‘
  • If the VM_MAP_WIRE_HOLESOK flag is set, it may operate upon an arbitrary range within the address space of map πŸ•³οΈ
  • If a contiguous range is desired, callers should explicitly express their intent by specifying the VM_MAP_WIRE_NOHOLES flag ⭐

🧚 IMPLEMENTATION NOTES 🧚

both functions will attempt to acquire a lock on the map using vm_map_lock(9) and hold it for the duration of the call. and if they detect MAP_ENTRY_IN_TRANSITION, they will call vm_map_unlock_and_wait(9) until the map becomes available again. like they're just patiently waiting their turn in the group chat, no drama πŸ’œ

but here's the thing β€” the map could have changed during this window, because it was held by another consumer 😭 so consumers of this interface should check for this condition using the return values below. please check them. don't be that person.


πŸ’– RETURN VALUES πŸ’–

vm_map_wire() and vm_map_unwire() have identical return values, they're matching, they're twins, they ate πŸ‘―

  • the functions return KERN_SUCCESS if all pages within the range were [un]wired successfully πŸŽ‰
  • otherwise, if the specified range was not valid, or if the map changed while the MAP_ENTRY_IN_TRANSITION flag was set, KERN_INVALID_ADDRESS is returned πŸ’€

🌈 SEE ALSO 🌈


πŸ‘‘ AUTHORS πŸ‘‘

this manual page was written by Bruce M Simpson <bms@spc.org>. shoutout to Bruce, fr fr 🫢


and that's the whole page bestie!! this one shipped with Debian and it's dated July 19, 2003 β€” vintage, lowkey a classic, and we love that for it πŸŒΈβœ¨πŸ’…

πŸ“¦ where this page comes from