2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93
37 .Nd lock (unlock) physical pages in memory
43 .Fn mlock "const void *addr" "size_t len"
45 .Fn munlock "const void *addr" "size_t len"
50 locks into memory the physical pages associated with the virtual address
58 system call unlocks pages previously locked by one or more
63 argument should be aligned to a multiple of the page size.
66 argument is not a multiple of the page size, it will be rounded up
68 The entire range must be allocated.
72 system call, the indicated pages will cause neither a non-resident page
73 nor address-translation fault until they are unlocked.
74 They may still cause protection-violation faults or TLB-miss faults on
75 architectures with software-managed TLBs.
76 The physical pages remain in memory until all locked mappings for the pages
78 Multiple processes may have the same physical pages locked via their own
79 virtual address mappings.
80 A single process may likewise have pages multiply-locked via different virtual
81 mappings of the same physical pages.
82 Unlocking is performed explicitly by
84 or implicitly by a call to
86 which deallocates the unmapped address range.
87 Locked mappings are not inherited by the child process after a
90 Since physical memory is a potentially scarce resource, processes are
91 limited in how much they can lock down.
92 The amount of memory that a single process can
94 is limited by both the per-process
96 resource limit and the
102 applies to the system as a whole, so the amount available to a single
103 process at any given time is the difference between
106 .Va vm.stats.vm.v_wire_count .
109 .Va security.bsd.unprivileged_mlock
110 is set to 0 these calls are only available to the super-user.
114 If the call succeeds, all pages in the range become locked (unlocked);
115 otherwise the locked status of all pages in the range remains unchanged.
123 .Va security.bsd.unprivileged_mlock
124 is set to 0 and the caller is not the super-user.
126 The address range given wraps around zero.
128 Locking the indicated range would exceed the system limit for locked memory.
130 Some portion of the indicated address range is not allocated.
131 There was an error faulting/mapping a page.
132 Locking the indicated range would exceed the per-process limit for locked
141 .Va security.bsd.unprivileged_mlock
142 is set to 0 and the caller is not the super-user.
144 The address range given wraps around zero.
146 Some or all of the address range specified by the addr and len
147 arguments does not correspond to valid mapped pages in the address space
150 Locking the pages mapped by the specified range would exceed a limit on
151 the amount of memory that the process may lock.
168 system calls first appeared in
171 Allocating too much wired memory can lead to a memory-allocation deadlock
172 which requires a reboot to recover from.
174 The per-process resource limit is a limit on the amount of virtual
175 memory locked, while the system-wide limit is for the number of locked
177 Hence a process with two distinct locked mappings of the same physical page
178 counts as 2 pages against the per-process limit and as only a single page
181 The per-process resource limit is not currently supported.