Locking all pages
mlock basically allows us to tell the OS to lock a certain range of memory into RAM. In some real-world cases, though, we cannot predict exactly which pages of memory we will require resident in advance (a real-time application might require various, or all, memory pages to always be resident).
To solve this tricky issue, another system call – mlockall(2) – exists; as you can guess, it allows you to lock all process memory pages:
int mlockall(int flags);
If successful (remember, the same privilege restrictions apply to mlockall as to mlock), all the process's memory pages – such as text, data segments, library pages, stack, and shared memory segments – are guaranteed to remain resident in RAM until unlocked.
The flags
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access