1.\" $NetBSD: mlockall.2,v 1.13 2008/04/30 13:10:51 martin Exp $ 2.\" 3.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8.\" NASA Ames Research Center. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd June 12, 1999 32.Dt MLOCKALL 2 33.Os 34.Sh NAME 35.Nm mlockall , 36.Nm munlockall 37.Nd lock (unlock) the address space of a process 38.Sh LIBRARY 39.Lb libc 40.Sh SYNOPSIS 41.In sys/mman.h 42.Ft int 43.Fn mlockall "int flags" 44.Ft int 45.Fn munlockall "void" 46.Sh DESCRIPTION 47The 48.Nm mlockall 49system call locks into memory the physical pages associated with the 50address space of a process until the address space is unlocked, the 51process exits, or execs another program image. 52.Pp 53The following flags affect the behavior of 54.Nm mlockall : 55.Bl -tag -width MCL_CURRENT 56.It Dv MCL_CURRENT 57Lock all pages currently mapped into the process's address space. 58.It Dv MCL_FUTURE 59Lock all pages mapped into the process's address space in the future, 60at the time the mapping is established. 61Note that this may cause future mappings to fail if those mappings 62cause resource limits to be exceeded. 63.El 64.Pp 65Since physical memory is a potentially scarce resource, processes are 66limited in how much they can lock down. 67A single process can lock the minimum of a system-wide 68.Dq wired pages 69limit and the per-process 70.Li RLIMIT_MEMLOCK 71resource limit. 72.Pp 73The 74.Nm munlockall 75call unlocks any locked memory regions in the process address space. 76Any regions mapped after an 77.Nm munlockall 78call will not be locked. 79.Sh RETURN VALUES 80A return value of 0 indicates that the call 81succeeded and all pages in the range have either been locked or unlocked. 82A return value of \-1 indicates an error occurred and the locked 83status of all pages in the range remains unchanged. 84In this case, the global location 85.Va errno 86is set to indicate the error. 87.Sh ERRORS 88.Fn mlockall 89will fail if: 90.Bl -tag -width Er 91.It Bq Er EINVAL 92The 93.Ar flags 94argument is zero, or includes unimplemented flags. 95.It Bq Er ENOMEM 96Locking the indicated range would exceed either the system or per-process 97limit for locked memory. 98.It Bq Er EAGAIN 99Some or all of the memory mapped into the process's address space 100could not be locked when the call was made. 101.It Bq Er EPERM 102The calling process does not have the appropriate privilege to perform 103the requested operation. 104.El 105.Sh SEE ALSO 106.Xr mincore 2 , 107.Xr mlock 2 , 108.Xr mmap 2 , 109.Xr munmap 2 , 110.Xr setrlimit 2 111.Sh STANDARDS 112The 113.Fn mlockall 114and 115.Fn munlockall 116functions conform to 117.St -p1003.1b-93 . 118.Sh HISTORY 119The 120.Fn mlockall 121and 122.Fn munlockall 123functions first appeared in 124.Nx 1.5 . 125.Sh BUGS 126The per-process resource limit is a limit on the amount of virtual 127memory locked, while the system-wide limit is for the number of locked 128physical pages. 129Hence a process with two distinct locked mappings of the same physical page 130counts as 2 pages against the per-process limit and as only a single page 131in the system limit. 132