Forum Moderators: bakedjake
I've got a situation which requires the allocation of large amounts of memory for a C++ program which absolutely must not be tampered with by the OS, even if there is a shortage of memory elsewhere (which would be unlikely).
What I'm thinging of is something along the lines of having servers with 24GB of RAM and only allowing the OS to address the first 8GB for what it needs, with the remaining 16GB being reserved at start-up so that the C++ program can directly address that space in the knowledge that nothing else will use it. (the machines will be running a still-to-be-decided 64 bit version of Linux, if a flavour of Linux makes it easier to ring-fence memory we may pick that version simply for that feature alone).
Is this possible? Am I mad?
I should say that, depending on what data any given machine is holding, the actual data size may be larger or smaller but there would always be at least 8GB of memory for the OS - which we never get anywhere near using in normal usage. The allocated RAM holds huge lookup tables - some may extend to 128GB on a 144GB machine (these tables will be used for very random lookups and lots of them, up to hundreds of millions a second - hence the OS swapping out lookup tables would be very bad for performance).
It could be swapped out, but that shouldn't happen along as the machine has enough memory. Unlike Windows, Linux uses all of the RAM before touching a significant amount of the swap space.
With the amount of RAM you're talking about, though, you could turn swapping off entirely.
Does anyone know exactly what happens when you turn of swapping?
I have created many real-time embedded software running on Linux. You can mark currently allocated memory and in the future to be allocated memory of your processes as locked in RAM. The call which you should put somewhere in your code is:
mlockall( MCL_CURRENT ¦ MCL_FUTURE );
You should know that many flavors of Linux by default only allow a small amount of memory (only 32 kB on Centos 5 for example) to be locked in memory. You should increase this system limit to your needs. The current setting of this limit (and others) can be viewed with the command ulimit -a.