Mlock
lastmod 2026-02-13created 2026-02-132 edits
The memory lock (mlock()) system calls let the calling process lock or unlock a specified range of its address space and prevent Linux from paging the locked memory to swap space. Once physical pages are allocated to the page table entries, references to those pages are relatively fast. The memory lock system calls fall into the mlock() and munlock() categories.
The mlock() and munlock() system calls lock and unlock a specified range of process address pages. On success, the pages in the specified range stay resident in memory until the munlock() system call unlocks them.
The mlock() and munlock() system calls take the following parameters.
-
addr- Specifies the start of the address range. -
Len- Specifies the length of the address space in bytes.
On success, the mlock() and munlock() system calls return 0. If an error occurs, they return -1 and set errno to indicate the error.
The mlockall() and munlockall() system calls lock or unlock the entire program space.