Is there a way to get OSX to use more RAM and less swap?

The problem I'm having is on a server (and other OSX boxes as well) we have 4GB of RAM, but we are finding that OSX only uses 40-60% of the available RAM while also having a 6-7GB swap. The server is running Apache and MySQL while the other machines are desktops.

I have been comparing it's usage to similar Linux boxes (hardware and software) and finding that Linux is typically using 80-90% of the RAM and has a much smaller swap file (2-3GB). The Linux servers also typically run much faster.

Is there a way to force OSX to use more or most of the RAM before using a disk swap file?

In Windows you can actually disable the swap altogether. Is there something similar for OSX?


The most basic of answer? No. The OS handles memory management for the user - giving a process as much memory as it requires as it requests it and doesn't provide a whole lot in terms of being able to modify how the system performs. It doesn't help a lot with trying to figure out if memory utilization is part of the equation as to why the Linux servers are outperforming the Mac servers.

Because of the lack of "hackability" in the virtual memory system your best options are to evaluate the performance of the virtual memory to see if it is truly the reason you're having performance issues - the most basic is to use vm_stat or use follow it live by using vm_stat [number of seconds] to see how many page outs are occuring. Moving unused pages from the RAM to the hard drive has a much lower cost than to retrieve the pages back from the hard drive to your RAM. A page in OS X terms refers to 4kb of data.

Additionally, 32 bit processes (eg. Illustrator) can not access more than 4GB so it's theoretically possible to have 2GB free and have a process run out of memory if you had 6GB installed.

On both your desktop and the servers I would run vm_stat 2 and check the last column - especially when you experience the multiple second delay when switching to say Illustrator.

To find out how large the swap actually is you can either check the swap size in Activity Monitor or run du -shc /var/vm/swap* | tail -n 1.

Using du -sh /var/vm has one caveat: on laptops that have the hibernate mode (anything for the past 4 years or newer) there may be a sleepimage roughly the size of how much memory you have installed.


Mac OS X Memory Jargon:

Wired : This refers to kernel code and such. Memory that should not ever be moved out of the RAM. Also know as resident memory.

Shared : Memory that is shared between two or more processes. Both processes would show this amount of memory so it can be a bit misleading as to how much memory is actually in use.

Real : This is the "real" memory usage for an application as reported by task_info() - a rough count of the number of physical pages that the current process has. (RSIZE)

Private : This is memory that a process is using solely on it's own that is used in Resident memory. (RPRVT)

Virtual : The total amount of address space in the process that's mapped to anything - whether that's an arbitrarily large space for variables or anything - it does not equate to actual VM use. (VSIZE)

Active : Memory currently labelled as active and is used RAM.

Inactive : "Inactive memory is no longer being used and has been cached to disk. It will remain in RAM until another application needs the space. Leaving this information in RAM is to your advantage if you (or a client of your computer) come back to it later." - Mac OS X Help

Free : The amount of RAM actually available without any data.


The best documentation I know of (and have been able to find in followup research) is Apple's own Managing Memory article on their developer website.

Other worthwhile sources: Darwin-dev mailing list: [1], [2] and an old article on MacOSXHints. Additionally Mike Ash has posted a good layman's introduction on his blog


It may be possible (I have not tried it out) to disable the virtual memory system by running sudo launchctl unload /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist and then restarting so that dynamic_pager (the program that actually does the virtual memory allocation) doesn't start up. However because the OS assumes it has virtual memory you may find yourself running into issues very, very quickly. To load it back up run sudo launchctl load /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist (if necessary from single user mode)