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)
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.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).