Apple - Isn't Inactive memory a waste of resources?

Inactive memory got a horrible rap due to a crappy name. It should have been called something like "make your Mac really fast the second, third, and fourth time it does the same task" memory except that's an awful name, too.

Apple re-wrote the activity monitor when it introduced several new features and added compressed memory, so some of this no longer applies to macOS that don’t show “Inactive Memory” but this still applies to Mac OS X memory management as documented against this version of Activity Monitor: https://support.apple.com/en-us/HT201538

Here's how I explained things to someone new to the concept of virtual memory on OS X:

  • Wired: The system cannot run without this amount of RAM (never swapped)
  • Active: Programs are really using this memory now or in the last few seconds
  • Inactive: Things that programs have read from the slow disk or elsewhere and said they never need again. Engineers know better, you will go back to Facebook in a few minutes or re-launch Word after quitting it. The same things happen again and again on computers.
  • Free: Totally Wasted RAM - the system only needs one or two MB free to cover short term allocation requests. For largest allocations, it simply uses some of the Inactive RAM by allocating it to active/wired and removing the information on what it used to hold.

The problem arises when Free+Inactive is less than roughly 1/3 of the total and then things can really get slow.

Inactive memory is bonus speed / double duty RAM. It serves as free at a moment's notice, but also makes repeated tasks much, much faster if the system guessed correctly and kept something in RAM that you will do again. It's faster than swapped memory since it's already loaded in RAM and accelerates things when the virtual memory system makes good guesses.

When you are wondering if RAM is a problem, rather than looking at each of the 4 categories (5 if you count active swap), you can couple W+A as slowing down a new program/task and F+I as speeding up a new program/task. The more F+I you have, the more new programs you can launch before the RAM needs to rely on swapping to juggle the memory that has been allocated.

You don't really need to know how swap works since I mentioned it above. Basically, when a program is sitting idle and hasn't been used for days (or hours) the system will write that RAM to the hard drive rather than kill the program. This lets the system shuffle and handle all sorts of things relating to memory management and keeps each program from needing to talk amongst themselves to agree who will use less memory when the system runs out.

Here is a real world example of how inactive RAM is used.

  1. Quit all apps and make sure the two Apps we are testing are not set to auto start when you log in
  2. Reboot your Mac
  3. Fire up your Activity Monitor and watch the RAM throughout
  4. Time how long it takes to start Application A (MS Word would be a good choice)
  5. Quit A
  6. Time how long it takes to start Application B (Adobe something would also be good)
  7. Quit B
  8. Time how long the second launch of A takes
  9. Quit A
  10. Time B's second launch.
  11. Time A's start the third time with B running.

You should see dramatic speedups for the second / third launch as the system learns to keep in inactive RAM the things these two apps need to run.


In your case - the total of Wired and Active means that some swapping to disk is likely happening and your Mac isn't as fast as it could be since your inactive RAM isn't large enough to store all the things you might need to reuse. If you have a fast SSD drive, this RAM allocation is OK and instead of starting to slow down once less than 1/2 of your RAM is F+I, you can cut things closer to like 1/4 of the total RAM for F+I before seeing noticeable slowness. These guidelines are general, and you'll want to watch vm_stat 15 or some similar interval to ensure continual and medium volume swapping isn't making your Mac slow.


The number which is the most important in determining if your Mac is getting memory 'stressed' is the 'Page outs' figure. In Activity Monitor in Mavericks this is no longer shown, they now show the information in 'Swap Used:'.

Page outs means the OS has determined there is not enough available RAM to run all the applications & processes which have been requested. What it then does is it 'pages' out to disk parts of memory which it determines are not being actively used. This means RAM memory (fast) is changed to HDD memory (slow). If this is happening a lot because there are a lot of applications running, and the user is going between applications, then there will be a lot of page outs, and page ins.

If you see page outs increasing then you should take action.


The problem on my Mac is the "inactive" memory never seems to get purged unless I do a manual purge in the command window. It builds up and builds up until I get a popup window telling me to kill applications. Even after killing all my applications, I still have too much inactive memory to run anything. So, on my Mac running the latest version of Mountain Lion it is NOT true that inactive memory gets reclaimed when the free memory gets low. Either I have an app somewhere that has locked up a chunk of inactive memory that never gets freed, or the iOS has a bug in it. (I have 8GB of physical memory ... that ought to be enough!)

Tags:

Macos

Memory

Mac