Skip to contentSkip to conversation

mlock() "bogus check" (locked > num_physpages/2) _does_ hurt!

DISCUSSION Lutz Vieweg 2 participants 2 messages Dec 11, 2003

lore
Share & tools
lore
#0 lore raw

Hi everyone,

in kernel 2.4.23, file mm/mlock.c, line 215, there's the following piece of code:

        /* we may lock at most half of physical memory... */
        /* (this check is pretty bogus, but doesn't hurt) */
        if (locked > num_physpages/2)
                goto out;

Obviously, the author already realized this check is bogus,
but the assumption that it doesn't hurt is very wrong... at least for me: I'm writing a server application that uses much more virtual memory than there's physical memory (and on 64bit systems, there can be a lot more virtual memory!). The application needs to access only a small fraction of the memory used during normal operation, the rest of the virtual memory used is used for (slowly) rebuilding indicies in the background. So it is completely ok for me that most of the applications memory is swapped out, and to make sure that response times are low even after much of the memory is on disk, I use mlock() to lock the interesting pages in memory.

And yes, I would very much like to use more than half of the physical memory for that purpose!

Is there any good reason to keep this check in the 2.4 kernel sources? Is there any good reason to not use a different default value
for the RLIMIT_MEMLOCK value (which is currently 0xffffffffffffffff), instead?

It's good to know the check is not present in the 2.6 sources, but I would like to get rid of it in 2.4, too...

Regards,

Lutz Vieweg

#1 lore raw
Quoted 1 line · Lutz Vieweg

Is there any good reason to keep this check in the 2.4 kernel sources?

Not really.

Quoted 2 lines

It's good to know the check is not present in the 2.6 sources, but I would like to get rid of it in 2.4, too...

It was removed from 2.6 for the reasons you cite. 2.4 could follow suit.

It does lead to problems, though, where you can memlock too much memory and lock the machine up. But we could file that under "don't do that".

Rob Love