1 .\" $NetBSD: mlock.2,v 1.3 1995/06/24 10:42:03 cgd 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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93
42 .Nd lock (unlock) physical pages in memory
44 .Fd #include <sys/mman.h>
47 .Fa "const void *addr"
52 .Fa "const void *addr"
59 locks a set of physical pages into memory.
60 The pages are associated with a virtual address range
68 call unlocks pages that were previously locked by one or more
73 parameter should be aligned to a multiple of the page size.
76 parameter is not a multiple of the page size,
77 it will be rounded up to be so.
78 The entire range must be allocated.
82 call, the indicated pages will cause neither a non-resident page
83 nor address-translation fault until they are unlocked.
84 They may still cause protection-violation faults or TLB-miss faults
85 on architectures with software-managed TLBs.
86 The physical pages remain in memory until all locked mappings
87 for the pages are removed.
89 Multiple processes may have the same physical pages locked
90 via their own virtual address mappings.
91 Similarly, a single process may have pages multiply-locked
92 via different virtual mappings of the same pages or via nested
94 calls on the same address range.
95 Unlocking is performed explicitly by
97 or implicitly by a call to
99 which deallocates the unmapped address range.
100 Locked mappings are not inherited by the child process after a
103 Because physical memory is a potentially scarce resource,
104 processes are limited in how much memory they can lock down.
108 a system-wide ``wired pages'' limit and
113 A return value of 0 indicates that the call succeeded
114 and all pages in the range have either been locked or unlocked,
116 A return value of -1 indicates an error occurred
117 and the locked status of all pages in the range remains unchanged.
118 In this case, the global location
120 is set to indicate the error.
129 The address given is not page-aligned or the length is negative.
132 Part or all of the specified address range
133 is not mapped to the process.
141 Locking the indicated range would exceed either the system or per-process
142 limit for locked memory.
145 Some portion of the indicated address range is not allocated.
146 There was an error faulting/mapping a page.
154 Some portion of the indicated address range is not allocated.
155 Some portion of the indicated address range is not locked.
158 .Fd #include <sys/types.h>
159 .Fd #include <sys/mman.h>
192 Unlike The Sun implementation, multiple
194 calls on the same address range require the corresponding number of
196 calls to actually unlock the pages, i.e.
199 This should be considered a consequence of the implementation
202 The per-process resource limit is a limit on the amount of virtual
203 memory locked, while the system-wide limit is for the number of locked
205 Hence a process with two distinct locked mappings of the same physical page
206 counts as 2 pages against the per-process limit and as only a single page
213 functions first appeared in 4.4BSD.