Reputation: 1543
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:
mlocks
exceeds the number of unlocks? or munlock
is called (Regardless of how many mlocks
have been called prior)? Upvotes: 0
Views: 95
Reputation: 62068
If it locks or unlocks, it does so for the entire page. There's no smaller granularity in the CPU (disregarding x86 segmentation, which is effectively disabled). The OS does not check each and every memory access either (would be prohibitively slow like going to computers of the 80's).
Does the kernel implement a mechanism where the page remains locked as long as the number of mlocks exceeds the number of unlocks?
No:
Memory locks do not stack, that is, pages which have been locked several times by calls to mlock() or mlockall() will be unlocked by a single call to munlock() for the corresponding range or by munlockall().
Upvotes: 1