2

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?

enter image description here

3
  • What OS are you running? Mojave seems to unnecessarily use swap; I'm currently testing if chflag uchg'ing the VM partition works as a method of disabling it. Commented Dec 6, 2020 at 0:59
  • @At0mic Catalina 10.15.7
    – Magnus
    Commented Dec 6, 2020 at 1:05
  • How does this look in activity monitor? Is your RAM pressure orange or red (the chart)? Here's mine showing green memory pressure and 7 GB of swap used: i.imgur.com/lId31CK.png
    – Ezekiel
    Commented Dec 6, 2020 at 4:50

1 Answer 1

3

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.

2
  • 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?
    – Magnus
    Commented 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.
    – jksoegaard
    Commented Dec 6, 2020 at 21:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .