1 .\" $NetBSD: mlock.2,v 1.20 2011/02/28 07:17:02 wiz Exp $
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93
38 .Nd lock (unlock) physical pages in memory
44 .Fn mlock "void *addr" "size_t len"
46 .Fn munlock "void *addr" "size_t len"
51 locks into memory the physical pages associated with the virtual address
59 call unlocks pages previously locked by one or more
62 The entire range of memory must be allocated.
66 call, the indicated pages will cause neither a non-resident page
67 nor address-translation fault until they are unlocked.
68 They may still cause protection-violation faults or TLB-miss faults on
69 architectures with software-managed TLBs.
70 The physical pages remain in memory until all locked mappings for the pages
72 Multiple processes may have the same physical pages locked via their own
73 virtual address mappings.
74 A single process may likewise have pages multiply-locked via different virtual
75 mappings of the same pages or via nested
77 calls on the same address range.
78 Unlocking is performed explicitly by
80 or implicitly by a call to
82 which deallocates the unmapped address range.
83 Locked mappings are not inherited by the child process after a
86 Since physical memory is a potentially scarce resource, processes are
87 limited in how much they can lock down.
91 a system-wide ``wired pages'' limit and
96 Portable code should ensure that the
100 parameters are aligned to a multiple of the page size, even though the
102 implementation will round as necessary.
104 A return value of 0 indicates that the call
105 succeeded and all pages in the range have either been locked or unlocked.
106 A return value of \-1 indicates an error occurred and the locked
107 status of all pages in the range remains unchanged.
108 In this case, the global location
110 is set to indicate the error.
116 Locking the indicated range would exceed either the system or per-process
117 limit for locked memory.
119 The length is negative; or the address or length given is not page
120 aligned and the implementation does not round.
122 Some portion of the indicated address range is not allocated.
123 There was an error faulting/mapping a page.
126 was called by non-root on an architecture where locked page accounting
134 The length is negative; or the address or length given is not page
135 aligned and the implementation does not round.
137 Some portion of the indicated address range is not allocated.
138 Some portion of the indicated address range is not locked.
159 functions first appeared in
162 The per-process resource limit is a limit on the amount of virtual
163 memory locked, while the system-wide limit is for the number of locked
165 Hence a process with two distinct locked mappings of the same physical page
166 counts as 2 pages against the per-process limit and as only a single page