MacNN Forums (http://forums.macnn.com/)
-   Mac Notebooks (http://forums.macnn.com/mac-notebooks/)
-   -   Seemingly bizarre memory management in Mountain Lion (http://forums.macnn.com/69/mac-notebooks/496292/seemingly-bizarre-memory-management-mountain-lion/)

 
D R Turbo Dec 19, 2012 12:45 AM
Seemingly bizarre memory management in Mountain Lion
I've got a 2009 MacBook that I'm working with using Mountain Lion. This unit is dual boot, one volume being Mountain Lion, and the other being Snow Leopard. The system only has 2G of RAM in it. Please don't give me a "lecturette" on more memory, that's not what this post is about.

When I installed Mountain Lion, I quite honestly expected to see a lot of problems (the install was done about 2 weeks ago, so this isn't an initial release). I heard of lock ups, USB drive problems, and the thing being a memory hog, which is what this post is about. As an FYI, it seems to work well.

I use Activity Monitor to monitor CPU and memory consumption. Mountain Lion seems to be doing a pretty good job of pushing the memory limits of the system, whereas Snow Leopard looks like there's tons of free memory always available. FWIW, I typically use XCode 3.X and 4.X, Safari, and Mail - these are running all the time.

Now for the oddity. I use Snow Leopard the same way. If I look at the memory consumption using Activity Monitor it will often show a fair amount of free memory, but the page outs count over time seems to show megabytes. Mountain Lion, on the other hand, often shows (seriously) next to no free memory, but the page outs show absolutely 0, and that's after hours of use.

This seems bizarre to me. How is it that Mountain Lion can apparently eat up every byte of memory on the system and yet not be swapping as much as Snow Leopard. I know the page outs for Snow Leopard aren't that excessive considering that it occurs after hours of use, but why a 0 bytes for Mountain Lion when there's apparently next to no free memory available.

This seems really weird to me. Has Apple, by chance, allocated part of the memory to a RAM disk, and that's why the swap is so low and the memory consumption so high?

Also, while I'm at it, why is mds such a total memory wart hog all of a sudden? Even on Lion it seemed to only be a memory wart hog when Spotlight indexing was occurring, now it's a memory wart hog all the time. Has mds been "promoted" to handle iCloud events, and now it needs 250M of memory (or more???)

Thanks in advance.
 
P Dec 19, 2012 05:04 AM
I'm not sure how much you know about virtual memory systems, so if the explanation below is a little too basic, I'm not trying to dismiss you. It's just that Apple's naming of the terms (which indeed follows UNIX standard) is confusing certain users, who then think that they have to manually "free" memory.

UNIX has developed in a sometimes surprising way - if a system component is important, it makes sense to optimize that component like crazy to improve performance. On the other hand, if a system component is highly optimized and efficient, it makes sense to make as much use of it as possible. This has happened with the virtual memory system - it is now used to include all disk cache functions (and indeed, that happened long before the first version of Mac OS X). What you are seeing is that Lion/Mountain Lion is much more aggressive about using RAM as disk cache than Snow Leopard and earlier was, while simultaneously keeping things in RAM that would have been paged out in earlier versions of the OS.

Memory pages (the smallest unit of memory that the virtual memory system bothers to organize) can be marked as one of four things: Wired (always resident in RAM - must not ever be paged to disk, or the system might crash), Active (currently used - should not be paged to disk, as that will hurt performance, but it can be done without crashing), Inactive (not currently used - can be paged to disk without a significant loss of performance, but kept around in case it might be useful) and Free (really free - can be reused immediately). Apple exposes these labels in Activity Monitor, which is fine, but the confusing bit is that it labels Wired+Active+Inactive as Used. It would be more honest to only say that Wired+Active is "Currently in use" and that Inactive+Free is "Available" or something like that. Inactive memory is a good thing! - the more Inactive memory you have, the better the OS is at making use of the RAM it has.

The situation is further complicated by the fact that there appears to be an issue in Lion where the OS is a bit too aggressive about keeping things as Inactive instead, causing slowdowns when there is no Free memory left for usage. The bug appears on low memory configurations and is at least more common on Macs with integrated graphics (in use or not - an MBP with discrete graphics also switches to the integrated variety to save energy). I have never seen a good analysis of what really happens, but in any case it seems to be fixed on Mountain Lion.

TL;DR: If you don't have performance problems, don't worry about it.
 
mduell Dec 19, 2012 07:14 AM
I'm surprised you're not seeing more effective memory usage in SL, especially with only 2GB. SL on my iMac has no problem utilizing all available memory.
 
D R Turbo Dec 20, 2012 01:19 AM
P: I'm an old Unix geek. That's why I switched to OS X. I used to be a devotee of Linux and FreeBSD (I still like both of them, but they're not primary OSes for me anymore.) About 10+ years ago I was shopping for a laptop to hold Windoze along with a FreeBSD and Linux partition. I heard that OS X was more or less a castrated version of BSD, but when I came across an iBook, I popped open a Terminal.app session and realized it was an actual, true BSD variant. Initially I used a really old (now) iBook as a client, and eventually the user interface plus the fact that I could still use X-Windows on it won me over (I used to do X-Windows development.)

In any case, your comment:

Quote
What you are seeing is that Lion/Mountain Lion is much more aggressive about using RAM as disk cache than Snow Leopard and earlier was, while simultaneously keeping things in RAM that would have been paged out in earlier versions of the OS.
makes absolutely perfect sense.

Additionally, your comment:

Quote
Inactive (not currently used - can be paged to disk without a significant loss of performance, but kept around in case it might be useful) and Free (really free - can be reused immediately). Apple exposes these labels in Activity Monitor, which is fine, but the confusing bit is that it labels Wired+Active+Inactive as Used. It would be more honest to only say that Wired+Active is "Currently in use" and that Inactive+Free is "Available" or something like that.
is absolutely ON THE HEAD. I have noticed that what Apple appears to display as a "lack of memory" isn't such. I've been, seriously, wondering about this for years.

The process, or should I say changes to the process, are with mds. mds used to more or less remain stagnant and then become more memory intensive during indexing (via the presence of mdworker threads.) On previous OS X versions, mds would, from a memory standpoint, go down to almost nothing, but on Mountain Lion it's using, at least on my system 230MB+ real memory, whereas, on Snow Leopard it's 1/5th that or less, with no mdworker threads present.

Do you, by chance, know if mds has been assigned new responsibilities? I'm a fan of Scannerz because it can detect hardware faults. Scannerz disables spotlight indexing either through a forked process to mdutil or somehow in code (you can check this by starting the program at which point mdutil indicates Spotlight indexing is disabled, but mds is still alive). At one point they had a version that actually unloaded mds but when I called their tech support, they stated that preferences couldn't be modified so they canned it - this tells me that mds is being used more than for Spotlight indexing, and now it has me wondering if this doesn't have something to do with added responsibilities for mds - like monitoring iCloud activity.

As an FYI, I've noticed that Spotlight on Mountain Lion seems much more aggressive on it as opposed to Lion and Snow Leopard.

mduell: Trust me guy - I can get this ML system to eat up every byte of memory available if I want to. For example, when I was using the system as I normally do, which I suspect is light by many people's standards, all I needed to do was bring up XCode 4 and suddenly the page out count skyrocketed. A fair number of users are doing a lot more memory intensive work with their systems - like video editing or gaming. I have an iMac running SL as my primary machine (I LOVE SL - sorry Apple:lol:) and with XCode 3.X, no page outs at all. I have yet to figure out why some page outs seem to occur when the memory isn't showing any signs of even being remotely full - now that to me is a little strange.

IMO, 2GB of RAM for Mountain Lion won't cut it. You can get by with it, but it won't cut it. It's kind of like running an iBook @500MHz with 640M of RAM with Tiger - it will do the job, just not very fast.
 
P Dec 20, 2012 03:11 AM
The Mac OS X UNIX userland is based on FreeBSD, and the guy who was in charge of it for many years is Jordan Hubbard, previously FreeBSD Core. Now he has been promoted up the ladder a notch, so I'm not sure what his responsibilities are exactly, but some of the innovations in OS X in later years, such as the launchd setup, always felt very BSD-y to me. The kernel, xnu, is nothing like BSD, but the userland organization is a lot like it - and if anything is missing, it's easy enough to install.

mds is the metadata server. It was introduced with Spotlight, but it was always more general in design than just that - it was made to be used by other things. What is using it now, I don't know. Versions, maybe? It could also be that they're simply optimizing towards minimizing disk access rather than low memory usage. Note that Spotlight was introduced in 10.4, which had a system requirement of 256 MB RAM - Apple may simply have decided that increased performance was worth some more memory usage.

You're right about the RAM req. 2GB is not really enough. I'm glad that Apple finally bumped the floor on the Macs to 4GB (the MBA was 2GB for a very long time).
 
mduell Dec 20, 2012 10:25 AM
Real memory is meaningless, it includes shared libs. You have to look at private mem usage.

Also I'm not convinced about the accuracy of your statements about SL mds memory usage; I show 547MB private with 0 CPU usage and not many file changes/indexings going on.
 
D R Turbo Jan 29, 2013 07:11 PM
I have never seen mds use any more than 100MB on Snow Leopard. That doesn't mean it can't happen. I disregard virtual memory usage when reading memory usage. Mountain Lion can, on the other hand show 50M in real memory one minute, and 20 minutes later be pushing 400MB, and this is all occurring without indexing occurring.

It just seems strange to me. I have to wonder what it's doing.
 
All times are GMT -4. The time now is 04:05 PM.

Copyright © 2005-2007 MacNN. All rights reserved.
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2015, vBulletin Solutions, Inc.


Content Relevant URLs by vBSEO 3.3.2