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