Understanding RAM and Activity Monitor

Hello,


I am hoping someone can help me make sense of the memory stats on the new activity monitor, some of the things I'm seeing don't make sense according to my (fairly rudimentary) understanding of how Mavericks manages RAM. I want to know because although my computer is running pretty satisfactorily, I'm thinking about buying RAM and just generally want to understand my system better and make sure I'm getting the most out of it.


I'm running a baseline model of the most recent Mac mini (Late 2012), which is about a year old now. It has a 2.5GHz Core i5 and 4GB memory, >100GB free hard disk space.


My problem is that I don't understand the information on Activity Monitor. As people will be aware, Apple changed the information it presents in Activity Monitor Mavericks. In typical daily use, things start to get a bit creaky with a Safari, Word, Mail, and my bigish iTunes (~60GB) and iPhoto (~15GB) libraries open, and Activity Monitor will tell me something like this:


Physical memory: 4.00 GB Memory Used: 3.93 GB Virtual Memory: 5.10 GB Swap Used: 0 bytes


This seems to mostly make sense in itself (I know Mavericks can compress RAM so it designed to maximise RAM utilisation and then just compress when space needs to be freed up for a new process), though I don't understand why virtual memory would be anything other than 0 bytes if Swap Used is also 0 bytes - is this just the amount of disk space set aside by the OS should it be required?


What I find really confusing is that if I run vm_stat in terminal I get numbers like this:


Pageins: 285651. Pageouts: 35809.


How can I have pageouts above 0 if Swap Used is 0 bytes? Moreover, Pageouts/Pageins > 0.1, which lots of people quote as a good rule of thumb for judging whether your RAM is overstretched. So what's going on? How can the system be writing pageouts without using any "swap". My "Memory Pressue" meter is nice and green and low but I'm not sure I trust this as it's unclear how much of an abstraction it is.


