0

Having trouble understanding just what mlockall does.

There is this in the man page:

mlockall() locks all pages mapped into the address space of the
       calling process.  This includes the pages of the code, data, and
       stack segment, as well as shared libraries, user space kernel
       data, shared memory, and memory-mapped files.  All mapped pages
       are guaranteed to be resident in RAM when the call returns
       successfully; the pages are guaranteed to stay in RAM until later
       unlocked.

What makes a page mapped so it can be locked by this call?

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
peewee6765
  • 49
  • 5

1 Answers1

0

In this context, "mapped" means any page that is present in the virtual address space of the program. In other words, all the pages you see listed under /proc/<PID>/maps, and that the program has access to.

Using MCL_CURRENT ensures that all the currently mapped pages are locked, and adding MCL_FUTURE ensures that even pages mapped in the future will be locked (without the need for another explicit call to mlock/mlockall). So for example if after mlockall(MCL_CURRENT|MCL_FUTURE) you map a page with mmap, or the stack or heap of the program grows, those new pages will be locked as well.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128