1 .\" $OpenBSD: mlockall.2,v 1.5 2008/06/26 05:42:05 ray Exp $
2 .\" $NetBSD: mlockall.2,v 1.6 2000/06/26 17:00:02 kleink Exp $
4 .\" Copyright (c) 1999 The NetBSD Foundation, Inc.
5 .\" All rights reserved.
7 .\" This code is derived from software contributed to The NetBSD Foundation
8 .\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 .\" NASA Ames Research Center.
11 .\" Redistribution and use in source and binary forms, with or without
12 .\" modification, are permitted provided that the following conditions
14 .\" 1. Redistributions of source code must retain the above copyright
15 .\" notice, this list of conditions and the following disclaimer.
16 .\" 2. Redistributions in binary form must reproduce the above copyright
17 .\" notice, this list of conditions and the following disclaimer in the
18 .\" documentation and/or other materials provided with the distribution.
19 .\" 3. All advertising materials mentioning features or use of this software
20 .\" must display the following acknowledgement:
21 .\" This product includes software developed by the NetBSD
22 .\" Foundation, Inc. and its contributors.
23 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
24 .\" contributors may be used to endorse or promote products derived
25 .\" from this software without specific prior written permission.
27 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 .\" POSSIBILITY OF SUCH DAMAGE.
45 .Nd lock (unlock) the address space of a process
52 .Fn mlockall "int flags"
58 system call locks into memory the physical pages associated with the
59 address space of a process until the address space is unlocked, the
60 process exits, fork()s, or execs another program image. Any pages which
61 are copy-on-write at the time of the function call will be force faulted.
62 Locked pages will not be paged to swap backing store.
64 The following flags affect the behavior of
66 .Bl -tag -width ".Dv MCL_CURRENT"
68 Lock all pages currently mapped into the process's address space.
70 Lock all pages mapped into the process's address space in the future,
71 at the time the mapping is established.
72 Note that this may cause future mappings to fail if those mappings
73 cause resource limits to be exceeded.
76 Since physical memory is a potentially scarce resource, processes are
77 limited in how much they can lock down.
78 A single process can lock the minimum of a system-wide
80 limit and the per-process
85 has two limitations, necessary to keep it functional on modern systems.
86 The first is that writable file-backed MAP_PRIVATE pages (such as shared
87 library mappings) which have not yet been write-faulted will retain their
88 read-only mapping to the file backing store and not be force-copied.
89 If we were to force copy these pages, it would cause immense unnecessary
90 overheads for the program.
91 So any unmodified but writable pages which are currently in
92 the pmap read-only will still take a COW fault if written to.
94 The second limitation is that when a fork() is issued, all writable pages
95 will be made copy-on-write (COW) in both the parent and the child. The child
96 of course does not inherit the locked memory state, but this action will
97 cause any locked pages in the parent to become copy-on-write and they will
98 be faulted if written to. So they will not be quite as locked as might have
99 been intended in this situation.
103 call unlocks any locked memory regions in the process address space.
104 Any regions mapped after an
106 call will not be locked.
108 A return value of 0 indicates that the call
109 succeeded and all pages in the range have either been locked or unlocked.
110 A return value of \-1 indicates an error occurred and the locked
111 status of all pages in the range remains unchanged.
112 In this case, the global location
114 is set to indicate the error.
122 argument is zero, or includes unimplemented flags.
124 Locking the indicated range would exceed either the system or per-process
125 limit for locked memory.
127 The calling process does not have the appropriate privilege to perform
128 the requested operation.
139 functions are believed to conform to
146 functions first appeared in
149 How could there be any bugs? This is soooo simple...
151 These system calls are not recommended for general use. They are obviously
152 not thread-safe, and the larger application context from which they are
153 called might be hostile to such actions due to non-deterministic resource
154 limits in the system. In a modern system, even semi-realtime and interactive
155 processes are already detected and handled by the system schedule.
160 to lock specific address ranges instead of locking the entire address space.