When I really push my computer (10 apps +), then it does start to use swap, but only really small amounts, even when the computer is really straining (SBBOD and app crashes left, right and centre). Even when it does use swap, the memory pressure stays green, but I read that it was meant to turn yellow when using Swap (another reason why I don't trust that it is telling me anything meaningful). These are the readouts in the high intensity situation (Activity Monitor and vm_stat respectively):


Physical memory: 4.00 GB Memory Used: 3.99 GB Virtual Memory: 7.59 GB Swap Used: 13.5 MB


Pageins: 1386280. Pageouts: 435686. [Pageouts/Pageins = 0.314]


Any help or explanation/perspectives would be greatly appreciated. I suppose my main question is whether the lagginess and unresponsiveness of my computer during moderate/heavy use is a result of limited memory, or whether it's simply that there are likely lots of CPU tasks running at the same time (or something else?).


Many thanks is advance.

Mac mini, OS X Mavericks (10.9.1)

Posted on Feb 4, 2014 3:17 PM

Reply
8 replies

Feb 13, 2014 8:25 PM in response to Origino

I suppose my only follow-up question would be about the compression. Most forums seem to characterize the memory compression as 'free' (making use of an idle core). I wonder how accurate this is?

I think the Compressed memory is what used to be called "Inactive" memory. Inactive memory are pages that have known data or code in them which has been released, but may be asked for again in the near future (for example a program that has just been quit, but may be launched again real soon now; if the program is launched before the data is flushed from the Inactive pool, it will start up much quicker and save both time and power reading it from disk; saving power by not using a disk extends the life of laptop batteries). By compressing the Inactive memory Mac OS X can keep even more idle code and data in RAM than before, and save even more time and power by avoiding the use of the disk. The new Activity Monitor does break out Inactive (compress) from the disk cache, all of which was lumped into Inactive memory in previous versions.


If I were to install 8 or even 16GB or RAM, no doubt the OS would find a way to fill this up. What else would be getting paged in, if there is no overflow at the moment (apart from compression)? Or would the OS just be less judicious about what it writes into the RAM?

It would most likely cache even more file system data. Unused RAM is wasted, and Mac OS X is very good at not wasting your RAM.


The only downside I've seen to the way Mac OS X maintains Inactive RAM is that I think it also avoids flushing modified data back to the file so that the modified data is stored in stable storage. The advantage is that Mac OS X avoid writing to disk until it is forced to and then it writes a lot to concentrate as much I/O into the shorted period of time, then allowing the disk to spin down and save power for as long as possible. The down side is that when Mac OS X need lots of free RAM, it is often forced to do lots of slow writes thus making the Mac appear slow as it is flushing modified data to disk.


The Apple move to using more Solid State Disks in many Mac models, is hiding that down side, but for those of use that are still using traditional disks, the effect is noticeable.

Feb 4, 2014 3:20 PM in response to Origino

Let's start here:


About OS X Memory Management and Usage


Using Activity Monitor to read System Memory & determine how much RAM is used

OS X Mavericks- About Activity Monitor


Understanding top output in the Terminal


The amount of available RAM for applications is the sum of Free RAM and Inactive RAM. This will change as applications are opened and closed or change from active to inactive status. The Swap figure represents an estimate of the total amount of swap space required for VM if used, but does not necessarily indicate the actual size of the existing swap file. If you are really in need of more RAM that would be indicated by how frequently the system uses VM. If you open the Terminal and run the top command at the prompt you will find information reported on Pageins () and Pageouts (). Pageouts () is the important figure. If the value in the parentheses is 0 (zero) then OS X is not making instantaneous use of VM which means you have adequate physical RAM for the system with the applications you have loaded. If the figure in parentheses is running positive and your hard drive is constantly being used (thrashing) then you need more physical RAM.


Adding RAM only makes it possible to run more programs concurrently. It doesn't speed up the computer nor make games run faster. What it can do is prevent the system from having to use disk-based VM when it runs out of RAM because you are trying to run too many applications concurrently or using applications that are extremely RAM dependent. It will improve the performance of applications that run mostly in RAM or when loading programs.

Feb 4, 2014 4:03 PM in response to Kappy

Thank you for your reply. I have in fact already read the information you posted above when you posted it on a different thread (on 30th Jan 2013). As far as I can see this doesn't really answer my question or explain the apparent contradiction in the figures I presented.


You have quoted this to me: "The Swap figure represents an estimate of the total amount of swap space required for VM if used, but does not necessarily indicate the actual size of the existing swap file." However, I was referring to "Swap Used" in Activity Monitor, not in top; the figure I was referring to surely does necessarily indicate the actual size of the existing (or previously existing) swap file.


Any information or explanation of the figures in Activity Monitor and vm_stat would be very helpful. Though otherwise similar to vm_stat, top appears to be an instantaneous readout, and doesn't particularly seem to provide any further information. (Additionally, when I run top, I there is no information reported on Pageins or Pageouts. I do get this information: "VM: 454G vsize, 1069M framework vsize, 11306(0) swapins, 14612(0) swapouts.". Are swapins and swapouts exactly equivalent to pageins and pageouts?


I'm sorry if I'm being slow, this isn't my field. I have read a number of the Apple Support articles about activity monitor but unfortunately most of them are out of date, and refer to the way information was presented in OS X 10.8 and earlier.


Thank you again for your help and thanks in advance for your reply.

Feb 4, 2014 4:27 PM in response to Kappy

Also what you said in yet another thread is interesting:


"PageIns is not a relevant figure nor is PageOuts. What is relevant is what is in the parentheses of PageOuts. For example, in your image PageOuts are 1.5 MB, but in parentheses it says (0 bytes/sec.) The first number is simply the cumulative value since the machine was last booted. The parenthetical value is the instantaneous number. If it's 0 bytes/sec, then there is no memory problem. If it's a positive number that is increasing continuously, then you do not have sufficient RAM and the memory manager is using hard drive virtual memory."


I understand this, but surely the absolute value (as opposed to the instantaneous) is of some interest when compared as a fraction of pagein (as this normalises for the time since you turned your computer on - hence the 10% rule). Also, surely the parenthetical (instantaneous) value will rise and fall even under stress, rather than increasing continuously?

Feb 4, 2014 6:51 PM in response to Origino

The numbers provided is simply a running total. There are always pageouts and pageins going on because that is part of memory management. It's the rate or pageouts that is important. When that rate is positive and continuous then the number in parentheses becomes positive and progressively larger. That is the sign of insufficient memory.


Why is this of importance to you?

Feb 5, 2014 2:20 PM in response to Origino

though I don't understand why virtual memory would be anything other than 0 bytes if Swap Used is also 0 bytes - is this just the amount of disk space set aside by the OS should it be required

Because virtual memory has nothing to do with disk. It is how the hardware manages the address space assigned to processes. A process has a virtual address space from 0 to n. That address space may have holes in it which will never have RAM associated with it, but it is still part of the process' address space. The address space may include a large memory mapped file, so that address space is large, but the data for that is backed by a real file, not swapfiles. Shared library/framework code is part of many address spaces, but it is still code residing in a regular file on disk, and again not swapfile space needed for that. Also that virtual address space is multiplied by the total number of programs sharing the library/framework creating larger virtual address spaces than you expect.


The size of your virtual address space if mostly something no one cares about except a very few operating system developers, and they tend to be the ones that are actually maintaining with the code that deals with virtual memory.


Pageins: 285651. Pageouts: 35809.


How can I have pageouts above 0 if Swap Used is 0 bytes? Moreover, Pageouts/Pageins > 0.1, which lots of people quote as a good rule of thumb for judging whether your RAM is overstretched. So what's going on? How can the system be writing pageouts without using any "swap". My "Memory Pressue" meter is nice and green and low but I'm not sure I trust this as it's unclear how much of an abstraction it is.

Because at that moment in time, no processes had any of their data written to the swapfiles. Sometime in the past a process (or processes) needed to be paged out. The vm_stat value is cumulative from the last boot.


Also a memory mapped file that is modified in memory will be written back to the file using pageouts, but that would not affect swapfiles.


I'm thinking about buying RAM and just generally want to understand my system better and make sure I'm getting the most out of it.

Start an Applications -> Utilities -> Terminal session, and run the command:


sar -g 60 100


which will report the pageout activity once a minute for 100 minutes (adjust the numbers to suit your tastes).


Now use your Mac under the load conditions where you think you might want more RAM. Come back later and look at the sar output. If you mostly have zeros, with maybe a small blip now and again, you are good. If you some a few small pageout blips, unless you notice the system performance is bad during those blips, then your are still good. If you have very large pageout numbers, or sustained pageouts, then you may benefit from additional RAM, especially if you can associate poor performance with paging activity.

Feb 13, 2014 6:49 PM in response to BobHarris

Thank you BobHarris! Both illuminating and helpful. It seems (using sar -g 60 100) that I have very little paging out even during heavy use.


I suppose my only follow-up question would be about the compression. Most forums seem to characterise the memory compression as 'free' (making use of an idle core). I wonder how accurate this is?


If I were to install 8 or even 16GB or RAM, no doubt the OS would find a way to fill this up. What else would be getting paged in, if there is no overflow at the moment (apart from compression)? Or would the OS just be less judicious about what it writes into the RAM?


Thanks again for your great answer.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Understanding RAM and Activity Monitor

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.