Your Mac comes with a set amount of physical memory applications can use. Your running programs, open files, and other data your Mac is actively working with are stored in this physical memory. But that’s a simplification—applications can also use “virtual memory”, which your Mac can compress and temporarily store on disk.

There’s no official way to disable virtual memory on a modern Mac, although this was possible in the days before Mac OS X—now named macOS—was released. While it may be possible to hack your system to prevent your Mac from storing virtual memory on disk, you shouldn’t do this.

What Is Virtual Memory?

While your Mac only has a limited amount of physical memory, it exposes a larger area of available virtual memory to running programs. For example, even if you have a Mac with 8 GB of RAM, every 32-bit process on your Mac is given 4 GB of available address space it can use. Every 64-bit process is given about 18 exabytes—that’s 18 billion gigabytes—of space it can work with.

Applications are free to use as much memory as they want within these limitations. When your physical memory fills up, macOS automatically “pages out” data that isn’t actively being used, storing it on your Mac’s internal drive. When the data is needed again, it’s transferred back to RAM. This is slower than simply keeping the data in RAM all the time, but it allows for the system to transparently just “keep working”. If Macs couldn’t store virtual memory data on disk, you’d see messages asking you to close a program to continue.

This is basically the same thing as the page file on Windows, and the swap space on Linux and other UNIX-like operating systems. In fact, macOS is a UNIX-like operating system itself.

Modern versions of macOS actually go through even more trouble to avoid paging out data to the disk, compressing data stored in memory as much as possible before paging it out.

Where Is It Stored?

Virtual memory data is stored in the /private/var/vm directory on your Mac’s internal storage if it has been paged to disk. The data is stored in one or more files named “swapfile” and ending with a number.

Most UNIX-like operating systems use a separate partition for the swap file, permanently allocating part of your storage to swap space. Apple’s macOS does not do this. Instead, it stores the swapfile files on your system storage drive. If applications don’t need additional virtual memory, these files won’t use much space. If applications need more virtual memory, these files will grow in size as needed—and then shrink back down when they don’t need be large anymore.

This directory also contains the “sleepimage” file, which stores the contents of your Mac’s RAM on disk when it hibernates. This allows the Mac to save its state—including all your open applications and files—while shutting down and not using any power.

To view the contents of this directory and see how much space these files are currently using on disk, you can open a Terminal window and run the following command. (To open a Terminal window, press Command+Space to open Spotlight search, type “Terminal”, and press Enter.)

ls -lh /private/var/vm

In the screenshot below, we can see that each of these files is 1 GB in size on my Mac.

Why You Shouldn’t Disable Virtual Memory

You really shouldn’t try to disable this feature. The macOS operating system and running applications expect it to be enabled. In fact, Apple’s official documentation says “Both OS X and iOS include a fully-integrated virtual memory system that you cannot turn off; it is always on.”

However, it is technically possible to disable the backing store—that is, those swapfiles on disk—on macOS. This involves disabling System Integrity Protection before telling your Mac not to run the dynamic_pager system daemon and then deleting the swapfiles. We won’t provide the relevant commands for doing this here, as we don’t recommend anyone do this.

The macOS operating system and the applications running on it expect the virtual memory system to work properly. If your physical memory fills up and the Mac operating system can’t page data out to disk, one of two bad things will happen: Either you’ll see a prompt telling you to quit one or more applications to continue, or applications will crash and you may experience general system instability.

Yes, even if you have 16 GB or more of RAM, it may sometimes fill up—especially if you run demanding professional applications like video, audio, or image editors that need to store a lot of data in memory. Leave it alone.

Don’t Worry About Disk Space, or Your SSD

There are two reasons why people might want to disable the virtual memory feature and remove the swapfile files from disk.

First, you may be concerned about disk space usage. You may want to get rid of these files to free up some space. Well, we wouldn’t worry about it. These files don’t waste a large amount of space on disk. If your Mac doesn’t need much virtual memory, they’ll be tiny. On our MacBook Air with only 4 GB of RAM, we noticed a swapfile file using about 1 GB of space—that’s it.

If they are using a lot of space, that’s because the programs you have open need it. Try closing demanding programs—or even rebooting—and the swapfile files should shrink and stop using space. Your Mac only uses disk space when necessary, so you aren’t losing anything.

If the virtual memory files are always very large, that’s a sign you need more RAM in your Mac, not that you need to disable the virtual memory feature. (You can see how much physical memory your Mac has by clicking Apple menu > About This Mac and reading what it says next to “Memory”.)

The other concern is wear of your Mac’s internal solid-state drive. Many people are worried that excess writes to a solid-state drive could reduce its lifespan and cause problems. This is true in theory, but in practice, this concern is generally overblown, and left over from the days when SSDs had far less longevity. Modern SSDs should last a good long time, even with features like this enabled. macOS won’t quickly wear down your SSD just because you leave a default system feature enabled—in fact, something else in your Mac will probably die before your SSD.

In other words, don’t worry about it. Leave virtual memory be and allow your Mac to work as it was designed to.

Profile Photo for Chris Hoffman Chris Hoffman
Chris Hoffman is Editor-in-Chief of How-To Geek. He's written about technology for over a decade and was a PCWorld columnist for two years. Chris has written for The New York Times and Reader's Digest, been interviewed as a technology expert on TV stations like Miami's NBC 6, and had his work covered by news outlets like the BBC. Since 2011, Chris has written over 2,000 articles that have been read more than one billion times---and that's just here at How-To Geek.
Read Full Bio »