mac virtual memory I was asked recently about the Mac OS X swapfile, specifically how to disable Mac OS X swapping entirely. I decided I will take this opportunity to talk a bit about Mac virtual memory (swap), it’s location in the Mac file system, and also to explain how to disable it.

Mac OS X Swap aka Virtual Memory

You may recall that in older versions of Mac OS (OS 8 and 9) you could manually disable swapping, then called Virtual Memory, by just adjusting a setting in the Control Panels. Mac OS X is a bit different because it’s built on top of a unix core which relies heavily on swap files and paging for general memory and cache management. Because of this, swap is actually more important now than it was in prior versions of Mac OS.

Basically when your Mac needs memory it will push something that isn’t currently being used into a swapfile for temporary storage. When it needs accessing again, it will read the data from the swap file and back into memory. In a sense this can create unlimited memory, but it is significantly slower since it is limited by the speed of your hard disk, versus the near immediacy of reading data from RAM.

If you’re curious, you can check Mac OS X’s virtual memory usage using the ‘vm_stat’ command, or by using the Activity Monitor (often erroneously called the Mac task manager by Windows converts).

Mac OS X Swap File Location

If you’re curious where the swap files are stored on your Mac, they’re located at:


This directly also contains your sleepimage file, which is essentially what your Mac has been storing in memory prior to system sleep. This file is read again when you wake your Mac up to return to it’s previous state. Anyway, back to swap files in the same directory: they are named successively swapfile0, swapfile1, swapfile2, swapfile3, swapfile4, swapfile5. You can see them for yourself with the following command:

ls -lh /private/var/vm/swapfile*

The swapfiles are generally staggered in size, ranging from 64MB to 512MB.

Disable Mac OS X Paging / Swap

Caution: I would highly recommend against modifying how Mac OS X handles memory management and swap files. Unless you know exactly what you’re doing and why, this is not a recommended adjustment. Again, if you don’t know what you’re doing, do not mess around with Mac OS X’s swapfiles or paging ability!

In the Terminal, enter the following command. This will unload the dynamic pager from the Mac OS X kernel:

sudo launchctl unload -w /System/Library/LaunchDaemons/

Again, this completely disables the Mac OS X paging ability, do not mess around with this for fun.

Your next step would be to remove the swapfiles that are currently stored, they are generally pretty large (it is your virtual memory after all) and take up a fair amount of disk space.

sudo rm /private/var/vm/swapfile*

That’s all there is to it.


Related Posts with Thumbnails
Tagged with:  

Comments are closed.

WordPress Themes