vote up 4 vote down star

Is there a simple way to compact the /var/vm/swapfile0 etc, short of rebooting?

They can get quite large if things start swap'ing, and my laptop doesn't have much free disc space..

flag

73% accept rate
1  
The only way to try to avoid swap space is to get more RAM or do your best to try and make sure your RAM usage stays as low as possible. (This snippet isn't worth it's own answer) – Chealion Jul 19 at 18:25

4 Answers

vote up 1 vote down check

As far as I know, the only way to force the /var/vm/swapfile* files to compact is (as you say) to reboot. I believe that more recent versions of OS X will compact these files automatically if enough memory is free and the system is idle. You could try closing some applications and waiting.

link|flag
vote up 2 vote down

Not really. Swap files are important system files and should not be modified by the user.

For more clarification, check out this article:

By default, Mac OS X uses 80mb fixed sized swap files. It'll create additional swap files as needed. This is controlled by the /etc/rc script file which is run during boot. You can see the part near the end where calls dynamic_pager. By fiddling with the parameters, you can hose your machine. Or you can change the default sizes. I did this on a PowerBook (Wallstreet) with a very small hard drive to have a finer granularity. Using 40mb swap file size, when consuming 90mb of swap, only 120mb of disk space would be dedicated instead of 160mb. Not a big change, and not worth doing for most people. You could have it create a much larger file too.

Mac OS X can actually do swap object re-location and swap file removal. This actually is a pretty cool improvement from the ever expanding swap file problem under NEXTSTEP/OPENSTEP.

link|flag
The xlr8yourmac.com article dates from 2001 and more recent versions of OS X have different behaviour. dynamic_pager is now launched by launchd and its default behaviour is to allocate 64MB, 64MB, 128MB, (then doubling each time) files. – Ben Lings Jul 19 at 20:22
vote up 2 vote down

Mac OS X does remove swap files that it has dynamically created, if it no longer needs them.

I always find exiting/restarting Safari (or Firefox, if that's your browser of choice) tends to help...

link|flag
vote up 1 vote down

Mac OS X really comes under pressure when you have less and less disk space, which can cause issues. I would suggest backing some data up and removing it. Also check out the Caches in your Library folder to make sure your programs are cleaning up after themselves.

link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.