Blame SOURCES/1573281-mpo-7.6.0-mlock.2-mlock2.2.patch

5a015b
From 88a7af51d8ef4d9199ff9073bc09eabb5182fe80 Mon Sep 17 00:00:00 2001
5a015b
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
5a015b
Date: Tue, 19 Jun 2018 13:14:13 +0200
5a015b
Subject: [PATCH 2/3] mlock.2, mlock2.2: document mlock2(2) and MCL_ONFAULT
5a015b
---
5a015b
 man-pages/man2/mlock.2 | 152 ++++++++++++++++++++++++++++++++++++-----
5a015b
 1 file changed, 136 insertions(+), 16 deletions(-)
5a015b
5a015b
diff --git a/man-pages/man2/mlock.2 b/man-pages/man2/mlock.2
5a015b
index 27189d8..595c9e9 100644
5a015b
--- a/man-pages/man2/mlock.2
5a015b
+++ b/man-pages/man2/mlock.2
5a015b
@@ -23,35 +23,39 @@
5a015b
 .\" <http://www.gnu.org/licenses/>.
5a015b
 .\" %%%LICENSE_END
5a015b
 .\"
5a015b
-.TH MLOCK 2 2011-09-14 "Linux" "Linux Programmer's Manual"
5a015b
+.TH MLOCK 2 2015-08-28 "Linux" "Linux Programmer's Manual"
5a015b
 .SH NAME
5a015b
-mlock, munlock, mlockall, munlockall \- lock and unlock memory
5a015b
+mlock, mlock2, munlock, mlockall, munlockall \- lock and unlock memory
5a015b
 .SH SYNOPSIS
5a015b
 .nf
5a015b
 .B #include <sys/mman.h>
5a015b
 .sp
5a015b
 .BI "int mlock(const void *" addr ", size_t " len );
5a015b
+.BI "int mlock2(const void *" addr ", size_t " len ", int " flags );
5a015b
 .BI "int munlock(const void *" addr ", size_t " len );
5a015b
 .sp
5a015b
 .BI "int mlockall(int " flags );
5a015b
 .B int munlockall(void);
5a015b
 .fi
5a015b
 .SH DESCRIPTION
5a015b
-.BR mlock ()
5a015b
+.BR mlock (),
5a015b
+.BR mlock2 (),
5a015b
 and
5a015b
 .BR mlockall ()
5a015b
-respectively lock part or all of the calling process's virtual address
5a015b
+lock part or all of the calling process's virtual address
5a015b
 space into RAM, preventing that memory from being paged to the
5a015b
 swap area.
5a015b
+
5a015b
 .BR munlock ()
5a015b
 and
5a015b
 .BR munlockall ()
5a015b
 perform the converse operation,
5a015b
-respectively unlocking part or all of the calling process's virtual
5a015b
+unlocking part or all of the calling process's virtual
5a015b
 address space, so that pages in the specified virtual address range may
5a015b
 once more to be swapped out if required by the kernel memory manager.
5a015b
+
5a015b
 Memory locking and unlocking are performed in units of whole pages.
5a015b
-.SS mlock() and munlock()
5a015b
+.SS mlock(), mlock2(), and munlock()
5a015b
 .BR mlock ()
5a015b
 locks pages in the address range starting at
5a015b
 .I addr
5a015b
@@ -62,6 +66,41 @@ All pages that contain a part of the specified address range are
5a015b
 guaranteed to be resident in RAM when the call returns successfully;
5a015b
 the pages are guaranteed to stay in RAM until later unlocked.
5a015b
 
