Updated: October 28, 2024 |
Lock all of a process's address space
#include <sys/mman.h> int mlockall(int flags);
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The mlockall() function causes all of the pages mapped by the address space of a process to be locked and made memory-resident until unlocked, or the process exits or executes another process. The pages that are locked depend on the flags argument.
The exception is any page with a PROT_NONE access setting; mlockall() skips those pages because there is no need to lock a page that can't be accessed.
Memory-resident is a term used to indicate that the addresses always reside in physical memory. For more information, see Locking memory in the Process Manager chapter of the System Architecture guide.
In order to lock pages, your process must have the PROCMGR_AID_MEM_LOCK ability enabled. For more information, see procmgr_ability().
Follow either of the following approaches when attempting to lock pages:
Memory that's mapped from a typed-memory file descriptor is implicitly locked. Shared memory objects that are populated with shm_ctl() are implicitly locked, unless you use the SHMCTL_LAZY flag.
If you use MAP_LAZY, there may not be an immediate effect on the mappings.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |