Apple fix the ram handling!

Discussion in 'OS X Mountain Lion (10.8)' started by Ritmo, Sep 20, 2012.

  1. macrumors member

    Ritmo

    Joined:
    Mar 27, 2009
    Location:
    Finland
    #1
    Ok. It seems that it doesn't matter how much ram you have, OSX will it eat just for fun. When I had 4Gb I thought "well I am using virtual machine and quite a lot of apps". Buying 8Gb helped a bit but it was still swapping. But today I've seen the worst and no matter how big apple fan boy you are, you have to admit this is pretty bad.
     

    Attached Files:

  2. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #2
    Mac OS X will use all the RAM you have installed. That's what it's there for. The only thing you need to watch for is page outs. If you have no page outs with your normal workload, you can forget about memory issues. Page outs are cumulative since your last restart, so the best way to check is to restart your computer and track page outs under your normal workload (the apps, browser pages and documents you normally would have open). If your page outs are significant (say 1GB or more) under normal use, you may benefit from more RAM. If your page outs are zero or very low during normal use, you probably won't see any performance improvement from adding RAM.

    Mac OS X: Reading system memory usage in Activity Monitor

    Running a VM is obviously placing high demands on memory. If that represents normal use for you, you may need more RAM.
     
  3. thread starter macrumors member

    Ritmo

    Joined:
    Mar 27, 2009
    Location:
    Finland
    #3
    Sir, are you working for apple? Because that i so helpful!
    Obviously I'm not using mac for the first time. And as you can see from the picture I'm complaining about how OSX manages the RAM. It's swapping 0,5Gb for no reason because there is still 3Gb of inactive RAM that could be released for use.
     
  4. dyn
    macrumors 68000

    Joined:
    Aug 8, 2009
    Location:
    .nl
    #4
    Than it is a very wise idea to read up on what swap is exactly and what its uses are. The OS will swap when it runs out of virtual memory addresses. In some cases apps actually make use of swap to save on RAM. VMware Fusion is one of those. It is why it is so memory efficient. Swap is not very fast memory is whatever isn't needed right away can be put in there. By doing that you free up the much faster RAM which will make certain operations a lot faster.

    It has nothing to do with being a fanboy, it has everything to do with knowing what on earth swap is and how it works. That and the overall memory management in OS X as explained in GGJstudios link. In other words: read the darn link!
     
  5. macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #5
    You might want to read that again and think about how it is wrong.

    S-
     
  6. macrumors 6502a

    dcorban

    Joined:
    Oct 29, 2007
    #6
    The basic idea is that the size of the swap file is almost meaningless in regards to performance.

    Stop staring at the stats and use the computer. When it starts feeling slow due to swapping, then be concerned.
     
  7. macrumors 68030

    Joined:
    Mar 30, 2004
    #7
    You are passing outdated information.

    Much of the inactive memory is used for disk cache. In theory, when free memory is running low, OS X's dynamic pager is supposed to flush disk cache from inactive memory.

    Both Lion and Mountain Lion (especially Lion) are not very good at reclaiming memory. Running "purge" command from Terminal (you may need to install Xcode) will flush disk cache out of inactive memory and return most of it back to free memory pool. But that is obviously not something any of us wants to do.

    Adding more RAM will certainly decrease the likelihood of free memory running out, but if you rarely reboot your Mac, you will probably run out of it eventually.
     
  8. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #8
    You don't know that. As page outs are cumulative since your last restart, they could have occurred at any time, not at the time of the screen shot, when there is both free and inactive memory available.
    No, it's not outdated. I have yet to see anyone provide proof that page outs are occurring at a time when there is free or inactive memory available, even on Lion or ML. To prove that, you need a video showing the page outs increasing while free and inactive memory is available at the time of the page outs. People don't seem to grasp the fact that the page outs reading is not a real-time indication that page outs are occurring now, but rather a historical accumulation of page outs that have happened in the past, since the last restart.
     
  9. dyn
    macrumors 68000

    Joined:
    Aug 8, 2009
    Location:
    .nl
    #9
    No need because it is 100% correct. If you want to take part in this discussion I strongly suggest that you do your homework properly. Apple is talking in its developer documentation about virtual memory addresses. When it runs out of these addresses it will start to shift things in memory and eventually swap.

    Now go read up on how it really works and admit you are wrong in every way ;)
     
  10. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #10
    Actually, it swaps when it runs out of physical memory, not virtual.
     
  11. sidewinder, Sep 20, 2012
    Last edited: Sep 20, 2012

    macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #11
    Maybe you should go read up on how it really works.

    The system never runs out of "virtual memory addresses" as you call them. Each process has a logical (virtual) address space created for it by the virtual memory manager. This space is chopped up into 4KB pages. This logical address space is always available to the process.

    What the system can do is run out of physical RAM. That is when these pages can get swapped out of memory onto disk and vice versa.

    So this sentence of yours:

    The OS will swap when it runs out of virtual memory addresses.

    Is completely incorrect.

    S-
     
  12. macrumors 68030

    Joined:
    Mar 30, 2004
    #12
    I don't really want to create a video to prove you wrong but if I run memory intensive task like (1) Final Cut Pro export or analyzing clips, (2) Aperture view entire photos, (3) Handbrake encode 1080p movie, inactive memory will gradually increase and deplete free memory. Eventually, free memory reaches 0 MB and page outs count starts to go up from 0. FYI, my 2011 MacBook Pro has 16GB RAM.

    This issue is also documented by Adam Fields as well as 56-page long discussion at Apple's support community site.
     
  13. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #13
    Inactive memory doesn't "deplete" free memory. Read the link in my first post to understand what free and inactive memory is, and how memory is marked as inactive.
    At the time page outs start increasing, free memory is zero, but what about inactive memory? That's the part that people claim, but never prove.
     
  14. macrumors 68030

    Joined:
    Mar 30, 2004
    #14
    Sure it does. Inactive memory is not directly available to applications. OS X will use free memory for disk cache, which then becomes inactive memory. At its discretion (e.g., when free memory is running low), it will release inactive memory back to free memory pool, by doing things like flushing disk cache.

    Unfortunately, Lion and (to less extent) Mountain Lion do not release inactive memory very well. Murphy's Law is that as inactive memory rises, free memory will decline. You just can't have both.

    When you run out of free memory, OS X will start swapping memory (page out) into disk (virtual memory). And when you start paging out, you will start to get things like beach balls (less severe on flash storage/SSD). The only workaround at this point is to reboot your Mac.

    Here's before:
    [​IMG]
    Here's after:
    [​IMG]
    In theory, this after state shouldn't happen.
     
  15. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #15
    Directly from the Apple link I first posted:
    Page outs occur when you have no free or inactive memory.
    You don't have to reboot. If you close the apps that are placing high demands on memory, that memory will be freed up by Mac OS X, returning to either free or inactive memory, or both.
    As I said before, the after picture shows that page outs occurred since the last restart, but does not prove that they occurred at a time when there was inactive memory available. I would be happy to concede that this is happening, but I've never seen any proof.
     
  16. dukebound85, Sep 20, 2012
    Last edited: Sep 20, 2012

    macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level
    #16
    From my experiences, as I keep posting about on this topic but you never acknowledge, if I run an app that requires a bunch of memory, inactive != free. My experience is running matlab files manipulating multiple variables well over 5 gigs (sometimes up to 10gigs) apiece

    Running the purge command does help with the task I am trying to conduct in those cases as it frees up the inactive ram for matlab, which is constantly wanting as much as it can get. When I have a bunch of inactive memory and no free memory, I get loads of pageouts and very poor performance.

    Not sure why you keep saying they are the same when they are clearly not in situations I have expereinced, told you about, yet ignored when you keep posting the same info.
     
  17. macrumors 65816

    SpyderBite

    Joined:
    Oct 4, 2011
    Location:
    Xanadu
    #17
    If the problem doesn't exist for everybody (I am not experiencing the same issue as you) then how can you be certain that it is something that Apple needs to address and it isn't something localized on your system or similar setup?

    Tech Support 101: if everybody is having the same problem it is a problem with the code. If only you are having a problem it is a problem with the way you are using the code.
     
  18. macrumors 68030

    Joined:
    Mar 30, 2004
    #18
    No no no. Look, I write software for living and I deal with garbage collection all the time.

    Apple's support document is "dummied down" for average Joes. Inactive memory can mean many things. But it generally means one of two things.
    1. When you quit an app, its contents are first moved from active to inactive memory pool. If you re-run the app before inactive memory is reclaimed (and becoming free), it will be able to access them again.
    2. When app needs to access data from disk, and there's free memory, it is first transferred to inactive memory (into disk cache). Sometimes, OS X puts restriction on the cache size. But on modern OSes like Mountain Lion and newer versions of Linux, there's no limit ("free memory is wasted memory").
    So what happens when you run out of inactive memory and app needs to create more object (write to memory)? If the data is in inactive memory (e.g., disk cache), all is well and it will be converted to active again. Otherwise, OS X will need to either release parts of inactive memory (and therefore making it available as free memory) or create virtual memory (which is disk being simulated as memory). The first part (reclaiming inactive to free) is a lot harder than it looks and doesn't happen as quickly as creating virtual memory.

    Writing to virtual memory is called page outs and is much slower than writing to memory. Virtual memory is a series of very large files on /var/vm directory. Since multiple apps and processes can use virtual memory files, it is next to impossible to reclaim virtual memory without restarting your Mac. In other words, even when OS regains free memory, it will not move data from virtual memory to free memory.
     
  19. macrumors Westmere

    GGJstudios

    Joined:
    May 16, 2008
    #19
    It's this that I have never seen proven, regardless of user claims. I have never seen anyone prove that page outs occur at a time when inactive memory is available.
    Thanks for the details, but I'm quite familiar with how memory management works. Nothing you've said proves paging out occurs when inactive memory is available, or that restarting your Mac is required to free up memory. I've heard such claims from several people, but zero proof.
     
  20. macrumors 65816

    Ledgem

    Joined:
    Jan 18, 2008
    Location:
    Northeast USA
    #20
    I believe you, but I think there's something weird with 10.8's memory handling. With OS X 10.7 and 6 GB of RAM, my memory usage would usually hit the 60%'s pretty quickly, and over the course of the week it would rise to 70%. This is all with normal usage - mostly email and web-browsing. Using Aperture or other media applications obviously pushes the RAM usage up farther and induces page outs.

    When I installed OS X 10.8 on that same system, my memory usage would stick around the 40-50%'s. I thought that OS X 10.8 was just more memory-efficient, but I was getting page outs even with my normal day-to-day usage. They weren't so numerous as to cause a system slowdown, but they were greater in number than with OS X 10.7.

    Now I'm using a system with 16 GB of RAM. My memory usage is typically well under 40% for day-to-day usage, yet I still build up a swap file and experience page outs. The swap file is pretty small and the page outs are much, much less in number compared to my old computer with 6 GB of RAM, but it strikes me as odd that I get any paging out at all when I'm not using anything particularly RAM-intensive, nor am I multitasking heavily. Paging out when RAM utilization is less than 50%? I don't remember having page outs like this under OS X 10.7, and definitely not under OS X 10.6 even when I had only 4 GB of RAM.
     
  21. macrumors 68030

    Joined:
    Mar 30, 2004
    #21
    Before and after screenshots are less than 15 minutes of each other. All I did was regenerate preview images in Aperture. If inactive memory is indeed available for anyone, OS X should never create virtual memory (and thus increasing page out count) in the first place.
     
  22. macrumors member

    Joined:
    Jun 15, 2007
    #22
    I updated yesterday to 10.8.2 and I'm on a 13" Macbook Pro 2011 with 8GB. I never used all the free memory but after the update my mac was running so slow I checked and I had 75MB of free memory and 4 GB of inactive? I think theres a problem...
     
  23. macrumors member

    Joined:
    Apr 27, 2011
    Location:
    CA
    #23
    To me it's the programs' fault. Or at least I think. . .

    I have a Mid 2011 iMac and I do experience problems with memory. Although I don't have loads of experience, I have personally determined it a software issue. Not an Apple software issue, but an issue with the program I am running.

    Almost any program runs smooth and superb with the exception of Safari of course as it is a memory hog, although it seems to have improved with each update since Lion. I love Safari and will only open Chrome when something doesn't quite open right due to Flash. Urg.

    Here is my point of where I'm going: What programs are you running when this memory issue occurs? Because the only time I have issues is when I run BOTH Lightroom and Photoshop at the same time. Not by themselves, but at the same time. It can get frustrating as it's easier for my workflow to have both open at the same time sometimes.

    I already know I need more RAM to fix my issue as I have a TON of pics and that is the primary reason for my issues. I will eventually get more RAM as I've been ready to, I can't count how many times, as I only have 4gigs. When I do upgrade I will upgrade to at least 12. It's just that with all that is going on in my personal life, I'd rather spend money on food or life stuff as times are harder than when I got my Mac. I did help my issue my creating a new Library for Lightroom with only my more recent photos and that has helped a lot. But as I keep adding more it does get slower with taking all the RAM and then everything goes to a crawl. (Maybe I need a better setup of how much Cache I use, as I haven't found the magic number yet.)

    I found the problem with most programs with taking up too much RAM depends solely on how much Cache I allow for certain programs. As I've adjusted things, things run smoother.

    Now this is just my 2 cents as I am no expert or seasoned user. But that is at least my observation. Also when I first got my iMac, It did have Snow Leopard on it and Photoshop and Lightroom Did run slower with the older version, even though I had WAY less apps on at the time.

    Now from any pro user, does what I just explained make sense? Or do I have it twisted? I'm still learning and I feel I know a great deal in the short time I've owned my Mac. Also when I do get somewhat frustrated for whatever reason, it's usually my fault for an issue, as I love to tinker with my system a lot to make it MINE, or I just remember the horror of a PC I owned before my iMac and then I relax, cause it's still a 1,000 times better.
     
  24. macrumors 65816

    Ledgem

    Joined:
    Jan 18, 2008
    Location:
    Northeast USA
    #24
    Yes, what you've said is correct. Multimedia programs in particular will take up a lot of memory, just because that's the nature of multimedia editing. Most of those programs don't have a set limit. If what you're doing is very demanding, their memory usage will increase up to the system's maximum capacity to accomodate it.

    The problem mentioned in this thread doesn't really deal with that, though. The operating system is responsible for managing the memory between programs. If the memory becomes full, the operating system will determine what's in there that isn't currently being used (or that was last touched the least recently), and then put it into a "page file" on the hard drive. This is what paging out is. When the paged out information is needed, it will be transferred from the hard drive to the memory. If the memory is still very full, then the operating system basically swaps things around: the next least-used thing in the memory is put into the swap file and is replaced with what the system needs. Alternately, if enough memory has been freed up, then no exchange is necessary: information goes from the hard drive to the memory, and that's it.

    It's worth noting that involving the hard drive drastically slows things down. Thus, paging out is very undesirable.

    The problem in this case is that the operating system is paging out even when there's a lot of free memory. In my case, for example, I may be using 7 GB of RAM, but I have 9 GB free. Despite this, the operating system will occasionally page out. In theory, there's no reason why it should be paging out under such circumstances.
     
  25. macrumors 6502

    Joined:
    Aug 10, 2012
    Location:
    Sweden
    #25
    I think there may be some misconception regarding what Inactive memory is. Reading up on FreeBSD memory management it seems Inactive memory is either:

    - memory recently released (clean);
    - memory recently paged out (clean);
    - or memory that has not been touched for a longer period (dirty).

    Clean memory is indeed similar to free memory. Only reason it is kept as inactive is to be able to reclaim it faster in the event the system that most recently used it is restarted/awaked again. However, dirty inactive memory must first be paged out before it can be used and hence can be more expensive to use.

    Basically, even with lot of inactive memory, depending on how much of it is dirty respectively clean you may or may not encounter lot of page outs (the man page states that purge flushes disk caches).

    Since unixes like OS X, FreeBSD and Linux love to cache lot of I/O accesses to speed those accesses up (especially if you use a HDD) I can imagine that disk intensive applications with frequent read and writes may eventually hog the system due to lot of caches being used.

    Since the purge command seems to resolve your issue, what I described above seems to be the most likely cause of your problem.

    Personally, even after weeks of uptime I have never experienced any kind of extensive page outs, slow downs or other memory issues and that with Safari, Mail and some other apps constantly running. Since none of my apps are disk intensive I guess my system uses very few caches and those used are probably periodically flushed from time to time leaving me with lot of "free" memory.

    Basically, I believe there is nothing wrong with the memory management. This is just how it is designed to work. As with all algorithms there are always trade offs made and hence no algorithm will work perfectly for every one all the time. What you have encountered is the trade off made by the memory management algorithm of OS X.

    The memory management in OS X does not differ much from other unixes like FreeBSD and Linux and I'm sure you can find similar discussions in forums related to those unixes as well.

    Does all this make sense to you ?
     

Share This Page