The mlock family of system calls allows a program to lock some or all of its address space into physical memory. This prevents Linux from paging this memory to swap
space, even if the program hasn't accessed it for a while.
A time-critical program might lock physical memory because the time delay of paging memory out and back may be too long or too unpredictable.
High-security applications may also want to prevent sensitive data from being written out to a swap file, where they might be recovered by an intruder after the program terminates.
Locking a region of memory is as simple as calling mlock with a pointer to the start of the region and the region's length.
For example, to allocate 32MB of address space and lock it into RAM, you would use this code:
To unlock a region, call munlock, which takes the same arguments as mlock.
Only processes with superuser privilege may lock memory with mlock.
In the output from the command top, the SIZE column displays the virtual address space size of each program (the total size of your program's code, data, and stack, some of
which may be paged out to swap space). The RSS column (for resident set size) shows the size of physical memory that each program currently resides in.