How to Extend iOS App Virtual Address Space and Boost Memory Limits
This article explores iOS memory optimization by enabling the 'com.apple.developer.kernel.extended-virtual-addressing' entitlement to expand virtual address space and the 'com.apple.developer.kernel.increased-memory-limit' entitlement to raise memory caps, detailing implementation steps, kernel analysis, test results, and practical implications for app stability.
1. Introduction
Recently we have been working on a DingTalk iOS memory‑specific remediation, addressing jetsam events and malloc crashes caused by insufficient memory. When a process is created, the system sets a maximum memory limit for each app and maintains a priority list of memory thresholds; low‑priority apps are terminated first when the device runs low on memory. While reading the XNU kernel source we discovered two entitlements that can extend an app’s virtual address space (com.apple.developer.kernel.extended-virtual-addressing) and increase its memory limit (com.apple.developer.kernel.increased-memory-limit).
2. Extend Virtual Address Space
Each app process has its own virtual address space. On 32‑bit systems this space is 4 GB. Although 64‑bit systems are theoretically unbounded, the XNU code shows that the virtual address space is device‑dependent. Enabling the entitlement "com.apple.developer.kernel.extended-virtual-addressing" causes the kernel to increase the app’s virtual address space, allowing larger allocations and preventing crashes caused by insufficient address space.
A Boolean value that indicates whether the app may access an extended address space. Use this entitlement if your app has specific needs that require a larger addressable space. For example, games that memory‑map assets to stream to the GPU may benefit from a larger address space.
2.1 Solution
To enable this capability, add the key "com.apple.developer.kernel.extended-virtual-addressing" with a value of true to the app’s entitlement file and update the signing certificate.
2.2 Data Validation
We wrote test code to compare the behavior with and without the entitlement. Because the entitlement expands the virtual address space, we repeatedly allocated 1 MB blocks without dirtying the memory until allocation failed, then summed the total allocated size.
Test data showed that without the entitlement the maximum reachable address space was about 2 GB, while with the entitlement it reached roughly 54 GB, confirming that the kernel expands the virtual address space when the entitlement is present.
2.3 Kernel Source Analysis
Analyzing the XNU source revealed that enabling the entitlement activates a “jumbo” mode. On devices running iOS 14 or later, jumbo mode expands the virtual address space up to 64 GB.
2.3.1 Enabling Jumbo Mode
During app process creation the kernel checks whether the entitlement "com.apple.developer.kernel.extended-virtual-addressing" is present; if so, it enables jumbo mode.
2.3.2 Jumbo Mode Address Request
On 64‑bit devices the kernel uses the pmap_max_64bit_offset interface to request virtual address space. When jumbo mode is active the option passed is ARM_PMAP_MAX_OFFSET_JUMBO; otherwise the option is ARM_PMAP_MAX_OFFSET_DEVICE, which varies by device.
3. Increase Memory Limit
When an app exceeds its default memory limit, the kernel triggers jetsam to terminate the process. The system provides three ways to raise an app’s memory limit. By adding the entitlement "com.apple.developer.kernel.increased-memory-limit", the kernel grants the app a higher memory ceiling, giving it higher priority in low‑memory situations.
A Boolean value that indicates whether core features of your app may perform better with a higher memory limit on supported devices. Add this entitlement to your app to inform the system that some of your app’s core features may perform better by exceeding the default app memory limit on supported devices. If you use this entitlement, make sure your app still behaves correctly if additional memory isn’t available.
3.1 Solution
Apple lists three methods to actively increase an app’s memory limit. Enabling any of them requires adding the appropriate entitlement to the app’s entitlement file; some methods rely on private kernel capabilities. The comparison of the three methods is shown below.
We enabled the "com.apple.developer.kernel.increased-memory-limit" entitlement in the DingTalk app.
To enable it, add the key "com.apple.developer.kernel.increased-memory-limit" with a value of true to the entitlement file and update the signing certificate.
3.2 Data Validation
We wrote test code that repeatedly allocated 20 MB of dirty memory each second, measuring the point at which the app is killed. The code snippet is shown below.
Tests showed that enabling the increased‑memory‑limit entitlement slightly raises the memory threshold before the app is terminated.
3.3 Kernel Source Analysis
3.3.1 Memory Warning Calculation
When a task is created the kernel reads the launch argument max_task_pmem to determine the app’s maximum memory limit. The warning threshold is set at 80 % of this limit, and it varies with the device’s total memory.
Core code excerpt:
3.3.2 Capability Activation
During process creation the kernel checks the entitlement "com.apple.developer.kernel.increased-memory-limit"; if present, it calls memorystatus_act_on_entitled_task_limit to raise the memory limit.
3.3.3 Setting Maximum Memory
When a task starts, the kernel reads the launch argument entitled_max_task_pmem (exposed as memorystatus_entitled_max_task_footprint_mb) and then invokes memorystatus_raise_memlimit to set the app’s maximum memory.
4. Conclusion
Through kernel exploration we gained an initial understanding of how the system manages virtual address space and memory‑limit allocation. Enabling the two entitlements allows an app to request a larger virtual address space and a higher memory ceiling, solving address‑space‑related crashes and improving overall performance.
5. References
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_kernel_increased-memory-limit?language=objc
https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_kernel_extended-virtual-addressing?language=objc
https://github.com/apple/darwin-xnu
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
