Essentially, this is akin to the page file on Windows, or the swap space on Linux and other UNIX-based operating systems. In practice, macOS stands as a UNIX-based operating system.
Modern macOS versions pose more intricacies to mitigate paging data to the hard drive, emphasizing the compression of data stored in memory before paging.
Where is virtual memory data stored?
If paged, virtual memory data finds its abode in the /private/var/vm directory on the Mac's internal drive. The data is stored in one or more files named 'swapfile' and concludes with a number.
Most UNIX-based operating systems utilize separate partitions for swap files, permanently allocating a portion of memory for swap space. Apple's macOS takes a different approach, storing swapfile files on the system's storage drive.
If applications don't require additional virtual memory, swapfile files won't occupy much storage space. If applications demand more virtual memory, the size of swapfile files will 'expand' and then decrease if unnecessary.
Additionally, the /private/var/vm directory also houses the 'sleepimage' file, storing the contents of RAM when putting Mac into hibernation mode. This enables Mac to preserve its state when shutting down without using the power button, including open applications and files.
To inspect the contents of the /private/var/vm directory and see how much disk space the occupied files take up, open the Terminal window, then execute the command below:
Execute ls -lh /private/var/vm command.
Note: To open the Terminal window, press Command + Space to activate Spotlight search, then type Terminal and press Enter.
In the example below, you can observe these files occupying 1GB of free space on your Mac.
Why should you not disable Virtual Memory on Mac?
It's advisable not to disable virtual memory for the macOS operating system and running applications to function properly. Apple's official documentation states, 'Both OS X and iOS integrate a system of virtual memory that users cannot turn off, and this virtual memory system is always active.'
Technically, you can disable virtual memory to reclaim disk space—meaning, disable the swapfile on the macOS hard drive. This process involves disabling System Integrity Protection before telling the Mac not to run dynamic_pager, then deleting the swapfile. However, Mytour recommends readers not to disable virtual memory on Mac.
If the physical memory capacity is full, and the Mac operating system cannot allocate data, two scenarios may unfold: either you'll receive a notification advising you to close one or more applications to continue, or your applications will hang, leading to a system error state.
Even with 16GB of RAM or more, sometimes there's a shortage of memory capacity. This holds true, especially when running professional applications that demand significant memory, such as video, audio, or image editing tools that need to store large amounts of data in memory.
No need to worry about drive space or SSD capacity
There are two main reasons why many users consider disabling virtual memory and removing swapfile files from the hard drive.
The first reason revolves around concerns about using hard drive space. Removing swapfile files aims to free up space, but in reality, these files don't occupy much free space on the hard drive. If a Mac doesn't require much virtual memory, swapfile files will take up a very small amount of free space. For a MacBook Air with 4GB of RAM, swapfile files only occupy 1GB of free space.
If swapfile files occupy a significant amount of free space, it's because the programs you have open rely on the assistance of swapfile. Try closing or restarting programs that require swapfile to 'reduce' the size of swapfile files and stop using free space. Your Mac only utilizes hard drive space when necessary, so you don't need to worry about data loss.
If the size of virtual memory files is consistently 'bloated,' it might be a signal that it's time to upgrade your Mac's RAM rather than disabling the virtual memory feature.
To check the physical virtual memory capacity on your Mac, right-click on the Apple menu =>About This Mac and inspect the Mac's capacity next to the Memory section.
The second reason you might be concerned is the SSD (solid-state drive) on your Mac. Many users worry that excess writing on an SSD could reduce its lifespan and cause various issues.
In theory, this is entirely accurate, but in practice, not so much. Modern SSDs have a relatively long lifespan, even with the virtual memory feature activated. macOS can't 'wear out' your SSD quickly just because the virtual memory feature is default on the system.
Here's why you shouldn't disable Virtual Memory on your Mac. In other words, it's advisable to refrain from turning off virtual memory on your computer. Maintain the status quo of virtual memory and allow your Mac to function normally. If you want your computer to run smoother without intervening with virtual memory, you can follow Mytour's high-efficiency, safe instructions on accelerating your Mac OS.