These are now just links; their content has been consoldiated intomlock.2

This commit is contained in:
Michael Kerrisk 2004-11-25 14:40:17 +00:00
parent 8176b81ab6
commit 8ce20bf7ba
3 changed files with 3 additions and 354 deletions

View File

@ -1,170 +1 @@
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) Markus Kuhn, 1996
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
.\" USA.
.\"
.\" 1995-11-26 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
.\" First version written
.\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
.\" Added notes on capability requirements
.\" Modified, 2004-11-23, mtk, Noted buggy MCL_FUTURE behaviour in 2.4.x
.\" Modified, 2004-11-25, mtk, 2.4 limits locks to half of physical mem.
.\" Modified, 2004-11-25, mtk, Noted MCL_FUTURE bug in 2.4.x, x < 18
.\"
.TH MLOCKALL 2 2004-11-25 "Linux 2.6.9" "Linux Programmer's Manual"
.SH NAME
mlockall \- disable paging for calling process
.SH SYNOPSIS
.nf
.B #include <sys/mman.h>
.sp
\fBint mlockall(int \fIflags\fB);
.fi
.SH DESCRIPTION
.B mlockall
disables paging for all pages mapped into the address space of the
calling process. This includes the pages of the code, data and stack
segment, as well as shared libraries, user space kernel data, shared
memory and memory mapped files. All mapped pages are guaranteed to be
resident in RAM when the
.B mlockall
system call returns successfully and they are guaranteed to stay in RAM
until the pages are unlocked again by
.B munlock
or
.B munlockall
or until the process terminates or starts another program with
.BR exec .
Child processes do not inherit page locks across a
.BR fork .
Memory locking has two main applications: real-time algorithms and
high-security data processing. Real-time applications require
deterministic timing, and, like scheduling, paging is one major cause
of unexpected program execution delays. Real-time applications will
usually also switch to a real-time scheduler with
.BR sched_setscheduler .
Cryptographic security software often handles critical bytes like
passwords or secret keys as data structures. As a result of paging,
these secrets could be transfered onto a persistent swap store medium,
where they might be accessible to the enemy long after the security
software has erased the secrets in RAM and terminated. For security
applications, only small parts of memory have to be locked, for which
.B mlock
is available.
The
.I flags
parameter can be constructed from the bitwise OR of the following
constants:
.TP 1.2i
.B MCL_CURRENT
Lock all pages which are currently mapped into the address space of
the process.
.TP
.B MCL_FUTURE
Lock all pages which will become mapped into the address space of the
process in the future. These could be for instance new pages required
by a growing heap and stack as well as new memory mapped files or
shared memory regions.
.PP
If
.B MCL_FUTURE
has been specified and the number of locked pages exceeds the upper
limit of allowed locked pages, then the system call which caused the
new mapping will fail with
.BR ENOMEM .
If these new pages have been mapped by the the growing stack, then the
kernel will deny stack expansion and send a
.BR SIGSEGV .
Real-time processes should reserve enough locked stack pages before
entering the time-critical section, so that no page fault can be
caused by function calls. This can be achieved by calling a function
which has a sufficiently large automatic variable and which writes to
the memory occupied by this large array in order to touch these stack
pages. This way, enough pages will be mapped for the stack and can be
locked into RAM. The dummy writes ensure that not even copy-on-write
page faults can occur in the critical section.
Memory locks do not stack, i.e., pages which have been locked several times
by calls to
.B mlockall
or
.B mlock
will be unlocked by a single call to
.BR munlockall .
Pages which are mapped to several locations or by several processes stay
locked into RAM as long as they are locked at least at one location or by
at least one process.
.SH "NOTES"
In Linux 2.4 and earlier, the kernel prevents a single process
from locking more than half of RAM.
.SH "RETURN VALUE"
On success,
.B mlockall
returns zero. On error, \-1 is returned, and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EINVAL
Unknown flags were specified.
.TP
.B ENOMEM
The process tried to exceed the maximum number of allowed locked
pages.
.TP
.B EPERM
The calling process has insufficient privilege to call
.BR mlockall .
Under Linux the
.B CAP_IPC_LOCK
capability is required.
.SH "BUGS"
In the 2.4 series Linux kernels up to and including 2.4.17,
a bug caused the
.B MCL_FUTURE
flag to be inherited across a
.BR fork (2).
This was rectified in kernel 2.4.18.
.SH AVAILABILITY
On POSIX systems on which
.B mlockall
and
.B munlockall
are available,
.B _POSIX_MEMLOCK
is defined in <unistd.h> to a value greater than 0. (See also
.BR sysconf (3).)
.\" POSIX 1003.1-2001: It shall be defined to -1 or 0 or 200112L.
.\" -1: unavailable, 0: ask using sysconf().
.\" glibc defines it to 1.
.SH "CONFORMING TO"
POSIX.1b, SVr4. SVr4 documents an additional EAGAIN error code.
.SH "SEE ALSO"
.BR mlock (2),
.BR munlock (2),
.BR munlockall (2),
.BR setrlimit (2),
.BR sysconf (3),
.BR capabilities (7)
.so man2/mlock.2

