mlockall locks all the pages in a process' virtual memory address
space, and/or any that are added to it in the future. 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.
flags is a string of single bit flags represented by the following
macros. They tell
mlockall which of its functions you want. All
other bits must be zero.
- Lock all pages which currently exist in the calling process' virtual
- Set a mode such that any pages added to the process' virtual address
space in the future will be locked from birth. This mode does not
affect future address spaces owned by the same process so exec, which
replaces a process' address space, wipes out
See Executing a File.
When the function returns successfully, and you specified
MCL_CURRENT, all of the process' pages are backed by (connected
to) real frames (they are resident) and are marked to stay that way.
This means the function may cause page-ins and have to wait for them.
When the process is in
MCL_FUTURE mode because it successfully
executed this function and specified
MCL_CURRENT, any system call
by the process that requires space be added to its virtual address space
ENOMEM if locking the additional space
would cause the process to exceed its locked page limit. In the case
that the address space addition that can't be accommodated is stack
expansion, the stack expansion fails and the kernel sends a
SIGSEGV signal to the process.
When the function fails, it does not affect the lock status of any pages
or the future locking mode.
The return value is zero if the function succeeds. Otherwise, it is
errno is set accordingly.
specific to this function are:
- At least some of the specified address range does not exist in the
calling process' virtual address space.
- The locking would cause the process to exceed its locked page limit.
- The calling process is not superuser.
- Undefined bits in flags are not zero.
- The kernel does not provide
You can lock just specific pages with
mlock. You unlock pages