23

After a day's of work at my MacBook Pro running Mac OS X 10.6.5, Activity Monitor shows that the majority of my computer's 8 GB of memory is "Inactive", and only a tiny sliver of the pie chart is "Free". This is even when I have closed all applications, with only the Finder running.

What does that mean? Is the "Inactive" memory taken up by something? Or is it actually still available for applications to use? Thanks.

1

5 Answers 5

29

OS X, like most modern operating systems, uses a virtual memory system for managing memory. Among other purposes, this allows the operating system to treat the computer as having an unlimited pool of memory. To achieve this, the OS will page unused parts of RAM out to a disk store known as the swapfile.

Of course, RAM is not unlimited, so OS X groups RAM into four categories: wired, active, inactive, and free. Wired memory is required by the operating system, and can never be paged out of memory. Active memory is memory used by currently-running programs. Inactive memory was used recently by programs which have now been terminated (or haven't been unused in a long time). Free memory is, as the name suggests, RAM that is not being used.

When you launch a program, it gets loaded into active memory. When you quit a program, however, it doesn't get removed from RAM; rather, it gets bumped into inactive memory. This is why it is often faster to re-launch a program -- it is still in RAM (try this with a big program like Firefox).

Once all your memory is used (free memory is 0), the OS will write out inactive memory to the swapfile to make more room in active memory.

If a program gets paged out to the swapfile, and you re-launch it, it'll get pulled from the swapfile into active memory.

So in short, you actually shouldn't care if your free memory is low. In fact, you want it to be low -- free memory is wasted memory (as the OS isn't using it for anything).

When examining how much memory your computer is using, you actually want to pay attention mostly to Swap used, which tells you the size of the virtual memory swapfile, and Page ins, which tells you how often the OS has to pull memory from the swapfile into active memory.

7
  • 2
    I find Page outs to be a better indicator of swap usage than Page ins, because Page ins includes loading programs as well as loading from the swapfile. Commented Nov 24, 2010 at 21:21
  • 1
    In Activity Monitor, my VM Size is more than 160 GB! Is there some sort of swapfile on my computer that's actually that big?!
    – hpy
    Commented Nov 24, 2010 at 21:42
  • 1
    @penyuan: No. That's theoretically how big the swapfile could go, but the actual size of the swapfile is labeled Swap used in Activity Monitor.
    – mipadi
    Commented Nov 24, 2010 at 22:22
  • 1
    Inactive Memory is partly as you say, though specifically a cache of the filesystem or libraries which might be re-accessed by an application, but is also blocks of memory from currently running applications that have allocated but not accessed in some time period (not sure of the exact length of time). The kernel marks those as Inactive so as to prioritise them for paging out to disk if the amount of free memory drops too low. Commented Nov 25, 2010 at 0:42
  • 2
    @deceze: Inactive memory gets paged out. Active memory gets moved to inactive when it's no longer needed. I suppose if you have so little memory that there's no room for inactive memory, active memory would get paged directly to disk, but that's a special circumstance. Indeed, the swapfile does theoretically grow indefinitely (until there's no more disk space), but that, too, is an extremely rare occurrence.
    – mipadi
    Commented Nov 28, 2010 at 21:37
9

This is most likely not a problem, and in fact is potentially speeding up your computer.

All (most?) operating systems utilise a Disk Cache, which stores some recently accessed files in memory so that repeated access of those files can be sped up. The disk cache on OS X is variable in size, and will appear as "Inactive Memory" being used.

If any program needs more memory, OS X will clear some of the disk cache (the least recently used files) to allow space for the program to run/expand.

I find that if I do a lot of compiling or photo-sorting (i.e. accessing thousands of files in succession) the disk cache will expand and use a lot of Inactive Memory. Provided its just this disk cache, its nothing to worry about.

If it is a background process or application that is expanding in its memory usage (but its pages are being marked inactive) then you'll be able to tell by checking for any programs with very high "Real Memory" usage in Activity Monitor. If there's nothing obviously large there (i.e. the total is a long way short of 8GB) then it'll be the file cache.

