14

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?

3
  • For clarification: 1. Is the bottleneck the VM system? As in when you see the memory stars there are a large amount if pageouts occurring. 2. Where are you getting your Free and VM size information? For example the VM Size stated in Activity Monitor is not the same as the size of the swap file.
    – Chealion
    May 13, 2009 at 0:58
  • I don't have proof that the VM system (VM or swap) is the problem, but I do know on my desktop I have 6GB of RAM, of which usually 2-3GB is usually free. When I switch programs, you would think it would be blazing fast because it's all in RAM, but instead, it takes 2-15s to switch back to something like Illustrator. I'm thinking similar things are happening on the server--something like the caching for MySQL or temporary tables. I am using top to determine the VM, RAM and swap usage. Any ideas? May 13, 2009 at 2:44
  • 3
    To determine the actual vm usage the easiest is to run du -sh /var/vm - that said it may be artificially high if there is a sleepimage (most often seen on laptops) present. There are several tools available that can help you determine if it's memory that is causing the slow ups: vm_stat - particularly you're interested in the pageouts value - if it increases quite a bit then you know you're swapping heavily. For more info on how Apple manages their memory: developer.apple.com/documentation/Performance/Conceptual/…
    – Chealion
    May 13, 2009 at 3:48

1 Answer 1

21

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)

You must log in to answer this question.

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