MacOS – If a Mac has 1GB inactive, and it has been idle for an hour, why it doesn’t swap the inactive RAM to the pagefile for “readiness”

macosvirtual-memory

I am sure Apple engineers have thought of and decided not to do it — if from the Activity Monitor, I see out of the 4GB of total RAM, 1GB is not active, and the Mac has been idle for 1 or 2 hours, then if I start a new app, it is still very slow due to "not enough RAM" — looks like the Mac is swapping things out to the pagefile so that the new app can run in the RAM space.

But if the Mac has been idle for 1, 2, or even 8 hours, why doesn't Mac OS X swap the inactive RAM to the pagefile first, so that there is 1GB of free RAM, so that when a new app is started, it is very fast, just like there is extra RAM there free to use. Maybe it is so that the user knows the RAM is getting used up and we don't want the pagefile getting bigger and bigger and out of control? But why not limit the getting bigger and bigger just to about 6GB total, or 8GB, and then start not swapping the inactive RAM automatically? In other words, for the first 1GB or 2GB of inactive RAM, swap it to the pagefile, so that more RAM is ready for use immediately. Just don't do it all the time later on. Does someone know why that isn't done or how can it be made so? (by changing a System Preference?)

Best Answer

The system does not know which action will be the next. If instead of opening a new application after an hour you decide to work on some stuff that was cached (and is part of the inactive memory) it will be already there.

Instead of swapping out to free memory or emptying disk caches the system waits to see if you actually need the memory to avoid unnecessary work.

You can always force the disk caches to be flushed (freeing some memory) with the purge command.