Sign up ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

When I run vm_stat on my 10.6.8 MacBook Pro with 2 GB of RAM I get the following:

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                          90518.
Pages active:                       205479.
Pages inactive:                      32417.
Pages speculative:                  134461.
Pages wired down:                    61009.
"Translation faults":             26323651.
Pages copy-on-write:                177180.
Pages zero filled:                15230394.
Pages reactivated:                       3.
Pageins:                            388108.
Pageouts:                                0.
Object cache: 14 hits of 797355 lookups (0% hit rate)

If you add up the free, active, inactive, speculative, and wired memory and multiply by 4096 (to turn the pages into bytes), you get 2,145,828,864 rather than the expected 2,147,483,648. There are 1,654,784 missing bytes (or 404 pages). This isn't a constant number though, it fluctuates:

$ vm_stat 1 | perl -MList::Util=sum -nle 'next unless /^\s*\d/; print 524288-sum((split)[0 .. 4])'

Are these missing pages just a reporting inaccuracy because the amount of one type of page has changed by the time vm_stat prints the next type of page? Or is there some other type of memory that I am missing?

share|improve this question
Please have a look at What is wired memory first. If this doesn't answer your question, commend or amend the question here. – patrix Feb 9 '13 at 13:11
@patrix Those answers have no bearing on my question. I understand what all five types of pages are and what they do. My question is about why the sum of the amounts of each type of page is not equal to the number of pages. This could mean there is a type of page I am unfamiliar with, a bug in vm_stat, no way to get a clean snapshot of the system because the calls vm_stat uses aren't atomic (which I would count as a bug, but others would not), or something I haven't thought of. – Chas. Owens Feb 9 '13 at 13:28

2 Answers 2

Short answer: the host_statistics64() function returns the bad data.

Still looking into why this is the case, but the bug (if it is a bug) is in the library vm_stat uses, not in vm_stat itself.

share|improve this answer
So I'm not very knowledgeable about the different types of RAM but I have been trying to solve the problem of calculating total physical memory using the vm_stat command. What I found is that adding Pages occupied by compressor or Compressed memory to the list in the title results in a value of 15.987 GB on my macbook pro which has 16 GB of RAM. Should compressed memory be considered apart of physical memory? – Austin A Jul 22 at 4:12

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

enter image description here

Activity Monitor OSX Yosemite

enter image description here

share|improve this answer
Somehow the screenshot doesn't match to the "Inarguable Math" box. – klanomath Jul 22 at 9:15
Hey @klanomath, so the math should match up with the numbers from OSX Pre-Yosemite screenshot. I've added the screenshot from my other question to avoid confusion in the future. Keep in mind the numbers are for OSX Pre-Yosemite. – Austin A Jul 22 at 17:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.