Shared (GTT) buffers are mapped at their GPU VA, which the driver picks
inside the host window. The window was reserved only long enough to
choose a base and then released as a placement hint, so the process's
own mappings could take its pages. On the iPad the model's safetensors
mmap landed at 0x406800000, inside the 16 GiB KFD window at
0x400000000, and the 32 MiB staging buffer the driver then placed there
failed to map (IOConnectMapMemory64 kIOReturnBadArgument, which XNU
reports for any mapping it cannot create). Weight binding stopped with
HSA_STATUS_ERROR_OUT_OF_RESOURCES.
The connection now keeps every free page of the window reserved
(inaccessible, no backing) once the session is ready, releases exactly
a buffer's range just before its placed mapping, and reserves it again
when the buffer is unmapped or its mapping fails. A failure to map at
the GPU VA is now reported on stderr, saying whether something else in
the process holds the range.
A host memory budget caps the bytes of shared buffers mapped at once:
MAC_HSA_HOST_MEMORY_BUDGET (bytes, K/M/G suffix) or
mac_hsa_set_host_memory_budget(), with the call winning. An allocation
past it fails with OUT_OF_RESOURCES and a message naming the budget,
and the shared pool reports the budget as its size. Unset, nothing
changes. The iOS mach_vm wrappers move to mach_vm_compat.h so the
reservation code shares them.