Mac OS X 10.6 memory management: fixed

There are many reports across the web of OS X’s poor memory management, and up until yesterday, I had been suffering a lot because of it. However, finally, I’ve found the the cure! Something which I thought I would never do: disable swap.

What is “poor memory management” exactly?

In Linux, when physical memory is used up, swap starts getting used. However in Mac OS X (and Windows too), memory will be paged to disk even when there is free or inactive memory — and this sucks.

The solution: turn off paging to disk.

If you have enough memory to run all your day-to-day applications (I have 4GB), you can turn off the paging daemon to prevent OS X from paging anything to disk. For me, this has meant less disk thrashing and more responsive applications.

Turning off paging is something I thought I’d never do. In the past, I was completely against it as I trusted memory managers to make good decisions. However, since using Mac OS X 10.6, I no longer feel this way.

Here’s how you do it:

Paging is handled by a daemon called dynamic_pager. Turn this off with launchctl:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Then, reboot:

sudo shutdown -r now

When the system boots back up, you can free some disk space by removing paging files:

sudo rm -f /private/var/vm/swapfile*

After this you’ll notice a lot more memory becomes “wired”, and memory is still marked “inactive” but it is freed straight away when other applications need it.

Notes

  1. vicchow reblogged this from dansimau
  2. julian-9 reblogged this from dansimau
  3. dansimau posted this