Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding vm_stat in mac os, how to convert those numbers to something similar to activity monitor?

I'm trying to write a mac os program to monitor the system (something similar to the activity monitor). I have looked at the function vm_stat and when I run it I got this:

Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                         438386.
Pages active:                       236438.
Pages inactive:                     113750.
Pages speculative:                   34293.
Pages wired down:                   225027.
"Translation faults":             11132566.
Pages copy-on-write:                319385.
Pages zero filled:                 6618647.
Pages reactivated:                   23071.
Pageins:                            421804.
Pageouts:                           153240.
Object cache: 14 hits of 24183 lookups (0% hit rate)

However when I run the activity monitor, I got something like:

Page Ins: 1.61gb (8.00kb/sec)
Page outs: 598.6 MB

I have a question regarding this: how come the pages free in vmstat is so small (comparing to activity monitor)

like image 896
Josh Avatar asked Nov 13 '22 14:11

Josh


1 Answers

  1. 256 is the number of pages in a megabyte (256 pages * 4096 bytes per page = 1048576 bytes aka 220 bytes aka 1 megabyte) assuming a page is 4096 bytes. The numbers from vm_stat are in pages, and it is also telling you that the page size is 4096 bytes, so you don't need to hardcode 256 necessarily.
  2. Since you don't show Activity Monitor to compare I can't say for certain, but I suspect this is again due to vm_stat using a unit of a page and activity monitor using "human readable" units, and they are indeed the same value (or close given that Activity Monitor updates continuously).
like image 140
Logan Capaldo Avatar answered Dec 21 '22 21:12

Logan Capaldo