The Rules
  • Feel free to leave constructive criticism, or point out a better way to do something.
  • Personal attacks or flames, on me or anyone else, will be deleted.
  • Past history has shown that 99% of comments I can't read (i.e. those in other languages) to be spam. Therefore, any comment I can't read will be removed.
  • I'm pretty mellow concerning profanity, but excessive (as determined subjectively by me), bad language will be removed.

Monday, March 5, 2007

Is my Mac using too much memory???

Edit/Update: Modern releases of OS X (Mountain Lion and particularly Mavericks) treat memory much differently. I'm leaving this post as-is for historical reasons, but if you're running Mavericks you'll see things pretty differently.

I have been a linux user for a few years, and I recently (6 months ago) switched to a MacBook. One of the reasons I originally switched from Windows to Linux was resource efficiency. There were others, but this is the one that leads to this discussion. A couple of weeks after I got my MacBook, I was working one day on a programming project for school with nothing open but iTerm and a couple of gvim windows. I happened to look at a resource monitor widget I had in my Dashboard, and was immediately concerned that I was only showing around 100 Mb free RAM. Concerned that I had some kind of memory leak going on I started digging around to find out where the "bug" was. It turns out that the bug was in my understanding of how OSX uses--and labels--memory. A friend of mine (Quinn) helped illuminate some of this for me. So here it is.

If you open the Activity Monitor (found in utilities) and select the "System Memory" tab at the bottom, you'll see something that looks roughly like this:
OSX labels physical memory (RAM) as follows: Wired, Active, Inactive, and Free.

Wired memory is used by the OS and is pretty much untouchable. Another application can't "borrow" wired memory.

Active memory is what is currently in use by running applications. Note that thanks to the splendors of virtual memory, all of the memory needed by an application isn't necessarily contained here. If you look at a running process in the Activity Monitor list, you'll see a column for Real and a column for Virtual Memory. Since we are talking about the amount of RAM in use, we won't worry about virtual memory for the moment. If there is no inactive, or free memory, active memory can be used by other applications, but this causes the OS to write the current state of the active memory being traded to its owner's virtual memory pages on disk before granting the memory to another application.

Inactive memory is memory that has recently been used by an application that is no longer running. OSX keeps track of what this is and what it belonged to because of the idea of temporal locality, the idea being that if you opened an application you are somewhat likely to do so again and if the memory is still labeled, the application can start very quickly. In the absence of sufficient free memory, inactive memory will be reclaimed by another running application that needs memory.

Free memory is just that, free. Nothing has a claim on it, and it's up for grabs for any application that needs it.

As you can see from my screen-shot image above, I tend to run with around 100-200 Mb free, between 150 and 300 Mb wired, and the rest split between active and inactive. What does this memory labeling have to do with how fast or slow the machine runs? Simple. When you log in, OSX claims the memory it needs to do all of its chores. This is wired. Other applications claim a smallish chunk of active memory as they are opened. Most applications that need to keep track of any kind of history or user data gradually use up more memory the longer they are open. Every now and then an application will need to use some part of its memory that it doesn't use frequently and OSX has to get this from disk and place it in that application's active memory allocation. All of these things can slow down a system. Also, virtualization applications such as Parallels or VMWare's Fusion require a large chunk of memory for the virtual machine that gets marked as wired.