You should see that there's little if any Swap usage, and if you open a memory-intensive program the amount of inactive memory will decrease without having to swap to disk.

(I believe there was a bug in 10.4 or 10.5 for a while where it wouldn't always free up this memory very effectively, and would cause swapping despite having a large disk cache, but in my experience this appears solved in 10.6).

1
  • Inactive memory is actually RAM, not memory that has been paged out to disk.
    – mipadi
    Commented Nov 24, 2010 at 18:53
3

"Inactive" memory is available for use by other programs -- it's just caching programs or data that you recently used, in case you need them again. If you launch different programs or need different data, the cached memory will cleared and made available to your new workload as needed.

That's the theory, at any rate, and I believe it to be sound. However, I did find this reference to a "purge" utility someone wrote because they didn't think inactive memory was being released quickly enough.

For official documentation on the subject, read this (and search for "inactive").

3
  • For the record, my MBP currently says: free 58 MB, wired 239 MB, active 1.84 GB, inactive 900 MB -- and the system is performing quite nicely.
    – Michael H.
    Commented Nov 23, 2010 at 22:47
  • 1
    I find purge command a god send tool. Having Photoshop + Firefox + Illustrator + Netbean + SmartGit can easily make a 4Gb iMac crawl to death. Of course, Firefox is the major culprit, but if you want to speed things up a bit, quit Firefox and issue "purge &" Good as new again
    – Antony
    Commented Oct 21, 2011 at 20:39
  • 2
    Purge's man page actually says it was written to flush disk cache only (not anonymous mem: stack, heap, or copy on write) for performance analysis (precisely because the disk cache speeds up the system). It wasn't written to release faster, since executing it is slower than the kernel dynamically reclaiming the memory when needed. Closing an app completely removes all allocated mem, and if you purge afterwards it makes the application load slower, see linuxatemyram.com/play.html. I guess there is something psychological about purge, just as compulsively emptying the trash.
    – Jano
    Commented Nov 15, 2011 at 11:47
2

Starting with OS X 10.5 there are evident memory management problems in MAC OS X.

I finally managed to reproduce the problematic scenario, so i run the test and recorded the screen, into video.

MAC OS X Lion performance problem - broken memory management

I run the tar+bzip command, which is basic unix stuff, on the large amount of picture files, in my Pictures/ folder. Just before start, i run the "purge" command, to delete inactive/cached program data.

You can see on the video that free memory starts to drop very fast, and inactive is constantly rising. If you take a look at "bsdtar" command, it takes only a fragment of RAM, so the problem is not in this process. You cannot say that it is a program memory leak, because then the problem would not be in inactive ram, rather in active/wired.

When the free memory dropped below 100mb, i started some apps, like Safari, iPhoto and MS Word, and you can see in the video, that it takes even minutes to start an app, when normally (when there is free RAM), it would take some 3-5 secs to load.

I run the same scenario and the same commands on my Linux Centos 6 box, no problem there ! Memory usage is some 10-20mb, no problems with cache/buffer.

The memory management must be very broken in Mac OS X !

2
  • 1
    Some of what you describe might form the basis of a different question, but it's not an answer to this question. Commented Apr 30, 2012 at 17:19
  • 2
    I would say that your description of free memory rapidly reducing to the set point and the system accumulating all the rest of non active and wired RAM as inactive is an indication that the system is working exactly as designed. Just because memory management is different on one OS versus another doesn't mean it's broken on either. Optimization choices always have a down side.
    – bmike
    Commented Nov 5, 2012 at 15:47
0

This discussion makes sense only if the statement that "your computer will run faster when free memory is low" - were true. Unless my Desktop Mac is wired weird, the minute my free memory (monitored) starts getting low, whatever program I am running at the time starts to bog down to the point where I can't do anything until it moves back up by itself or by my Free Memory intervention. I have an iMac 2118 (2006 or later) that maxes out at 3 GB RAM so I try to manage it when I can but this is very frustrating. Any thoughts?

You must log in to answer this question.

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