Upgrade less(1). 1/2
[dragonfly.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. 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.
15 .\"
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
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)mlock.2     8.2 (Berkeley) 12/11/93
29 .\" $FreeBSD: src/lib/libc/sys/mlock.2,v 1.6.2.5 2001/12/14 18:34:01 ru Exp $
30 .\" $DragonFly: src/lib/libc/sys/mlock.2,v 1.4 2006/02/17 19:35:06 swildner Exp $
31 .\"
32 .Dd May 18, 2004
33 .Dt MLOCK 2
34 .Os
35 .Sh NAME
36 .Nm mlock ,
37 .Nm munlock
38 .Nd lock (unlock) physical pages in memory
39 .Sh LIBRARY
40 .Lb libc
41 .Sh SYNOPSIS
42 .In sys/types.h
43 .In sys/mman.h
44 .Ft int
45 .Fn mlock "const void *addr" "size_t len"
46 .Ft int
47 .Fn munlock "const void *addr" "size_t len"
48 .Sh DESCRIPTION
49 The
50 .Fn mlock
51 system call
52 locks into memory the physical pages associated with the virtual address
53 range starting at
54 .Fa addr
55 for
56 .Fa len
57 bytes.
58 The
59 .Fn munlock
60 call unlocks pages previously locked by one or more
61 .Fn mlock
62 calls.
63 For both, the
64 .Fa addr
65 parameter should be aligned to a multiple of the page size.
66 If the
67 .Fa len
68 parameter is not a multiple of the page size, it will be rounded up
69 to be so.
70 The entire range must be allocated.
71 .Pp
72 After an
73 .Fn mlock
74 call, the indicated pages will cause neither a non-resident page
75 nor address-translation fault until they are unlocked.
76 They may still cause protection-violation faults or TLB-miss faults on
77 architectures with software-managed TLBs.
78 The physical pages remain in memory until all locked mappings for the pages
79 are removed.
80 Multiple processes may have the same physical pages locked via their own
81 virtual address mappings.
82 A single process may likewise have pages multiply-locked via different virtual
83 mappings of the same pages or via nested
84 .Fn mlock
85 calls on the same address range.
86 Unlocking is performed explicitly by
87 .Fn munlock
88 or implicitly by a call to
89 .Fn munmap
90 which deallocates the unmapped address range.
91 Locked mappings are not inherited by the child process after a
92 .Xr fork 2 .
93 .Pp
94 Since physical memory is a potentially scarce resource, processes are
95 limited in how much they can lock down.
96 A single process can
97 .Fn mlock
98 the minimum of
99 a system-wide ``wired pages'' limit and
100 the per-process
101 .Li RLIMIT_MEMLOCK
102 resource limit.
103 .Pp
104 These calls are only available to the super-user.
105 .Sh RETURN VALUES
106 .Rv -std
107 .Pp
108 If the call succeeds, all pages in the range become locked (unlocked);
109 otherwise the locked status of all pages in the range remains unchanged.
110 .Sh ERRORS
111 .Fn Mlock
112 will fail if:
113 .Bl -tag -width Er
114 .It Bq Er EPERM
115 The caller is not the super-user.
116 .It Bq Er EINVAL
117 The address given is not page aligned or the length is negative.
118 .It Bq Er EAGAIN
119 Locking the indicated range would exceed either the system or per-process
120 limit for locked memory.
121 .It Bq Er ENOMEM
122 Some portion of the indicated address range is not allocated.
123 There was an error faulting/mapping a page.
124 .El
125 .Fn Munlock
126 will fail if:
127 .Bl -tag -width Er
128 .It Bq Er EPERM
129 The caller is not the super-user.
130 .It Bq Er EINVAL
131 The address given is not page aligned or the length is negative.
132 .It Bq Er ENOMEM
133 Some portion of the indicated address range is not allocated.
134 Some portion of the indicated address range is not locked.
135 .El
136 .Sh "SEE ALSO"
137 .Xr fork 2 ,
138 .Xr mincore 2 ,
139 .Xr minherit 2 ,
140 .Xr mmap 2 ,
141 .Xr munmap 2 ,
142 .Xr setrlimit 2 ,
143 .Xr getpagesize 3
144 .Sh HISTORY
145 The
146 .Fn mlock
147 and
148 .Fn munlock
149 functions first appeared in
150 .Bx 4.4 .
151 .Sh BUGS
152 The per-process resource limit is a limit on the amount of virtual
153 memory locked, while the system-wide limit is for the number of locked
154 physical pages.
155 Hence a process with two distinct locked mappings of the same physical page
156 counts as 2 pages against the per-process limit and as only a single page
157 in the system limit.
158 .Pp
159 The per-process resource limit is not currently supported.