The main thing you want to be aware of is not necessarily how much memory you have marked as free, but how much wired, active, and inactive memory you have and how often OSX has to swap memory pages in from or out to disk (Page ins/outs in the Activity Monitor). For example, my MacBook (which has 1 Gb of RAM) is almost always very responsive, except when I'm running anything in a virtual machine. When I start up Windows (which happens as rarely as possible), Parallels grabs its virtual machine memory and my usage graph looks like this:
You'll notice that wired has more than doubled in size, there is significantly less inactive memory, and next to none free. Page ins/outs are ok. "Ins" has a pretty high count from a human standpoint, but it's no big deal. "Outs" is still pretty low and my system is still fairly responsive. However, if I then try to run lots of other applications, I run into problems.Just opening Firefox caused the "Outs" to nearly double almost instantly. Inactive memory has gone down even more, and my system is noticeably less responsive. Continuing on this trend leads to a condition where "Ins" and "Outs" are nearly equal, and climbing fast. When this happens, OSX is spending all its time shuttling memory in and out of the virtual memory pages on disk, and doesn't have time to do much else. Similarly, your running applications are all waiting on OSX to swap memory to and from disk, and take much longer to do what you want them to do. This is bad. Closing the memory hogs in a condition like this will lead to almost instantaneous relief.

In this case, you'll notice that closing Parallels immediately caused a huge leap in free memory, and a marked decrease in active. This is sort of an isolated case in that the memory that was previously wired for the virtual machine is now free. In a normal case, closing applications like Photoshop, Office programs, etc. will cause a slower increase in free memory and a more immediate increase in inactive memory, with an additional decrease to active. It will take a little while for your system to get "balanced" again, and the more applications you close, the faster this will happen. You'll notice that in the time it took me to shut down my windows system running in Parallels, close Parallels, and take another screen-shot that page "Outs" increased by 9 times, and by proportion were rapidly gaining on page "Ins".

The moral of the story is: If you happen to look at Activity Monitor or some other system resource monitor and notice that you only have about 10-15% of RAM free, don't worry about it unless your system is noticeably unresponsive. This is not to say that some third party applications don't have memory leaks, but that's a topic for another day.

61 comments:

Nicole said...

"If you happen to look at Activity Monitor or some other system resource monitor and notice that you only have about 10-15% of RAM free, don't worry about it unless your system is noticeably unresponsive."

Seeing as how I have never once looked at my activity monitor, I think I'm safe from these kinds of worries. But thank you, sweet boosh, for the reassurance that all is well. I will sleep soundly tonight.

Anonymous said...

Nice article Alex, I always wanted to know this but was too lazy to go look it up. Thanks

Anonymous said...

page outs are the sign that things are bad bad bad -- they happen only under severe memory pressure, and make the effective memory speed slow slow slow

Anonymous said...

Thanks for finally clearing this all up for me in such easy to understand terms.

You mentioned that Page Ins and Outs aren't great when they are a high number. Is that if either is high or is it more of a ratio that I am looking for?

Daniel Larsen said...

I use Parallels regularly, too, and have noticed a couple more dubious ramifications than what you got into. The Free memory cleared up by quitting Parallels is bad Free memory. That is, all the data that has been swapped out to disk has to not only be swapped back into memory, but allocated space from the Free memory space.

You're definitely right in saying that inactive memory contains the shell of old data. The ideal running state, in my opinion, has next to no free memory, but the vast majority is inactive.

I recently upgraded my MacBook to have 2GB of RAM, in order to run Parallels. If you have a MacBook, and want to run Parallels and other applications at the same time, I'd say that's a prerequisite.

Anonymous said...

Don't forget that Mac OS X has adopted FreeBSD's unified VM/file cache structure. This means that opening large files can also have an impact on the amount of free memory. In my experience, I believe that this caching is marked as "Inactive" memory, but that may not be true in all cases.

Also, the page in/out counter is cumulative. Having a high uptime can make both values relatively large without having an impact on real day-to-day performance.

JMJDave said...

How do you figure out what is causing a memory leak? My wired memory keeps slowly rising until it is taking up most of my memory and then my Mac starts really slowing down.

Anonymous said...

Some more information on Memory at Apple's ADC site.

Alex said...

If you usually run a lot of applications, figuring out what is causing a memory leak can be a bit of fun. Either you have to use some kind of memory profiling tool on each application that you run regularly, or you have to do an annoying process of elimination and drop an application for a while and see if that stops the wired memory increase.

Alex said...

