So today I wasted a bit of time trying to figure out why the memory_pressure tool in Mavericks was giving me some surprising news:
‘The system has 2147483648 (524288 pages with a page size of 4096).’
This machine is supposed to have 8GiB. So what gives? We peek into the sauce to find they’ve used this:
phys_mem = read_sysctl_int(“hw.physmem”);
And what do we see in man sysctlbyname? This:
The bytes of physical memory represented by a 32-bit integer (for backward compatibility). Use HW_MEMSIZE instead.
Sure enough, hw.memsize is the one we want – tells me I have 8589934592 bytes. That’s better.
My current gig has me spending a fair bit of time looking at stuff on opensource.apple.com and I must say I’m actually a bit surprised by the number of not so great things I’ve encountered. It seems like they might benefit from more code review rigour. Then again, their revenues and customer satisfaction numbers don’t really bear that out I guess, so fuck it.