mlock
mlock is a system call in Unix-like operating systems that locks a portion of a process's virtual address space into physical RAM. By doing so, the locked pages are prevented from being paged out to swap, which helps protect sensitive data from being written to disk and reduce latency for critical workloads. Common use cases include handling cryptographic keys, passwords, and other secret material in memory.
On Linux, mlock takes a pointer and length. It requires appropriate privileges to lock memory, typically the
Programs can also lock all current and future memory using mlockall with flags such as MCL_CURRENT and
Locked memory remains resident for as long as the lock is active or until it is explicitly