Skip to content
Advertisement

Are mlock()-ed pages static, or can they be moved in physical RAM?

According the the mlock() man page:

All pages that contain a part of the specified address range are guaranteed to be resident in RAM when the call returns successfully; the pages are guaranteed to stay in RAM until later unlocked.

Does this also guarantee that the physical address of these pages is constant throughout their lifetime, or until unlocked?

If not (that is, if it can be moved by the memory manager – but still remain in RAM), is there anything that can be said about the new location, or the event when such change occur?

UPDATE:

Can anything be said about the coherency of the locked pages in RAM? If the CPU has a cache, then does mlock-ing guarantee RAM coherency with the cache (assuming write-back cache)?

Advertisement

Answer

No. Pages that have been mlocked are managed using the kernel’s unevictable LRU list. As the name suggests (and mlock() guarantees) these pages cannot be evicted from RAM. However, the pages can be migrated from one physical page frame to another. Here is an excerpt from Unevictable LRU Infrastructure (formatting added for clarity):

MIGRATING MLOCKED PAGES

A page that is being migrated has been isolated from the LRU lists and is held locked across unmapping of the page, updating the page’s address space entry and copying the contents and state, until the page table entry has been replaced with an entry that refers to the new page. Linux supports migration of mlocked pages and other unevictable pages. This involves simply moving the PG_mlocked and PG_unevictable states from the old page to the new page.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement