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