> The ideal running state, in my
> opinion, has next to no free
> memory, but the vast majority is
> inactive.

This is good if you routinely use a relatively small set of applications without much variation. If the set of regularly used applications you use changes frequently (or even regularly) you need a little bit of clean memory to clobber to avoid the overhead (however small it may be) of the OS trying to decide which "dirty" memory to replace.

Anonymous said...

"Inactive Memory" also includes file and device data cached by the kernel, but not attributed to any specific application or process.

For example, if you copy a large amount of data to an external drive, you'll see the inactive memory steadily consume all of the free memory.

High "Free" memory is bad, actually. Free memory is RAM that isn't being used by the system make your machine run faster, either because you have too much RAM, or more likely you just quit an application that was consuming a large amount of RAM (and therefore the RAM couldn't be used for caching.)

Unknown said...

Thanks for posting this! I have been staring at the pie graph for years wondering what to make of all the colours, using it only to monitor CPU cycle hogs. I was always worried about my lack of "free" memory when I have 4G on board, but now I see if most of it is labelled inactive it is still free if needed.

Brau

Alex said...

Not really, they are cumulative.

if you run "uptime" from the terminal and it's less than a day or two I'd worry, otherwise it's no big deal.

Keep in mind that page ins/outs can occur when you open and close applications a lot, especially memory intensive ones. If you do this, and your uptime is several days or more, high numbers in the page ins/outs category are just a result of more or less normal use accumulating numbers.

Anonymous said...

As others have said, inactive pages are, effectively, a buffer cache for application binary pages, plus file cache.

Do lots of I/O - a big copy for example - and you'll see inactive pages zoom up in usage.

MacOS is pretty bad at reclaiming this memory, particularly with apps like Photoshop, that are doing large file I/O AND wanting to use memory. My experience is that it won't reduce the buffer cache (inactive).

You can force it by doing some recursive small file I/O - du -sx / > /dev/null from the Terminal, for example. Bang, you get some free mem back. There's no point doing this unless your app is memory starved though.

Anonymous said...

'page outs are the sign that things are bad bad bad '(Anonymous)

Actaully this isn't the case. Page ins are bad as they only occur for 2 reasons.
The first is that the OS is preloading pages from disk because it believes that they will be required soon.
The second is because a page on disk has been requested and an application is blocked during this.
Most OSs will intelligently swap out pages that haven't been used in a long time to increase the amount of available memory. While this can slow down applications that have large working sets that are touched infrequently, if done correctly it makes the system appear to be more responsive since requests for extra memory can be grated without a page out. This is because if there are no free pages one has to be written to disk before it can be re-used, blocking the app that requested the extra memory.

In short, buy as much memory as you can afford. Unless you're running on a 32-bit system with 32-bits apps, in which case don't bother going above 3GB as performance will decrease.

Jono said...

Thanks, (like a lot of people here) I've always wanted to know this but was too lazy to go look it up.

Anonymous said...

iFreeMem can improve your Mac's performance by maximizing Free memory and reducing Inactive memory!

http://www.apple.com/downloads/macosx/system_disk_utilities/ifreemem.html

http://www.activata.co.uk/products/ifreemem.html

Garrett Albright said...

So what about the "Real" numbers in the process list? What significance do those have? The list says that Safari is currently using 400MB of "Real" memory, but my "Wired" and "Active" slices add up to less than 300MB. Would I be correct in guessing that much of Safari's "Real" number is attributed to cached web pages and such, which, being non-critical, would be counted in the "Inactive" slice?

Alex said...

> So what about the "Real" numbers in
> the process list?

Real is the amount of RAM that the application is using. Virtual memory is the total memory address space needed by the application, most of which resides on disk. This is used to hold program data, cache, etc.

Unknown said...

A great tool to see how much memory an app is using is call MemoryCell. You can get it here. http://www.rogueamoeba.com/freebies/

it shows you how much memory the current active app is consuming right on the menubar.

Anonymous said...

Great article, posted to OSXDaily.com

Unwired said...

What then would be a good tool for monitoring a mac (I have a Macbook) to see during the day how much memory you are using and consuming? is there a log file for this or do you just have to restart the Mac and then open activity monitor and keep constant tabs on the usage to determine how much memory you are consuming and such?

Alex said...

I like iStat Pro myself. It's a pretty comprehensive system monitoring widget. Most of the time I use top of Activity Monitor, but for those who don't like the terminal or just want the basics it does well.

David McCabe said...

Excellent. Next can you tell us what the RSIZE, VSIZE, and especially Private columns mean? I assume that Private is excluding shared libraries, but that is just a guess. Thanks for the write-up.

Jon said...

Great article - thanks!

Anonymous said...

hey hope everything is ok now

Anonymous said...

In response to those concerned with page-ins and page-outs, the total number is next to meaningless. As a number number of people have said it is cumulative. What is important is the number of page-ins or outs per second. This information is displayed in brackets after the total within the terminal application "top", or on the "Disk Activity" tab in Activity Monitor. If you're concerned about the amount of memory in your machine, you need to watch these values as you're executing tasks. High values indicate disk "thrashing" and the need for more ram.

Cheers,
Backspace

Anonymous said...

The "purge" command, available at the Terminal, releases inactive memory back to free.

I created an Automator app around the purge command, which I dock near the Activity monitor that displays mem on the icon. When the monitor has little teal (free) and most dark blue (inactive), I run the purge command.

Sounds like the iFreeMem app effectively executes the purge command.

Anonymous said...

Excellent explanation, but I'm still wondering one thing; why is the virtual memory allocation for each application so large? I can see in your screenshot the same sort of thing I see in Activity Viewer; tiny applications like dashboard widgets each having a virtual memory size of around 350MB. Once you've got a reasonable number of applications open, I can easily have a VM size in excess of 15GB in total, which is actually getting pretty close to how much free disk space I have (worrying!). And yet if I use the iStat Menu tool, the swap file never goes above 2GB (the same as my physical memory).

So what's the story there?

Alex said...

@Kapowaz: Not 100% sure without doing some research that I don't really have time for during the semester. A quick thought is that OSX allocates virtual memory base on page table entries or a certain block size. Something to consider is that most Dashboard widgets and Cocoa apps link against the same libraries and frameworks. Activity Monitor may be showing the total amount of virtual memory used by each widget or process, but Dashboard apps, for example, may be sharing a large portion of that virtual memory space.

If I remember I'll dig around and see if I can learn anything else once the semester is over. If anyone else knows better or more than that feel free to correct me.

Joseph Riesen said...

The VM used by an application pretty much consists of the application itself and shared libraries. Using the ever-handy vmmap command, you can get a lot of useless information about a process' VM usage, and some useful tidbits towards the end in the summary breakdown by region.

It appears that, on Mac OS X, a solid 256MB is used by IOKit, the device driver layer, along with 34MB for ATS (font support), ~7MB for the CoreGraphics library, and so forth.

If you use "vmmap -resident" you can also see how much of the program is actually using up physical memory, broken down by region in that same summary section at the end.

In other words, to throw out a quick answer to the question, about 300MB is mapped into the virtual memory space of any app specifically written for Mac OS X (not the various UNIX tools and services). However, this doesn't take up disk space in the swap file, nor is it actually using memory - this 300MB consists of just common OS libraries that are mapped into the address space of every application.

For that matter, most of the IOKit isn't even loaded into physical memory. It's certainly not wired, or at least not in its entirety, since I've only got 205MB of wired memory on my system at the moment. Most likely the IOKit is loaded up and then most of it is paged to disk, since I'm sure a substantial chunk isn't used at any given time. (In fact, it may not really even be 256MB; that number seems a little too perfect, making me think there's some other reason it's exactly N pages...)

