14

I got myself a m1 macbook air with 8 gb of ram
Ive been using it for a month now and noticed that my swap usage is unusally high, is that something to worry about?

As you can see from the screenshot swap is around 3 gigs, and it hasnt gone done down yet.

enter image description here
I was hoping that 8 gigs was enough for vscode and node but now I doubt it

Also, my ram usage in the activity monitor always peaks at 6.6-6.7 gigs, never goes up more than that.

enter image description here labels are: all ram, used ram, cache, swap

Should I be concerned?

6
  • 1
    Have you experienced any problems with actual use? Slow downs, spinning wheels, etc? If not, then all is well. The trouble with iStat is it gives you numbers to worry about, most of which are entirely normal.
    – benwiggy
    Commented Feb 10, 2021 at 13:52
  • How does the memory graph in Activity Monitor look like? This usually gives a better assessment than the bare numbers.
    – nohillside
    Commented Feb 11, 2021 at 8:55
  • @benwiggy no, never, havent had any issues or slowdowns, only worries
    – ddruganov
    Commented Feb 11, 2021 at 9:13
  • @nohillside is there anything you can say looking at the graph now?
    – ddruganov
    Commented Feb 11, 2021 at 14:15
  • 1
    Same as the two answers already do with more details: no memory pressure at all, so no problem to solve.
    – nohillside
    Commented Feb 11, 2021 at 14:25

2 Answers 2

26

So long as memory pressure looks OK, there's nothing to worry about.

macOS keeps things cached in RAM as long as that RAM is not needed by anything else - that gives it a tendency overall to look like it fills up & never empties.

The same can be said of swap. It fills, the contents may change, but the swap figure displayed is always a "high tide" figure. You never see it go down until you reboot.

It doesn't serve you or the OS well at all if it were to periodically flush unused RAM or swap just to "look tidier". Its purpose is best served by it just hanging onto it all in case it's needed again.

2
  • 1
    Indeed, this behavior is actually normal for almost any OS that uses virtual memory paged out to slow storage. It’s a very common misunderstanding in the Linux world also, especially for users coming from Windows because Windows does not show page-file usage in a way that most people ever really notice this behavior there. Commented Feb 11, 2021 at 12:18
  • 6
    This is called "opportunistic swapping". If the OS didn't do this, as soon as it actually needed to swap, it would have to do a whole bunch of writing before it could discard anything from memory. By writing data to storage before the OS needs to swap, it can reduce the I/O demand when and if it has to start swapping, which eliminates the huge burst of lag you'd otherwise have. Commented Feb 12, 2021 at 0:26
19

There are two major misconceptions that are often seen in relation to memory management:

  • Full RAM is bad.
  • Full swap is bad.

Both are wrong.

RAM is extremely fast compared to other types of storage, both latency-wise and bandwidth-wise. RAM is also extremely expensive compared to other types of storage. Hence, you want RAM to be always full, otherwise you are wasting fast and expensive storage.

Swapping is bad. Swap isn't. Most OSs will flush pages from RAM to swap preemptively during periods of low system load but keep them in RAM at the same time as well. Why? Because swapping is slow, and thus you want stuff be already in swap in case the proverbial feces hit the proverbial air circulation unit. You don't want your system to start swapping out at the same time when it is already under high load anyway.

So, an OS will try to use as much RAM as possible by e.g. caching recently and regularly accessed files in RAM. And it will try to use as much swap as possible by preemptively copying data from RAM to swap, so that if the OS needs the RAM quickly, it can simply use it for a different purpose without having to save it to swap first.

Now, when I wrote above that the OS will try to use "as much RAM as possible", that is not 100% true. It is more like the OS will try to use "as much RAM as it deems sensible", and defining what, precisely, "sensible" means is one of the things that performance engineers and kernel developers have been trying to improve upon ever since memory management was invented some 70 years ago.

MacOS in, particular, will try to keep some amount of RAM free, and will also compress some parts of RAM.

1
  • "Most OSs will flush pages from RAM to swap preemptively .." and "So, an OS..." These paragraphs might be correct for Windows, there are NOT for macOS. When short of memory, macOS likes to compress memory and only when it gets desperate does stuff get copied to swap and removed from RAM. There is no 'preemptive' copying to swap like Windows does with the Modified Page Writer. In my view this is where macOS (and other unixes) have inferior memory management to Windows and (before it) VMS.
    – Gilby
    Commented Apr 30, 2022 at 4:52

You must log in to answer this question.

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