5a015b
+.BR mlock2 ()
5a015b
+.\" commit a8ca5d0ecbdde5cc3d7accacbd69968b0c98764e
5a015b
+.\" commit de60f5f10c58d4f34b68622442c0e04180367f3f
5a015b
+.\" commit b0f205c2a3082dd9081f9a94e50658c5fa906ff1
5a015b
+also locks pages in the specified range starting at
5a015b
+.I addr
5a015b
+and continuing for
5a015b
+.I len
5a015b
+bytes.
5a015b
+However, the state of the pages contained in that range after the call
5a015b
+returns successfully will depend on the value in the
5a015b
+.I flags
5a015b
+argument.
5a015b
+
5a015b
+The
5a015b
+.I flags
5a015b
+argument can be either 0 or the following constant:
5a015b
+.TP
5a015b
+.B MLOCK_ONFAULT
5a015b
+Lock pages that are currently resident and mark the entire range to have
5a015b
+pages locked when they are populated by the page fault.
5a015b
+.PP
5a015b
+
5a015b
+If
5a015b
+.I flags
5a015b
+is 0,
5a015b
+.BR mlock2 ()
5a015b
+behaves exactly the same as
5a015b
+.BR mlock ().
5a015b
+
5a015b
+Note: currently, there is not a glibc wrapper for
5a015b
+.BR mlock2 (),
5a015b
+so it will need to be invoked using
5a015b
+.BR syscall (2).
5a015b
+
5a015b
 .BR munlock ()
5a015b
 unlocks pages in the address range starting at
5a015b
 .I addr
5a015b
@@ -93,9 +132,36 @@ the process.
5a015b
 .B MCL_FUTURE
5a015b
 Lock all pages which will become mapped into the address space of the
5a015b
 process in the future.
5a015b
-These could be for instance new pages required
5a015b
-by a growing heap and stack as well as new memory mapped files or
5a015b
+These could be, for instance, new pages required
5a015b
+by a growing heap and stack as well as new memory-mapped files or
5a015b
 shared memory regions.
5a015b
+.TP
5a015b
+.BR MCL_ONFAULT " (since Linux 4.4)"
5a015b
+Used together with
5a015b
+.BR MCL_CURRENT ,
5a015b
+.BR MCL_FUTURE ,
5a015b
+or both.
5a015b
+Mark all current (with
5a015b
+.BR MCL_CURRENT )
5a015b
+or future (with
5a015b
+.BR MCL_FUTURE )
5a015b
+mappings to lock pages when they are faulted in.
5a015b
+When used with
5a015b
+.BR MCL_CURRENT ,
5a015b
+all present pages are locked, but
5a015b
+.BR mlockall ()
5a015b
+will not fault in non-present pages.
5a015b
+When used with
5a015b
+.BR MCL_FUTURE ,
5a015b
+all future mappings will be marked to lock pages when they are faulted
5a015b
+in, but they will not be populated by the lock when the mapping is
5a015b
+created.
5a015b
+.B MCL_ONFAULT
5a015b
+must be used with either
5a015b
+.B MCL_CURRENT
5a015b
+or
5a015b
+.B MCL_FUTURE
5a015b
+or both.
5a015b
 .PP
5a015b
 If
5a015b
 .B MCL_FUTURE
5a015b
@@ -148,7 +214,8 @@ to perform the requested operation.
5a015b
 .\"SVr4 documents an additional EAGAIN error code.
5a015b
 .LP
5a015b
 For
5a015b
-.BR mlock ()
5a015b
+.BR mlock (),
5a015b
+.BR mlock2 (),
5a015b
 and
5a015b
 .BR munlock ():
5a015b
 .TP
5a015b
@@ -157,9 +224,9 @@ Some or all of the specified address range could not be locked.
5a015b
 .TP
5a015b
 .B EINVAL
5a015b
 The result of the addition
5a015b
-.IR start + len
5a015b
+.IR addr + len
5a015b
 was less than
5a015b
-.IR start
5a015b
+.IR addr
5a015b
 (e.g., the addition may have resulted in an overflow).
5a015b
 .TP
5a015b
 .B EINVAL
5a015b
@@ -172,19 +239,36 @@ Some of the specified address range does not correspond to mapped
5a015b
 pages in the address space of the process.
5a015b
 .LP
5a015b
 For
5a015b
-.BR mlockall ():
5a015b
+.BR mlock2 ():
5a015b
 .TP
5a015b
 .B EINVAL
5a015b
 Unknown \fIflags\fP were specified.
5a015b
 .LP
5a015b
 For
5a015b
+.BR mlockall ():
5a015b
+.TP
5a015b
+.B EINVAL
5a015b
+Unknown \fIflags\fP were specified or
5a015b
+.B MCL_ONFAULT
5a015b
+was specified without either
5a015b
+.B MCL_FUTURE
5a015b
+or
5a015b
+.BR MCL_CURRENT .
5a015b
+.LP
5a015b
+For
5a015b
 .BR munlockall ():
