I understand the concept behind the various memory usage, but I don't understand why there are Inactive memory and Page In upon boot up. There are no applications that have started which hasn't quit, and what was in RAM that was written to HD that is being brought back as shown in Page In?
Upon boot up why is there usage in Inactive and Page In for memory
memory
Related Solutions
I've been researching this very question for some time, and I've come to the conclusion that while there are several so-called "solutions" offered in various places, none of them really fixes the problem or makes the symptoms go away. The best I've found is techniques that change when inactive memory is swapped, such as the use of the purge
command you referred to. I believe that MacLemon is correct that swapping can be disabled only in entirety and not selectively, and so disabling the swapping of inactive memory would in practice be equivalent to disabling virtual memory altogether—which could be a workable solution on a machine with really large amounts of RAM, but is impractical on machines with a low maximum RAM capacity, such as MacBooks or Minis.
The reason that none of the ad-hoc purging solutions make the situation significantly better is that there are really only two ways to force OS X to clear inactive memory: the purge
command, or forcing allocation of all free memory (and since I'm not certain what method purge
uses, these two may actually be more or less the same). purge
, as you mentioned, takes a non-trivial amount of time to complete. Allocating all free memory simply accelerates the process by which the contents of inactive memory would be swapped out naturally, and so still takes up the same large amount of system resources. The only advantage of either of these solutions is that they allow you to choose when the swapping occurs, so it can be done before you would be normally trying to allocate that memory to something else. Whether that is actually useful to you depends on several factors, so the simplest way to find out is to just try it.
I've been testing a few of the memory-clearing utilities out there, and I've found that for me, manually forcing inactive swap requires more active monitoring of memory levels than is practical while I'm actually working, and using a utility that automatically forces the swap when free memory drops below a certain threshold is no better than letting the OS do it on its own, as I still have no control over when the swapping will occur and my apps will SPOD. So while there is an app that will do exactly what your alternative question asks for, that doesn't actually make the situation any less painful.
Until Apple's OS development team decides that the memory management system isn't working the way it's supposed to, and they figure out a way to make it work properly, the only real solution is to identify which apps are generating the most inactive memory and stop using them. In my situation, this has meant changing web browsers. I've been testing a variety of them, and Chrome is so far the one that seems to generate the least inactive memory, probably in part because every tab and every extension runs as a separate process, allowing the OS's native memory management to treat each one separately in terms of prioritizing swapping. Safari is the worst I've tried; starting with Safari 5.1, I could open a few tabs, do absolutely nothing, and watch the inactive memory rise rapidly in Activity Monitor—it would easily go from <1gb inactive to >3gb inactive within about five minutes, run the swap cycle, and then do the exact same thing. (Granted, memory that is doing nothing is exactly what makes it inactive in the first place, but it shouldn't create more inactive memory than was allocated active in the first place.) Safari 6 under Mountain Lion is a bit better, but not better enough to be worth switching back. Firefox, not being based on WebKit, ought to be better about this than either Safari or Chrome, but it has its own legacy of memory management problems, including a history of memory leaks, that make it no better in practice.
What would really fix the issue is if there was an option, likely a hidden option in the OS, telling the OS to simply dump the contents of inactive memory when needed instead of swapping its contents to disk. But I don't expect Apple to ever make such an option available.
After spending some time looking into this and a SO question coming out of it, I think I've nailed this down.
Before I get started, I want to point out the philosophical debate that Apple must have had when they tried to answer the question What is used memory? If you look at the activity monitor on in OSX Pre-Yosemite (you can see this in my question I link and below) you'll see that Used Memory is made up of four parts; App Memory, File Cache, Wired Memory, and Compressed Memory. Now, if you look at the activity monitor below, from OSX Yosemite, you'll see that File Cache is missing. Not sure why there was a change between OS's, but there is one none-the-less. Since you're using a pre-Yosemite OS in the question, I'll defer to the former definition.
Let's get back to business, calculating the total memory, more specifically Used Memory since Free memory is given to us using vm_stat
.
In order to calculate this, we need to map the four parts of Used Memory to the different stats given to us from vm_stat
. A few of these are pretty easy.
Activity Monitor to vm_stat Mappings
- File Cache: -> File-backed pages
- Wired Memory: -> Pages wired down
- Compressed: -> Pages occupied by compressor
- App Memory: -> Pages Active + Pages Speculative
Figuring out App Memory is the tricky one, and to be honest, I don't quite understand why speculative memory is apart of it, but the math is inarguable.
Inarguable Math (goes with OSX Pre-Yosemtie Activity Monitor)
vm_stat Activity Monitor
------------------------------------------------
Free Mem. 9.97 GB 9.85 GB
Pages Active 2.38 GB xxx
Pages Speculative 0.57 GB xxx
App Mem. xxx 2.95
Cached Files 1.24 GB 1.22 GB
Wired Mem. 1.43 GB 1.41 GB
Compressed 0.57 GB 0.58 GB
------------------------------------------------
Total Mem. 16.16 GB 16.01 GB
(keep in mind rounding error)
Activity Monitor OSX Pre-Yosemite
Activity Monitor OSX Yosemite
Related Question
- MacOS – My Mac crashes when it runs out of RAM
- MacOS – Understanding active, inactive, free and swap memory allocation
- MacOS – Apps still in Activity Monitor after being closed
- MacOS – Why does leaked memory appear malloced to kernel_task, and why can’t OS X therefore garbage collect it
- MacOS – 30GB out of 32GB being used for wired memory
- IOS – How does iOS and apps deal with low to no disk storage
Best Answer
The Inactive memory is probably the result of the boot process itself. Any of the files the boot process used, and then no longer needed are still cached for retrieval until something else needs the space.
I believe the page-outs have to do with the way OS X handles loading of dynamically linked libraries and files. Say you load an app called ReallyComplexApplication. This may point to a number of different libraries of code, but don't all need to be loaded into RAM when the app first loads. So OS X loads the core program into memory, and sets up RAM in such a way that if ReallyComplexApplication tries to grab code or data from BigLibraryOfCode it is automatically loaded from disk to memory.
That would be a page in. The OS expects data to be in RAM, but it isn't really there. This isn't really a problem, per say, because it is designed that way. But it is still considered a "page fault"
[EDIT] Source: https://developer.apple.com/library/mac/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html
In that article they actually differentiate, so what you're probably seeing is what they call "Soft fault."
On my machine that has been up for 2 days, I have 16GB of RAM, 0 page-outs but 22,288,514 page ins.