xref: /freebsd/share/man/man9/vm_map.9 (revision d37ea99837e6ad50837fd9fe1771ddf1c3ba6002)
1.\"
2.\" Copyright (c) 2003 Bruce M Simpson <bms@spc.org>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd July 19, 2003
29.Dt VM_MAP 9
30.Sh NAME
31.Nm vm_map
32.Nd virtual address space portion of virtual memory subsystem
33.Sh SYNOPSIS
34.In sys/param.h
35.In vm/vm.h
36.In vm/vm_map.h
37.Sh DESCRIPTION
38The
39.Nm
40subsystem is used to manage virtual address spaces.
41This section describes the main data structures used within the code.
42.Pp
43The
44.Fa struct vm_map
45is a generic representation of an address space.
46This address space may belong to a user process or the kernel.
47The kernel actually uses several maps, which are maintained as
48subordinate maps, created using the
49.Xr vm_map_submap 9
50function.
51.Bd -literal -offset indent
52struct vm_map {
53        struct vm_map_entry header;
54        struct lock lock;
55        struct mtx system_mtx;
56        int nentries;
57        vm_size_t size;
58        u_char needs_wakeup;
59        u_char system_map;
60        u_char infork;
61        vm_map_entry_t root;
62        unsigned int timestamp;
63        vm_map_entry_t first_free;
64        pmap_t pmap;
65};
66.Ed
67.Pp
68The fields of
69.Vt struct vm_map
70are as follows:
71.Bl -tag -width needs_wakeupXXX
72.It Va header
73Head node of a circular, doubly linked list of
74.Vt struct vm_map_entry
75objects.
76Each object defines a particular region within this map's address space.
77.It Va lock
78Used to serialize access to the structure.
79.It Va system_mtx
80A mutex which is used if the map is a system map.
81.It Va nentries
82A count of the members in use within the circular map entry list.
83.It Va size
84Specifies the size of the virtual address space.
85.It Va infork
86Indicates if the map structure is currently undergoing fork processing.
87.It Va needs_wakeup
88Indicates if a thread is waiting for an allocation within the map.
89Used only by system maps.
90.It Va system_map
91Set to TRUE to indicate that map is a system map; otherwise, it belongs
92to a user process.
93.It Va root
94Root node of a binary search tree used for fast lookup of map entries.
95.It Va timestamp
96Used to determine if the map has changed since its last access.
97.It Va first_free
98Provides a hint to the first free space within the map.
99.It Va pmap
100Pointer to the underlying physical map with which this virtual map
101is associated.
102.El
103.Pp
104The following flags can be passed to
105.Xr vm_map_find 9
106and
107.Xr vm_map_insert 9
108to specify the copy-on-write properties of regions within the map:
109.Bl -tag -width MAP_PREFAULT_MADVISEXXX
110.It Dv MAP_COPY_ON_WRITE
111The mapping is copy-on-write.
112.It Dv MAP_NOFAULT
113The mapping should not generate page faults.
114.It Dv MAP_PREFAULT
115The mapping should be prefaulted into physical memory.
116.It Dv MAP_PREFAULT_PARTIAL
117The mapping should be partially prefaulted into physical memory.
118.It Dv MAP_DISABLE_SYNCER
119Do not periodically flush dirty pages; only flush them when absolutely
120necessary.
121.It Dv MAP_DISABLE_COREDUMP
122Do not include the mapping in a core dump.
123.It Dv MAP_PREFAULT_MADVISE
124Specify that the request from a user process calling
125.Xr madvise 2 .
126.El
127.Pp
128The
129.Vt struct vm_map_entry
130is a generic representation of a region.
131The region managed by each entry is associated with a
132.Vt union vm_map_object ,
133described below.
134.Bd -literal -offset indent
135struct vm_map_entry {
136        struct vm_map_entry *prev;
137        struct vm_map_entry *next;
138        struct vm_map_entry *left;
139        struct vm_map_entry *right;
140        vm_offset_t start;
141        vm_offset_t end;
142        vm_offset_t avail_ssize;
143        union vm_map_object object;
144        vm_ooffset_t offset;
145        vm_eflags_t eflags;
146        /* Only in task maps: */
147        vm_prot_t protection;
148        vm_prot_t max_protection;
149        vm_inherit_t inheritance;
150        int wired_count;
151        vm_pindex_t lastr;
152};
153.Ed
154.Pp
155The fields of
156.Vt struct vm_map_entry
157are as follows:
158.Bl -tag -width struct_vm_map_objectXXX
159.It Va prev
160Pointer to the previous node in a doubly-linked, circular list.
161.It Va next
162Pointer to the next node in a doubly-linked, circular list.
163.It Va left
164Pointer to the left node in a binary search tree.
165.It Va right
166Pointer to the right node in a binary search tree.
167.It Va start
168Lower address bound of this entry's region.
169.It Va end
170Upper address bound of this entry's region.
171.It Va avail_ssize
172If the entry is for a process stack, specifies how much the entry can grow.
173.It Va object
174Pointer to the
175.Vt struct vm_map_object
176with which this entry is associated.
177.It Va offset
178Offset within the
179.Va object
180which is mapped from
181.Va start
182onwards.
183.It Vt eflags
184Flags applied to this entry, described below.
185.El
186.Pp
187The following five members are only valid for entries forming part of
188a user process's address space:
189.Bl -tag -width struct_vm_map_objectXXX
190.It Va protection
191Memory protection bits applied to this region.
192These are identical to those defined for
193.Xr vm_page_protect 9 .
194.It Va max_protection
195Mask for the memory protection bits which may be actually be applied to
196this region.
197These are identical to those defined for
198.Xr vm_page_protect 9 .
199.It Va inheritance
200Contains flags which specify how this entry should be treated
201during fork processing.
202.It Va wired_count
203Count of how many times this entry has been wired into physical memory.
204.It Va lastr
205Contains the address of the last read which caused a page fault.
206.El
207.Pp
208The following flags may be applied to each entry, by specifying them
209as a mask within the
210.Fa eflags
211member:
212.Bl -tag -width MAP_ENTRY_BEHAV_SEQUENTIALXXX
213.It Dv MAP_ENTRY_NOSYNC
214The system should not flush the data associated with this map
215periodically, but only when it needs to.
216.It Dv MAP_ENTRY_IS_SUB_MAP
217If set, then the
218.Va object
219member specifies a subordinate map.
220.It Dv MAP_ENTRY_COW
221Indicate that this is a copy-on-write region.
222.It Dv MAP_ENTRY_NEEDS_COPY
223Indicate that a copy-on-write region needs to be copied.
224.It Dv MAP_ENTRY_NOFAULT
225Specifies that accesses within this region should never cause a page fault.
226If a page fault occurs within this region, the system will panic.
227.It Dv MAP_ENTRY_USER_WIRED
228Indicate that this region was wired on behalf of a user process.
229.It Dv MAP_ENTRY_BEHAV_NORMAL
230The system should use the default paging behaviour for this region.
231.It Dv MAP_ENTRY_BEHAV_SEQUENTIAL
232The system should depress the priority of pages immediately preceding
233each page within this region when faulted in.
234.It Dv MAP_ENTRY_BEHAV_RANDOM
235Is a hint that pages within this region will be accessed randomly,
236and that prefetching is likely not advantageous.
237.It Dv MAP_ENTRY_IN_TRANSITION
238Indicate that wiring or unwiring of an entry is in progress, and that
239other kernel threads should not attempt to modify fields in the structure.
240.It Dv MAP_ENTRY_NEEDS_WAKEUP
241Indicate that there are kernel threads waiting for this region to become
242available.
243.It Dv MAP_ENTRY_NOCOREDUMP
244The region should not be included in a core dump.
245.El
246.Pp
247The
248.Fa inheritance
249member has type
250.Vt vm_inherit_t .
251This governs the inheritance behaviour for a map entry during fork processing.
252The following values are defined for
253.Vt vm_inherit_t :
254.Bl -tag -width VM_INHERIT_DEFAULTXXX
255.It Dv VM_INHERIT_SHARE
256The object associated with the entry should be cloned and shared
257with the new map.
258A new
259.Vt struct vm_object
260will be created if necessary.
261.It Dv VM_INHERIT_COPY
262The object associated with the entry should be copied to the new map.
263.It Dv VM_INHERIT_NONE
264The entry should not be copied to the new map.
265.It Dv VM_INHERIT_DEFAULT
266Specifies the default behaviour,
267.Dv VM_INHERIT_COPY .
268.El
269.Pp
270The
271.Vt union vm_map_object
272is used to specify the structure which a
273.Vt struct vm_map_entry
274is associated with.
275.Pp
276The fields of
277.Vt union vm_map_object
278are as follows:
279.Bd -literal -offset indent
280union vm_map_object {
281        struct vm_object *vm_object;
282        struct vm_map *sub_map;
283};
284.Pp
285.Ed
286Normally, the
287.Va sub_map
288member is only used by system maps to indicate that a memory range
289is managed by a subordinate system map.
290Within a user process map, each
291.Vt struct vm_map_entry
292is backed by a
293.Vt struct vm_object .
294.Sh SEE ALSO
295.Xr pmap 9 ,
296.Xr vm_map_check_protection 9 ,
297.Xr vm_map_clean 9 ,
298.Xr vm_map_create 9 ,
299.Xr vm_map_delete 9 ,
300.Xr vm_map_find 9 ,
301.Xr vm_map_findspace 9 ,
302.Xr vm_map_inherit 9 ,
303.Xr vm_map_init 9 ,
304.Xr vm_map_insert 9 ,
305.Xr vm_map_lock 9 ,
306.Xr vm_map_lookup 9 ,
307.Xr vm_map_madvise 9 ,
308.Xr vm_map_max 9 ,
309.Xr vm_map_min 9 ,
310.Xr vm_map_pmap 9 ,
311.Xr vm_map_protect 9 ,
312.Xr vm_map_remove 9 ,
313.Xr vm_map_simplify_entry 9 ,
314.Xr vm_map_stack 9 ,
315.Xr vm_map_submap 9 ,
316.Xr vm_map_wire 9 ,
317.Xr vm_page_protect 9
318.Sh AUTHORS
319This manual page was written by
320.An Bruce M Simpson Aq bms@spc.org .
321