The man page for these system calls state that memory locking and unlocking is preformed in units of whole pages.
Assume that I have called mlock(2)
to lock multiple address ranges from a single page of memory. If I call munlock(2)
on one of these ranges, will the lock be released for the entire page (i.e implicitly unlocking all other ranges in the page)? or does the lock on the page remain until all address ranges have been released?
Edit: To clarify, my question is not about the granularity of mlock
(the man page is very clear on that part). My question is about locking and unlocking multiple distinct ranges within a single page. My question could be rephrased as follows:
- Does the kernel implement a mechanism where the page remains locked as long as the number of
mlocks
exceeds the number of unlocks? or - does the kernel naively unlocks the whole page when a single
munlock
is called (Regardless of how manymlocks
have been called prior)?