Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

It seems to be that in OS X, whenever you are out of ram the system happily swaps to disk. This easily becomes an disaster due to the fact that the swapped out memory eventually fills my drive. On my Macbook Air with 2GB ram and 64GB disk this is a major problem.

In order to solve this I've created a crontab running a purge-command every 10:th minute. It minimizes the swap from growing and also makes the system more responsive whenever the system is swapping. I've tried to disable swap but it's far to unreliable.

Can you configure this behavior? Is there a better solution?

Disk swap on OSX never stops growing

$crontab -e

*/10 * * * * purge
share|improve this question
    
Run sysdiagnose at boot and then again after launching your usual apps and finally when you notice that swap is running away. I have Macs that run for months at a time and never have swap pressure like you show here. The system only swaps when a program asks for memory, leaks it and never frees it. You've probably got several leaks - the severity of which would be measured by how short the timeperiod needed to accumulate each gig of swap to disk. –  bmike Sep 19 '12 at 13:14
    
And by all means reboot your Mac frequently. If your system performance seems to become sluggish, it's time to reboot. Modern memory management makes this less necessary than in the past, but there is never any harm in rebooting! –  Wheat Williams Sep 19 '12 at 13:23
    
@bmike Great command, thanks! –  Gustav Sep 19 '12 at 13:30
    
I still feast on how much information is in that one shell script and all the information it spews. Be sure to pass in a PID to the script if you have a program you are particularly interested in seeing usage. –  bmike Sep 19 '12 at 13:39
    
The sum of the sizes of the eleven swap files is not extraordinary. For my MacBookPro5,2 with a much larger internal hybrid drive, I created a 32 GB partition for hibernatefile (8.59 GB) plus swap files. In most cases I treat purge as a last resort because of the resulting increase in disk activity. –  Graham Perrin Feb 2 '13 at 14:29
show 1 more comment

1 Answer 1

up vote 4 down vote accepted

Yes you can configure the dynamic_pager, but for most it is simpler to just disable it and see which program crashes due to the inevitable out of memory errors.

Why would I disable swap file in Mac OS X?

Pay attention to programs that implement their own virtual memory / cache / paging systems like virtualization and the Adobe Suite in case you have inadvertently tuned them to use more RAM than is available on the system. They tend to be first on my investigation list when I see a mac with runaway swap allocation on the filesystem.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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