VM_MAP(9)
πΈ VM_MAP(9) πΈ
okay bestie, sit down, hydrate, and let's talk about the vm_map situation, because this is the virtual address space portion of the virtual memory subsystem and honestly? it's giving main character energy for the whole kernel. this is a Kernel Developer's Manual page, iykyk π
β¨ SYNOPSIS β¨
like, first of all, you gotta include the girlies:
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_map.h>
π DESCRIPTION π
so the vm_map subsystem? it's literally what manages virtual address spaces. this section is about the main data structures used in the code, no skips, we're reading the whole thing, periodt.
The struct vm_map is a generic representation of an address space. this address space might belong to a user process, or it might belong to the kernel (she contains multitudes). fun fact: the kernel actually uses several maps, and those are maintained as subordinate maps, created using the vm_map_submap(9) function. iconic behaviour tbh.
struct vm_map {
struct vm_map_entry header;
struct sx lock;
struct mtx system_mtx;
int nentries;
vm_size_t size;
u_int timestamp;
u_char needs_wakeup;
u_char system_map;
vm_flags_t flags;
vm_map_entry_t root;
pmap_t pmap;
int busy;
};
The fields of struct vm_map are, one by one, no crumbs left behind:
headerβ head node of a circular, doubly linked list ofstruct vm_map_entryobjects. each one of those defines a particular region within this map's address space πlockβ used to serialize access to the structure. she's the bouncer.system_mtxβ a mutex which is used if the map is a system map.nentriesβ a count of the members in use within the circular map entry list.sizeβ specifies the size of the virtual address space.timestampβ used to determine if the map has changed since its last access.needs_wakeupβ indicates if a thread is waiting for an allocation within the map. used only by system maps, bestie.system_mapβ set toTRUEto indicate that map is a system map; otherwise, it belongs to a user process.flagsβ map flags, described below πrootβ root node of a binary search tree used for fast lookup of map entries.pmapβ pointer to the underlying physical map with which this virtual map is associated.busyβ map busy counter, prevents forks.
π¦ Possible map flags π¦
MAP_WIREFUTUREβ wire all future pages in this map.MAP_BUSY_WAKEUPβ there are waiters for the map busy status.
π The following flags can be passed to vm_map_find(9) and vm_map_insert(9) to specify the copy-on-write properties of regions within the map π
MAP_COPY_ON_WRITEβ the mapping is copy-on-write.MAP_NOFAULTβ the mapping should not generate page faults.MAP_PREFAULTβ the mapping should be prefaulted into physical memory.MAP_PREFAULT_PARTIALβ the mapping should be partially prefaulted into physical memory.MAP_DISABLE_SYNCERβ do not periodically flush dirty pages; only flush them when absolutely necessary.MAP_DISABLE_COREDUMPβ do not include the mapping in a core dump.MAP_PREFAULT_MADVISEβ specify that the request is from a user process callingmadvise(2).MAP_ACC_CHARGEDβ region is already charged to the requestor by some means.MAP_ACC_NO_CHARGEβ do not charge for allocated region.
π§ the struct vm_map_entry π§
The struct vm_map_entry is a generic representation of a region. the region managed by each entry is associated with a union vm_map_object, described below.
struct vm_map_entry {
struct vm_map_entry *prev;
struct vm_map_entry *next;
struct vm_map_entry *left;
struct vm_map_entry *right;
vm_offset_t start;
vm_offset_t end;
vm_offset_t avail_ssize;
vm_size_t adj_free;
vm_size_t max_free;
union vm_map_object object;
vm_ooffset_t offset;
vm_eflags_t eflags;
/* Only in task maps: */
vm_prot_t protection;
vm_prot_t max_protection;
vm_inherit_t inheritance;
int wired_count;
vm_pindex_t lastr;
};
The fields of struct vm_map_entry are as follows:
prevβ pointer to the previous node in a doubly-linked, circular list.nextβ pointer to the next node in a doubly-linked, circular list.leftβ pointer to the left node in a binary search tree.rightβ pointer to the right node in a binary search tree.startβ lower address bound of this entry's region.endβ upper address bound of this entry's region.avail_ssizeβ if the entry is for a process stack, specifies how much the entry can grow.adj_freeβ the amount of free, unmapped address space adjacent to and immediately following this map entry.max_freeβ the maximum amount of contiguous free space in this map entry's subtree.objectβ pointer to thestruct vm_map_objectwith which this entry is associated.offsetβ offset within the object which is mapped fromstartonwards.eflagsβ flags applied to this entry, described below.
π The following five members are only valid for entries forming part of a user process's address space π
protectionβ memory protection bits applied to this region.max_protectionβ mask for the memory protection bits which may be actually be applied to this region.inheritanceβ contains flags which specify how this entry should be treated during fork processing.wired_countβ count of how many times this entry has been wired into physical memory.lastrβ contains the address of the last read which caused a page fault.
π The following flags may be applied to each entry, by specifying them as a mask within the eflags member π
MAP_ENTRY_NOSYNCβ the system should not flush the data associated with this map periodically, but only when it needs to.MAP_ENTRY_IS_SUB_MAPβ if set, then theobjectmember specifies a subordinate map.MAP_ENTRY_COWβ indicate that this is a copy-on-write region.MAP_ENTRY_NEEDS_COPYβ indicate that a copy-on-write region needs to be copied.MAP_ENTRY_NOFAULTβ specifies that accesses within this region should never cause a page fault. β οΈ if a page fault occurs within this region, the system will panic. not a drill, bestie.MAP_ENTRY_USER_WIREDβ indicate that this region was wired on behalf of a user process.MAP_ENTRY_BEHAV_NORMALβ the system should use the default paging behaviour for this region.MAP_ENTRY_BEHAV_SEQUENTIALβ the system should depress the priority of pages immediately preceding each page within this region when faulted in.MAP_ENTRY_BEHAV_RANDOMβ is a hint that pages within this region will be accessed randomly, and that prefetching is likely not advantageous.MAP_ENTRY_IN_TRANSITIONβ indicate that wiring or unwiring of an entry is in progress, and that other kernel threads should not attempt to modify fields in the structure.MAP_ENTRY_NEEDS_WAKEUPβ indicate that there are kernel threads waiting for this region to become available.MAP_ENTRY_NOCOREDUMPβ the region should not be included in a core dump.
π inheritance, a whole personality π
The inheritance member has type vm_inherit_t. this governs the inheritance behaviour for a map entry during fork processing. the following values are defined for vm_inherit_t:
VM_INHERIT_SHAREβ the object associated with the entry should be cloned and shared with the new map. a newstruct vm_objectwill be created if necessary.VM_INHERIT_COPYβ the object associated with the entry should be copied to the new map.VM_INHERIT_NONEβ the entry should not be copied to the new map.VM_INHERIT_DEFAULTβ specifies the default behaviour,VM_INHERIT_COPY.
π the union vm_map_object π
The union vm_map_object is used to specify the structure which a struct vm_map_entry is associated with.
The fields of union vm_map_object are as follows:
union vm_map_object {
struct vm_object *vm_object;
struct vm_map *sub_map;
};
Normally, the sub_map member is only used by system maps to indicate that a memory range is managed by a subordinate system map. within a user process map, each struct vm_map_entry is backed by a struct vm_object. yes queen, backing store π
π₯ SEE ALSO π₯
pmap(9), vm_map_check_protection(9), vm_map_create(9), vm_map_delete(9), vm_map_entry_resize_free(9), vm_map_find(9), vm_map_findspace(9), vm_map_inherit(9), vm_map_init(9), vm_map_insert(9), vm_map_lock(9), vm_map_lookup(9), vm_map_madvise(9), vm_map_max(9), vm_map_min(9), vm_map_pmap(9), vm_map_protect(9), vm_map_remove(9), vm_map_simplify_entry(9), vm_map_stack(9), vm_map_submap(9), vm_map_sync(9), vm_map_wire(9)
π AUTHORS π
This manual page was written by Bruce M Simpson <bms@spc.org>. absolute legend, we love to see it π«Ά
and that's the whole vibe check, bestie β this page came from Debian, dated July 3, 2018, on VM_MAP(9). go forth and map those virtual addresses, no cap πβ¨
π¦ 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) 2003 Bruce M Simpson <bms@spc.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms