mlockall, munlockall - lock or unlock address space
int mlockall(int flags<b>);
mlockall locks all pages mapped in the address space of the calling
process into memory, including: text, data, stack and mmaped regions.
Locked pages are immune to all routine swapping.
The value of flags determines whether the pages to be locked are those
currently mapped by the address space, those that will be mapped in the
future, or both:
MCL_CURRENT Lock current mappings
MCL_FUTURE Lock future mappings
munlockall unlocks all memory mapped pages in the address space of the
calling process, regardless of the number of times the pages were locked.
Automatic memory locking of future memory mappings is disabled for the
Locks established with mlockall are not inherited by a child process
after a fork.
If the address space contains autogrow regions [see mmap(2)], mlockall
will only cause the pages through the current end of file to be locked
In the event automatic memory locking of future mappings is enabled for a
process (MCL_FUTURE), and the locked memory of that process stack space
exceeds either the system's physical memory or the maximum amount of
lockable pages per process as determined by the system variable maxlkmem,
the process will receive a SIGSEGV with a signal code of ENOMEM [see
sigaction(2) and signal(5)]. If the locked memory of the process heap
space exceeds either the system's physical memory or the maximum amount
of lockable pages per process maxlkmem, the system call which attempts
the expansion will fail without making a change to the amount of
allocated space, and errno is set to ENOMEM.
mlockall or munlockall will fail if one or more of the following are
[EAGAIN] There was insufficient lockable memory to lock the entire
address space. This may occur even though the amount
requested was less than the system-imposed maximum number of
[EBUSY] munlockall will fail with this error if a region of the
address space has some active I/O initiated by some other
process belonging to same share group.
[EINVAL] The flags argument is zero or contains invalid flags.
[ENOMEM] The caller was not super-user and the number of pages to be
locked exceeded the maximum number of lockable pages per
process as defined by the system variable maxlkmem [see
[ENOMEM] The total number of pages locked by the caller would exceed
the maximum resident size for the process [see setrlimit(2)].
[ENOSPC] The address space of the calling process contains a memorymapped
file, and there is insufficient space on the device to
allocate the entire file.
exec(2), exit(2), fork(2), mmap(2), mlock(3C), munlock(3C), mpin(2),
munpin(2), plock(2), sigaction(2), sysconf(3C)
Upon successful completion, the functions mlockall and munlockall return
0, otherwise, they return -1 and set errno to indicate the error.
The mlockall/munlockall pair and the plock function provide similar
functionality. Developers should choose the set that best suites their
application and stick with it, as mixing the interfaces may result in
PPPPaaaaggggeeee 2222 [ Back ]