]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/sys/mlock.2
This commit was generated by cvs2svn to compensate for changes in r53910,
[FreeBSD/FreeBSD.git] / lib / libc / sys / mlock.2
1 .\" Copyright (c) 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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. All advertising materials mentioning features or use of this software
13 .\"    must display the following acknowledgement:
14 .\"     This product includes software developed by the University of
15 .\"     California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\"    may be used to endorse or promote products derived from this software
18 .\"    without specific prior written permission.
19 .\"
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)mlock.2     8.2 (Berkeley) 12/11/93
33 .\" $FreeBSD$
34 .\"
35 .Dd June 2, 1993
36 .Dt MLOCK 2
37 .Os
38 .Sh NAME
39 .Nm mlock ,
40 .Nm munlock
41 .Nd lock (unlock) physical pages in memory
42 .Sh SYNOPSIS
43 .Fd #include <sys/types.h>
44 .Fd #include <sys/mman.h>
45 .Ft int
46 .Fn mlock "const void *addr" "size_t len"
47 .Ft int
48 .Fn munlock "const void *addr" "size_t len"
49 .Sh DESCRIPTION
50 The
51 .Fn mlock
52 system call
53 locks into memory the physical pages associated with the virtual address
54 range starting at
55 .Fa addr
56 for
57 .Fa len
58 bytes.
59 The
60 .Fn munlock
61 call unlocks pages previously locked by one or more
62 .Fn mlock
63 calls.
64 For both, the
65 .Fa addr
66 parameter should be aligned to a multiple of the page size.
67 If the
68 .Fa len
69 parameter is not a multiple of the page size, it will be rounded up
70 to be so.
71 The entire range must be allocated.
72 .Pp
73 After an
74 .Fn mlock
75 call, the indicated pages will cause neither a non-resident page
76 nor address-translation fault until they are unlocked.
77 They may still cause protection-violation faults or TLB-miss faults on
78 architectures with software-managed TLBs.
79 The physical pages remain in memory until all locked mappings for the pages
80 are removed.
81 Multiple processes may have the same physical pages locked via their own
82 virtual address mappings.
83 A single process may likewise have pages multiply-locked via different virtual
84 mappings of the same pages or via nested
85 .Fn mlock
86 calls on the same address range.
87 Unlocking is performed explicitly by
88 .Fn munlock
89 or implicitly by a call to
90 .Fn munmap
91 which deallocates the unmapped address range.
92 Locked mappings are not inherited by the child process after a
93 .Xr fork 2 .
94 .Pp
95 Since physical memory is a potentially scarce resource, processes are
96 limited in how much they can lock down.
97 A single process can
98 .Fn mlock
99 the minimum of
100 a system-wide ``wired pages'' limit and
101 the per-process
102 .Li RLIMIT_MEMLOCK
103 resource limit.
104 .Pp
105 These calls are only available to the super-user.
106 .Sh RETURN VALUES
107 A return value of 0 indicates that the call
108 succeeded and all pages in the range have either been locked or unlocked.
109 A return value of -1 indicates an error occurred and the locked
110 status of all pages in the range remains unchanged.
111 In this case, the global location
112 .Va errno
113 is set to indicate the error.
114 .Sh ERRORS
115 .Fn Mlock
116 will fail if:
117 .Bl -tag -width Er
118 .It Bq Er EPERM
119 The caller is not the super-user.
120 .It Bq Er EINVAL
121 The address given is not page aligned or the length is negative.
122 .It Bq Er EAGAIN
123 Locking the indicated range would exceed either the system or per-process
124 limit for locked memory.
125 .It Bq Er ENOMEM
126 Some portion of the indicated address range is not allocated.
127 There was an error faulting/mapping a page.
128 .El
129 .Fn Munlock
130 will fail if:
131 .Bl -tag -width Er
132 .It Bq Er EPERM
133 The caller is not the super-user.
134 .It Bq Er EINVAL
135 The address given is not page aligned or the length is negative.
136 .It Bq Er ENOMEM
137 Some portion of the indicated address range is not allocated.
138 Some portion of the indicated address range is not locked.
139 .El
140 .Sh "SEE ALSO"
141 .Xr fork 2 ,
142 .Xr mincore 2 ,
143 .Xr minherit 2 ,
144 .Xr mmap 2 ,
145 .Xr munmap 2 ,
146 .Xr setrlimit 2 ,
147 .Xr getpagesize 3
148 .Sh BUGS
149 Unlike The Sun implementation, multiple
150 .Fn mlock
151 calls on the same address range require the corresponding number of
152 .Fn munlock
153 calls to actually unlock the pages, i.e.
154 .Fn mlock
155 nests.
156 This should be considered a consequence of the implementation
157 and not a feature.
158 .Pp
159 The per-process resource limit is a limit on the amount of virtual
160 memory locked, while the system-wide limit is for the number of locked
161 physical pages.
162 Hence a process with two distinct locked mappings of the same physical page
163 counts as 2 pages against the per-process limit and as only a single page
164 in the system limit.
165
166 The per-process resource limit is not currently supported.
167 .Sh HISTORY
168 The
169 .Fn mlock
170 and
171 .Fn munlock
172 functions first appeared in
173 .Bx 4.4 .