VM page size on iPhone6 and iPhone6 Plus

There is some inconsistency in the documentation regarding the system page size.


According to documentation on virtual memory, the system page size is 4096 Bytes (4KB):

https://developer.apple.com/library/ios/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html


The 64-bit transition guide document states: "Never hard code the page size". The document recommends using getpagesize(), however getpagesize() is deprecated in POSIX and so I am using sysconf() instead.
https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/ConvertingYourAppto64-Bit/ConvertingYourAppto64-Bit.html#//apple_ref/doc/uid/TP40013501-CH3-SW1


size_t s = 4096;
assert(sysconf(_SC_PAGESIZE) == (long)s);


I do not know the actual value returned by sysconf(), only that the assertion failure indicates that the page size is different to the documented size. This assertion passes on my iPhone5 and in the iPhone6 Plus simulator, but fails on a physical iPhone6 Plus device.


What is the correct way to determine the page size?

Replies

According to documentation on virtual memory, the system page size is 4096 Bytes (4KB):

That document is out of date. Modern iOS devices support a larger page size. Please file a bug against the doc, and post your bug number, just for the record.

The 64-bit transition guide document states: "Never hard code the page size". The document recommends using getpagesize(), however getpagesize() is deprecated in POSIX and so I am using sysconf() instead.

I typically use

getpagesize
for this. AFAICT it was deprecated by POSIX because it returns an
int
but I think that’s being overly picky. It’s hard to imagine any platform where the page size would overflow the
int
size.

Regardless, both

getpagesize
and
_SC_PAGESIZE
return the same value:
  • 16 KiB on 64-bit ARM platforms

  • 4 KiB on everything else

Likewise for the

vm_page_size
global variable (as used by Mach).

One interesting edge case here is that various low-level Mach APIs (those that deal with the kernel’s address space) continue to work in terms of 4 KiB pages. You can get that value using

vm_kernel_page_size
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"