Examining htop
on iTerm2, I'm finding that my machine is maxing out swap space while leaving ~4GB of normal RAM. Why?! This seems like it's going to really slow up my machine. What's going on here? Is there something I can do to improve the distribution?
1 Answer
When your computer runs out of physical RAM, it swaps some of the data in RAM out to disk.
Later when the need for RAM decreases, you will have a situation where you have free RAM, but still an amount of data swapped out to RAM.
You could argue that the operating system should start swapping that data back into RAM immediately. However there are arguments that this is not a good strategy, namely because:
a) swapping in resources takes away resources from other programs running
b) swapping in resources will occupy RAM that another program might need in a short while, provoking another swap out
These are reasons why the swapped out data isn't immediately swapped in when RAM is freed. Instead it is swapped in when needed.
-
So let me see if I understand: the 9.22G of swap space in the image above does not necessarily represent "active" memory, but possibly the vestige of previous activity? Or, to put this question another way, if a process generates some footprint in the swap space, does that part of the swap space NOT get erased (or otherwise marked as available) when that process ends?– MagnusCommented Dec 6, 2020 at 15:07
-
Not quite. The data in swap might be "active" (as in something that's going to be used for some purpose soon), and it might be "inactive" (such as a collection of memory leaks that are not going to be used for anything again). When a process ends, all its allocated memory is freed again - including any use of swap. So no, it is no so that a part of swap space is "taken up" by processes that have ended. Commented Dec 6, 2020 at 21:57
chflag uchg
'ing the VM partition works as a method of disabling it.