everyday mac tools

Swap files on a Mac: why they grow and what to do about it

· 6 min read

Swap is what macOS writes to disk when it runs out of physical memory. It is not junk, it is not a fault, and it is not something you delete. If several gigabytes of your disk are swap, the Mac is telling you it needed more memory than it had, and the fix is on the memory side rather than the storage side.

The one action that reliably shrinks swap is a restart. Everything else here is about understanding why it grew, so that the restart lasts more than a day.

What swap actually is

Your Mac has a fixed amount of physical memory. When the programs you are running want more than that, macOS does two things in order.

First it compresses. Memory that has not been touched recently gets squeezed in place, which is fast and costs no disk at all. This is why a Mac can appear to be using more memory than it physically has and still feel fine.

When compression is not enough, macOS writes the least recently used pages out to files on the disk and reclaims the memory they were in. Those files are swap. They live in /System/Volumes/VM, named swapfile0, swapfile1 and so on, and macOS adds another whenever the existing set is full. You can see them with ls -lh /System/Volumes/VM.

This is a normal mechanism. A Mac with a few hundred megabytes of swap after a long day is doing what it was designed to do. A Mac holding many gigabytes of swap, all day, every day, is running out of room.

Reading the numbers

Two ways to check, and they should agree with each other.

Terminal, for the number. sysctl vm.swapusage prints a total, how much is in use and how much is free, in megabytes. The total will match the combined size of the files in /System/Volumes/VM.

Activity Monitor, for the cause. Open Activity Monitor (Applications, Utilities) and choose the Memory tab. At the bottom you get Physical Memory, Memory Used, Cached Files, Swap Used and a graph labelled Memory Pressure.

That graph matters more than the swap figure itself. Green means memory is fine whatever the other figures say, so green with several gigabytes of swap in use means the Mac paged something out earlier, coped, and is comfortable now. Yellow means it is compressing and swapping to keep up, which is normal under heavy work. Red means it does not have enough: this is when a Mac becomes unresponsive and you see the warning that your system has run out of application memory.

Then sort the process list by the Memory column. Whatever is at the top is what pushed the Mac into swap.

Why swap grows and does not come back down

The usual surprise is that swap use stays high long after you quit whatever caused it. That is deliberate. macOS does not shrink swap eagerly, because unwinding it costs work and the space may be needed again in an hour. Swap files go away when the system decides they are spare, and reliably when the Mac restarts.

The usual causes, roughly in order of how often they turn out to be it:

  • A browser with many tabs open, especially tabs running video calls, spreadsheets or maps. Every open tab is a live process.
  • Virtual machines and containers, which reserve memory whether or not they are using it.
  • Photo, video and audio applications working on files larger than your memory.
  • A Mac that has been awake for weeks. Sleep is not a restart.

There is also a feedback loop worth knowing about. Swap needs free disk. When the disk is nearly full, macOS cannot grow the swap files, so it has nowhere to page to, and a Mac short of both gets slow in a way that feels like hardware failure. If you are near the limit on both, clear disk space first, because it is the faster of the two to fix.

What not to do

Do not delete the swap files. They are owned by the system and actively mapped into running processes. Removing one from a running Mac risks losing whatever was paged into it, and macOS will create a replacement anyway.

Do not try to turn swap off. Advice to disable the pager circulates and it is a bad idea on any current macOS. Without swap, a Mac that runs out of memory has no fallback, and applications start being killed instead of slowing down. It is not a cache and not a leftover, so any approach that frames it as deletable is describing something else.

Leave the sleep settings alone. On some Macs the same folder holds an image of memory written for deep sleep, roughly the size of your installed memory. It exists so a machine losing power does not lose your session, and changing hibernation behavior to reclaim it trades a safety net for space you can find more easily elsewhere. Purgeable space on a Mac covers the other space that looks free and is not.

What actually helps

In the order worth trying:

  1. Restart the Mac. Not sleep, not closing the lid. This clears the swap files and gives you a clean baseline. If the answer is that you had not restarted since March, you are done.
  2. Quit rather than close. Closing the last window of a Mac app usually leaves it running. Command-Q it, or use Activity Monitor to see what is still there.
  3. Deal with the browser. Close tabs you are keeping open as bookmarks, and audit extensions, which each add a process.
  4. Prune login items. System Settings, General, Login Items (called Login Items and Extensions on more recent versions). Everything listed there, plus the background items list below it, is using memory from the moment you log in.
  5. Free some disk. Aim for at least 15 to 20 percent of the drive free, which gives swap room to work and stops the compounding problem above. What System Data is on a Mac is the place to start, because swap is counted inside that figure.
  6. Stage your heavy work. Rendering a video while a virtual machine runs and forty tabs are open is three demands on the same memory.

If you want to know how much of your System Data figure is swap rather than guessing, Crumb breaks System Data into its parts, swap included, in a read-only audit that is free. Knowing the number tells you whether to look at memory or keep looking at storage.

When it means you need more memory

Some of this cannot be arranged away. If memory pressure sits in yellow or red during ordinary work, after a restart, with nothing unusual open, the machine has less memory than your work needs. That is worth being honest about, because on Apple silicon Macs memory is part of the chip and cannot be added later. What you can do is reduce what runs at once, move the heaviest job to another machine, or plan the next purchase around what you actually do rather than what the base configuration costs.

The consolation is that swap makes this survivable rather than fatal. A Mac that swaps is slower than one that does not, and it still finishes the work.

Questions

Is swap bad for an SSD? Not in any way you will notice. Modern SSDs are rated for far more writing than a Mac’s swap produces over the life of the machine. This concern was more reasonable fifteen years ago than it is now.

Why does Activity Monitor show swap in use when memory pressure is green? Because swap in use is a record of the past, not a description of the present. Something was paged out earlier when memory was tight, and those pages have not been needed since, so macOS left them where they are. Green means the Mac is comfortable now, and that is the reading to trust.

Does more free disk space mean less swap? No. Free disk gives swap room to grow, which prevents a specific kind of slowdown, but it does not reduce how much memory your applications want. The two are related only at the point where the disk runs out.

Will restarting every day keep swap down? It keeps the files small, though a daily restart is treating the symptom. If a Mac needs one to stay usable, look at the memory side instead: something is holding far more than it should, and Activity Monitor sorted by memory will name it.