Заблокировать весь диапазон адресного пространства процесса
#include <sys/mman.h>
int mlockall( int flags );
- flags
- Flags that indicate which pages to lock; one or more of the following bits:
- MCL_CURRENT
- Lock the pages currently mapped into the address space of the process.
- MCL_FUTURE
- Lock the pages that become mapped into the address space of the process in the future, when the mappings are established.
libc
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.
Memory-resident is a term used to indicate that the addresses always reside in physical memory.
You have to be a superuser to lock pages. Follow either of the following approaches when attempting to lock pages:
- Tightly controlled approach
- Lock the pages one by one, by calling mmap() and then mlock().
- Global approach
- Lock all pages at the same time, by doing one of the following:
- Call mlockall(
MCL_FUTURE
), followed by one or more calls to mmap(). - Optionally call mmap(), and then call mlockall(
MCL_CURRENT
).
- 0
- Успешное завершение.
- -1
- Возникла ошибка. Код ошибки записан в errno.
- EAGAIN
- Some or all of the memory identified by the operation couldn't be locked when the call was made.
- EINVAL
- The flags argument is zero.
- ENOMEM
- Locking all of the pages currently mapped into the address space of the process would exceed an implementation-defined limit on the amount of memory that the process may lock. lock. This implementation-defined limit is set by
RLIMIT_MEMLOCK
rlimit. - EPERM
- The calling process doesn't have the appropriate privilege to perform the requested operation.
POSIX 1003.1 ML
- Точка остановки потока
- Нет
- Обработчик прерываний
- Нет
- Обработчик сигналов
- Да
- В потоке
- Да
mlock(), mmap(), munlock(), munlockall()
Предыдущий раздел: Описание API системной библиотеки