I am wondering if there are certain numbers that are double-counted or something. I am also curious if there is a difference between Intel and M-series Macs, as I have an M2 Mac Mini.
Mine is 2019 iMac - Intel. So I don't think this is an Intel/ASi difference. Whilst physical connection to memory is somewhat different, I believe that memory management (apart from page size and some tuning) is the same - and indeed the same as in iOS, etc.
State of documentation:
1) Activity Monitor's help has some nonsense in it, e.g. "
App Memory: The app could not be installed".
2) As far as I can see, the Apple Developer documentation is aimed at developers understanding the memory behaviour of their apps, not the system as a whole.
3)
man vm_stat
is dated 1997 and certainly does not describe all the output of
vm_stat
.
4)
man sysctl
is dated 2011 and does not mention
sysctl vm
.
5) Non-Apple: Mac OS X and iOS Internals (2013) and *OS Internals Vol II (2019) by Jonathan Levin are too detailed for me!
Using the output of
vm_stat
, you can get two views of memory statistics. The first view is of the "traditional" Unix counters (free, active, inactive, speculative, throttled, and wired along with pages occupied by the compressor) which do add up to physical RAM. Secondly, with a bit of guesswork/interpretation, the Activity Monitor counters can also be reproduced.
In Activity Monitor:
A) App+Wired+Compressed+Cached does add to Physical Memory less what is in Free Memory (you can only get that vm_stat). That seems to be consistently correct.
B) App+Wired+Compressed is greater (usually be a small amount) than Memory Used. This is even though the style of the display suggests that they do add up.
C) Not showing Free Memory hides the facts that Memory Used + Cached + Free Memory is greater than Physical Memory.
d) When Free Memory is very small, you can get Memory Used + Cached greater than Physical Memory. This is what you are seeing.
I
suspect that the error is due to Activity Monitor counting vm_stat's Pages Purgeable into both Memory Used and Cached Files. But I need to explore that further.
If you do look at the output of vm_stat, do be aware that the numbers are in pages where a page is 4096 bytes (Intel) or 16,384 (ASi). And that memory as GB, is where a GB is 2^30 bytes, not 10^9 bytes.