One more thing - I've never used it before (I just ran across it in the man pages for vmmap), but there's apparently this nifty "leaks" command you can run that searches for unreferenced malloc'd memory in a given process. Maybe that would help with tracking down memory leaks, as someone was asking about earlier? Then again, they had constantly-growing wired memory, which sounds like a proliferation of kernel objects, so it might not help in that case, dunno.

Anonymous said...

mine looks like this

wired = 445mb
active = 724mb
inactive = 117mb
free = 2.73gb
swap = 0mb/64mb
ins = 65,536
outs = 0

my shit flies!!

imac 24" imac 2.4ghz core2duo

Anonymous said...

This is a great site. Thank you for your information. I THANK YOU I SALUTE YOU IT,S A AMZING SITE.

Alex said...

Ok people. I speak English. I don't read or speak any other language. If you have something constructive to add to the discussion, do it in English, please.

If I can't understand what you're writing, I'll remove it.

Thanks.

Anonymous said...

nice post

Srini said...

Nice article Alex. Still learning things in MAC OS.

SaraS said...

Thanks for the post Alex! It was really helpful!

Vivek Nagaraj said...

First of all, I found your topic about physical memory in Mac useful. Thanks for letting me know the facts.

I just wanted to know why inactive memory tend to quickly eat up all the free memory making the capacity seem almost in a single digit!

Sometimes when I watch movies in VLC on my mac, probably the entire movie enters the RAM! Once you completely delete it, the inactive RAM is freed.

Anonymous said...

is this normal? (also i just opened and closed everything in my dock)

uptime-6hr
Free:1.17GB
wired:312mb
Active:550mb
Inactive:2.02GB
Used:2.85
VM size: 119.98GB
Page ins:110,247
Page outs:140
swap used:5.7mb


(this is 4gb of ram...i have activity monitor open, one safari page, and blizzard installer installing world of warcraft...)

Alex said...

> uptime-6hr
> Free:1.17GB
> wired:312mb
> Active:550mb
> Inactive:2.02GB
> Used:2.85
> VM size: 119.98GB
> Page ins:110,247
> Page outs:140
> swap used:5.7mb

This looks fairly normal to me. Again, page-ins aren't a terrible thing, you're just reading something into memory to be used. And as long as you have plenty of physical memory you can page in all you want. The problem comes when you have to swap something out to virtual memory in order to have room to page in. This is when you start thrashing.

Anonymous said...

This is a really good article. Very informative.

Anonymous said...

Hey Thanks, I have been a linux admin for over 10 years and my home mac mini was running real bad. Your article quickly enlightened me on how the OS reports / groups memory.

Anonymous said...

Awesome article. Thank you very much. :-)

Anonymous said...

Just want to say that, as accurate as this information is, when the little green slice of my memory pie starts to get thin (50MB or less) everything grinds to a halt even though there's 500MB of Inactive. I have 2GB with Snow Leopard booting in 64-bit mode, and I've already ordered an upgrade to 4.

Steve said...

Many thanks for this useful information, and thanks to other contributors for the useful links.
Bookmarking, with respect ...
(~*~)
Steve the Healer.

Anonymous said...

Thank a lot for the information. I was freaking out because my activity monitor widget was telling me i was using a lot of memory and i didn't know why. Lion uses a lot of the memory when i start multitasking so having four gigs of ram on my pro is apparently a necessity.

thanks again.

MoonLWolf said...

I tried doing that and the wired did get lessen but it went back up quickly.....

Jeremy said...

I am relatively new to the mac world but I need to use parallels pretty much all day. I was running into problems when my free memory is pretty much obsolete. I had the guy that works on our macs come in and upgrade the memory. So now I have a processor that is 3.06 Ghz Intel Core 2 Duo with memory of 8GB 1067MH DDR3...... From what I understand that this is pretty close to top of the line? But when I run the parallels and all of the applications that I use day to day once my free memory becomes really small this mac starts acting crazy...... Do you have any suggestions?

