Node:Page Lock Functions, Previous:Locked Memory Details, Up:Locking Pages
The symbols in this section are declared in sys/mman.h
. These
functions are defined by POSIX.1b, but their availability depends on
your kernel. If your kernel doesn't allow these functions, they exist
but always fail. They are available with a Linux kernel.
Portability Note: POSIX.1b requires that when the mlock
and munlock
functions are available, the file unistd.h
define the macro _POSIX_MEMLOCK_RANGE
and the file
limits.h
define the macro PAGESIZE
to be the size of a
memory page in bytes. It requires that when the mlockall
and
munlockall
functions are available, the unistd.h
file
define the macro _POSIX_MEMLOCK
. The GNU C library conforms to
this requirement.
int mlock (const void *addr, size_t len) | Function |
The range of memory starts at address addr and is len bytes long. Actually, since you must lock whole pages, it is the range of pages that include any part of the specified range. When the function returns successfully, each of those pages is backed by (connected to) a real frame (is resident) and is marked to stay that way. This means the function may cause page-ins and have to wait for them. When the function fails, it does not affect the lock status of any pages. The return value is zero if the function succeeds. Otherwise, it is
You can lock all a process' memory with To avoid all page faults in a C program, you have to use
|
int munlock (const void *addr, size_t len) | Function |
|
int mlockall (int flags) | Function |
flags is a string of single bit flags represented by the following
macros. They tell
When the function returns successfully, and you specified
When the process is in 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
You can lock just specific pages with |
int munlockall (void) | Function |
The return value is zero if the function succeeds. Otherwise, it is
|