I have the following problem: When I run processes that consume a lot of memory, Mac OS X seems to refuse to release a large portion of the filesystem cache:

activity monitor

In fact, instead of letting go of the ~ 30 GB of inactive memory, it prefers to swap 45 GB (which were rising at the point in time captured in the picture).

Running purge freed a large portion of that memory, leading to ~ 15 GB of free memory and Mac OS X finally stopping to bug me with that really useless OOM dialog asking me to quit one of my GUI applications…

Useless OOM dialog

Is there any way the kernel can be instructed to be less insisting when it comes to caching file I/O?

  • If you ignored for a moment that inactive memory was classified differently than free memory and considered them both to be in the "ready to use pool", is there something measurable that you are seeing as a problem like program load times, malloc failing, etc??? A reboot wipes the virtual memory tables and if you open programs that allocate RAM, they will immediately eat away at "inactive" so this sure looks like a non-problem to me. – bmike Feb 8 '13 at 17:03
  • @bmike As I said... Mac OS X bugs me constantly with that OOM dialog (Please select applications to close...), also the system became partially unresponsive (while not all CPU cores were utilized) and that 45 GB swap file on disk also annoys me. – barbaz Feb 8 '13 at 17:09
  • OOM dialog - perhaps expanding on that might help. My guess is with 45 G of swap, you really have a leaky code problem and not a paging algorithm problem. If you change the paging allocation system, you'll still break down, just in another way. Ill try to make time this weekend to make a proper answer explaining how I'd attack this without needing to hack the VM system. I did miss how deep the problem was on my first comment. Have you filed a bug with Apple if you can make this happen on demand? sysdiagnose should give the engineers all they need to recommend a tuning workaround. – bmike Feb 8 '13 at 17:16
  • @bmike This is the OOM dialog: photomics.org/IeWia1Ee_OOM.png - the text is pretty confusing, I guess what it means to say that Mac OS X won't swap any more than it does right now (there were still hundreds of GB free on my startup disk). The text is just another proof that Macs are not meant to be used as number crunchers, given that it lists only my low-memory GUI applications while my analysis software is using up all the memory... – barbaz Feb 11 '13 at 10:38
  • Despite having run enterprise software like OracleDB for years on OS X and having zero issues with the kernel or memory, I can see how if it doesn't work for your software, you'd be upset and feel it's unfit. However, if you look carefully, you need space on your boot volume filesystem. I'll work up a short answer in case this helps. – bmike Feb 11 '13 at 13:03

It's hard to tell without access to your system or steps to reproduce your error, but in my experience, the OS is performing like any other UNIX when the swap device and root filesystem fills. The simplest way to avoid the dialog is ensure you have enough free space to make another swap file (they top out at 2 GB I believe on Mountain Lion).

Most people like to have 25% (or more) free space since the OS optimizes hot files and defragments on the fly and these self-disable when free space becomes low to avoid churning the IO when there isn't space to write or many free places on the drive to choose for faster file access.

One notable difference between OS X and other UNIX is that the Apple OS does late page allocation to swap, so you don't see large swap files when they are not needed. For this, you can either disable swap entirely or ensure your drive has sufficient free space to handle whatever amount of swap you see in practice.

I've not heard of anyone messing with the paging algorithm itself, but Apple has open sourced that part of the OS, so anyone who cares can make code level changes and run with it.

I would start with buying the next largest side storage drive and monitor your space usage to ensure you don't get less than 10 GB empty as a starter rule of thumb. If you're doing serious work, you might invest more in drive space to ensure you don't run out.

|improve this answer|||||
  • As I said... There were hundreds of GB of free space available on the startup disk. The swapping simply stopped at 50 GB. However, I wouldn't consider even more swapping a solution, I would expect the system to drop the FS cache and start using it for program memory. – barbaz Feb 12 '13 at 13:42
  • Hmm - seems odd that message would pop up. I've had machines with far more swap. Have you filed a bug with Apple on this? It could be something on a specific build / specific chipset thats wrong in the code. I didn't see how much free space you had in the question - perhaps I missed it from the comment thread... – bmike Feb 12 '13 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .