Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

munlock(2) [redhat man page]

MUNLOCK(2)						     Linux Programmer's Manual							MUNLOCK(2)

NAME
munlock - reenable paging for some parts of memory SYNOPSIS
#include <sys/mman.h> int munlock(const void *addr, size_t len); DESCRIPTION
munlock reenables paging for the memory in the range starting at addr with length len bytes. All pages which contain a part of the speci- fied memory range can after calling 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 mlock or mlockall will be unlocked by a single call to munlock for the corresponding range or by 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 mlock and munlock are available, _POSIX_MEMLOCK_RANGE is defined in <unistd.h> and the value PAGESIZE from <lim- its.h> indicates the number of bytes per page. RETURN VALUE
On success, munlock returns zero. On error, -1 is returned, errno is set appropriately, and no changes are made to any locks in the address space of the process. ERRORS
ENOMEM Some of the specified address range does not correspond to mapped pages in the address space of the process. EINVAL len was not a positive number. CONFORMING TO
POSIX.1b, SVr4 SEE ALSO
mlock(2), mlockall(2), munlockall(2) Linux 1.3.43 1995-11-26 MUNLOCK(2)

Check Out this Related Man Page

mlock(3)						     Library Functions Manual							  mlock(3)

NAME
mlock, munlock - Locks or unlocks a specified region in memory (P1003.1b) LIBRARY
Realtime Library (librt.so, librt.a) SYNOPSIS
#include <sys/mman.h> int mlock ( const void *addr, size_t len); int munlock ( const void *addr, size_t len); PARAMETERS
*addr A pointer to the starting address of the region to lock or unlock. The addr argument must be a multiple of the page size returned by the sysconf system call. len The size of the memory region to lock or unlock. The value of len is rounded up to a multiple of the page size before decrementing by 1. DESCRIPTION
The mlock and munlock functions lock and unlock whole pages containing any part of the process address space starting at addr and continu- ing for len bytes. The mlock function guarantees all whole pages mapped by the range addr to addr+len-1 (inclusive) to be memory resident. (The area locked is the same as if the len argument were rounded up to a multiple of the page size before decrementing by 1.) The locked area remains locked until unlocked with a call to the munlock function, until the process calls the exec function, until an address space associated with the lock is unmapped, or until the process terminates. A lock is not inherited across a fork or an exec. The munlock function unlocks whole pages previously mapped by the range addr to addr+len-1 (inclusive), regardless of how many times the mlock function was called by the process for any pages within the specified range. A call to the munlock function does not affect pages that may be mapped into another process's address space or locked by another process. You must have superuser privileges to call the mlock or munlock functions. RETURN VALUES
On a successful call to the mlock function, a value of 0 (zero) is returned and the region becomes locked and memory resident. On an unsuccessful call, a value of -1 is returned, no changes are made to any locks in the process address space, and errno is set to indicate that an error occurred. On a successful call to the munlock function, a value of 0 (zero) is returned and the memory is unlocked with respect to the process's address space. On an unsuccessful call, a value of -1 is returned, none of the memory is unlocked, and errno is set to indicate that an error occurred. ERRORS
The mlock and munlock functions fail under the following conditions: [EINVAL] The addr argument is not a multiple of the page size returned by sysconf. [ENOMEM] Some or all of the address range specified by the addr and len arguments does not correspond to valid mapped pages in the process's address space. For the mlock function, locking the pages mapped by the specified range would exceed an implemen- tation-defined limit on the amount of memory that the process may lock. If any of the following conditions occur, the mlock function fails: [EAGAIN] Some or all of the memory identified by the operation could not be locked when the call was made. [EPERM] The calling process does not have the appropriate privileges to perform the requested operation. RELATED INFORMATION
Functions: exec(2), _exit(2), fork(2), munmap(2), sysconf(3) Guide to Realtime Programming delim off mlock(3)
Man Page