To really drive this point home (because it's important, and maybe not everyone has gotten it yet). Here my system under normal workload:



As you can see, it uses 15.1 Gb of the available 16 Gb. App memory is application memory, file cache is, well, memory used by the filesystem to speed up disk accesses and wired memory is memory allocated inside the kernel that can't be paged out.

Now, I wrote a test application that allocates 2gb of memory and writes them (to assure that the kernels memory manager actually maps the virtual pages to physical one). If you'd just looked at the free memory, you'd assume that your budget is 900mb, and 2gb is far more than that. Here is how the system deals with the increase in memory pressure (note the small bump):



As you can see, the system started to shuffle memory around. It compressed some of the memory and took away from the files cache. But the swap file is still 0kb in size, so it's still all in main memory, nothing has been written to disk.

Alright, here is what happens when further increasing the memory pressure (allocating and writing 4gb of memory):



Still NO paging! Some disk accesses will become slower as more got evicted from the filesystem cache, but oh well.


So, the long story short is that a modern kernel is excellent at managing resources! You want your system to use all of your memory while idling, because it can put it to good use. The system will reclaim resources when there is pressure for resources, and it's really good at keeping up with the pressure.

Of course, that 4 gb experiment doesn't work well when you only have 4gb of RAM, after all, these are all hot pages and the kernel itself also needs a place to reside. That's why you need a minimum requirement of memory. If you constantly need 4gb of memory, a minimum requirement of 6gb is what you are looking for.

Trust yo kernel, trust yo compiler. Hide yo kids, hide yo wives, hide yo husbands!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com