View File

@ -1,98 +1 @@
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) Markus Kuhn, 1996
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
.\" USA.
.\"
.\" 1995-11-26 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
.\" First version written
.\"
.TH MUNLOCK 2 2003-08-21 "Linux 2.4" "Linux Programmer's Manual"
.SH NAME
munlock \- reenable paging for some parts of memory
.SH SYNOPSIS
.nf
.B #include <sys/mman.h>
.sp
\fBint munlock(const void *\fIaddr\fB, size_t \fIlen\fB);
.fi
.SH DESCRIPTION
.B munlock
reenables paging for the memory in the range starting at
.I addr
with length
.I len
bytes. All pages which contain a part of the specified memory range
can after calling
.B munlock
be moved to external swap space again by the kernel.
Memory locks do not stack, i.e., pages which have been locked several times
by calls to
.B mlock
or
.B mlockall
will be unlocked by a single call to
.B munlock
for the corresponding range or by
.BR munlockall .
Pages which are mapped to several locations or by several processes stay
locked into RAM as long as they are locked at least at one location or by
at least one process.
On POSIX systems on which
.B mlock
and
.B munlock
are available,
.B _POSIX_MEMLOCK_RANGE
is defined in <unistd.h> and the value
.B PAGESIZE
from <limits.h> indicates the number of bytes per page.
.SH "RETURN VALUE"
On success,
.B munlock
returns zero. On error, \-1 is returned,
.I errno
is set appropriately, and no changes are made to any locks in the
address space of the process.
.SH ERRORS
.TP
.B EINVAL
(Not on Linux)
.I addr
was not a multiple of the page size.
.TP
.B ENOMEM
Some of the specified address range does not correspond to mapped
pages in the address space of the process.
.LP
Linux adds
.TP
.B EINVAL
.I len
was negative.
.SH "CONFORMING TO"
POSIX.1b, SVr4
.SH "SEE ALSO"
.BR mlock (2),
.BR mlockall (2),
.BR munlockall (2)
.so man2/mlock.2

View File

@ -1,86 +1 @@
.\" Hey Emacs! This file is -*- nroff -*- source.
.\"
.\" Copyright (C) Markus Kuhn, 1996
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" The GNU General Public License's references to "object code"
.\" and "executables" are to be interpreted as the output of any
.\" document formatting or typesetting system, including
.\" intermediate and printed output.
.\"
.\" This manual is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public
.\" License along with this manual; if not, write to the Free
.\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
.\" USA.
.\"
.\" 1995-11-26 Markus Kuhn <mskuhn@cip.informatik.uni-erlangen.de>
.\" First version written
.\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
.\" Added notes on capability requirements
.\"
.TH MUNLOCKALL 2 2004-05-27 "Linux 2.6.6" "Linux Programmer's Manual"
.SH NAME
munlockall \- reenable paging for calling process
.SH SYNOPSIS
.nf
.B #include <sys/mman.h>
.sp
\fBint munlockall(void);
.fi
.SH DESCRIPTION
.B munlockall
reenables paging for all pages mapped into the address space of the
calling process.
Memory locks do not stack, i.e., pages which have been locked several times
by calls to
.B mlock
or
.B mlockall
will be unlocked by a single call to
.BR munlockall .
Pages which are mapped to several locations or by several processes stay
locked into RAM as long as they are locked at least at one location or by
at least one process.
On POSIX systems on which
.B mlockall
and
.B munlockall
are available,
.B _POSIX_MEMLOCK
is defined in
.I <unistd.h> .
.SH "RETURN VALUE"
On success,
.B munlockall
returns zero. On error, \-1 is returned and
.I errno
is set appropriately.
.SH ERRORS
.TP
.B EPERM
The calling process has insufficient privilege to call
.BR munlockall .
Under Linux the
.B CAP_IPC_LOCK
capability is required.
.\" Weirdness this way comes: CAP_IPC_LOCK is required for munlockall()
.\" and shmctl(SHM_UNLOCK), but is *not* required for munlock
.\" (as at kernel 2.6.6)
.SH "CONFORMING TO"
POSIX.1b, SVr4
.SH "SEE ALSO"
.BR mlock (2),
.BR mlockall (2),
.BR munlock (2),
.BR capabilities (7)
.so man2/mlock.2