xref: /freebsd/share/man/man9/vm_map.9 (revision cec50dea12481dc578c0805c887ab2097e1c06c5)
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.Os
31.Sh NAME
32.Nm vm_map
33.Nd virtual address space portion of virtual memory subsystem
34.Sh SYNOPSIS
35.In sys/param.h
36.In vm/vm.h
37.In vm/vm_map.h
38.Sh DESCRIPTION
39The
40.Nm
41subsystem is used to manage virtual address spaces.
42This section describes the main data structures used within the code.
43.Pp
44The
45.Vt "struct vm_map"
46is a generic representation of an address space.
47This address space may belong to a user process or the kernel.
48The kernel actually uses several maps, which are maintained as
49subordinate maps, created using the
50.Xr vm_map_submap 9
51function.
52.Bd -literal -offset indent
53struct vm_map {
54        struct vm_map_entry header;
55        struct sx lock;
56        struct mtx system_mtx;
57        int nentries;
58        vm_size_t size;
59        u_int timestamp;
60        u_char needs_wakeup;
61        u_char system_map;
62        vm_flags_t flags;
63        vm_map_entry_t root;
64        pmap_t pmap;
65#define min_offset      header.start
66#define max_offset      header.end
67};
68.Ed
69.Pp
70The fields of
71.Vt struct vm_map
72are as follows:
73.Bl -tag -width ".Va needs_wakeup"
74.It Va header
75Head node of a circular, doubly linked list of
76.Vt struct vm_map_entry
77objects.
78Each object defines a particular region within this map's address space.
79.It Va lock
80Used to serialize access to the structure.
81.It Va system_mtx
82A mutex which is used if the map is a system map.
83.It Va nentries
84A count of the members in use within the circular map entry list.
85.It Va size
86Specifies the size of the virtual address space.
87.It Va timestamp
88Used to determine if the map has changed since its last access.
89.It Va needs_wakeup
90Indicates if a thread is waiting for an allocation within the map.
91Used only by system maps.
92.It Va system_map
93Set to TRUE to indicate that map is a system map; otherwise, it belongs
94to a user process.
95.It Va flags
96Map flags.
97.It Va root
98Root node of a binary search tree used for fast lookup of map entries.
99.It Va pmap
100Pointer to the underlying physical map with which this virtual map
101is associated.
102.It Va min_offset
103The minimum
104.Va vm_offset_t
105in this map.
106Programs should never use
107.Va header.start
108or
109.Va header.end
110directly, use
111.Va min_offset
112and
113.Va max_offset
114instead.
115.It Va max_offset
116The maximum
117.Va vm_offset_t
118in this map.
119.El
120.Pp
121The following flags can be passed to
122.Xr vm_map_find 9
123and
124.Xr vm_map_insert 9
125to specify the copy-on-write properties of regions within the map:
126.Bl -tag -width ".Dv MAP_PREFAULT_MADVISE"
127.It Dv MAP_COPY_ON_WRITE
128The mapping is copy-on-write.
129.It Dv MAP_NOFAULT
130The mapping should not generate page faults.
131.It Dv MAP_PREFAULT
132The mapping should be prefaulted into physical memory.
133.It Dv MAP_PREFAULT_PARTIAL
134The mapping should be partially prefaulted into physical memory.
135.It Dv MAP_DISABLE_SYNCER
136Do not periodically flush dirty pages; only flush them when absolutely
137necessary.
138.It Dv MAP_DISABLE_COREDUMP
139Do not include the mapping in a core dump.
140.It Dv MAP_PREFAULT_MADVISE
141Specify that the request from a user process calling
142.Xr madvise 2 .
143.El
144.Pp
145The
146.Vt struct vm_map_entry
147is a generic representation of a region.
148The region managed by each entry is associated with a
149.Vt union vm_map_object ,
150described below.
151.Bd -literal -offset indent
152struct vm_map_entry {
153        struct vm_map_entry *prev;
154        struct vm_map_entry *next;
155        struct vm_map_entry *left;
156        struct vm_map_entry *right;
157        vm_offset_t start;
158        vm_offset_t end;
159        vm_offset_t avail_ssize;
160        vm_size_t adj_free;
161        vm_size_t max_free;
162        union vm_map_object object;
163        vm_ooffset_t offset;
164        vm_eflags_t eflags;
165        /* Only in task maps: */
166        vm_prot_t protection;
167        vm_prot_t max_protection;
168        vm_inherit_t inheritance;
169        int wired_count;
170        vm_pindex_t lastr;
171};
172.Ed
173.Pp
174The fields of
175.Vt struct vm_map_entry
176are as follows:
177.Bl -tag -width ".Va avail_ssize"
178.It Va prev
179Pointer to the previous node in a doubly-linked, circular list.
180.It Va next
181Pointer to the next node in a doubly-linked, circular list.
182.It Va left
183Pointer to the left node in a binary search tree.
184.It Va right
185Pointer to the right node in a binary search tree.
186.It Va start
187Lower address bound of this entry's region.
188.It Va end
189Upper address bound of this entry's region.
190.It Va avail_ssize
191If the entry is for a process stack, specifies how much the entry can grow.
192.It Va adj_free
193The amount of free, unmapped address space adjacent to and immediately
194following this map entry.
195.It Va max_free
196The maximum amount of contiguous free space in this map entry's subtree.
197.It Va object
198Pointer to the
199.Vt struct vm_map_object
200with which this entry is associated.
201.It Va offset
202Offset within the
203.Va object
204which is mapped from
205.Va start
206onwards.
207.It Va eflags
208Flags applied to this entry, described below.
209.El
210.Pp
211The following five members are only valid for entries forming part of
212a user process's address space:
213.Bl -tag -width ".Va max_protection"
214.It Va protection
215Memory protection bits applied to this region.
216These are identical to those defined for
217.Xr vm_page_protect 9 .
218.It Va max_protection
219Mask for the memory protection bits which may be actually be applied to
220this region.
221These are identical to those defined for
222.Xr vm_page_protect 9 .
223.It Va inheritance
224Contains flags which specify how this entry should be treated
225during fork processing.
226.It Va wired_count
227Count of how many times this entry has been wired into physical memory.
228.It Va lastr
229Contains the address of the last read which caused a page fault.
230.El
231.Pp
232The following flags may be applied to each entry, by specifying them
233as a mask within the
234.Va eflags
235member:
236.Bl -tag -width ".Dv MAP_ENTRY_BEHAV_SEQUENTIAL"
237.It Dv MAP_ENTRY_NOSYNC
238The system should not flush the data associated with this map
239periodically, but only when it needs to.
240.It Dv MAP_ENTRY_IS_SUB_MAP
241If set, then the
242.Va object
243member specifies a subordinate map.
244.It Dv MAP_ENTRY_COW
245Indicate that this is a copy-on-write region.
246.It Dv MAP_ENTRY_NEEDS_COPY
247Indicate that a copy-on-write region needs to be copied.
248.It Dv MAP_ENTRY_NOFAULT
249Specifies that accesses within this region should never cause a page fault.
250If a page fault occurs within this region, the system will panic.
251.It Dv MAP_ENTRY_USER_WIRED
252Indicate that this region was wired on behalf of a user process.
253.It Dv MAP_ENTRY_BEHAV_NORMAL
254The system should use the default paging behaviour for this region.
255.It Dv MAP_ENTRY_BEHAV_SEQUENTIAL
256The system should depress the priority of pages immediately preceding
257each page within this region when faulted in.
258.It Dv MAP_ENTRY_BEHAV_RANDOM
259Is a hint that pages within this region will be accessed randomly,
260and that prefetching is likely not advantageous.
261.It Dv MAP_ENTRY_IN_TRANSITION
262Indicate that wiring or unwiring of an entry is in progress, and that
263other kernel threads should not attempt to modify fields in the structure.
264.It Dv MAP_ENTRY_NEEDS_WAKEUP
265Indicate that there are kernel threads waiting for this region to become
266available.
267.It Dv MAP_ENTRY_NOCOREDUMP
268The region should not be included in a core dump.
269.El
270.Pp
271The
272.Va inheritance
273member has type
274.Vt vm_inherit_t .
275This governs the inheritance behaviour for a map entry during fork processing.
276The following values are defined for
277.Vt vm_inherit_t :
278.Bl -tag -width ".Dv VM_INHERIT_DEFAULT"
279.It Dv VM_INHERIT_SHARE
280The object associated with the entry should be cloned and shared
281with the new map.
282A new
283.Vt struct vm_object
284will be created if necessary.
285.It Dv VM_INHERIT_COPY
286The object associated with the entry should be copied to the new map.
287.It Dv VM_INHERIT_NONE
288The entry should not be copied to the new map.
289.It Dv VM_INHERIT_DEFAULT
290Specifies the default behaviour,
291.Dv VM_INHERIT_COPY .
292.El
293.Pp
294The
295.Vt union vm_map_object
296is used to specify the structure which a
297.Vt struct vm_map_entry
298is associated with.
299.Pp
300The fields of
301.Vt union vm_map_object
302are as follows:
303.Bd -literal -offset indent
304union vm_map_object {
305        struct vm_object *vm_object;
306        struct vm_map *sub_map;
307};
308.Pp
309.Ed
310Normally, the
311.Va sub_map
312member is only used by system maps to indicate that a memory range
313is managed by a subordinate system map.
314Within a user process map, each
315.Vt struct vm_map_entry
316is backed by a
317.Vt struct vm_object .
318.Sh SEE ALSO
319.Xr pmap 9 ,
320.Xr vm_map_check_protection 9 ,
321.Xr vm_map_clean 9 ,
322.Xr vm_map_create 9 ,
323.Xr vm_map_delete 9 ,
324.Xr vm_map_find 9 ,
325.Xr vm_map_findspace 9 ,
326.Xr vm_map_inherit 9 ,
327.Xr vm_map_init 9 ,
328.Xr vm_map_insert 9 ,
329.Xr vm_map_lock 9 ,
330.Xr vm_map_lookup 9 ,
331.Xr vm_map_madvise 9 ,
332.Xr vm_map_max 9 ,
333.Xr vm_map_min 9 ,
334.Xr vm_map_pmap 9 ,
335.Xr vm_map_protect 9 ,
336.Xr vm_map_remove 9 ,
337.Xr vm_map_simplify_entry 9 ,
338.Xr vm_map_stack 9 ,
339.Xr vm_map_submap 9 ,
340.Xr vm_map_wire 9 ,
341.Xr vm_page_protect 9
342.Sh AUTHORS
343This manual page was written by
344.An Bruce M Simpson Aq bms@spc.org .
345