Please email me if you like...... jeremy@domiconeprinting.com

Alex said...

Last time I checked, Parallels claimed as active or wired all of the memory you configured for your VM, whereas VMWare Fusion only claimed the amount your VM was actively using. This could be a contributing factor.

Anonymous said...

We are new to Mac and seem to have out MacBook running slow. All my wife runs is Safari and MSN most of the time. We keep getting the pin wheel. Our number are like this:
Free 8.2mb
Wired: 469mb
Active: 1.02 gb
Inactive: 521.9mb

She uses Facebook and plays Packrat a lot. Any ocean why this are Soooo slow and why the pin wheel keeps coming up? Please help.

Mark

Alex said...

I have no idea what Packrat is, but list your processes by Real Memory usage in Activity Monitor and you can see who the culprits of using the most memory are.

Sometimes just quitting Safari for a minute or two can free up a surprising amount of memory.

Syazwi Mazli said...
This comment has been removed by the author.
Syazwi Mazli said...

Even though this article was from 4 years ago, you just made me understand my machine a little better. I thank you good sir.

Yogurt said...

There is a handy little free app called "FreeMemory" that can free up inactive memory. It seems to force the system into freeing up all the memory allocated to the Inactive category and after it's done there is now a much bigger block of Free Memory. You can find out more about it at their website at http://www.rockysandstudio.com/apps/freememory - it installs itself into the system menu at the top of your screen so you can run it at anytime or it also shows the current state of memory allocated to the four different categories (active, inactive, free and wired). I've used it but not sure if there isn't a better way or if Alex's trick with "purge" is better or not as I'm not sure how they really go about maximizing free memory. The only down side is that the system will slow down to a crawl while it does it's thing, and sometimes it takes a while to finish. Not sure why it is sometimes so slow to finish, but it can take a minute or two to finish at times. You need to install from the AppStore and I think it only runs on Lion and Snow Leopard. Also for some strange reason the AppStore claims that it needs updating when in fact the version it wants to upgrade to is already installed. Not sure what causes that,

Basically what it allows you to do is force OS X to free up all the inactive memory when you run it not when the OS wants to do it for you. For that you have to wait while it does the work as the system will come to a crawl until it finishes - just like would happen any other time the system needs to start paging in/out memory. The downside I suppose is that whatever speed up the system would yield due to running another app that you just exited (and is probably still in the inactive memory) from what is already stored in Inactive Memory would be lost. But the plus side is if you need a lot of memory for some other purpose now, it lets you force it the OS to do it now when you want it.

Max said...

Okay. But what does the "Used" thing mean?

Alex said...

@Max: "Used" is the total of everything that isn't "Free"

Unknown said...

Now i m got mac book pro and i want to upgrade memory any one tell me please because i m newb

Unknown said...

Alex already answered question how much more RAM to get: as much as you can afford, unless you have a 32 bit processor. Go to a website such as http://www.crucial.com or the OWC site http://www.macsales.com/ and check the specs for your machine. Upgrades are not too expensive and are generally easy to do.

Lyle Yeung said...

I have changed from PC to Mac in last few days, I am confused about the wired memory before. Now I am understanding the memory usage in Mac. Thank you.

Mendo Dave said...

Im pretty new to MAC. I Bought a Mac Mini On Black friday 2013, thought it would be work well with the two iPads, apple TV, and iPod I already had and besides windows 8 looked like a train wreck and I wasn't going to go there.

Anyway I think Mavericks is a bit different than some of the earlier version os OSX. The activity monitor displays slightly different info for one thing.

http://s1201.photobucket.com/user/dapaoli/media/ScreenShot2014-04-10at63220PM_zpsc7cfd42c.png.html

I thought that 4GB was a lot of memory but evidently not. I have 16GB from Crucial due to arrive tomorrow.

Anonymous said...

I like goats