5a015b
 .TP
5a015b
 .B EPERM
5a015b
 (Linux 2.6.8 and earlier) The caller was not privileged
5a015b
 .RB ( CAP_IPC_LOCK ).
5a015b
+.SH VERSIONS
5a015b
+.BR mlock2 (2)
5a015b
+is available since Linux 4.4.
5a015b
 .SH CONFORMING TO
5a015b
-POSIX.1-2001, SVr4.
5a015b
+POSIX.1-2001, POSIX.1-2008, SVr4.
5a015b
+
5a015b
+mlock2 ()
5a015b
+is Linux specific.
5a015b
 .SH AVAILABILITY
5a015b
 On POSIX systems on which
5a015b
 .BR mlock ()
5a015b
@@ -247,6 +331,15 @@ Memory locks are not inherited by a child created via
5a015b
 and are automatically removed (unlocked) during an
5a015b
 .BR execve (2)
5a015b
 or when the process terminates.
5a015b
+The
5a015b
+.BR mlockall ()
5a015b
+.B MCL_FUTURE
5a015b
+and
5a015b
+.B MCL_FUTURE | MCL_ONFAULT
5a015b
+settings are not inherited by a child created via
5a015b
+.BR fork (2)
5a015b
+and are cleared during an
5a015b
+.BR execve (2).
5a015b
 
5a015b
 The memory lock on an address range is automatically removed
5a015b
 if the address range is unmapped via
5a015b
@@ -254,7 +347,8 @@ if the address range is unmapped via
5a015b
 
5a015b
 Memory locks do not stack, that is, pages which have been locked several times
5a015b
 by calls to
5a015b
-.BR mlock ()
5a015b
+.BR mlock (),
5a015b
+.BR mlock2 (),
5a015b
 or
5a015b
 .BR mlockall ()
5a015b
 will be unlocked by a single call to
5a015b
@@ -264,15 +358,40 @@ for the corresponding range or by
5a015b
 Pages which are mapped to several locations or by several processes stay
5a015b
 locked into RAM as long as they are locked at least at one location or by
5a015b
 at least one process.
5a015b
+
5a015b
+If a call to
5a015b
+.BR mlockall ()
5a015b
+which uses the
5a015b
+.B MCL_FUTURE
5a015b
+flag is followed by another call that does not specify this flag, the
5a015b
+changes made by the
5a015b
+.B MCL_FUTURE
5a015b
+call will be lost.
5a015b
+
5a015b
+The
5a015b
+.BR mlock2 ()
5a015b
+.B MLOCK_ONFAULT
5a015b
+flag and the
5a015b
+.BR mlockall ()
5a015b
+.B MCL_ONFAULT
5a015b
+flag allow efficient memory locking for applications that deal with
5a015b
+large mappings where only a (small) portion of pages in the mapping are touched.
5a015b
+In such cases, locking all of the pages in a mapping would incur
5a015b
+a significant penalty for memory locking.
5a015b
 .SS Linux notes
5a015b
 Under Linux,
5a015b
-.BR mlock ()
5a015b
+.BR mlock (),
5a015b
+.BR mlock2 (),
5a015b
 and
5a015b
 .BR munlock ()
5a015b
 automatically round
5a015b
 .I addr
5a015b
 down to the nearest page boundary.
5a015b
-However, POSIX.1-2001 allows an implementation to require that
5a015b
+However, the POSIX.1 specification of
5a015b
+.BR mlock ()
5a015b
+and
5a015b
+.BR munlock ()
5a015b
+allows an implementation to require that
5a015b
 .I addr
5a015b
 is page aligned, so portable applications should ensure this.
5a015b
 
5a015b
@@ -284,6 +403,7 @@ file shows how many kilobytes of memory the process with ID
5a015b
 .I PID
5a015b
 has locked using
5a015b
 .BR mlock (),
5a015b
+.BR mlock2 (),
5a015b
 .BR mlockall (),
5a015b
 and
5a015b
 .BR mmap (2)
5a015b
-- 
5a015b
2.17.1
5a015b