Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I recently had data loss because the hard drive was completely used up by virtual memory and some programs couldn’t handle zero free space on the hard drive. How can I prevent this from happening (besides always keeping a few GB as a buffer)?

share|improve this question
This question may be a duplicate of Is there a way to limit the size of the disk swap file in Mac OS X? (2012-09-19), which has an accepted answer. – Graham Perrin Apr 27 '13 at 7:40

I can propose you one way to do that, although it is not complete.

You can set memory limit per process using launchctl limit (see the man page). However this is per process not system wide.

In real life, few processes are consuming vast amount of memory. Therefore, I would advise you to look at Activity Monitor output and see which are the process consuming the most. Count the ones that are using more than 20% of your RAM. How many such processes do you have? Let's assume n and assume that you have m GB of RAM. How much maximum swap space do you want to use? Let's assume s GB of swap.

I would do the following calculation: (m + s - 1) / n = <max memory per process in GB>

Convert the GB into B: <max memory per process in GB> / 1024 / 1024 / 1024 = <max mem per proc in B>

Now try this limit and see if it works (note, this setting will be lost after a reboot, so it is "safe" to perform):

sudo launchctl limit rss <max mem per proc in B> <max mem per proc in B + 1073741824>

If you are happy with this choice, then you can save them, so they are permanent. Edit the file /etc/launchd.conf and add:

limit rss <max mem per proc in B> <max mem per proc in B + 1073741824>
share|improve this answer
@bmike I am sorry but can't you put your comments in your own answer or comment? I am not sure the ton you use fits with mine. Although valuable, I will ask for you edit to be undone. Feel free to add it as a comment of my answer or as a plain answer. – Huygens Feb 24 '13 at 16:23
Just click edit and revert my changes - do be aware that the site is very open to more than one contributor to any post. What I proposed is an answer component and not a comment IMO, but I'll probably copy your words and add mine if that makes you feel better. I figured you did the bulk of the work and wanted the authorship to remain yours, but I'm open to leaving your entry as is and adding a second answer. – bmike Feb 24 '13 at 16:38
I know, I also did set some of my post as community wiki. But this time I felt that the style of our answers were too different, and it felt awkward. Thank you, I did found that one can revert changes! Great tool! – Huygens Feb 24 '13 at 17:49

Your Answer


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.