mlock(3C) mlock(3C) NAME mlock, munlock - lock or unlock pages in memory SYNOPSIS #include <sys/types.h> #include <sys/mman.h> int mlock(const void *addr, size_t len); int munlock(const void *addr, size_t len); DESCRIPTION mlock locks the pages associated with the address range (addr, addr + len) into memory. The super-user can lock as many pages as it wishes, other users are limited to a per process maximum {PLOCK_MAX}. Locks established with mlock are not inherited by a child process after a fork. munlock unlocks the pages associated with the address range (addr, addr + len), regardless of the number of times the pages were locked. Page locks established by other processes are unaffected, when the pages are shared amongst multiple processes. Address addr is not required to be page aligned, as the system automatically rounds the address down to the nearest page boundary. mlock or munlock will fail if one or more of the following are true: [EAGAIN] There was insufficient lockable memory to lock the entire address range (addr, addr + len). This may occur even though the amount requested was less than the system-imposed maximum number of locked pages. [EBUSY] munlock will fail with this error if the address range specified has some active I/O initiated by some other process belonging to same share group. [ENOMEM] The addresses specified by (addr, addr + len) are not mapped into the user's address space. [ENOMEM] The caller was not super-user and the number of pages to be locked exceeded the per process limit {PLOCK_MAX} [see intro(2)]. [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 range (addr, addr + len) contains a memory-mapped file, and there is insufficient space on the device to allocate the entire file. SEE ALSO exec(2), exit(2), fork(2), mlockall(3C), munlockall(3C), mmap(2), mpin(2), munpin(2), plock(2) DIAGNOSTICS Upon successful completion, the functions mlock and munlock return 0, otherwise, they return -1 and set errno to indicate the error. WARNING The functions mlock/munlock and mpin/munpin provide similar functionality. The major difference between the two sets is that mpin/munpin maintains a per page lock counter and mlock/munlock does not. Developers should choose the set that best suites their application and stick with it, as mixing the interfaces may result in unexpected behavior. Page 2