#include <sys/mman.h>
int mlock(const void *addr, size_t len);
int munlock(const void *addr, size_t len);
The mlock() and munlock()
functions lock and unlock, respectively, a range of whole pages.
This range consists of any whole
page containing any part of the address space starting at address
addr and continuing for len bytes.
When the mlock() locks the page range, the pages
become memory-resident until unlocked or until the process exits
or execs another process image.
The munlock() unlocks the page range,
regardless of how many times mlock() has been
called by the range for any page within the range.
When any of the pages within the specified range of a
munlock() call are also mapped into the
address spaces of other processes, any locks established on
those pages by another process are unaffected.
When any of the pages within the specified range of a
munlock() call are also mapped into
other portions of the address space of the calling space
outside the range specified, any locks established on those pages
via the other mappings are also unaffected by the
munlock() call.
- addr
-
Points to a memory address that determines the first page of
the page range.
- len
-
Specifies the size, in bytes, of the address space used to determine
the full extent of the specified page range.
On success,
the mlock() and munlock()
functions return 0.
On failure, these functions make no changes to any locks
in the address space of the process, return -1, and sets
set errno to one of the following:
- EAGAIN
-
Some or all of the memory identified by the operation could not be
locked when the call was made.
- EINVAL
-
The addr argument is not a multiple of {PAGESIZE}.
- ENOMEM
-
Some or all of the address range specified by the addr and
len arguments does not correspond to valid mapped pages in the
address space of the process.
This can also be caused if Windows' working set is set too small to
make all the required pages memory-resident.
- EPERM
-
The calling process does not have the appropriate privilege to perform
the requested operation.
UNIX 03.
MT-Safe.
On the NuTCRACKER Platform, the mlock() and
munlock() use Windows' working sets.
On Windows, a working set is the set of memory pages in
physical RAM that are currently visible to a process.
For performance reasons, Windows attempts to keep the
size of a working set down. This means that realtime
applications may need to increase the size of the
working set so that more pages than what Windows defaults
to allow can be locked. Of course, with the appropriate
privilege (SE_INC_BASE_PRIORITY_NAME),
the calling process can call the Win32
SetProcessWorkingSetSize() function
to change the size of the working set and then call
mlock() again.
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
- Functions:
- exec(), exit(), fork(), mlockall(), munmap()
PTC MKS Toolkit 10.5 Documentation Build 40.