MacOS – Why does Finder use 59GB of swap space

crashfindermacosmemory

My new retina MacBook Pro(with 16GB RAM) keeps receiving this "Your Mac OS X startup disk has no more space available for application memory" message. I have 300 GB of free space on my hard drive, and 16 GB of RAM. This shouldn't be happening.

But it keeps happening, even when I'm not actively using my Mac. I went to lunch, came back, and saw this: too much RAM usage 59 GB of swap used.

What is going on?

Best Answer

I believe this is a bug in OS X 10.7. I also have a retina MacBook Pro. Mine is 2.6/16/512, and I noticed that there were 0 page outs but a very large swap file being created (mine was about 8 GB). Closing applications actively reduced the swap space being used. Again there were no page outs being recorded.

I believe this has to do with the sleep image file that also gets housed alongside the virtual memory files in /private/var/vm. When pmset hibernatemode is set to 3 (default for laptops, suspend to RAM and disk), sleepimage gets written upon sleep. This is why it takes a few moments for these laptops to go to sleep: it's writing up to 16 GB of RAM to the sleepimage.

However, changing this setting so that the RAM gets powered on sleep and NO sleepimage is written has resulted in no abnormal increases in swap file size. My suspicion is that the sleepimage is in some cases being preserved post-sleep and prompting the creation of swap files. Perhaps it is this incorrect behavior that is also resulting in the unusually large swap file sizes you are seeing.

From the manpage for pmset, to change to NO suspend to disk you would run in a Terminal:

sudo pmset -a hibernatemode 0

To delete the sleepimage (and reclaim 16 GB on your computer with 16 GB of RAM), run:

sudo rm /var/vm/sleepimage

I restart after these operations just to ensure there's no weirdness. On each power source, you can check the status with:

pmset -g

You should be aware that, in the event of a total power loss (battery dies and not plugged in) the contents of the RAM will not have been saved to the hard drive, and you will lose your work. For me, this is a small but calculated risk because the speed of sleep/wake, coupled with the great battery life and reclaimed storage space. Additionally, for me it seems to have mitigated this issue, which I have not seen on any other Mac laptop I've owned. I wish we had those battery indicator lights, though.