Give Switch 2 (spec: Ounce) titles a 128 GB default alias region on Mac in hle_svc.c while keeping iOS on the profile's mem_alias, clear DM_ALIAS_SIZE in region_check so Switch 2 probes run in the host's console-sized alias region, and enforce Horizon's physical-pool limit (mem_map_limit) by default on Switch 2 while keeping explicit on/off overrides and Switch 1's existing default. This resolves the Switch 2 startup allocator failures diagnosed in PR #3188 (two 60 GB reservations exceeding 64 GB and an uncapped physical-memory probe nulling the allocator) in the host without putting a 128 GB reservation into provisional iOS profiles. Co-authored-by: Eriksrevenge1 <[email protected]>
216 KiB
Memory and address space
The guest address space, heaps, pools, virtual address memory and the allocators games bring. Each entry: symptom, cause, fix, the games it was found on. The symptom index lists every symptom.
Host registration tables
Registration section layout under ASan
- Symptom: a sanitizer build reports
global-buffer-overflowint_time.c'ssection_fn, immediately afterhle_lib_memcpy; other linker-collected registration tables can fail the same way. - Cause: HLE, libc, Vulkan, OpenGL/EGL, NVN and service registrations are separate globals collected into Mach-O sections and walked as arrays. ASan inserts redzones between globals unless each declaration opts out. Symbol-prefix ignorelists miss producers with another naming convention, including libc's
hle_lib_*, graphics'e_*and services'sf_service_*. - Fix: every producer uses
DM_REGISTER(dm/host/registration.h), which owns the__DATAsection attribute, natural entry alignment andno_sanitize("address")on the entry. Functions and pointed-to data remain instrumented. Entries in one section must all have the same type; stronger per-entry alignment must not introduce gaps. No registration prefixes remain in the sanitizer ignorelist. - Check:
make -C dm/gfx/tests GAME=<id> registration-asanlinks all graphics producers and libc, exercises HLE, forced and service declarations, and walks the real import, graphics bootstrap and service lookup paths without a GPU or a global ignorelist. It also checks 24-byte entries and confirms that an ordinary global retains its ASan redzone. On supported Apple clang 21, six separate 24-byte globals occupied 384 bytes with redzones and 144 bytes with declaration-level suppression, across two translation units. - Found on: the host unit suite's
t_time, after it began linkinghle_table.c(PR #2856); no game execution change.
Guest layout
The Mac's alias region is the Switch's 64 GB
- Symptom: on the Mac, a game crashes once its address regions pass the profile's alias region: at launch (Trails in the Sky 1st Chapter:
sig=11 addr=0x1atsdk+0x15576c, after an 11.27 GB region at alias +1.00 GB) or a little later (Just Dance: a null allocation past 4.375 GB after about 40 s, then a crash atmain+0x639ab0), though the build's address region check reports a larger reach. A provisional profile's red linepast the profile's … alias region, the iPhone layoutsays the same. Tears of the Kingdom's long-session memory-shortage Blood Moon ([game] MSF / R / Rfafter about 87 minutes at +2.25 of 2.38 GB, issue #639) may be this too: not confirmed by a long session, and a mark near the top alone is not exhaustion. - Cause: the profile's
mem_aliasis sized for an iPhone, which gives a process one reservation of at most 6 GB without the extended virtual addressing entitlement, and the Mac used it too. A Switch's alias region is 64 GB, and games lay regions out for that much. - Fix: on the Mac
hle_svc.creserves the larger of the profile'smem_aliasand the console's alias region — 64 GB (DM_SWITCH_ALIAS) for Switch 1 and 128 GB (DM_SWITCH2_ALIAS) for Switch 2 (dm_sdk_ounce(), which holds Monolith's two 60 GB reservations on Xenoblade Chronicles 2 Switch 2 Edition); an iPhone keeps the profile'smem_aliasso provisional profiles stay within iOS's reservation limit. It is address space, not memory: the application pool still bounds what is mapped, and the bitmaps are lazy zero pages. With room for the request, StandardAllocator's and Unreal's gates change nothing on the Mac; a profile'sstdalloc_capand the rewriter's cuts still apply.DM_ALIAS_SIZEsets another size, and the profile's value reproduces an iPhone's address space on the Mac, which is how the NSP script's heap check runs, since the keys it sets are for that layout.region_checkruns withoutDM_ALIAS_SIZEso the Mac host supplies the console-sized alias region while still checking reach against the profile'smem_alias. - Addresses past 2^39: a Switch's addresses stay below 2^39, and on macOS 27 this block cannot. The system reserves
0x1000000000–0x7000000000, which leaves exactly 64 GB below 2^39, with two reservations of about 12 GB at random addresses inside it (the largest free block is 21–26 GB), and the block is larger than 64 GB. So the block crosses 2^39, at a place that changes per launch: over 600 launches of a bare process a 68 GB block started 0–33 GB below 2^39, with a median of 13.5 GB, and 15% of launches left under 5 GB. The block is laid out heap, stacks, alias region, so the crossing usually falls in the alias region; when the heap and stacks reach past it the host logs[mem] the heap and stacks reach past 2^39. The block's end stays below 2^40, which NVN GPU addresses (host pointers) need. No game is known to keep a tag at bit 39: a crash on a cut-off pointer in a log with that line would be the first, andDM_ALIAS_SIZE=<profile's mem_alias>is the check. - Found on: Trails in the Sky 1st Chapter (#877), Just Dance (#1049) and Trails in the Sky 2nd Chapter (PR #1276), reported on their bring-ups, none of them in the games table yet; The Legend of Zelda: Tears of the Kingdom (the Blood Moon, unconfirmed).
Provisional Unreal profiles asked an iPhone for 64 GB
- Symptom: an iPhone build from a provisional profile of an Unreal game stops at launch, before the game runs any code:
FATAL reserve guest ASright after>>> nnosInitialize, frommem_init_once. - Cause:
profile_guess.pygave every Unreal main with an NPDM system resourcemem_reserve 0x1028000000/mem_alias 0x1000000000, a 64 GB alias region for the 62 GB engine region. An iPhone reserves the profile's block as it is, and iOS without the extended virtual addressing entitlement grants one reservation of about 6 GB. The Mac gained nothing from it, as it reserves the Switch's 64 GB alias region whatever the profile says (The Mac's alias region is the Switch's 64 GB), and it hid iPhone-layout faults from the address region check, which measures against the profile's alias region (TRIANGLE STRATEGY's engine region form, Unreal's engine address region and its options). - Fix: the guesser has no Unreal memory rule: an Unreal game with virtual address memory takes the 5 GB block of every game with it (4.375 GB alias region, 256 MB stacks, 128 MB heap until the heap check). The rewriter's engine-wide rules already fit Unreal to any alias region: FMallocBinned3 is cut (
dm/tools/ue_malloc.py) and the engine region gets what the alias region has room for (dm/tools/ue_region.py), 4.06 GB in this block. The 5 GB block is the most proven on a phone, and Unreal games play on the iPhone in it (FINAL FANTASY RESONANCE, DRAGON QUEST XI S, Pikmin 4).test_profile_guess.pychecks that the guessed Unreal block is at most 5 GB. - Found on: Dispatch (
01008BA02525A000, update v720896, SDK 20.5.15, Unreal with FMallocBinned3), GitHub issue #2278, iPhone 15 Pro Max: withDM_ALIAS_SIZE=0xC8000000(a 3.75 GB block) it played five minutes at about 58 fps and a 2.5–3 GB footprint; not yet in the games table. Minecraft Dungeons II's profile had the same 64 GB values.
Cuts that only fit an iPhone's alias region
- Symptom: a game whose
patches.pyshrinks its own allocator's virtual address reservation to fit an iPhone's alias region runs short of virtual space on the Mac too: a null allocation and a crash in a later scene, though the Mac's alias region is the Switch's 64 GB and has room for the original layout. - Cause: a static rewriter cut modifies the rewritten module once for every platform, so the Mac executed the iPhone's compact layout even when running with a 64 GB alias region.
- Fix: mark iOS-only address-space cuts in
ALIAS_CUTS(for build-boundCUTS) or withalias_only=Trueon aMATCH_CUTSrule (dm/tools/patch_nso.py,dm/tools/nso_match.py). The rewriter verifies those cut bytes survive later passes and records# ALIAS_CUT <off> <orig> <cut>rows in<module>.fixups.tsv. On the Mac,undo_alias_cuts(dm/host/loader.c) restores the original bytes while text is still writable whenever the run's alias region is at least the Switch's 64 GB (DM_SWITCH_ALIAS), failing closed if the cut bytes do not match. A smallerDM_ALIAS_SIZE(such asheap_checkreproducing an iPhone layout on the Mac) orDM_KEEP_ALIAS_CUTS=1(region_checkmeasuring the iPhone binary's reservations) keeps the cuts; iOS maps signed code as rewritten and always keeps them. - Found on: Xenoblade Chronicles 3 (GitHub issue #3149, PR #3218): Monolith's 60 GB reservation cut to 4 GB with a 512 MB first arena returned null on a 0x217a0-byte allocation (
sig=11 addr=0x8atmain+0x43060) in the first chapter's cutscene on the Mac; restoring the 60 GB layout cleared that scene on M3 Max.
Partitioning the guest block between alias region, stacks and heap
- Symptom: large resources silently skipped, later a null deref where the resource is used; also visible as
SetHeapSizeasking for much less than the pool. - Cause: the game reserves "virtual address memory" (Mario: 1.75 GB in
HeapDef.byml) and maps it into the alias region withMapPhysicalMemoryon demand; the alias region left after the node area (The SDK's address-region node area) was too small. - Fix: repartition the guest block (
hle_svc.cmem_init): Mario uses alias 2.875 GB, stacks 256 MB, heap 1.625 GB (it asks for 1.47 GB), 5 GB in total. - Found on: Super Mario Bros. Wonder.
- Check: measure before sizing (
DM_SVC=1: theSetHeapSizerequest and the highestMapPhysicalMemoryaddress). - Note: on iOS without the extended-virtual-addressing entitlement a single 6 GB reservation succeeds and 7 GB fails, but Metal and the rest of the process need address space too; 5 GB is the total proven on a phone (D2R).
Thread stacks placed at random in the stack region
- Symptom: an
nn::diagabort with Result 0 undernn::os::detail::ThreadManager::CreateThread→ThreadManagerImplByHorizon::MapAliasStack, on some boots and not on others, with noMapMemory refusedline. - Cause:
CreateThreadmoves each stack into the stack region at a random address:StackGuardManager::MapAtRandomAddressasksAddressSpaceAllocatorBase::AllocateSpacefor a place, which tries 512 random addresses and gives up when none has the stack and its guard pages free;MapAliasStackaborts on that. Horizon gives a 39-bit process a 2 GB stack region; the host's is the profile'smem_stack, 256 MB in every profile until then. Super Monkey Ball Banana Rumble's Unity player maps 48 stacks, 106 MB, in its first 30 s, nine of them 8 MB: the positions those stacks rule out for a new 8 MB one add up to more than 256 MB, so some boots found none. A game whose stacks fill a smaller part of the region only fails more rarely. - Fix: the profile's
mem_stacksized for the game's stacks with room to spare: 640 MB for Super Monkey Ball Banana Rumble, taken from its alias region in the same 5 GB block (an iPhone has no room for a larger one). - Found on: Super Monkey Ball Banana Rumble (SDK 17.5.8:
MapAliasStackatsdk+0x13b23c, the abort at+0x13b2b8). - Check:
DM_THR=1 DM_SVC=1: theMapMemory <stack region address> <- … +<size>lines are the stacks; their sum and the largest againstmem_stack(theguest ASline gives the stack region's start).
Heap and application pool
Provisional Unreal layout leaves no heap
- Symptom:
SetHeapSize OOM: req 0x600000 > cap 0, followed by an SDK abort innninitStartupon the first provisional boot. - Cause: the provisional Unreal profile reserved
0x1028000000bytes but assigned0x1008000000to the alias region. The 256 MB module region and 256 MB stacks consumed the remainder, leaving no heap. - Fix: the alias region was set to exactly 64 GB (
0x1000000000), leaving 128 MB for the initial heap. Since GitHub issue #2278 the guesser has no Unreal layout: Unreal games with virtual address memory take the 5 GB block of every such game, whose 4.375 GB alias region leaves the same 128 MB before the heap check measures the game (Provisional Unreal profiles asked an iPhone for 64 GB).test_profile_guess.pychecks the partition through the real profile generator. - Found on: SHIN MEGAMI TENSEI V: Vengeance 1.0.3, whose C library asks for 6 MB.
Heap sized from the application pool less used memory
- Symptom:
nnMainreturns right afternv::InitializeGraphics, with no error (Hyrule Warriors: Age of Calamity);[mem] SetHeapSize … + modules … > app pool(Monster Hunter Rise),[mem] SetHeapSize … + modules 0x5c00000 > app pool(Catherine: Full Body), annn::diagabort innninitStartupafter[mem] SetHeapSize 0xc9400000 + modules 0x4400000 > app pool 0xcd500000(MIO: Memories in Orbit; the host now logs[mem] SetHeapSize … > app pool … less used memory …);SetHeapSizeasks for almost the whole application pool and fails at boot (Metroid Dread: 0xc9400000, larger than the heap region); the memory pool for the game's 96 MB GPU heap has no storage (MemoryPoolInitializered line), then a null read atmain+0x2eb954(Catherine: Full Body); heap allocations fail late in a busy scene. - Cause: the SDK sizes the heap as total − used memory (
QueryMemoryInfo), so the reported application pool and used memory decide the game's heap size. Age of Calamity'snninitStartupdoes so, callsSetMemoryHeapSizeand hands the block to its own malloc. The host reported 64 MB used beside the heap ("used" = heap + 64 MB), butSetHeapSizechecks a request against the real size of the loaded modules (66.6 MB in Age of Calamity), soSetHeapSize(pool − 64 MB)failed with ResultLimitReached,AllocateMemoryBlockreturned 0x1003, malloc was never set up, the 866 MB graphics heap allocation came back null andnnMainreturned. Monster Hunter Rise's modules take 320 MB (mainalone 314 MB), so itsSetHeapSize(pool − 64 MB − bss)failed the same way. Catherine: Full Body's rewritten modules take 92 MB, soSetHeapSize(pool − 64 MB)failed and the game ran on a 32 MB heap; MIO: Memories in Orbit's take 68 MB, and itsnninitStartupaborted. The host answered with two figures:GetInforeportedmem_used,SetHeapSizecharged the rewritten modules' size, patch areas and key pages included, which the Switch never counts. The 64 MB covers ordinary modules (Mario's two are about 74 MB, and its heap request matches hardware), but Metroid Dread'smaincarries a 1.8 GB bss that the Switch counts as used. - Fix: report Switch-accurate numbers. The application pool was a host constant (
APP_POOL, 3285 MB); it is now the profile keyapp_pool(hle_svc.c:#define APP_POOL DM_GAME_APP_POOL, Mario 0xCD500000, the same 3285 MB). The profile keymem_usedsets the used-memory figure: 72 MB for Age of Calamity (the image plus stacks); 328 MB for Monster Hunter Rise, which gives a 2.88 GB heap; 96 MB for Catherine: Full Body, the NSP script's guess after the rewrite. Used memory now also adds the bss of modules in the front-patch layout (big_bss_bytesinhle_svc.c; the layout is in Patch area before the module base for a large bss); Dread then asks for 1.38 GB. The host keeps one figure for the used memory beside the heap (used_beside_heapinhle_svc.c:mem_used, the giant bss and, withmem_map_limit, the pages mapped in the alias region):GetInforeports it andSetHeapSizeandMapPhysicalMemorycharge it, so a request for total − used always fits, as on Horizon (GitHub issue #941).mem_usedonly decides the game's heap size; the profiles' values that came from the rewritten modules' size (the NSP script's guess after the rewrite and its heap check, both removed) give a heap close to hardware's and stay.t_svc_memory.cchecks that a heap of total − used fits beside modules four times the pool. - Found on: Hyrule Warriors: Age of Calamity; Monster Hunter Rise; Metroid Dread; Catherine: Full Body (SDK 8.2.1; one boot); MIO: Memories in Orbit (01000A001E978000, 1.2.0, a provisional profile, no note; GitHub issue #941). The source names no game for the late failures in a busy scene.
- Check: probe
DM_SVC=1'ssvc 0x1request and theAllocateMemoryBlockresult.
Offline NRO copies are not additional guest memory
- Symptom:
SetHeapSize OOM: req 0xffffffffe0000000 > cap 0xd0000000, followed by an abort when allocating the launcher NRO. - Cause:
big_bss_bytescounted the bss of every offline-mapped NRO, including inactive ones, as additional used memory. The game already allocates the original NRO image and bss buffers from its heap. Subtracting the inflated used value from the application pool underflowed the startup heap request. - Fix: exclude NROs from
big_bss_bytes(and fromimage_bytes, whichSetHeapSizecharged then). Ordinary NSO modules' large bss still counts. No application-pool increase or heap clamp is needed. - Found on: FINAL FANTASY X/X-2 HD Remaster; after the fix its startup heap is 3.08 GB.
- Check: the memory SVC tests compare used-memory queries with an ordinary large-bss module and a larger NRO present together.
Module data on the code's 16 KB page
- Symptom:
CRASH sig=10 addr=nro<N>+0x… pc=relocate+…withlr=nro_load+…underh_ro_LoadModule(or inrelocateat startup for an NSO), at the first load of a module whose data starts belowtext_endrounded up to 16 KB;x9points at a RELA entry of type0x403(R_AARCH64_RELATIVE). - Cause: Horizon maps modules at 4 KB, the hosts at 16 KB.
map_image(loader.c) seals[0, text_end rounded up to 16 KB)read + execute, andgen_embed.pyputs the same range in the iOS executable's__TEXT, so any NSO or NRO whose data starts below that boundary has read-only data, and the first relocation into it faults. FINAL FANTASY VIII Remastered's Math.nro is text, ro and data of 4 KB each (data at0x2000); its Platform.nro has data at0x3000. - Fix:
dm/tools/mod_layout.py, run bypatch_nso.pyafternso.load(), moves writable data and bss up by whole 4 KB pages until data starts on a 16 KB page of its own. Read-only data stays at its original address so linker-generated relative references between it and text, including signed jump-table entries, keep working. The rewriter updates the embedded NRO header and adjusts references that cross into or out of writable data inMOD0, dynamic tags, symbol values, RELA / JMPREL / RELR, code references, and unwind metadata.read_layoutinloader.crejects a module whose rewritten data still shares the code's page. - Found on: FINAL FANTASY VIII Remastered (Math.nro and Platform.nro of its 14 NROs).
- Check:
dm/tools/tests/test_mod_layout.pycovers synthetic NRO and NSO images,patch_nso.pyend-to-end,MOD0in text,DT_RELR, inline literal pools,STT_TLS, and.eh_frame/ LSDA edge cases.dm/tools/tests/test_jump_solver.pyverifies that a relaid-out NRO still dispatches to the exact targets encoded in its read-only jump table.
Thread stacks backed by active NRO data
- Symptom: repeated
[RED] MapMemory refused (0xd401)for a stack source inside a loaded NRO's writable data, then an abort inMapAliasStack/CreateThread. - Cause: the host rejected all NRO-backed stack sources because reload can overwrite their backing. The launcher's static allocator legitimately supplies thread stacks from its bss.
- Fix: permit the writable, unsealed range of an active NRO. Deactivation checks outstanding stack borrowers and marks the module inactive under the same memory-map lock used by
MapMemory; reload cannot replace borrowed backing. Unloading with a live borrower is rejected. Loaded-state reads are atomic. - Found on: FINAL FANTASY X/X-2 HD Remaster, launcher
nro815+0x124854, through SDK 5.4's thread creation path. - Check:
make -C dm/host/tests GAME=01007BB017812000 memorychecks active-NRO mapping, refusal to deactivate with a live mapping, successful deactivation after unmap, and rejection of an inactive source under the sanitizers.
A heap request beyond the heap region returns ResultOutOfMemory
- Symptom:
SetHeapSize OOM: req 0x120000000 > cap 0xd0000000, thenBreak#1 reason=0innninitStartup, with a backtrace throughnn::os::SetMemoryHeapSize(sdk+0x967a4). - Cause: a game may look for the largest heap it can have by asking for more than there is. Donkey Kong Country: Tropical Freeze's
nninitStartup(main+0x1e84c) binary-searchesSetMemoryHeapSizebetween 3 and 6 GB (6 GB is the heap region of a 39-bit address space) and narrows on every failure. SDK 4'sSetMemoryHeapSize(sdk+0x9672c) turns the kernel's ResultOutOfMemory (description 104), 103 and ResultLimitReached (132) intoos::ResultOutOfMemory(0x1003) and aborts on any other result. For a size larger than the heap region the host returned 0xD401 (InvalidCurrentMemory, 106), so the SDK aborted. Horizon'sKPageTable::SetHeapSizereturns ResultOutOfMemory there. - Fix: a request larger than the heap region returns 0xD001 (
hle_svc.c, svc 0x1). The search then settles on 3.09 GB, the pool less the rewritten modules (the same LimitReached check as before). - Found on: Donkey Kong Country: Tropical Freeze (SDK 4.4.0).
The heap check grows the block around the profile's alias region
- Symptom: a provisional profile's heap check reports "the heap request did not fit; set mem_reserve", the build finishes, and the game still stops at its first run:
SetHeapSize OOM: req 0x18ce00000 > cap 0xb8000000, thenCRASH sig=10(SIGBUS) innninitStartupon the heap it never got. - Cause: when the block has not even 1 GB left for the alias region beside the requested heap region,
profile_guess.pyheap_signalsgrewmem_reserveto 256 MB + 1 GB + the stack region + the heap region, as if the alias region were 1 GB, but set onlymem_reserve. The heap region is whatmem_reserveleaves after 256 MB,mem_stackandmem_alias(hle_svc.cmem_init; the Mac's larger alias region is added to the block and takes nothing from it), so a guessed alias region above 1 GB came off the heap region: the Switch 2 guess for a game with a system resource, 4.375 GB (0x118000000), left a 6.20 GB request 2.88 GB. - Fix: the grown block keeps the profile's alias region (at least 1 GB, as before):
mem_reserve= 256 MB + max(mem_alias, 1 GB) +mem_stack+ the request rounded up to 128 MB. A profile whose alias region is 1 GB or less gets the same keys as before.test_profile_guess.py(HeapSignals) checks the layout the keys give. Keeping the alias region rather than cutting it to 1 GB changes nothing on the Mac, whose alias region is a Switch's 64 GB either way; it matters to the region check, which measures against the profile's value, and to an iPhone, though a block this size is over its reservation limit in both cases. A provisional profile stamped by the old check keeps its keys and is reused: delete the profile (<build folder>/profile/<title ID>/) so the next run surveys and checks again. Deleting only its# heap check:line solves from the old block instead and gives a 1 GB alias region. - Found on: The Legend of Zelda: Ocarina of Time (Switch 2, 0400486024DEC000, update v131072, SDK 22.2.8), GitHub issue #1361:
mem_reserve 0x1f0000000from the old check,0x2c8000000now (a 6.25 GB heap region beside the 4.375 GB alias region). Open: the boot then stops at the NPLN / gRPCnn::diagabort atsdk+0xb8fe8, reported on pull request #1373; pull request #1299's eventfd change addresses it.
The heap check stopped before the app pool check
- Symptom: a provisional profile's heap check reports "the heap request did not fit; set mem_alias", and every later boot aborts in
nninitStartup(annn::diagabort) after[mem] SetHeapSize 0x… + modules 0x… > app pool 0x…; the NSP script's GLSLC capture then finds no shaders and stops with "captured only 0 run-time shaders". - Cause: the heap check booted once and stopped at the first heap request. A request larger than the heap region (
SetHeapSize OOM) never reaches the app pool check behind it (hle_svc.c, svc 0x1), so the boot that sized the heap region could not show that the heap and the modules overflow the pool, whichheap_signalsanswered withmem_used. - Fix: a boot that set
mem_aliasormem_reserveis followed by another on the resized layout, up toHEAP_CHECK_ROUNDS(3) boots (build_ipa_from_nsp.pyheap_check); the stamp names every boot's result and every key set.test_nsp_incremental.pychecks the two boots and their keys. The pool check no longer refuses a request for total − used (Heap sized from the application pool less used memory), so no boot setsmem_usednow; a later boot still checks the request on the resized layout. - Found on: Pokémon FireRed Version and LeafGreen Version (0100554023408000, 010034D02340E000, SDK 20.5.19, provisional profiles), pull request #1620: a 3.14 GB heap plus 102 MB of modules over the pool; the second boot set
mem_used0x6a00000.
nninitStartup's heap only without virtual address memory
- Not needed in the end for Ace Attorney Investigations Collection (1.0.0.2, SDK 17.5.3): the process heap of pull request #16.
nninitStartupcallsSetMemoryHeapSize/AllocateMemoryBlockonly without virtual address memory, and nothing else inmaincalls them (Virtual address memory follows the NPDM's system resource).
Unreal games without virtual address memory take a heap
- Symptom: the app quits at launch; the host log shows
SetHeapSize OOM: req 0xc5200000 > cap 0. - Cause:
profile_guess.pygave every Unreal game the 64 GB alias region and no heap, after the Unreal 4.26+ games (Unreal's engine address region and its options). An older Unreal game whose NPDM declares no system resource has no virtual address memory, and itsnninitStartupsets a heap of the application pool less used memory instead (Heap sized from the application pool less used memory). - Fix: the guesser's Unreal memory rule applied only with an NPDM system resource; other Unreal games get the usual heap region (3.25 GB here). The rule is gone since GitHub issue #2278 (Provisional Unreal profiles asked an iPhone for 64 GB).
- Found on: Yoshi's Crafted World (Unreal Engine 4.18, SDK 4.4.1): a 3.15 GB heap; GMalloc is a FMallocBinned on it.
Sizing the pool and alias region for virtual address memory
- A title that uses virtual address memory may never call
SetHeapSize: everything comes fromMapPhysicalMemoryin the alias region. The[mem]log lines show what it maps (Measuring address regions and commits). - What fills the alias region first is address space, not memory. StandardAllocator reserves the whole free pool (pool − 64 MB, 1 GB aligned) but Engage commits only 0.58 GB of it, and Unity's own regions commit 0.97 GB. So Engage's profile reports a 2.5 GB pool (
app_pool) and uses a 4.375 GB alias region in a 5 GB block (reserved address space peaks at 3.47 GB of 4.31 GB). - iOS without the extended-virtual-addressing entitlement allows a single 6 GB reservation, but Metal needs address space too; 5 GB is the total proven on a phone (Partitioning the guest block between alias region, stacks and heap).
- The pool a game is told decides how much StandardAllocator requests (
Initialize(nullptr, pool − used)), but games can also read it to choose their graphics quality. Use the host'sstdalloc_capto limit that allocator's address space while keeping the hardware pool (The heap check's 1 GB pool picked a game's low graphics). The following measurements used the earlier reduced-pool approach; those registered profiles have not been changed:- Ace Attorney Investigations Collection: with Engage's 2.5 GB pool the game ran, but StandardAllocator's 2.44 GB reservation beside Unity's pools (1.06 GB live, from
main+0x40f1d4) ended 4.37 GB into the 4.375 GB alias region after 140 s, while theMapPhysicalMemorylog showed StandardAllocator committing 0.19 GB. The profile reports a 1 GB pool, a little less than the 1.02 GB the game maps at its peak; ten minutes then peak at +2.85 GB of address space, against +3.91 GB with a 1.5 GB pool. - Brain Memory Training Academy: with Ace Attorney's 1 GB pool and 5 GB block the game boots to its title in 5 s with no red line; StandardAllocator ends at +1.0 GB, and five minutes of level loads take the alias high-water mark to +2.25 GB with at most 0.5 GB mapped.
- Patrick's Parabox: with Ace Attorney's 1 GB pool and 5 GB block (in place of the provisional profile's hardware pool) it boots to its title with no red line, and the alias region is mapped up to +1.5 GB with 0.27 GB in use.
- Advance Wars 1+2: Re-Boot Camp: the hardware pool used the alias region up to +4.25 GB; the heap check's 1 GB pool starved its malloc (Unity's GPU pool block allocation spins at size 0); with a 2 GB pool the game maps up to 2.26 GB of the alias region through its menus and first battle.
- Ace Attorney Investigations Collection: with Engage's 2.5 GB pool the game ran, but StandardAllocator's 2.44 GB reservation beside Unity's pools (1.06 GB live, from
- Found on: Fire Emblem Engage; Ace Attorney Investigations Collection (Unity 2022.3, SDK 17.5.3); Brain Memory Training Academy; Patrick's Parabox; Advance Wars 1+2: Re-Boot Camp.
- Note: to measure regions and commits, see Measuring address regions and commits.
The heap check's 1 GB pool picked a game's low graphics
- Symptom: a provisional Unity profile renders its 3D blurry: the main camera at 672x378, where a larger pool gives 1920x1080 render targets at the same frame time. The profile has
app_pool 0x40000000and a# heap check:line, and a profile with a larger pool stays blurry with the same save. - Cause: the heap check set a 1 GB pool when a game that sets no heap used its alias region up to within 0.25 GB of the end (Sizing the pool and alias region for virtual address memory), to shrink the address region
nninitStartuphands StandardAllocator (pool − used). The game also reads the pool as the machine's memory: Pokémon Friends takesSystemInfo.systemMemorySize(GetPhysicalMemoryMB), saves its Low graphics quality at 2048 MB or less, and keeps that setting in its save once the pool changes. - Fix: general (
profile_guess.pyheap_signals): the heap check setsstdalloc_cap 0x40000000instead, and the pool stays the hardware's. The host's allocator gate gives StandardAllocator's region the cap (StandardAllocators over 12 to 62 GB of address space), so its region is about the size the 1 GB pool gave it (pool − used), while the game reads the Switch's 3.2 GB; Sonic Superstars plays that way with a 1.5 GB cap set by hand. The NSP script's region check then checks the cap as one set by hand, and does not take it out. The cap is an address-space workaround for the iPhone's platform limit, using the engine's allocator contract through the existing SDK-symbol host gate. The 1 GB stays a starting point: Advance Wars 1+2: Re-Boot Camp needed a 2 GB pool for its malloc (Unity's GPU pool block allocation spins at size 0); its equivalent allocator cap has not been measured. - Existing profiles: deleting only
# heap check:does not restore a pool the earlier check reduced: the script reusesgame.tsv, and the rule leaves a pool of 1 GB or less alone. For an original Switch profile whose heap check setapp_pool 0x40000000, explicitly restoreapp_pool 0xCD500000and, if no cap is already set, addstdalloc_cap 0x40000000. Keep any cap tuned by hand. Then remove both the# heap check:and# address regions:stamps, repack and check scene loading with the profile's alias limit (DM_ALIAS_SIZE=<mem_alias>on the Mac). A save that already stored Low graphics also needs its quality raised in the game's options, or a fresh save for comparison. - Check:
dm/tools/tests/test_profile_guess.py(HeapCheckAddressSpace): a nearly full alias region with no heap setsstdalloc_capand noapp_pool; a heap, no system resource, a profile with a cap or a pool of 1 GB or less, and a region with room set nothing.test_nsp_incremental.py(test_the_heap_checks_stdalloc_cap_survives_the_region_check): the heap check's cap goes into the profile with the hardware pool, and the region check after it keeps it. - Runtime check: TUNIC, Memory: the real heap and region probes, then a paired Mac scene-load run with the hardware pool and allocator cap under the iPhone's alias limit. This checks Unity's allocator interaction; Pokémon Friends' fresh-save quality selection with the cap and an iPhone runtime check remain open.
- Found on: Pokémon Friends (
010008C01E742000, Unity 2022.3; no profile in the repository yet), issue #2830: with a 1 GB pool on the Mac its scene had mostly low-resolution render targets; withapp_pool 0x88000000(2176 MB) 1920x1080 targets and the same frame time, and an iPhone build has run on that pool. LEGO Voyagers has the same call, according to the issue; not checked.
nv::GetGraphicsMemoryInfo with no graphics device
- Symptom:
CRASH sig=11 addr=0 pc=sdk+0x4656c8right after the window is created, withx0 = 0and the return address inmain(main+0x3508a90): the faulting code isldr x0,[0xc5d000+0xc68]; ldr x8,[x0]; ldr x1,[x8,#0x68]; br x1. - Cause: the game reports GPU memory in its startup log, so it calls
nv::GetGraphicsMemoryInfoand thennv::DumpGraphicsMemoryInfo(both imported bymain). The SDK's implementation reads a driver object from its own static (0xc5d000+0xc68) that onlynv::InitializeGraphicssets; a game that never initialises an NVN device — as every EGL/OpenGL game does — leaves it null, and the SDK dereferences it.nv::MemoryInfois 64-bit counters filled from sign-extended 32-bit driver counters, and its size follows the SDK: 0x20 bytes (four counters) on SDK 10 and older, 0x40 bytes from SDK 11 on, where the SDK zeroes all 0x40 when nv is not initialised. Every sdk module checked, from 3.4.0 to 20.5.22, fills four counters; on SDK 3.4.0–10.8.1 the function has no 0x40 path, from 11.4.3 on it has. A host answer of 0x40 bytes on an old SDK overruns the caller's 32-byte record. - Fix:
dm/gfx/hle_nv.canswers thenv::symbols such a game imports that would reach the driver: it records the pool fromInitializeGraphics(void*, size_t), andGetGraphicsMemoryInforeports that pool (total and free = its size) or zeroes the structure when nothing was initialised. It writes the record of the game's SDK: 0x20 bytes whenDM_SDK_OLD(dm_sdk_major()), 0x40 otherwise (the boundary the NVN API version and the shared-font layout follow too); the pool figures lie in the first four counters, so both sizes carry them. The allocator setters (SetGraphicsAllocator,SetGraphicsDevtoolsAllocator) are the SDK's own (Movie extractor allocations need the SDK graphics allocator). - Found on: Well Dweller (SDK 22.2.0, GameMaker Studio 2, OpenGL through EGL). The game's allocator is never called again, so a zeroed report is equally correct on a GL-only title. The 32-byte overrun on old SDKs was found on Hyrule Warriors: Definitive Edition 1.0.1 (SDK 3.5.1, KTGL, NVN; GitHub issue #708, PR #709): its startup caller passes a 32-byte record, and AddressSanitizer reported the write past it.
An SDK 21 Switch 2 game with a 4.5 GB alias region
- Symptom: a null pointer in the game's resource code (
main+0x15a69b0, null + 0x78, threadBaseProcCreateAndDeleteThread): a model's load returned null, its status 9, written hundreds of times by a loader thread. The[mem]lines end near the top of the alias region. - Cause: the alias region ran out. An SDK 21 game keeps the SDK's 1 GB node area, as the sdk patches that cut it do not match this SDK, and maps past 4.25 GB of it at the first level.
- Fix: the profile's
mem_alias: 16 GB (Splatoon Raiders:0x400000000, withmem_reserve 0x550000000). The peak then is about +8.5 GB. - Found on: Splatoon Raiders. Fire Emblem Fortune's Weave (SDK 22.2.0) takes the same split, and its SDK has its node-area cut (
dm/tools/sdk_patches.py), from 1 GB to 62 MB, becausealias_roomaborted inStandardAllocator::Initializewithout one. Open: 16 GB is over iOS's reservation limit, so an IPA needs the SDK 21 node-area and alignment cuts first.
Virtual address memory and the alias region
Virtual address memory follows the NPDM's system resource
- Symptom:
StandardAllocator::Initializeaborts innninitStartup(Fire Emblem Engage);nn::diagabort inStandardAllocator::Initialize(void *, size_t, bool)fromnninitStartup(sdk+0x2f98e4←main+0x5b69e0, Big Brain Academy: Brain vs. Brain). - Cause: the SDK's
IsVirtualAddressMemoryEnabledisGetInfo(TotalSystemResourceSize) != 0(VammManager::IsVirtualAddressMemoryEnabled,sdk+0x34e074), the system resource the NPDM declares (offset 0x14 ofMETA). With it the game's allocator takes its memory as address regions in the alias region. Engage's NPDM declares one, soIsVirtualAddressMemoryEnabledis true and the allocator reserves all free memory (about 3.2 GB for Engage) as one region in the alias region, after the ~1 GB node area (The SDK's address-region node area). Big Brain Academy'snninitStartup(main+0x5b6984) asksos::IsVirtualAddressMemoryEnabled(): when true it gives StandardAllocator a 60 GB address region (0xf00000000), when false it sets a heap of pool − used (2 MB aligned) and hands that over. The host reported a 32 MB system resource to every game, while this game's NPDM declares none. - Fix: the profile key
sys_resourcereports the NPDM's size (0 for Big Brain Academy, so the heap path, as on hardware;hle_svc.c); the survey writes it for every new game, and profiles without it keep the 32 MB answer. A game with virtual address memory needs a profilemem_alias/mem_reservethat holds its regions: Engage first used 5.5 / 8 GB on the Mac; its profile now hasmem_reserve 0x140000000/mem_alias 0x118000000(5 GB / 4.375 GB) with the node area cut and a 2.5 GBapp_pool(Sizing the pool and alias region for virtual address memory). - Found on: Fire Emblem Engage; Big Brain Academy: Brain vs. Brain (SDK 11.4.3, NintendoWare Bezel Engine).
The SDK's address-region node area
- Symptom: the first
AllocateAddressRegionfails with 0x1803;StandardAllocator::Initializeaborts innninitStartup(annn::diagabort; the NSP script's heap check reports "the host stopped before nnMain"); the alias region fills in minutes; regions a game reserves later fail (Size-aligned regions exhaust the alias address space, The movie player's own StandardAllocator). - Cause: SDK 16's AddressRegionManager takes 0x3fe00000 at the start of the alias region as a node area, so the alias region must be larger than 1 GB; SDK 8 has the same 1 GB node area as the newer SDKs, and SDK 7 / 8 builds load it in another form (below). On hardware the alias region is 64 GB. On Ace Attorney Investigations Collection's SDK 17 build,
CentralHeap::Init(nullptr, pool − used)got no 1 GB-aligned region for 3.14 GB after the 1 GB node area. - Fix: shrink the node area with a rewriter cut for that SDK build (
dm/tools/sdk_patches.py): the twomov w8/w9, #0x3fe00000in the AddressRegionManager constructor → 62 MB. - SDK-wide: the same cut is also an SDK-wide function patch (
sdk_patches.pyMATCH_CUTS), which every game'ssdkgets when its build has noCUTS: a new game, or a new version of one, needs no cut of its own on a reviewed implementation. A registered build whose cuts the rules give exactly has no row (19 builds, checked on the game drive on 2026-10-29, 2026-10-30 and 2026-11-09, Hollow Knight: Silksong's the last), nor does one whose game was run with the rules' alignment cuts more (Fire Emblem Engage's, Pokémon Brilliant Diamond's, Ace Attorney Investigations Collection's, Brain Memory Training Academy's and Patrick's Parabox's, 2026-11-09, with the iPhone's alias region); a build a profile was brought up on gets the rules too (before, the rules skipped such builds, which kept those rows). Nine implementations cover the cut builds on the game drives (SDK 7.3.2 / 8.2.1, 10.4.x, 11.4.3 to 13.3.5, 15.3.2 to 18.3.5, 19.3.x / 20.5.x, 22.2.0, and SDK 19.3 / 20.5, 21.4 and 22.2.0 built for the Switch 2); on those 19 each rule gives exactly the registered cuts, and on the 36sdkbuilds there it matched once or not at all. The older VammManager in SDK 3.5.1 and 4.4.0 has two reviewed implementations that each match the constructor and large-region alignment together. These also match equivalent functions in six other SDK builds. The SDKs of Fire Emblem: Three Houses and Bayonetta have other implementations, not reviewed. A build with no reviewed implementation keeps the 1 GB node area; the NSP script lists it (not red: a game without virtual address memory never reaches it) (Function-matched cuts for unregistered builds). - Finding the constructor on a new
sdkbuild: search its text for the twomov w8 / w9, #0x3fe00000words (08fca752,09fca752);sdis.py --fnnames the functionAddressRegionManagerC2Emmfrom its dynamic symbols. SDK 7 / 8 builds load the node area withorr w8 / w9, wzr, #0x3fe00000(e8230b32,e9230b32), so themovsearch finds nothing there. - Found on (the builds that take the cut):
- Mario + Rabbids Kingdom Battle (SDK 4.4.0): the older
VammManagerconstructor reserves a full 1 GB rather than 0x3fe00000; its limit and occupied length atsdk+0x93dfc/+0x93e8care reduced together to 64 MB. Nodes are mapped in 4 KB increments as needed. - South Park: The Fractured But Whole (SDK 3.5.1): the same 64 MB limit and occupied length at
sdk+0x8cc60/+0x8ccf4, with the alignment cut at+0x8ce48. The SDK-wide rule matches the constructor and placement functions together for each of these two SDK implementations. - Xenoblade Chronicles 3 (SDK 12.3.9): constructor
sdk+0x346420, cuts+0x346430/+0x3464cc, the same offsets as Engage's SDK 12.3.7, beside the large-region alignment cut. The game's own allocator needs a separate compact layout. - Pokémon Brilliant Diamond (Unity 2019.4.27f1, SDK 11.4.3): constructor
sdk+0x34e0b8, node-area limit+0x34e0c8and occupied length+0x34e164. The original node area prevents StandardAllocator's pool-minus-used reservation from fitting at startup. - Yoshi and the Mysterious Book (Unreal Engine 5.4, SDK 20.5.15 for the Switch 2, the
sdkof Hyrule Warriors: Age of Imprisonment): constructorsdk+0x14df00, cuts+0x14df18/+0x14dfa4. The same function in Mario Kart World's and Donkey Kong Bananza'ssdk. Unreal's engine region counts on the 62 MB: with 1 GBnninitStartupcallsexit(1), agame called nn::diag abortunderabortfromexit. - Orbitals (Unreal Engine 5.6.1, SDK 21.4.2 for the Switch 2): constructor
sdk+0x16db70, cuts+0x16db88/+0x16dc14, the 20.5 build's instructions in another order with an abort code per failing result. No rule matched this build, so Unreal's engine region started at alias +1.00 GB, after the full node area, and did not fit Engage's 5 GB block. The same function, at the same offset, in thesdkof Sonic Frontiers Definitive Edition (21.4.1), Resident Evil 4 (21.4.3) and Splatoon Raiders (21.4.4); region placement aligns to 64 KB or 2 MB only (sdk+0x16dd14). - Fire Emblem Engage: the two
mov w8/w9, #0x3fe00000in the constructor → 62 MB; without it the alias region ran out of address space minutes into play (Size-aligned regions exhaust the alias address space). - Ace Attorney Investigations Collection (Unity 2022.3, SDK 17.5.3):
StandardAllocator::Initializeaborts innninitStartupon SDK 17, then the alias region fills in minutes; the same node area as Engage's SDK; the constructor is atsdk+0x139458on that build and takes the same cut. - Brain Memory Training Academy (Unity 2022.3.5f1, SDK 16.2.4):
nn::diagabort atsdk+0x126490,StandardAllocator::Initialize, called fromnninitStartupatmain+0x73adcc. ItsnninitStartupis Ace Attorney's:Initialize(nullptr, pool − used)with virtual address memory and noSetMemoryHeapSize. Thesdkbuild is Unicorn Overlord's, whose NPDM declares no system resource, so it never needed the cut; the constructor (AddressRegionManagerC2,sdk+0x134768) takes it at+0x134778/+0x13480c. - Sea of Stars (Unity 2021.3.25f1, SDK 16.2.0, the
sdkbuild of Super Mario Bros. Wonder 1.0.0):nn::diagabort atsdk+0x126440,StandardAllocator::Initialize, called fromnninitStartupatmain+0x8b6710; the heap check reports "the host stopped before nnMain". Brain Memory Training Academy's constructor atsdk+0x134718takes the cut at+0x134728/+0x1347bc, beside the region alignment cut. - Patrick's Parabox (Unity 2020.3.30f1, SDK 13.3.7):
StandardAllocator::Initializeatsdk+0x324dec, called fromnninitStartupatmain+0x1cd080; the samenninitStartupand the same cut, on this build's constructor (sdk+0x37c3a0:+0x37c3b0/+0x37c44c). - Advance Wars 1+2: Re-Boot Camp (Unity 2020.2.1f3, SDK 10.4.1):
StandardAllocator::Initializeatsdk+0x2edf90, called fromnninitStartupatmain+0x365310; the heap check reports "the host stopped before nnMain"; the samenninitStartup. Thesdkbuild is The Great Ace Attorney Chronicles', which has no virtual address memory; its constructor (sdk+0x340e90) has theorrform (e8230b32at+0x340ea0,e9230b32at+0x340f3c). - Pikmin 4 (SDK 10.4.8): the build's AddressRegionManager is the 10.4.1 build's at the same offsets and takes the same three cuts (node area and alignment).
- Super Smash Bros. Ultimate (SDK 8.2.1): constructor
sdk+0x336b40,orr w9, wzr, #0x3fe00000at+0x336b50/+0x336bf0(A 62 GB page allocator behindnu::VirtualAllocHook). - DRAGON QUEST XI S (SDK 7.3.2): the node area cut on that SDK build (
sdk_patches.py). - Paper Mario: The Thousand-Year Door (SDK 15.3.2, Celeste's
sdkbuild, which has no virtual address memory): constructorsdk+0x12e0e0:+0x12e0f0/+0x12e184. - Super Mario Galaxy 2 (SDK 18.3.5):
sdk+0x13be4c/+0x13bee0(The movie player's own StandardAllocator). - Absolum (SDK 18.3.2): the node-area cut beside the alignment cut.
- Octopath Traveler 0 (SDK 19): SDK 19's AddressRegionManager node area is cut to 62 MB as Engage's (
sdk+0x1423fc/+0x142468). - Pokémon Legends: Z-A (SDK 19.3.11): the same constructor offsets,
sdk+0x1423fcand+0x142468, beside the host's StandardAllocator cap (StandardAllocators over 12 to 62 GB of address space). - FINAL FANTASY RESONANCE (SDK 20.5.17): the
sdkis STEINS;GATE RE:BOOT's build; its node area takes the same cut (sdk+0x145cbc/+0x145d28). - Hollow Knight: Silksong (SDK 20.5.8):
sdk+0x145bfc/+0x145c68(Unity 6 takes its memory with no StandardAllocator and no heap). - The Legend of Zelda: Tears of the Kingdom (SDK 20.5.22, the same
sdkbuild as Breath of the Wild 1.9.0): constructorsdk+0x145cfc,+0x145d0c/+0x145d78; no alignment cut (VammManager::AllocateAddressRegion,sdk+0x145df0, aligns regions to 64 KB or 2 MB only). Its resource heaps live in address regions after the node area: at the first descent from the Great Sky Island the alias region's high-water mark was +2.25 GB of its 2.375 GB with 1.00 GB mapped, and the game took a memory shortage (its frame check atmain+0x1fd32eclogsMSF/R/Rfand plays the memory-shortage Blood Moon, which puts Link back at the start; GitHub issue #70, 7 of 8 Mac runs from the issue's save). With an 8 GB alias region the mark went on to +2.50 GB; with the cut it stays at +1.75 GB, and neither showed the shortage. - BALL x PIT (SDK 20.5.19):
sdk+0x145d0c/+0x145d78, the SDK 20.5.22 build's offsets. - EA SPORTS FC 27 (Frostbite, SDK 22.2.0,
sdkfed212d6…, also Well Dweller's): constructorsdk+0x14def0,+0x14df00/+0x14df6c. SDK 22's constructor is SDK 19 / 20's instruction for instruction, with 32 more bytes on its cold path (an abort code per failing result), so it is the SDK-wide rule's sixth implementation; region placement aligns to 64 KB or 2 MB only (sdk+0x14e060). Frostbite'sVirtualAlloc(main+0x17f9884) reserves 264 regions, 2.8 GB of address space, in its first minute while mapping 0.7 GB; behind the 1 GB node area they ran past the alias region (Couldn't reserve memory of size: 536870912, a deliberate null store atmain+0x17f98c4). - Cult of the Lamb (Unity 2022.3.62f3, SDK 19.3.14,
sdk871fb219…):sdk+0x1423fc/+0x142468, Octopath Traveler 0's offsets. The SDK-wide rule cut it while the profile was provisional and skipped it once the profile named the build (the rewrite had no cut), so the cuts are registered for this build; region placement aligns to 64 KB or 2 MB only (sdk+0x142544). It also needs a 1 GB pool, as Ace Attorney Investigations Collection and Monster Train 2. - Batman: Arkham Knight (SDK 14.3.0,
sdk2aef2cff…): constructorsdk+0x12d8a0,+0x12d8b0/+0x12d94c, registered as Cult of the Lamb's was until 2026-10-30; the SDK-wide rules now give it the node area cut and the 2 MB alignment (placement constantssdk+0x12daa4/+0x12daac/+0x12dab0).
- Mario + Rabbids Kingdom Battle (SDK 4.4.0): the older
Size-aligned regions exhaust the alias address space
- Symptom: a null-based write minutes into play, at the pool size minus 0x20 (Engage: a write to
NULL + 0x1fffe0,addr=0x1fffe0atmain+0x9a4664); NULL index pointers written on several job threads at once (main+0xdb0ad4,0xdaea58,0xdadb5c), with 32-bit mesh indices turning up inside texture objects. - Cause: the alias region ran out of address space, not memory (the SDK's node area took about 1 GB of it), so new address regions came back empty. Unity's TLSF heap allocator (
main+0x9a45d0) added a pool (a new 2 MB pool), and its low-level virtual allocator (vtable atmain+0x61ffeb0; reservemain+0x9aa0f4→nn::os::AllocateAddressRegion) got no address region and returned 0. Buffers mapped fresh past 2 MB got no mapping: Unity's particle geometry scheduler (main+0xd91e0c) takes its vertex and index chunks from a fallback that creates and maps a fresh buffer each time (main+0x7b9c64; Unity's Switch renderer always takes it, as on hardware). The AddressRegionManager aligns each region by its size (64 KB under 2 MB, 2 MB under 4 MB, 4 MB under 32 MB, 32 MB under 1 GB, else 1 GB) and Unity asks for its block plus alignment slack, so a 2.25 MB block takes a 4 MB slot and a 16.25 MB block a 20 MB one. At the crash Engage held 4.17 of the 4.375 GB left after the node area (StandardAllocator 3.14 GB, Unity about 1.05 GB, the rest fragments). On hardware the alias region is 64 GB. - Fix: shrink the node area with a rewriter cut for the game's SDK build (
dm/tools/sdk_patches.py, Engage: the twomov w8/w9, #0x3fe00000in the constructor → 62 MB; The SDK's address-region node area). - Found on: Fire Emblem Engage: the prologue battle crash (scripted run, about 357 s; a 12-minute scripted run now plays through the battle) and the idle attract demo crash after about 220 s (from about 180 s 32-bit mesh indices also turned up inside Unity's texture objects). With the cut an 850 s idle run is clean, with no corrupted texture objects; with the old SDK the same run dies at 159 s in Unity's heap allocator.
- Check: probe the SDK's
VammManager::AllocateAddressRegionat its success path andFreeAddressRegionafter its prologue, and sum the live regions by caller (Measuring address regions and commits). - Note: to reproduce the old state:
boot.sh <log> 245with no input on an SDK rewritten without the cut.
1 GB alignment of regions of 1 GB and more
- Symptom: a cut engine region still does not fit; two large regions lose up to 1 GB each to alignment, depending on where
mmapput the guest block (Absolum); the region comes 0.69 GB past the 1 GB node area, at the next 1 GB boundary (Paper Mario: The Thousand-Year Door). - Cause:
AllocateAddressRegionaligns a region of 1 GB or more to 1 GB in absolute address (SDK 18:sdk+0x13c03c; 32 MB from 32 MB up). SDK 19.3.14 and SDK 20 align to 64 KB or 2 MB only. - Fix: an SDK-wide function patch beside the node area's (above) gives the three classes from 4 MB up SDK 20's 2 MB, what SDK 19.3.14 and SDK 20 do themselves, which also closes the gaps of Size-class alignment doubles Unity's regions: four implementations (SDK 7.3.2 to 10.4.8, 11.4.0, 12.3.9 to 15.3.2, 16.2.0 / 18.3.2), with the 32 MB, 1 GB and 4 MB constants at
+0x64,+0x6cand+0x70in each. Until 2026-10-30 it aligned only the 1 GB class, to 32 MB (what the SDK gives from 32 MB up), and two builds' rows gave every large class 2 MB; one rule now covers both, and the rows were removed. The older VammManager implementations in SDK 3.5.1 and 4.4.0 use a separate SDK-wide rule that aligns their largest regions to 32 MB and shrinks the node area to 64 MB in the same patch. - Found on:
- Pokémon Scarlet (1.0.0, SDK 13.3.5).
- Pokémon Legends: Arceus (1.1.1, SDK 11.4.0,
sdkb39add63…, Kirby and the Forgotten Land's build):StandardAllocator::Initialize(nullptr, 32 GB), capped to 4.06 GB by the host, is placed at the next 1 GB boundary after the 62 MB node area and runs past the 4.38 GB alias region (Breakatsdk+0x39fb54innninitStartup). The placement helper (sdk+0x34e1d8, 360 bytes: the 12.3.9 implementation's size classes with 8 more bytes) takes the cuts at+0x64,+0x6cand+0x70; the SDK-wide rules serve this build (its row, the same cuts, was removed); on the 41sdkbuilds on the game drive it matches only this one and the SDK 11.4.3 build of Metroid Dread and Brilliant Diamond besides (which keeps its registered cuts). - Mario + Rabbids Kingdom Battle (SDK 4.4.0): large-region alignment at
sdk+0x93fe0, beside its older VammManager node-area cut. - Absolum (SDK 18.3.2:
sdk+0x13c03c): the two large regions, with a 4 KB one between them, lost up to 1 GB each. - DRAGON QUEST XI S (SDK 7.3.2): 32 MB alignment for large regions on that SDK build.
- Advance Wars 1+2: Re-Boot Camp (SDK 10.4.1):
AllocateAddressRegion(sdk+0x341030) aligns a region of 1 GB or more to 1 GB (+0x34109c), as DRAGON QUEST XI S's SDK 7.3.2 build, and takes the same 32 MB cut. - Super Smash Bros. Ultimate (SDK 8.2.1): alignment at
sdk+0x336d5c, cut as DRAGON QUEST XI S's SDK 7.3.2 build. - Paper Mario: The Thousand-Year Door (SDK 15.3.2, Celeste's
sdkbuild):AllocateAddressRegion's alignment atsdk+0x12e2e0, as Absolum's did. - Pikmin 4 (SDK 10.4.8): the 10.4.1 build's offsets.
- Xenoblade Chronicles 3 (SDK 12.3.9): large-region alignment at
sdk+0x34662c, 1 GB to 32 MB; its compact 4 GB allocator reservation then fits after the 62 MB node area. - OCTOPATH TRAVELER II (SDK 12.3.2,
sdk5bcf525f…): the 2 GB engine region came at alias +0.75 GB behind the 62 MB node area; with the rules (constants atsdk+0x346384/+0x34638c/+0x346390) it starts at +0.06 GB, and the alias region's high-water mark on the smoke route fell from +1.75 GB to +1.00 GB (2026-10-30).
- Note: FINAL FANTASY RESONANCE's SDK 20.5.17 build aligns regions of 2 MB and more to 2 MB only (
VammManager::AllocateAddressRegion,sdk+0x145e00), so it needs no alignment cut.
Size-class alignment doubles Unity's regions
- Symptom: a write at NULL + 0x3fffe0 (a 4 MB pool − 0x20) at
main+0x48b770, about six minutes into the prologue, with Unity'sALLOC_CACHEOBJECTS_THREADallocator in x19; the[mem]high-water mark at +4.26 GB of the 4.375 GB alias region while 1.26 GB is mapped (Sea of Stars). - Cause: before SDK 20,
VammManager::AllocateAddressRegionaligns a region by its size (64 KB under 2 MB, 2 MB under 4 MB, 4 MB under 32 MB, 32 MB under 1 GB, else 1 GB) and starts the next one at that alignment past a 4 KB guard. Unity 2021.3's virtual allocator (main+0x48deb0→main+0x12e12c0) asks for N MB + 252 KB and aligns its blocks to 256 KB itself, so every region spills just past a size class: a 16.25 MB region takes a 20 MB slot, a 4.25 MB one an 8 MB slot, a 32.5 MB one 64 MB. Measured with probes on the success path (sdk+0x134868: x21 size, x22 address) and onFreeAddressRegion(sdk+0x1350cc: x1 address): 94 regions of 16.25 MB, 35 of 4.25 MB and 15 of 2.25 MB among 167 live regions holding 2.59 GB, with 0.86 GB of gaps between them, ending at +4.22 GB. On a Switch the alias region is 64 GB. - Fix: the 4 MB, 32 MB and 1 GB classes take SDK 20's 2 MB: first a cut on each
sdkbuild, now the SDK-wide alignment rule (1 GB alignment of regions of 1 GB and more), which gives both builds below the same cuts. The same route then ends its live regions (2.59 GB) at +3.24 GB with 0.58 GB of gaps, and the high-water mark stays at +3.0 GB over 20 minutes. - Found on: Subnautica: Below Zero (Unity 2019.4.36f1, SDK 13.3.5, the
sdkbuild of AI: THE SOMNIUM FILES - nirvanA Initiative and Pokémon Scarlet 1.0.0:sdk+0x37c334,+0x37c33c,+0x37c340; 336 live regions ended at +4.37 GB with 0.87 GB of gaps at the opening's crash site, before any crash; the cut alone took the end to +4.29 GB, and the game also needed its 1 GB bucket allocator reservation cut to reach +3.50 GB). Sea of Stars (SDK 16.2.0:sdk+0x134914,+0x13491c,+0x134920), beside the node-area cut and a 1.5 GB pool.
Unity 6 takes its memory with no StandardAllocator and no heap
- Symptom: nothing aborts at startup as with Unity 2022.3, but the provisional profile gave a 1 GB block and a 256 MB alias region while Unity maps 1.5 GB in the first room.
- Cause:
nninitStartup(main+0x118cb70) only callsQueryMemoryInfoandSetMemoryAllocatorForThreadLocal; Unity's own allocator reserves address regions withnn::os::AllocateAddressRegionand commits pages withAllocateMemoryPages.mainimports noSetMemoryHeapSize, and the provisional profile took that for a game living in its bss. - Fix:
profile_guess.pynow gives every game with an NPDM system resource the 5 GB block (Absolum and Pokémon Legends: Z-A, heapless too, came out right with it). The node area still sits at the start of the alias region: without the cut the high-water mark was +1.00 GB atnninitStartupand +3.00 GB in the first room, with it (sdk+0x145bfc/+0x145c68) +2.26 GB. - Found on: Hollow Knight: Silksong (Unity 6000.0.50f1, SDK 20.5.8); BALL x PIT (Unity 6000.0.62f1, SDK 20.5.19) is the same: the provisional profile was right as generated, and its
sdkbuild only needed the same cut (sdk+0x145d0c/+0x145d78, the SDK 20.5.22 build's offsets): +2.00 GB in the base. Also Absolum and Pokémon Legends: Z-A (the 5 GB rule).
The movie player's own StandardAllocator
- Symptom:
nn::diagabort fromStandardAllocator::Initializelong afternninitStartup, right after the first Vulkan query pool (sdk+0x12dad0←main+0x62c52c). - Cause: the movie player initializes its own allocator with virtual address memory,
Initialize(nullptr, 384 MB)(main+0x62c280); Super Mario Galaxy, on the same SDK, allocates that block from its main allocator first. The guessed 256 MB alias region holds no region after the 1 GB node area. - Fix: the same node area cut for that
sdkbuild (sdk+0x13be4c/+0x13bee0) and a 512 MB alias region: the region is 32 MB aligned, so it starts 64 MB in. - Found on: Super Mario Galaxy 2 (SDK 18.3.5); compare Super Mario Galaxy.
Measuring address regions and commits
- What a game really needs: boot it on the Mac, whose alias region is a Switch's 64 GB, so whatever it reserves fits;
DM_ALIAS_SIZE=<profile's mem_alias>shows what an iPhone's would do (the heap and stacks stay as the profile has them either way). Absolum, Super Smash Bros. Ultimate and Paper Mario: The Thousand-Year Door were sized this way, then withmem_reserve/mem_aliaskeys. - Regions: the rewriter puts three observation gates in every
sdkthat exportsVammManager::AllocateAddressRegionandFreeAddressRegion(patch_nso.py"Address regions"): the entry (the size in x2, the caller's frames), the one store of the new address through the out pointer (mov xB, x1in the prologue,str xA, [xB]; A rides in the gate number), andFreeAddressRegion's entry (x1). They are found by those symbols, so they hold for any SDK build that has them (all 35 of the 36sdkbuilds on the game drives that have a symbol table; New Super Mario Bros. U Deluxe's is a 32-bit module, whose table this does not read). The host keeps the table (hle_svc.c"Address regions", growing as needed): where the request returns to in the game (the first return address outside thesdkon the frame chain: the function that asked, or its caller when it tail-called the SDK API, whose frame is gone by then; Z-A's size is set in a function that tail-callsStandardAllocator::Initialize, so its request returns tonninitStartup) and the SDK API it came through. A region of 256 MB or more is logged when made ([mem] address region 4.00 GB at alias +0.06 GB, returning to main+0x37c9a64);DM_REGIONS=<file>writes the live table every 2 s with each region's mapped bytes and the part ever opened. - The NSP script's region check: for a provisional or derived profile whose game has virtual address memory, it boots the game that way for 15 s into
nnMainand reports each region of 256 MB or more and where the regions reach against the profile's alias region. A derived build (a version the profile was not brought up on) has none of the registered builds' fixed-address cuts, only the function-matched ones, so a region those cuts shrank is red here at pack time rather than an abort on the iPhone (Super Smash Bros. Ultimate 13.0.1, GitHub issue #375). That reach is a lower bound: regions the game takes later in play (Tears of the Kingdom's at the first descent, Engage's minutes in) are not in the table (profile_guess.py region_findings; stamped# address regions:in the profile with the rewrite's key, so a run with other rewritten modules, a new cut for instance, checks again). A red line when they reach past it, which says who lays the region out: one that comes throughnn::mem::StandardAllocator::Initializethe host makes fit at run time (StandardAllocators over 12 to 62 GB of address space), and when the regions made after it need more than the 256 MB the host leaves them, the check setsstdalloc_capin the provisional or derived profile: the alias region less the regions before it, those after it and the same 256 MB for regions made later in play, in 32 MB steps (profile_guess.py stdalloc_room; a red line only when that leaves it no room, or when a value set by hand leaves them too little; one the check set is worked out again by a later check); one the game takes withnn::os::AllocateAddressRegionfor its own allocator works smaller only if that allocator places nothing by fixed offsets (Super Smash Bros. Ultimate: A 62 GB page allocator behindnu::VirtualAllocHook). Where a region is used does not tell them apart: Z-A's StandardAllocator puts its 3.15 GB startup block at the top of its region, Smash's engine its node pool. Measured: Smash's region 4 GB throughnn::os::AllocateAddressRegion, returning tomain+0x37c9a64, opened up to 14 MB below its end; Z-A's 4 GB throughnn::mem::StandardAllocator::Initialize, returning tomain+0x1b2e690, opened to its end (both with their cuts). - Commits: probe
VammManager::AllocateMemoryPages/FreeMemoryPages(x1 address, x2 size) and split them by region. On DRAGON QUEST VII Reimagined,nn::os::AllocateMemoryPageswas probed past itsadrp(sdk+0x140f84). - Windows:
DM_ALIAS_WINDOWS=<window MB>(for exampleDM_ALIAS_WINDOWS=512) logs, every 30 s, the mapped memory of each window of that size in the alias region (hle_svc.c); it measured Octopath Traveler 0's allocator pools and Super Smash Bros. Ultimate's battle commits. - Log: the
[mem]lines report the alias high-water mark (one line per 256 MB), the total actually mapped (page bitmap) and every heap growth.
An alias high-water mark near the top is not exhaustion
- Symptom: the
[mem]high-water mark climbs close to the end of the alias region while far less is mapped (SUPER ROBOT WARS Y: +4.27 GB of 4.38 GB with 1.82 GB of live regions), and it looks like the address space is about to run out. - Cause: none to fix: this is how
VammManager::AllocateAddressRegionplaces regions. It walks its tree from the highest region down, takes the first hole that fits and places the region at that hole's low end (read on SDK 18.3.5,sdk+0x13bfd0; other implementations not read). So while the top has room, every new region lands just past the highest one and freed holes below stay idle, and the mark rises with address churn, not with use. Only when no hole fits does the function return its failure (w0 = 2atsdk+0x13c11c). - Fix: none. To judge the room left, read the live regions and their holes in the
DM_REGIONStable, not the mark, or run with a smaller alias region (DM_ALIAS_SIZE): if the game goes on with the end of the table pinned at the top, the holes are serving it. A real exhaustion is what Size-aligned regions exhaust the alias address space and Size-class alignment doubles Unity's regions describe: a request no hole fits. - Found on: SUPER ROBOT WARS Y: every one of 228 regions placed above the top skipped a hole that would have held it, and with the alias region cut to 3 GB the end stayed at +2.99 GB for about 10 minutes of battle demos with no failure.
Engine allocators
StandardAllocators over 12 to 62 GB of address space
- Symptom:
StandardAllocator::Initializeaborts innninitStartup(Pokémon Legends: Z-A:main+0x1b2e690);nn::diagabort atsdk+0x11ff34(StandardAllocator::Initialize) innninitStartup, SDK 15.3.2, called frommain+0x31370c(Paper Mario: The Thousand-Year Door). - Cause: with virtual address memory the game initializes a StandardAllocator over more address space than a phone gives a process, as the Switch's 64 GB alias region allows.
- Pokémon Legends: Z-A (a 16 MB system resource) initializes its allocator over 12 GB,
StandardAllocator::Initialize(nullptr, 0x300000000)(main+0x1b3e3ec). The alias region must hold the SDK's 1 GB node area and that region, 13 GB. - Paper Mario: The Thousand-Year Door's malloc is a StandardAllocator over 62 GB of address space (
Initialize(nullptr, 0xf80000000, false),main+0x3136e8), out of which it cuts 256 MB, 16 MB and 1 MB allocators. Booted once with a 64 GB alias region, the region came 0.69 GB past the 1 GB node area, at the next 1 GB boundary: thissdkbuild (Celeste's, which has no virtual address memory) aligns regions of 1 GB and more to 1 GB, as Absolum's did (1 GB alignment of regions of 1 GB and more).
- Pokémon Legends: Z-A (a 16 MB system resource) initializes its allocator over 12 GB,
- Fix: the node-area cut on the
sdkbuild (The SDK's address-region node area), where that build aligns large regions to 1 GB the alignment cut, and less address space for the allocator, as below. SDK 19's AddressRegionManager puts the region right after the node area (+0x3fe2c000 before the cut), not 1 GB aligned as Engage's SDK did, so Z-A's 4.25 GB alias region (mem_alias 0x110000000) holds both; Paper Mario'ssdk(Absolum's cuts on Celeste's build) puts its region at alias +62 MB to +4.06 GB in Engage's 5 GB block. The allocator's size was first a cut on each game'smain(to 4 GB; Absolum's to 2.5 GB); the host's cap replaced those cuts. - The host gives the request what the alias region has room for, in every game and build. The rewriter places a gate at the entry of both
nn::mem::StandardAllocator::Initializeoverloads, found by symbol in everysdkthat has them (patch_nso.py"Address regions"). With a null address (virtual address memory) and a size the alias region has no room for, the host lowers the size in x2 before the SDK sees it (hle_svc.c"StandardAllocator's address space"): to the alias region less the regions already made (at least the 62 MB node area) and 256 MB for the regions made after it, in 32 MB steps. The SDK lays the region and itsCentralHeapout from that size, so it holds all the way down, and the pool, not the region, bounds what the heap maps. The profile keystdalloc_capsets the size instead, where the regions made after it need more room (Absolum's garbage collector); the NSP script's address region check sets it in a provisional or derived profile (Measuring address regions and commits): a provisional pack of Absolum 1.1.1 with itsgame_envset0xa2000000(2.53 GB), between the 2.5 GB and 2.72 GB that both play its route (withoutgame_envits GC's region is 3.75 GB and the check reports no room). A request that fits is never changed, so a Switch-sized alias region (DM_ALIAS_SIZE) sees the game's own size. It is a workaround for the iPhone's address space, as the cuts are; a region the game's own allocator takes withnn::os::AllocateAddressRegionis not touched, since its layout may be fixed (A 62 GB page allocator behindnu::VirtualAllocHook). Checked withmainrewritten without its cut: Pokémon Legends: Z-A 2.0.2 (12 GB → 3.94 GB, frame 2,571 in 90 s headless; without the gate it aborts atsdk+0x134214as before the cut; with a 64 GB alias region the request stays 12 GB), Paper Mario: The Thousand-Year Door 1.0.1 (62 GB → 4.06 GB, frame 1,800 in 75 s), Absolum 1.1.1 (40 GB: the default 4.06 GB leaves its GC's 1.5 GB region no room and the SDK aborts atsdk+0x13a684; withstdalloc_cap 0xa0000000, 2.5 GB, frame 3,900 in 75 s; the region check computes 2.72 GB). Pokémon Scarlet was not checked (no game files). Then themaincuts of Z-A, Paper Mario and Absolum (and Z-A's matched rule) were removed: each game's route from a fresh save into play, headless, with and without the cut on the same build (Z-A 380 s into Lumiose City, Paper Mario 480 s into Rogueport, Absolum 320 s into the first level, fighting), reached the same frames with the same[RED]kinds and alias region use, and screenshots of the same scenes. Z-A's cut of 4 GB had already been lowered to 3.94 GB by the cap. Pokémon Scarlet keeps its cut (no game files to check it on). - Found on: Pokémon Legends: Z-A (2.0.2, SDK 19.3.11; one boot); Paper Mario: The Thousand-Year Door: the allocator maps 1.5 GB at boot and 2.0 GB by the arrival in Rogueport. The
sdkbuild is Celeste's. Absolum's malloc StandardAllocator (40 GB, 2.5 GB with itsstdalloc_cap) is in .NET NativeAOT malloc and the GC region range. Sonic Superstars (Unity 2021.3, SDK 16.2.0): a request that fits, 3.12 GB of the pool, capped to 1.5 GB bystdalloc_capbecause Unity's own regions, taken after the region check's 15 s, need the room. - Also found on: Pokémon Scarlet (1.0.0, SDK 13.3.5): its
maincut was removed for the cap (2026-10-30, 4.06 GB on its 4.375 GB alias region). - Note: on Pokémon Legends: Z-A,
QueryMemoryInforeporting more than 4 GB would take the game's big-memory path (heaps of allocatable − 4.27 GB instead of − 2.76 GB).
Bezel Engine's two memory setups
- Symptom: a SIGSEGV writing just past a null base as a menu or board loads (
nn::bezel::CoreSystem::Allocatereturned null for a 46 MB request atmain+0x8d9a48, Super Mario Party Jamboree 2.3.0), sometimes first[RED] fs ReadFile into 0x0+0x400000 failed at +0 (EFAULT), a read into a null buffer from the same allocator; the alias region's[mem]lines showStandardAllocator::Initialize(nullptr, 56.00 GB) … 2.06 GB of address space. - Cause: Bezel's
nninitStartupchooses between two setups byos::IsVirtualAddressMemoryEnabled(). With virtual address memory, malloc's StandardAllocator gets a 2 GB address region and Bezel's own a 56 GB one (Big Brain Academy: 60 GB); without, it sets a heap of pool − used memory, gives malloc 32 MB of it and Bezel the rest. In the 4.375 GB alias region of the 5 GB block, the host's allocator gate leaves Bezel 2.06 GB beside malloc's 2 GB, and Bezel runs out: measured with a 64 GB alias region (DM_ALIAS_SIZE), malloc's region held 5 MB and Bezel's 2.3 GB at Jamboree's Party Plaza. Holding both needs about 5.2 GB of alias region, more than a phone without extended addressing leaves beside Metal. - Fix: profile data:
sys_resource 0, so the game takes its heap path, with the 4 GB layout and the Switch's 3285 MB pool (app_pool 0xCD500000): a 3.14 GB heap, all but 32 MB of it Bezel's, as much memory as the Switch's pool gives it. The NPDM's 16 MB of system resource are not reported, so this is a choice between the game's own two setups, made for the phone's address space, not a fix of the virtual-memory path. - Found on: Super Mario Party Jamboree (Bezel Engine 2.9, SDK 17.5.9); Big Brain Academy: Brain vs. Brain has the same
nninitStartupand declares no system resource, so it always took the heap path.
Unity 2019's bucket allocator reserves 1 GB at once
- Symptom: a Unity 2019 game's alias region fills during its opening on an iPhone's address space:
DM_REGIONSshows a region of 1 GB + 4 MB made at boot, of which the game commits a few dozen MB. - Cause: Unity's memory manager setup constructs the
ALLOC_BUCKETBucketAllocator with its name inx1, the granularity inw2(16), the bucket count inw3, the block size inw4(4 MB) and the most blocks inw5, and its constructor reserves (blocks + 1) × block size of address space at once. Unity 2019 passes 255 blocks, 1 GB, and reads nomemorysetupoption for it;AddMoreBucketsreturns false at the limit and the allocation goes to Unity's other allocators, so the limit sizes only the reservation. On a Switch the alias region is 64 GB, on an iPhone 4.375 GB. Unity 2020.3 passes 1 block; 2021 and later take the sizes from the player's settings (boot.config, one block by default). - Fix:
dm/tools/unity_bucket.py, called bypatch_nso.pyfor anymain, finds the one reference to the nameALLOC_BUCKETand, before the constructor'sbl, the block size and limit as plainmovs, without a build ID; when the reservation is over 256 MB it cuts the limit to what 256 MB holds (63 blocks of 4 MB), a platform-limit cut. The name referenced more than once, or a branch before the call, is a red line and no cut; sizes passed in registers (Unity 2021 and later) or a small limit are a plain line. - Found on: Subnautica: Below Zero (Unity 2019.4, 1.23.55063: with a test limit of 2 blocks the opening loaded and played) and Subnautica (1.23.83358); until 2026-11-09 each had the cut in its
patches.py, and the rule rewrites both mains byte-identical. On the 48 other mains on the game drive (2026-11-09) it cuts nothing: Fire Emblem Engage and Patrick's Parabox (Unity 2020.3) pass 1 block; Pokémon Brilliant Diamond (Unity 2019.4) has noALLOC_BUCKET. - Check:
dm/tools/tests/test_unity_bucket.py(Unity 2019's 255 cut to 63, 2020's one block, sizes in registers, two references);unity_bucket.py <main>...prints what it finds in each.
Separate virtual ranges in Snowdrop's page allocator
- Symptom: a write to
0x20000ffffin static initialization (main+0x164990), afterAllocateAddressRegionreturns0x1803; reducing the request to 3 GB still returns0x1803with the SDK's original large-region alignment. With only the outer ranges reduced, a later free crashes atmain+0x1668dcafter reading compressed file data as a slab-owner pointer. With all three ranges cut, a write to0x78atmain+0x2c534a8(lr=main+0x2c53484) when the opening quest's overalls bush is shaken, or when a later save loads. With a pool too small for the area:nn::diagabort withResult 0and an empty message while a world loads, backtracesdk+0x16ba48 sdk+0x37d1b0 sdk+0x37c2f4 sdk+0x37c27c sdk+0x37a980 main+0x12300c main+0x164b40 main+0x164954 main+0x168e54on Sparks of Hope 1.6.2225577 and SDK 13.3.5. - Cause: the engine reserves three adjacent virtual ranges before committing pages in them. Its enclosing reservation exceeds the iPhone's available guest address space, and the engine does not check the failed reserve before deriving the page addresses. A smaller reservation also needs the SDK's node area and large-region alignment adapted: a separate metadata reservation comes first, and the 1 GB alignment wastes the remaining contiguous space. The large-allocation child has an independent maximum page count; reducing only the outer range lets it allocate across the boundary used by
freeto distinguish allocation classes. Beside the three ranges, the memory system's startup reserves a 1.06 GB pool of 272-byte slots that nothing allocates from, and every UI node context reserves two small ranges of its own (576 KB and 256 KB) without checking them. With the pool, the regions fill the 4.375 GB alias region in the opening quest; a context left without its range writes its first entry toNULL + 0x78. A range below the game's peak has its own failure: the slab allocators' fallback asks for another 4 GB (main+0x164b34for 64 KB pages,main+0x164a34for 512 KB pages), which never runs on a Switch, where a 4 GB range is larger than the whole application pool. Here it does not fit, and the fallback retries without end. Each failedAllocateAddressRegionleaks a 48-byte node (sdk+0x37c3f8returns without freeing whatsdk+0x37d0c8allocated), until the SDK's 62 MB node area is full and it aborts (sdk+0x37d1ac). The abort is thus far from its cause, and says nothing about address space. - Fix:
dm/tools/snowdrop_pools.py, called bypatch_nso.pyfor anymain, finds the constructor by its structure, without a build ID: the 4 GB constant and its three adjacent size fields, the two reservations through one function that overwrites x1, the two 12 GB constants (either encoding) and the large allocator's page count. Every part is checked, one match or nothing is cut, with a red line if the shape is there. It reduces the range sizes, their combined reservation and the large allocator's maximum page count together, to the profile'ssnowdrop_pools(large, 512 KB and 64 KB ranges in MB; 2048 512 1280 without the key). The profile's build-gated cut reduces the unused pool to 17 MB. The fixed metadata reserve remains large enough, and page allocation, commits and frees retain their behavior. The SDK build gets the SDK-wide node-area cut and 2 MB alignment of the large classes. Each range is still a fixed limit below what the game could ask for, so per-range occupancy and the original growth fallbacks remain open until sustained gameplay validates them; see the game note for the layout and current validation. To reproduce the abort, give the 64 KB range less than the area uses (128 MB in Sparks of Hope's opening: the abort comes right after the title). - Found on: Mario + Rabbids Sparks of Hope (1.6.2225577, SDK 13.3.5; the rule also finds the base game's allocator, and the abort is GitHub issue #1010); Mario + Rabbids Kingdom Battle (1.9.589692, SDK 4.4.0), with the same three-pool layout and an independent large-allocation page count. Its base game has no such routine, and the rule leaves it alone. South Park: The Fractured But Whole uses an older initializer with separate pool-bound immediates. Its game-level function patch matches 1.0 and 1.05 and keeps the 64 KB pool at 2 GB.
.NET NativeAOT malloc and the GC region range
- Symptom:
nn::diagabort atsdk+0x12dad0innninitStartup, called frommain+0x756310(1.1.1:main+0x7562d0). - Cause: malloc's
StandardAllocator::Initialize(nullptr, 0xa00000000): 40 GB of address space (main+0x28c084; 1.1.1:main+0x28bff4). Absolum's regions (measured on a 64 GB alias region): malloc's (2.19 GB used into the first level, 1.75 GB of it FNA3D's GPU heap, allocated whole atFNA3D_CreateDevice), the .NET GC's region range (3.75 GB) and a few small ones. The GC sizes its range as 5 × its hard limit (768 MB = 75% of the 1 GB itsGetPhysicalMemoryLimit,main+0x28c08cin 1.1.2,main+0x28bffcin 1.1.1, reports), and it readsDOTNET_GCRegionRangethroughgetenvfirst. - Fix: the host now answers
getenvfrom the profile keygame_env(hle_os.c; every other name goes to the SDK's owngetenv, an empty environment), which sets 1.5 GB. The GC then uses its range from both ends, 756 MB from the start and 748 MB from the end, where it used only the first 1.14 GB of 3.75. The profile'sstdalloc_capgives malloc 2.5 GB through the host's allocator gate, in every build (the 1.1.1 cut onmainit replaced is gone). One more thing kept it from fitting, the 1 GB alignment of large regions (1 GB alignment of regions of 1 GB and more), cut beside the node-area cut. The regions then end 4.13 GB into the 4.375 GB alias region of Engage's 5 GB block. - Found on: Absolum (.NET NativeAOT on SDK 18.3.2).
- Check: boot once on the Mac with a 64 GB alias region (
mem_reserve 0x1030000000,mem_alias 0x1008000000) and probeVammManager::AllocateAddressRegion's success path (sdk+0x13bf8c: x21 size, x22 address) withDM_SVC=1's map log.
A 62 GB page allocator behind nu::VirtualAllocHook
- Symptom: the game aborts in its static initialisers, before
nnMain, when its own 62 GB address region fails (main+0x37c9bd0,AllocateAddressRegion(&p, 0xf80000000)atmain+0x37c9a5c). - Cause: the allocator behind
nu::VirtualAllocHookis a 64 KB page allocator whose own tables fill the region's last 14 MB, so the size, the header offset, the page count and three region-end bounds all follow from 62 GB. - Fix: the profile's
patches.pycuts all 11 instructions to a 4 GB region. The cut region still did not fit: SDK 8 has the same 1 GB node area and 1 GB alignment of regions of 1 GB and more as the newer SDKs (constructorsdk+0x336b40,orr w9, wzr, #0x3fe00000at+0x336b50/+0x336bf0; alignment at+0x336d5c), cut insdk_patches.pyas DRAGON QUEST XI S's SDK 7.3.2 build; the region then starts 64 MB into the 4.375 GB alias region of the 5 GB block. - Found on: Super Smash Bros. Ultimate (13.0.5, SDK 8.2.1). Booted once with a 64 GB alias region (
mem_reserve 0x1030000000,mem_alias 0x1008000000) andDM_SVC=1's map log, the game commits from the region's start upward (1.73 GB contiguous at the title) and its page tables from the top; a battle commits up to 2.5 GB (DM_ALIAS_WINDOWS).
Unreal's engine address region and its options
-
Symptom: the game calls
exit(1)innninitStartup(Octopath Traveler 0:main+0x12e74);nn::diag::Abortfrommain+0x352fbec(Unreal's fatal error) after the first commit,AllocateMemoryPages(0, 2 MB)while the RHI starts (main+0x353ff8c, result 0xe03) (Pikmin 4); a crash inNumberLineAllocator::Compactionat boot (DRAGON QUEST XI S, region option 4224). -
Cause: Unreal's
nninitStartupneeds virtual address memory and reserves one address region for the engine withAllocateAddressRegion, 62 GB by default (-SwitchVirtualAddressSpaceSize=in MB, or in bytes above 4095). The other options it reads are-SwitchMaxMemorySize=,-NVNCommandBufferGranularity=,-NVNControlBufferSize=,-SwitchMainThreadStackSize=,-NVNTempMemoryPageSize=,-ResX=/-ResY=and-SwitchDisableVirtualAllocator, which also exits. It reads them from the game arguments, which the host used to set only afternninitStartup. -
Fix: the game arguments are set before
nninitStartupnow, as on hardware. The region's size no longer comes from them: the host gives the region what the alias region has room for, in any Unreal Engine 4 / 5 main. -
Engine-wide: the rewriter finds the reservation without a build ID (
dm/tools/ue_region.py, called bypatch_nso.py), each link unique or nothing is gated: the option's nameSwitchVirtualAddressSpaceSizein ro,nninitStartup(abto the engine's function; in UE 4.18 ablto it), and in that function the oneblto thenn::os::AllocateAddressRegionPLT stub whose straight-line code sets x0 to the region's base variable and stores the size in the word after it. x1 at the call must be that size (the stored register, or both set from one constant), and written after the store only with that same constant while the stored register still holds it; the rewriter then makes that instructionmov x1, xS. Observation gateOBS_UE_REGIONgoes on that store, with the register in the gate number's upper bits. The host (hle_svc.c) sets that register and x1 to StandardAllocator's room (StandardAllocators over 12 to 62 GB of address space): the alias region less the regions made so far and 256 MB for later ones, in 32 MB steps. That is 2.81 GB in the 3.75 GB block and 4.06 GB in Engage's 5 GB block. With a Switch-sizedDM_ALIAS_SIZEthe request fits and nothing changes. A chain that breaks after the option's name is a[RED]line in the rewrite, and the engine asks for its whole default.- Forms found:
- a
cselof the default and the option's size rounded up to 4 KB, thenstr x1(UE 4.27 and 5); - the default stored only while the variable is 0, then rounded into x1 and stored again (OCTOPATH TRAVELER II);
str x8of the default, with x1 set from the same constant (Pikmin 4, UE 4.26);- the same with the constant set after the store (TRIANGLE STRATEGY, UE 4.27). Until 2026-11-02 this form was a
[RED]line in the rewrite: the provisional 64 GB alias region hid it, and a 3.75 GB block aborted innn::diagjust after the NVN device started (main+0xd0f130), with no region in the log; str x1of the 16 GB default (DRAGON QUEST XI S, UE 4.18).
- a
- Checked (2026-10-31): on the 123
mainfiles on the game drives, it found the reservation of each of the nine Unreal builds with the option and nothing in the others. OCTOPATH TRAVELER and Yoshi's Crafted World (UE 4.18, no virtual address memory) have the same code, which theirnninitStartupnever reaches. Checked again on 2026-11-02 for the form after the store, on the 131mainfiles on the drive: only TRIANGLE STRATEGY's result changed. - Before: until 2026-10-31, seven profiles set
-SwitchVirtualAddressSpaceSize=ingame_args(2048 MB in the 3.75 GB block, 4064 MB in the 5 GB one), and Pikmin 4'spatches.pycut its default to 4064 MB.
- Forms found:
-
Found on:
- Octopath Traveler 0 (Unreal Engine 5):
main+0x12e24. With the host allocator (Unreal's FMallocBinned3 replaced by the host allocator) the region holds only what the engine maps itself; with SDK 19's node area cut the guest block is 3.75 GB, and the region 2.81 GB (2 GB until 2026-10-31). - DRAGON QUEST VII Reimagined (Unreal Engine 4.27, SDK 19.3.1): the same 62 GB region from
nninitStartup(main+0xe8a2c0). With a 2 GB region it was mapped up to +0.75 GB through the opening and the new-game menus. - FINAL FANTASY RESONANCE (Unreal Engine 5.6.1, SDK 20.5.17):
nninitStartup(main+0x13370) reserves the same 62 GB region (main+0x137d0); the region gets 4.06 GB in Engage's 5 GB block, as DRAGON QUEST XI S's (Unreal 5.6's page allocator never gives address space back). - Pikmin 4 (Unreal Engine 4.26.2, 1.1.1, SDK 10.4.8): the region option is the trap. This
nninitStartupreserves the region only while its size variable is 0 (ldr x8,[x22,#0x130]; cbnz x8past the default 62 GB and itsAllocateAddressRegion,main+0x353f564): the variable is also its "reserved" flag, so with the argument the base stayed 0 and the first commit went into Unreal's fatal error. The game's own code, not the host's: UE 4.27 and 5 reserve in both cases (thecselform). The default path takes the gate (str x8atmain+0x353f57c). With Engage's 5 GB block and a 4064 MB region, from the boot into the Olimar prologue: up to +1.5 GB of the alias region with 1.0 GB mapped, an Unreal heap of 1 GB. - DRAGON QUEST XI S (Unreal Engine 4.18, SDK 7.3.2) reads the same option and the others from
argv[1]on (main+0x177b5a4;main+0x177c440parses each one:atoi, MB up to 4095, bytes above). Its region is 16 GB by default, reserved atmain+0x177bbf4in the functionnninitStartupcalls first. A value of 4224 was taken as bytes: a 4 KB region, and the first 2 MB request crashed inNumberLineAllocator::Compactionat boot. With the node area cut and 2 MB alignment for large regions on that SDK build (sdk_patches.py), the region starts 64 MB into Engage's 4.375 GB alias region. On the Mac, with 4064 MB, the mapped total stays at 1.5 GB from the title to the first field (Cobblestone Tor), used up to +1.75 GB of the alias region; the process holds about 2.1 GB, 1.1 GB of it Metal allocations. - SHIN MEGAMI TENSEI V: Vengeance (Unreal Engine 4.27):
main+0x1b89038, thecselform. - OCTOPATH TRAVELER II (Unreal Engine 4.27, SDK 12.3.2):
main+0xbec3b4.
- Octopath Traveler 0 (Unreal Engine 5):
-
Note: without virtual address memory there is no engine region: OCTOPATH TRAVELER (Unreal Engine 4.18, SDK 3.5.1, no system resource in its NPDM) has
nninitStartupset a heap of pool − used (3.08 GB) and the engine runs on it, so it takes the 4 GB heap layout. The provisional profile used to give every Unreal game the 64 GB alias layout, which left this one no heap region (SetHeapSize OOM: req 0xc5400000 > cap 0and aBreakinnninitStartup);profile_guess.pynow gives it only with virtual address memory.
Unreal's FMallocBinned3 replaced by the host allocator
- Symptom: a null read in the out-of-memory report at
main+0x1005824when the engine region is smaller than the allocator's pools (Octopath Traveler 0). On Unreal Engine 4.24, the rewrite saidthe name getter is slot 17, a slot layout the host does not know, and the game crashed in the allocator's out-of-memory path with the iPhone-sized address space (DRAGON BALL Z: KAKAROT). - Cause: Unreal's allocator, an FMallocBinned3, reserves 37 GB of the engine region (74 pools of 512 MB, pool index = offset >> 29). The pools are uneven (at character creation the largest holds 68 MB, the 74 together 732 MB; measured with
DM_ALIAS_WINDOWS=512), so no smaller window fits a phone's ~5 GB. - Fix: the host puts its own allocator in the object instead (
hle_uemalloc.c: the FMalloc vtable on a host malloc zone, the trivial slots kept). With it the region holds only what the engine maps itself (709 MB at Octopath Traveler 0's character creation). - Engine-wide: the rewriter finds the allocator in any Unreal Engine 4 / 5 main without a build ID (
dm/tools/ue_malloc.py, called bypatch_nso.py), each link unique or nothing is cut: the UTF-16 nameBinned3, its getter (adrp x0+add x0,ret), the one data word holding the getter once the module's relative relocations are applied (OCTOPATH TRAVELER II's and Pikmin 4's vtables are relocated, the others' are in place), the vtable it is a slot of (back to two words of 0: offset to top, no RTTI), the one function other than the vtable's two destructors that stores the vtable (the constructor) and its calls, each abl(ab, a tail call, stops the chain: a nop there would fall through). It cuts each call and puts observation gateOBS_UE_MALLOCon it, where x0 is the object (made byGCreateMalloc, or a bss object innninitStartup); the fixups table names the vtable and the getter's slot (UE_MALLOC_VT,UE_MALLOC_SLOT), which selects the slot layout inhle_uemalloc.c. A chain that breaks after the name is a[RED]line in the rewrite and Unreal's own allocator runs. On the 68mainbuilds on the game drive (2026-10-30) it found exactly the call, vtable and layout of the five that had a cut of their own, and nothing in the other 63, Batman: Arkham Knight's included; on SHIN MEGAMI TENSEI V: Vengeance's main, extracted from the archive drive, its registered ones too. Those cuts were removed, with FINAL FANTASY RESONANCE's Asian release's, which had the global release's offsets. DRAGON BALL Sparking! ZERO (UE 5.1, slot 19) calls its constructor from two places, one lazy construction inlined twice (nninitStartupatmain+0x1e4db30and a getter atmain+0x1e4e048: if the global atmain+0x92ec6a0is null, malloc 0x1c38 bytes, construct, store). The rule asked for exactly one call until 2026-11-07, so it printed[RED] … 2 calls and 0 jumps, not one calland Unreal's own allocator ran, reserving 37 GB of the engine region; now both calls are cut and gated (its note). Until then each build had a cut and a gate in its profile'spatches.pyand a row of fixed addresses inhle_uemalloc.c. - In the tested Unreal Engine 4.23 and 4.24 builds, getter slot 17 selects the 18-slot vtable in
hle_uemalloc.c. This layout predatesTryMallocandTryRealloc. Slots 3–7 areMalloc,Realloc,Free,QuantizeSizeandGetAllocationSize, which stores a 64-bit size. The existing constructor matcher and the host malloc zone handle this layout without fixed addresses. - Found on:
- Octopath Traveler 0 (Unreal Engine 5): the allocator is constructed in place in the bss.
- DRAGON QUEST VII Reimagined (Unreal Engine 4.27, SDK 19.3.1): an FMallocBinned3 whose 37 GB of pools are cut out of the 62 GB region (the mapped high-water mark reached +38 GB of a 64 GB alias region at boot), so a capped region would starve it. Here the allocator is not in the bss:
GCreateMalloc(main+0x32758b0) mallocs 0x1c38 bytes on the first allocation, during the static constructors, and constructs it there. Found from the commit calls (probenn::os::AllocateMemoryPagespast itsadrp,sdk+0x140f84: every backtrace runs through the allocator's methods aroundmain+0x3270000), the relative relocations that point at them (the vtablemain+0x5e4c0e8; this build has no RTTI) and the one store of that vtable outside the destructors. No code outside the allocator reads its pool base or calls its methods directly. UE 4.27's FMalloc has one FExec slot, not four, so the slot numbers differ from UE5's (Malloc 3 … GetAllocationSize 9;Freeismain+0x10, right after the 16-byte module header). - FINAL FANTASY RESONANCE (Unreal Engine 5.6.1, SDK 20.5.17):
nninitStartupconstructs its FMallocBinned3 in place in the bss, as Octopath Traveler 0's (main+0x77c6210; the call atmain+0x137f0is cut, and its constructor would reserve 38 GB). UE 5.5 and later addMallocZeroed/TryMallocZeroedafterFree, two TLS cache calls (MarkTLSCachesAsUsed/Unused) and two cached-memory queries, so the FMalloc vtable has 32 slots (layoutUE5_6inhle_uemalloc.c: Malloc 6 … Free 10, QuantizeSize 13, GetAllocationSize 14). The base vtable shows it: its three pure slots are 0, and its slots 11 and 12 are one function that calls slot 6, thenmemset. - Pikmin 4 (Unreal Engine 4.26.2, 1.1.1, SDK 10.4.8): the allocator is made as in 4.27, with the same 21-slot FMalloc vtable (
GCreateMallocmain+0x353f770mallocs 0x1c38 bytes and calls the constructormain+0x35ba610, the one store of the vtablemain+0x8da4758outside its two destructors; found from the FMallocBinned3 error strings through the relocated slots). The engine-wide rule's first relocated vtable with OCTOPATH TRAVELER II's. - OCTOPATH TRAVELER II (Unreal Engine 4.27, 1.1.1, SDK 12.3.2): as DRAGON QUEST VII Reimagined's (
GCreateMallocmain+0xbecbf0, the constructormain+0xc4d778, the vtablemain+0x64710b0), with 20 slots: noOnMallocInitialized, so the 21st word the host copies is the next vtable's offset to top, which nothing calls. - DRAGON BALL Z: KAKAROT (Unreal Engine 4.24, 1.70): getter slot 17. The host replacement let it boot in the 5 GiB guest block on the Mac.
- BRAVELY DEFAULT Ⅱ (Unreal Engine 4.23, 1.0.0): the same getter slot. The host replacement let it reach frames in the 5 GiB guest block on the Mac.
- SHIN MEGAMI TENSEI V: Vengeance (1.0.3, SDK 15.3.2): the same UE4 layout (
GCreateMalloccalls the constructormain+0x1578bc0atmain+0x1f2f63c; the vtablemain+0x5a7f0a8), checked on its main from the archive drive. - Batman: Arkham Knight (Unreal Engine 3 with a binned allocator of this kind, 1.0.5, SDK 14.3.0): the static constructors reserve 1 GB for its tables and 37 GB for its pools (
main+0x192eee8,main+0x192fe50; the region check stops the provisional build there). The object is in the bss (main+0x51818c0) and its constructor is inlined into the guarded function behindGMalloc(main+0x192eb30), so the cut is a branch from the guard's acquisition to its release, not a nop;hle_uemalloc.cchecks for that word. It has noBinned3name for the engine-wide rule, so its cut stays its build's (patches.py) with a row of fixed addresses. Its FMalloc interface is UE3's: 25 slots with 32-bit sizes and noTryMalloc/TryRealloc(layoutUE3: QuantizeSize 3, Malloc 4, Realloc 5, Free 6, GetAllocationSize 20, which stores a 32-bit size), found by the vtable offsets ofGMalloc's 36,800 call sites (+0x20/+0x28/+0x30for 8,090 / 8,423 / 20,308 of them). The host heap held 1.75 GB 45 s into the boot.
- Note: Unreal Engine 4.18 (DRAGON QUEST XI S) needs no allocator cut: the SDK's
NumberLineAllocatorhands its region out in 64 KB units (main+0x177c4d0), and the engine maps only what it uses.
Wwise loses the span header in a virtual block from Unreal's heap
- Symptom: Wwise crashes in
AK::MemoryMgr::Initwhile reallocating or freeing a block, after Unreal switches to the host heap. Whether a boot crashes depends on where the heap puts the block, and the fault address can be a null read or garbage. - Cause: Wwise requests page-aligned virtual memory through Unreal and locates a span header by clearing the low 16 bits of an interior pointer. A host allocation aligned to only 4 or 16 KiB can put that address before the block. Unreal's virtual allocator supplies 64 KiB alignment for these spans. On an M6 Mac with 16 GB, 10 of 16 boots of Princess Peach: Showtime! crashed this way, and none of 15 with the fix.
- Fix: the host preserves the 64 KiB boundary for allocations and reallocations of at least 64 KiB, and honors larger requested alignments. A reallocation still calls the zone's
reallocfirst and copies only a block that comes back off the boundary. Copying every block of that size instead held 1,053 MB of footprint where 289 MB was enough for one array grown to 256 MB by 1.375 times, took 5 times as long, and gave nothing back on a shrink (a synthetic run on a Mac). Aligning the allocations themselves cost little: the footprint of 68 KiB blocks went from 1.182 to 1.185 times the requested size, and at frame 1,500 of a boot with no shader libraries DRAGON QUEST I & II held about 2% more resident memory over four runs each (2,192 to 2,237 MB, overlapping ranges). - Found on: Princess Peach: Showtime! 1.0.0 (#996), whose Wwise integration requests 4 KiB alignment.
Thread stacks from the host's Unreal heap
- Symptom: an abort right at
nnMain, undernn::os::CreateThread→ThreadManagerImplByHorizon::MapAliasStack→StackGuardManager::MapAtRandomAddress; with the log line,[RED] MapMemory refused (0xd401): <stack region> <- <address outside the guest block>. - Cause: Unreal allocates the stacks of the threads it creates with FMemory (OCTOPATH TRAVELER II's game thread:
nnMainmallocs it with 4 KB alignment atmain+0x544; its FRunnableThreads take theirs from inside larger allocations), andCreateThreadmoves such a stack into the stack region withsvcMapMemory. With the host allocator that memory is a host malloc zone outside the guest block, andMapMemorytakes only a backed source: the heap, mapped alias pages or a module's writable data (map_source_backed,hle_svc.c). - Fix: with the host allocator installed, a source outside the guest block that the host has mapped readable and writable is taken too (
dm_ue_heap_owns,hle_uemalloc.c;vm_region_64, since malloc has no cheap lookup from an interior pointer). A refused map now logs its arguments. - Found on: OCTOPATH TRAVELER II, after the stricter source check of
MapMemory; Pikmin 4 boots with the same host.
Unreal 5.6's page allocator never gives address space back
- Symptom:
nn::diagabort frommain+0x11bc, no message, in the first battle, with about 1 GB mapped (FINAL FANTASY RESONANCE with DRAGON QUEST VII Reimagined's 2 GB region). - Cause: the engine hands its region out with a page allocator of its own (
main+0x13ef0), a bump pointer plus free lists per size class, so the address space it has used only grows, and past the region's end it callsOnOutOfMemory(main+0x13c74). - Fix: the profile gives the region 4064 MB in Engage's 5 GB block, as DRAGON QUEST XI S's (profile key
game_args). This SDK build aligns regions of 2 MB and more to 2 MB only (VammManager::AllocateAddressRegion,sdk+0x145e00), so it needs no alignment cut. - Found on: FINAL FANTASY RESONANCE (Unreal Engine 5.6.1, SDK 20.5.17). Probed where each new block comes back (
DM_PROBE=main:13fcc: x0 the block, x21 its size, x8 the region's end): a 1 GB block at boot from a static constructor, +1.5 GB 15 s in, +2.0 GB in the battle, level at +2.03 GB over seven minutes.
Ring heaps cut from a pool at 64 KB alignment
- Symptom: write to
0x268right after the title screen (main+0x5d6708, a constructor whosethisis0x200). - Cause:
operator new(main+0x5a55d4) takes the thread's ring heap, a bump allocator whose cursor starts at its base. One ring heap kept base 0, as in 13 Sentinels: the engine cuts ring heaps out of a memory pool at 64 KB GPU alignment, and the host's pool storage from malloc is only 4 KB aligned. The first allocation returned 0, whichoperator new's null check skipped, and the next returned0x200. - Fix: the profile key
alloc_big_alignaligns allocations of 64 KB or more to 64 KB (dm/games/README.md); the game then plays from the title screen into its opening story scene. - Found on: Unicorn Overlord (SDK 16.2.4, Vanillaware's engine as in 13 Sentinels: Aegis Rim; one boot).
Mapping SVCs
svcQueryMemory must report each module's real layout
- Symptom: C++ exception aborts in
nn::ro::detail::GetExceptionInfo. - Cause: the SDK's unwinder finds a module from
svcQueryMemory: it walks back over Code+RX regions to the module start, forward over Code then CodeData, and readsMOD0for.eh_frame_hdr. - Fix: the host reports each loaded module's real layout and reports other host memory as free (
hle_svc.c). - Found on: Fire Emblem Engage (its note lists it among the host changes first needed there). IL2CPP throws a C++ exception for every managed exception, so Unity games need this; Mario (Super Mario Bros. Wonder) never threw.
svcQueryMemory walks the whole guest process
- Symptom: the SDK's module enumeration keeps calling
svcQueryMemoryafter it has seen the last module and the game stays beforennMain. - Cause: the SDK advances from address zero by each block's reported size. Outside the guest reservation the host reported one free 4 KiB page per query, so the walk kept going page by page across the host address space.
- Fix: outside the guest reservation, report each free span up to the adjacent loaded module, front patch area, current stack or guest reservation. Borrowed ranges still split the result. Inactive NROs are free until loaded. At Darwin's user address limit, report a reserved block whose end wraps to zero, as Horizon does at its process limit.
- Found on: Hitman Absolution, PR #3023 (v131072, SDK 22.2.0). After the loader lookup fix, the old map was still scanning at the 10 s cutoff. With the free spans and reserved tail, the same SDK completes both list passes.
MapPhysicalMemory in 16 KB host pages
- Symptom:
MapPhysicalMemoryfaults on part of a page. - Fix: round to 16 KB host pages.
- Found on: the source names no game.
Maps past the application pool fail as on Horizon
- Symptom: the alias region's mapped total runs past the application pool in the first minute.
- Cause:
nninitStartupallocates and frees everything allocatable (pool − used, 3.15 GB, mapped at the top of the region) and the SDK keeps the freed pages mapped; later allocations map new pages at the bottom until a map fails, and only then does it unmap the cached block and retry. The host never refused a map, so the block stayed mapped beside the 0.4 GB the game used. - Fix: profile key
mem_map_limit(hle_svc.c): a map past the pool fails with ResultLimitReached, and the used memoryGetInforeports counts the mapped pages, as on Horizon (without that, the startup probe itself, sized as total − used, was refused). When the profile omitsmem_map_limit, the host enables it by default for Switch 2 (dm_sdk_ounce(), which has no reduced-pool legacy profiles) and leaves it off for Switch 1 (where Ace Attorney Investigations Collection maps slightly more than its profile's reduced 1 GB pool); explicitmem_map_limit onoroffalways wins. - Found on: Pokémon Legends: Z-A (2.0.2, SDK 19.3.11; one boot). Measured: one refused 4 MB map, the 3.15 GB unmap, the same map again. Also needed at startup on Xenoblade Chronicles 2 Switch 2 Edition (PR #3188), where an uncapped probe mapped all 60 GB and left the next arena null.
Unmapped guest memory stays resident
- Symptom: after a large
UnmapPhysicalMemory, heap shrink or repeated stack unmaps, RAM does not come back.phys_footprintmay still fall. Theguestclass inDM_MEMSTATreports residency. - Cause: on Darwin
mprotect(PROT_NONE)only removes the page table entries. The pages stay resident and dirty, out ofphys_footprint, andmadvise(MADV_FREE)on pages that are not writable does nothing, though it returns 0. Measured on 1 GiB on the Mac: 1,024 MiB still resident and dirty, footprint 1.2 MiB. - Fix:
guest_release(hle_svc.c) puts a fresh inaccessible mapping over the range (MAP_FIXED), which empties it at once and gives zero pages.UnmapPhysicalMemorythen clears the range's exposed bits, so mapping it again needs nomemset. A memory pool's no-copy buffer over the range keeps the old pages for the GPU until the buffer goes (measured: the GPU still reads the old data, the CPU sees zeros). A guest that unmaps and remaps under a pool it never finalized would see the two diverge, which Horizon does not allow, and neither does the host now: Device-shared memory is not unmapped. MapMemorydirties the destination when it copies a stack to its randomly chosen address. After copying the contents back,UnmapMemoryreleases anonymous host pages wholly inside the destination. Partial edge pages can still hold a live 4 KiB neighbor.MapMemoryreopens the pages on reuse. File-backed stacks retain their backing after copyback. Thet_svc_memoryteststack_pages_releasedchecks the interior page, both neighbors and reuse.- Found on: Pokémon Scarlet, one A/B on its 180 s route on the Mac: peak footprint 4,540 → 3,775 MiB, guest charged 1,809 → 1,372 MiB, 30 fps held. 437 MiB of the footprint drop is guest memory; the other 328 MiB is not explained. Tears of the Kingdom on its 95 s route: footprint flat (4,935 → 4,969 MiB), guest charged 1,887 → 1,685 MiB, with the baseline's pages partly compressed, so that drop is less certain. Open: the iPhone and Z-A, whose shader libraries were stale, were not measured.
Device-shared memory is not unmapped
- Symptom: the GPU hangs or stalls with no failing draw: compute shaders that read counts from a memory pool loop forever (on the Mac a silent stall right after the title screen; on an iPhone "Caused GPU Hang Error"), and text or other data in that pool comes out scrambled.
- Cause: the game gives back pages of a live memory pool with
svcUnmapPhysicalMemoryand maps them again. On Horizon that call fails: NVN gives a pool's storage to the GPU through nvmap, whose device mapping (LockForMapDeviceAddressSpace→KMemoryBlock::ShareToDevice) setsKMemoryAttribute_DeviceSharedon the pages, andKPageTableBase::UnmapPhysicalMemoryrefuses any page with an attribute set (ResultInvalidCurrentMemory, 0xD401), as does aSetHeapSizethat shrinks (both read in Atmosphère'skern_k_page_table_base.cpp). The host accepted it:guest_releaseput fresh pages under the addresses while the pool's zero-copyMTLBufferkept the old ones, so the CPU wrote one copy and the GPU read the other. - Fix:
hle_nvn.cregisters each NVN pool's storage atnvnMemoryPoolInitializeand unregisters it atnvnMemoryPoolFinalize.dm_device_sharecounts registrations over the same storage. As on Horizon, any device-shared page in anUnmapMemorydestination, anUnmapPhysicalMemoryrange or a shrinkingSetHeapSizerange causes 0xD401 before the host changes the mapping. The host logs the first few refusals, for example[mem] UnmapPhysicalMemory … refused: it holds device-shared memory. - Found on: Monster Jam Steel Titans 2 (
010051B0131F0000, 1.0.2), in PR #1616: the 2 MB pool holding Unreal's forward light data ring is unmapped and mapped again at frame 6, and its light-grid compute shaders read stale light counts (0xff000000); about ten other pools of that game go through the same. The PR followed the pages in the graphics layer instead. Open: this fix was not run on that game (no profile or game files here), so how the game takes the refusal is unknown. If it aborts, it never unmaps a live pool on hardware, and the host's list of live pools is wrong further up. - Check:
t_svc_memorydevice_shared_refusedchecks that unmap and heap shrink over a registered page leave the pages, mapped total and bytes intact. Ranges touching a registration can still be released. A range registered twice stays shared until both registrations are removed. A device-shared stack edge page blocks unmap and copyback.
GetInfo(UserExceptionContextAddress) returns a real buffer
- Symptom: a write through a null pointer at +0x1c0 during startup.
- Fix:
GetInfo(UserExceptionContextAddress)must return a real buffer. - Found on: the source names no game.
Running out of memory
A null-pool buffer from a game heap that ran out
- Symptom: a null-pool buffer even with virtual pools working (Virtual memory pools mapped onto one physical pool).
- Cause: the game's own heap ran out.
- Tracing it with probes (05): the gsys GPU allocator at
main+0x4290c0and the heap'stryAlloc(vtable slot +0x30) show which heap, its size and every allocation into it; the!xNheap walk shows the free and used blocks at the moment of failure. - Note: read the probe log carefully:
tryAllocprobes show requests, not successes, so a running total that already exceeds the heap means an earlier request failed. - Found on: Super Mario Bros. Wonder, The Legend of Zelda: Breath of the Wild (the two entries below).
Model heaps sized by the host's command record sizes
-
Symptom: a model load exhausts its resource heap: a null
operator newat the world load, orBufferInitialize: pool has no storagefollowed by a null-pool crash. A display-list heap that runs out shows asAddCommandMemorywith a null pool outside a recording, then host-lent segments growing untilFATAL NVN command memory(Host-lent command memory segments). -
Cause: games size model allocations by measuring scratch command recordings; oversized host records can exceed the budgets in their resource-size tables. In Breath of the Wild, each model's heap is its table entry + 0x1008, the file goes in 4 KB aligned, and the setup (
main+0x155a2ac) takes the rest as a frame heap (vtablemain+0x1d4f950, head+0xe0, tail+0xe8). Its use is the same in every run; only the file's alignment pad varies (0 to 0xff8), and the entries leave room for any pad, about 0xd00 to spare on most models. Three models were a 4 KB page short, so the loads with a large pad failed. The game sizes the model's prerecorded commands by recording each mesh's draw and each shape's per-pass state into a scratch command buffer and summingGetCommandMemoryUsed(main+0xf9aeb4,main+0xf9bb54), and our records were larger than the driver's (draws carried the indirect and multi-draw fields, every recording began with a BEGIN record). Super Mario Odyssey keeps its display lists in a 62 MB GPU bump heap named "DisplayList" (main+0x5e8280: used at+0x68, capacity at+0x6c, a null block when full), allocated while a kingdom loads; with 40-byte state binds (39% of the display-list bytes) it filled at the load and every later list got a null block. -
Fix: plain draws leave unused indirect fields out and recordings start with their first command. Uniform and single vertex-buffer bindings also use compact 24-byte records instead of 32, preserving full GPU addresses and retaining full-width fallback records for ranges above
UINT32_MAX; multi-vertex ranges retain their array representation. State binds carry only the state object's bytes (16 bytes for color, channel mask and polygon state, 24 for blend, multisample and depth-stencil, instead of 40), and a single texture bind drops its pool bases when both are 0 (24 bytes instead of 32, the handle still 16 bytes in). Replay expands the compact forms into the same canonical binding state. The native inline uniform command takes 20 bytes and the native vertex-buffer command 24, so these small differences can accumulate into an extra 4 KB GPU-pool chunk. Report the bytes actually recorded; do not underreport usage or add a game-specific heap allowance. A recording's end, the links between its pieces and its calls take no command memory, as in NVN: they are entries in control memory (A recording's end and links are in control memory), which saves the 8 bytes of END on each scratch recording. On top of that, what games record per mesh and per pass takes compact forms that only command memory holds:nvn_obj.hOPC_*, with small arguments in the header's upper 24 bits. The queue's flatten expands each into the canonical records (hle_nvn.crec_expand), so replay, capture and the replay walkers see no new op. They were sized against the driver's own commands, measured by running the NVN driver linked into a game'ssdkin an emulator (dm/tools/nvn_native_sizes.py). The results, in command bytes, were identical on NVN1 (Fire Emblem: Three Houses, Cuphead, Minecraft Dungeons II) and NVN2 (Ocarina of Time, Donkey Kong Bananza) except where noted:Call Driver Host before Host now DrawElements / with base vertex 24 / 48-72 40 24 DrawArrays / instanced 16 / 24 32 16 / 24 DrawElementsIndirect 28-36 64 24 BindUniformBuffer / two 20 / 24-40 24 / 48 16 / 24 BindTextures (two) / BindImage 28 / 20 48 / 40 16 SetViewports (one) / SetStencilRef 36 / 8 400 / 32 24 / 8 BindVertexAttribState (four) / stream (two) 24 (NVN1: 68 / 72) 32 24 color / polygon / depth-stencil state 12 / 20-24 / 8 16 / 16 / 24 8 / 8 / 16 a mesh: vertex buffer, uniform buffer, texture, draw 132 112 88 Five calls stay above the driver's, at the floor of an 8-byte header and 8-byte records: the depth-stencil state (16, driver 8), BindTexture (24, driver 16), which keeps its layout because Luigi's Mansion 3 patches its handle 16 bytes in, BindStorageBuffer and SetBlendColor (24, driver 20), and SetScissor (16, driver 12). An empty recording takes no command memory, as on the driver. The driver also uses 56 bytes of control memory for a recording of a few commands and 24 for an empty one; the host uses 8.
t_nvnrecords 51 calls both ways and checks that each compact record expands to exactly the canonical records. Donkey Kong Bananza's recorded command bytes per frame fell by a third on the same route (127 → 88 KB at frame 900, 334 → 223 KB at frame 3,000; Mac, no shader libraries for this chain). See WhatGetCommandMemoryUsedcounts. -
Check: for Breath of the Wild's whole scene, probe where the setup heap is cut (
main+0x155a520with!x21, the resource heap) and the end of the setup (main+0x155a5f4with!x2, the frame heap), withDM_PROBE_HEAP=28,38,40,e0,f8 DM_PROBE_HEAPFRAME=1d4f950 DM_PROBE_HEAPWORDS=1(05). A model fits any placement when entry + 0x1008 covers the resource heap's header and object (0x310), the file, the frame heap's block header and its peak use, plus 0xff8 of pad. -
Found on: The Legend of Zelda: Breath of the Wild, Super Mario Bros. Wonder (buffer bindings; the game note records the failed allocation, measured sizes and validation), Super Mario Odyssey (state and single texture binds; the note has the heap's measurements); reported for the Nintendo Switch 2 Edition of Super Mario Bros. Wonder and for Drag x Drive, the end of each recording in command memory (PR #1609, not run here).
Unity's GPU pool block allocation spins at size 0
- Symptom: the frames stop at the first loading screen, a graphics worker at 100% CPU (17 s in,
UnityGfxDeviceWorkerrunning, the main thread waiting on a condition variable, no red line). - Cause: the heap check's 1 GB pool (the hardware pool had used the alias region up to +4.25 GB) left the game's malloc too little: Unity's GPU memory pool block allocation (
main+0x96f430) callsaligned_allocthroughmain+0x866810, halves the request after each failure, and once the request rounds to 0 it calls on for ever with a size of 0. - Fix: a 2 GB pool: the game then maps up to 2.26 GB of the alias region through its menus and first battle.
- Found on: Advance Wars 1+2: Re-Boot Camp (Unity 2020.2.1f3, SDK 10.4.1), after the node-area and alignment cuts.
- Check:
sample <pid>on the Mac host shows such a spin (the guest frames are???in the host's image list; subtract the module base from the log'sbaselines); it worked here where lldb does not.
Host calls on small guest stacks
- Symptom: SIGBUS inside a host hook (
snprintfundermount_ex/h_fs_MountSave), then the process hangs (Super Mario 3D World + Bowser's Fury); SIGBUS inside Metal (AGCDeserializedReply, an AGX compiler block) at an address in the guest stack region (Breath of the Wild). - Cause: host hooks run on the calling guest thread's stack. Super Mario 3D World's save thread has an 8 KB stack (CreateThread stack top
0x…9fe0, fault0x21a0below it), and the file system hooks size their path buffers by PATH_MAX: one file open takes 6–7 KB (-fstack-usage:OpenFile1.3 KB →host_path_ex1.9 KB →path_component3.2 KB); on hardware the same call is one IPC. In Breath of the Wild a host NVN call did Metal work on a game thread with a small stack:nvnQueueSubmitCommandsreplays the frame, and ending a render pass made the driver compile its fast-clear blit program on the calling thread. - Fix: every take-over runs on a per-thread 512 KB host stack (with a guard page) when it is called on a guest stack:
HLE_FORCE(hle.h) registers a compile-time stub, local to its file, that loads the implementation into x16, the bytes of stack arguments its caller passes into x17 (8 per parameter past the eighth, rounded up to 16; the parameter count is checked at compile time, at most 16), and jumps todm_bigstack_enter(hle_bigstack.c). The entry switches when sp lies in the guest address block, passing x0–x8, d0–d7 and those stack bytes through, and goes straight through anywhere else (a host thread, or already on the host stack); variadic functions reading the stack cannot use it. iOS forbids generating code at run time, so the stubs are static. Until 2026-11-13 this was an opt-in (HLE_FORCE_BIG) that each take-over got after it crashed on a small stack: the file system here, add-on content (Add-on content queries on a small guest stack), AudioOut, the controller applet (Log lines on small guest stacks), Mario Kart 8 Deluxe's offline page (Offline HTML startup overflows a small guest stack); 13 of 1,067 take-overs had it.HLE_FORCE_DIRECTkeeps the caller's stack for take-overs that run the game's own code, whose stack use is the game's and which may switch stacks itself:ro::LoadModule/UnloadModule(an NRO's init and fini) and the JIT plugin's calls. A take-over that logs its game call site maps__builtin_return_address(0)throughdm_bigstack_caller. Programs that do not linkhle_bigstack.c(unit tests) gethle.h's weak pass-through entry. NVN functions are not registered throughHLE_FORCE, so they got their own big-stack entry: every implemented NVN function except thenvnCommandBuffer*recording calls goes throughnvn_big_entry(nvn_entry.S), which finds the implementation by slot and hands it todm_bigstack_enter(NVN entry points on the big host stack). - Check:
t_bigstack(register and stack arguments through the switch, a 12-parameter take-over called from the top of a stack, the game call site);t_web_stack(the offline page's entries on an 8 KB stack). - Found on: Super Mario 3D World + Bowser's Fury (file system hooks); The Legend of Zelda: Breath of the Wild (NVN entry points).
Log lines on small guest stacks
- Symptom: SIGBUS in
__sfvwrite/__vfprintfunderfprintf, from a hook that only logs (focus_syncunderh_hid_ShowCtrl, the controller applet), at an address a few bytes below sp and just under a page of the guest thread's stack; then the process hangs in the crash handler. - Cause: formatting one log line takes about 2.7 KB of stack (
fprintfto the unbufferedstderr, measured on macOS 27.2), and a hook runs on the stack of the game thread that calls it (Host calls on small guest stacks). Any hook that logs was exposed on a thread with less left; the library applet stand-ins log twice before they answer (DM_APPLET'soe library appletline, thenfocus_sync's focus state), and Drag x Drive opens the controller applet from such a thread. - Fix:
LOGis one call,dm_log(dm.h), and the host's definition (hle_bigstack.c) formats the line throughdm_bigstack_enter: on a guest stack the line is written on the thread's host stack, the variable arguments read from where the caller left them; anywhere else it is written directly. So aHLE_FORCE_DIRECTtake-over, or host code called on a guest stack, logs safely. Programs that do not linkhle_bigstack.c(unit tests) getdm.h's weak definition, which writes on the caller's stack. The controller applet's two hooks (ShowControllerSupport,hle_hid.c) were moved to the big host stack as well: with too few players the front end's prompt runs on the game's thread. The graphics layer'sMLOG(nvn_mtl.m) is the same call:nvnCommandBuffer*recording runs on the game thread's stack. Writes that stay direct run on host stacks: SVCs (theOutputDebugStringline) on the thread's gate stack (entry.S), the crash handler and its thread dumps on its alternate stack, probes, haptics and save sync on host threads or on the big host stack.dm_backtracewrites directly;nn::diag's abort hooks, which call it, run on the host stack since every take-over does (resolved 2026-11-13, until then they ran on the game's stack). - Check:
t_bigstacklogs from a hook with 1 KB of guest stack left (SIGBUS with the line written on the guest stack). - Found on: Drag x Drive (
040041601D83A000, v196608; PR #1943, its profile is a pull request of its own): once in a session, on the screen after a time trial. Not rerun there with this fix.
Deferred-release drain without an autorelease pool
- Symptom: the iPhone app is killed for memory; resident memory grows steadily (about 0.2 MB a frame) while the residency set and the texture counts stay flat.
- Cause: the deferred-release drain ran on the guest submit thread with no autorelease pool, so autoreleased Metal objects were never freed (the Metroid Dread leak).
- Fix:
defer_drainhas its own@autoreleasepool. - Found on: The Legend of Zelda: Breath of the Wild: GitHub issue #9 (iPhone 16 Pro Max, handheld), killed in the first shrine. An 8 GB iPhone gives this app about 3.4 GB (resident plus
headroom to the system memory limitstayed at 3,375 MB); resident memory grew from 2.6 GB at the shrine load until the kill. On the Mac a host without that pool grew 1 MB a frame in the shrine (GPU 3.0 → 4.4 GB in 2,400 frames); with it the shrine stays at 2.7–2.9 GB resident and 1.5–1.7 GB GPU, idle or walking (vmmap at 2.8 GB: about 1.6 GB guest memory, 0.75 GB private textures, 0.17 GB IOAccelerator). - Note: found on the way: dead texture serials and the fixed-size pool tracking table (Dead texture serials kept in a ghost table, Memory-pool tracking table grows in blocks).
Autoreleased temporaries collect during background pipeline builds
- Symptom: Objective-C temporaries can accumulate across a burst of background pipeline builds.
- Cause: the private utility queues inherit Dispatch's autorelease policy, and the global queues supply no pool for an individual work item. Worker-created autoreleased objects can live past the build that used them.
- Fix: give each pending render, pulling-base, amplified, tile-reading and geometry mesh build its own
@autoreleasepool. The worker publishes results to their owning slots or caches before the pool drains. - Check: a synthetic burst on an M4 Pro MacBook Pro (macOS 27.2.1) peaked at 256 live temporaries across 256 jobs on a serial utility queue, and one with a per-job pool. All five trials gave the same result. See the matched Mac load in Ocarina of Time's memory notes.
- Found on: Esteban Viera identified the missing pools while auditing memory ownership during profiling of The Legend of Zelda: Ocarina of Time in PR #2714.
Retired pool buffers pile up while a game submits nothing
- Symptom: out of focus, with the picture still and the sound on, GPU allocated climbs by hundreds of MB a second while the residency set stays flat, and swap follows it.
- Cause: a finalized pool's zero-copy buffer waited for the next submission's fence, and only a submission (at its start, or in its feedback handler) drained the deferred-release queue. A game may stop submitting while its other threads go on: Ocarina of Time out of focus waits in
oe::PopNotificationMessage(main+0x3bc0354) while its streaming threads remake a run of about 10 MB of a virtual pool 70 times a second (vrun_set). The queue took 770 MB a second, and GPU allocated went from 11 to 20 GB in 12 s, with 6.7 GB of swap in 20 s, until the run was killed. A user's session that stayed frozen after a window switch fits this, but that link is inferred: that host was not run again. - Fix:
mtl_pool_del(nvn_mtl.m) bumps the pool generation first, then makes the buffer wait only for the last committed fence when no submission is open (pool_gone_release;g_sub_open, with a full fence on each side, so a submission that opens meanwhile either is seen or sees the bump and cannot look the buffer up). The open flag holds the open submission's own fence and is read beforeg_fence: a commit clears it only after its++g_fence, so a 0 read means theg_fenceread after it counts that submission. As one expression,g_fence + (open ? 1 : 0), C left the order of the two reads open, and a commit landing between them could leave the buffer at the fence before its own, freed while the submission ran; a 0/1 flag read first left it one fence late, which a game that stops submitting never reaches. An entry queued with its fence already passed is drained at once off the submit thread (defer_kick). A drain's removals from the residency set free nothing until the set's next commit, so a feedback handler or a closing submission that finds none open commits them the same way (defer_idle_commit). - Check:
make -C dm/gfx/tests GAME=<id> check_t_pool_retire: a buffer retired between submissions goes with none after it, one retired with a submission open stays until that submission completes, one retired with a submission in flight waits for that fence, and one retired while a commit lands between the two reads (a test hook,g_pool_gone_between) waits for exactly that commit's fence. In a game,DM_OE_SCRIPT="focus=2@60,focus=1@90": GPU allocated stays flat between the two. - Found on: The Legend of Zelda: Ocarina of Time, measured and diagnosed by Pedro Nascimento in PR #1392. The unordered reads were found by reading the code in PR #2328, not in a game.
Vulkan and GL presentation textures were never released
- Symptom: in a Vulkan or GL game, the memory line's deferred-release queue grows by one entry a frame for the whole session, and each swap chain recreation or window surface of another size keeps its textures (about 24 MB for three 1920x1080 RGBA8 images).
- Cause: the Vulkan layer's swap chain images and the GL layer's window surface are registered with the present path (
mtl_ext_tex: a serial, the residency set) with no way back:vkDestroySwapchainKHRandwin_makeonly dropped their own references. Each present also pinned its texture, and the unpin hands the pin's reference to the deferred-release queue, which only an NVN submission's fence drains; the Vulkan and GL layers submit on queues of their own, so no entry ever left. A console mode switch from the iPhone's in-game menu or a TV connected or disconnected (dm_set_opmode) is when a game may recreate its swap chain. - Fix:
mtl_ext_tex_release(nvn_mtl.m) is the pair ofmtl_ext_tex: after the producer has waited for its presents' tickets, it waits for every present queued so far (a submitted present's ticket counts at its completion), takes the serial out of the table without the deferred-release queue (own_ext_take), and takes the texture out of the residency set, at once or, while a present is still in flight, when the last one completes. A present of an external texture is not pinned.vkDestroySwapchainKHRandwin_makecall it. - Check:
make -C dm/gfx/tests GAME=<id> t_vk_swapchain_life && dm/gfx/tests/t_vk_swapchain_life: 140 swap chains of 3 images, each presented 3 times to an offscreen layer and destroyed, leave none alive (before: 420 of 420, and 420 queue entries). - Found on: an audit of the presentation path, then reproduced by that test; no game's log measured. Every Vulkan game (Hades, Super Mario Galaxy) and GL game (Balatro) is on this path.
The pool walk's statistics made chunks of a large pool
- Symptom: in an area load GPU allocated jumps by 6-10 GB between two stats windows (Ocarina of Time: 3.3 GB at frame 900, 15.8 GB at frame 1200 on a 16 GB M5, issue #2068; 3.5 to 13.7 GB inside the load on an M5 Pro) while the residency set grows by about 4 GB, and stays there. The memory census's "not counted" line is 8 GB, and the pool buffers made sum to twice the pools' size.
- Cause: the pool walk's log (
pool walk: ... in wired pools, the first pool-table build of a scene and every 500th after) and the raw-memory log's pool age askedpool_find(addr, 1)where each texture's storage lies. For a large pool (BIG_MINand up, in 16 MB strides)pool_findmakes the stride's chunk, a zero-copy buffer of the asked length plus a stride, and a length of 1 then meant 64 MB past the address (BIG_UNKNOWN, since gone: Unknown-length lookups made a chunk at every stride): 80 MB or more, not in the residency set, overlapping its neighbours' chunks, none used by the GPU. A stride that had a shorter chunk got a longer one the same way, and the GPU's next lookup there put that one into the residency set beside the old. Ocarina's 2,432 MB pool has 153 strides; the walk touched 77 of them: 6.7 GB thatcurrentAllocatedSizecounts in full (it counts a no-copy buffer at its whole length, in a residency set or not). The pages are shared, so resident memory did not grow by that much (10.9 GB against 14.1 GB allocated), but the 16 GB Macs that run this game reach 17-18 GB allocated. - Fix:
pool_peek(nvn_mtl.m) answers the same question without making or lengthening a chunk: the stride's entry if it has one, else -1; it sharespool_find's search of the other entries (pool_held). Both statistics use it. - Check:
make -C dm/gfx/tests GAME=<id> check_t_pool_chunks: asking where an address is makes no chunk, and finds the chunk of a stride that has one. In a game, the memory census line ("GPU allocation census") at the same point before and after: Metal's total and the pool buffers made. - Found on: The Legend of Zelda: Ocarina of Time, diagnosed from the allocation census of Pedro Nascimento's M5 Pro runs and the numbers in issue #2068.
Unknown-length lookups made a chunk at every stride
- Symptom: command buffers fail with
Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)once a game has played a while, though the game's own memory is far from the Mac's. The residency census (DM_CTLrestop, or the one printed at the first out-of-memory error) is mostly shared buffers of 80 to 96 MB each, several times the size of the one large pool they lie in. - Cause: a lookup that does not know how far it reads asks for length 1: an indirect indexed draw's index buffer (
draw_, the index count is in GPU memory) and a storage buffer whose address the game keeps in its own uniforms or pushes (NVN_RB_SBUFU,NVN_RB_SBUFQ). In a large poolbig_lookupgave it a chunk reaching 64 MB past the address, made or lengthened at its 16 MB stride. Each stride such lookups started in got its own chunk of 80 to 96 MB; they overlap one another, a lengthened chunk keeps its shorter one alive for what was encoded with it, and Metal counts each no-copy buffer at its whole length. The guess was also no bound: the GPU may read further. - Fix: a lookup of unknown length takes one buffer of the whole pool (
big_full,nvn_mtl.m), as raw global memory's pool table already did, and every later lookup of that pool shares it. The per-thread lookup cache answers one only with a buffer that reaches its pool's end (pc_holds,REACH_SHORT). Chunks made before stay, resident, for what was encoded with them. Lookups of known length keep their chunks until a pool needs the whole buffer. The host logsmemory pool …: one buffer of the whole pool (a lookup of unknown length); the chunks made before it stay: N, M MBonce a pool is made whole. Cost: such a pool is wired whole, though the GPU may read only part of it. - Check:
make -C dm/gfx/tests GAME=<id> check_t_pool_chunks: a short chunk in the lookup cache does not answer an unknown-length lookup, twenty starts in different strides and the pool's end share one buffer of the whole pool, a known-length lookup then takes it too, the short chunk stays, and the GPU writes 96 MB past the address through it. 23 of the checks fail on the 64 MB guess. - Found on: Trails in the Sky 1st Chapter (
01002C9022770000, 1.0.7, not yet in the games table; issue #877, PR #1002), on an M1: 4,243 MB of shared buffers over its 1,507 MB pool, then out-of-memory failures. With the fix, 2,685 MB allocated after a save load and about 3,150 MB after seven minutes of walking and combat, with no failure (the PR author's runs). Not run here.
Upload staging grows within one rendering submission
- Symptom: travelling produces a brief multi-GB footprint spike, then memory returns to its earlier level; periodic memory lines can miss the peak. Upload diagnostics show many swapped-out blocks still alive in one batch.
- Cause:
up_alloccould append unlimited staging blocks beforeup_flush. Overflow staging then retired on the main rendering fence, so splitting uploads alone still retained completed staging while that submission was being built. Weak-table insertion and enumeration in the staging diagnostics also left temporary strong references in the submission's autorelease pool. - Fix: split GPU deswizzle batches before another block would exceed 128 MiB. The three upload allocator slots provide backpressure, publishing deferred commits before waiting. Retire overflow and CPU-upload staging from the upload completion handler, remove residency and clear its retained array before freeing the slot; keep diagnostic weak-table operations in their own autorelease pools. Rendering destinations keep their existing lifetime. A single texture larger than the batch budget still gets its own block; this is not a cap on all renderer memory.
- Check:
make -C dm/gfx/tests GAME=<id> check_t_upload_budgetuses actual Metal uploads during an open render pass, with direct and deferred encoding and Metal validation. A 2 GiB burst retained 2,048 MiB before the fix; afterwards it peaks at 384 MiB and retains only the three reusable blocks (96 MiB) after upload completion, before the rendering fence. It also checks every uploaded pixel and the render pass's clear. For a game, capture both frequentphys_footprintsamples and the kernel's peak ledger; the existingresidentlog label denotes footprint, and staging blockscreated in totalis cumulative, not live memory. - Found on: The Legend of Zelda: Tears of the Kingdom, investigating issue #147. Mac reproduction and device validation are tracked in the game note.
Upload staging keeps its largest blocks after a load
- Symptom: up to 192 MiB of private GPU memory stays in upload slots after a scene load, even when steady play needs little staging.
- Cause: the three slots retain a primary block sized by past demand and one overflow block, each up to 32 MiB. The upload batch budget limits temporary staging and leaves these cached blocks resident.
- Fix: opt-in for NVN (
DM_NVN_UPLOAD_IDLE_MS, default0on all platforms). At the start of a submission, completed slots idle for the interval drop both blocks and their cached demand. An active slot drops an unused overflow block after the interval and sizes its next primary allocation by recent demand. Busy slots keep their buffers until upload completion. The host commits the removals before it encodes new uploads. Setting the switch explicitly, including to0, logs retained slot MiB, allocations and trims at startup, on the first trim, and every 30 seconds while submitting. - Found on: The Legend of Zelda: Ocarina of Time. The original PR reported 192 MiB retained with trimming off and 0 MiB at the 30-second samples with a 2,000 ms interval during five minutes on an M4 Pro Mac. Staging allocations rose from 19 to 46, and GPU p50 was 21–23 ms in both runs. The matched M5 iPad Pro test is pending.
- Check:
make -C dm/gfx/tests GAME=<id> check_t_upload_idlechecks retention by default and at explicit zero, pending uploads behind a GPU gate, overflow and primary trimming, residency removal, allocation size after trimming, and upload readback with Metal validation.
Two source buffers for each staged upload from a large pool
- Symptom: the first frame of a scene that draws hundreds of new packaged textures takes a quarter to half a second, nearly all of it in
submit+present([longframe] … texture uploads 855 first …, 908.5 MB), and theresidency set up to frameline of that window counts about twice as many shared buffers fromup_big_srcas packaged textures (2,866 and 1,433). - Cause: an upload from a pool no address was given out in, or from a large pool (
BIG_MIN), reads the texture's storage through a zero-copy buffer of the upload batch (up_big_src), which the batch makes resident and retires.pkg_upload_made that buffer, then took the texture's staging (up_alloc), which may flush the batch, and made a second buffer in case it had; it did that for every texture, flush or not. So each staged upload put its storage into the residency set twice, and the second copy was made, wired and committed for nothing. - Fix:
pkg_upload_makes the second buffer only whenup_allocbegan a new batch (g_up_seqmoved). - Found on: Nintendo Switch Sports Resort (
04008E001F098000, no profile yet), the first frame of the court behind the sport menu (855 textures, 908 MB) on an M2 Max, two 75 s runs each from the same save and pipeline state: the residency commits to frame 2,400 went from 678-692 ms to 520-523 ms, the shared buffers added in that window from 2,852-2,858 (3.0 GB) to 1,429-1,437 (1.6 GB), that frame from 263-270 ms to 243-251 ms and the next load's (340 textures, 188 MB) from 155-157 ms to 134-138 ms. Most of what is left of it is the residency set taking the new textures and their staging (about 0.12 ms and 0.05 ms per MB, measured per commit), memory a first use has to allocate. - Check:
make -C dm/gfx/tests GAME=<id> check_t_upload_src: eight textures in one batch make eight source buffers (sixteen before), and three 64 MB ones whose staging splits the batches make one more for the texture that flushed its batch (six before); every texel is compared with the CPU reference, under Metal validation.
Residency changes waited for another thread's commit
- Symptom: in a frame that makes many new textures (a scene's first),
res_addon the submit thread takes tens of milliseconds in all, a few milliseconds at a time, though each is a hash-table insert. - Cause:
res_commitheldg_res_mu, the lock everyres_addandres_removetakes, for the whole[MTLResidencySet commit], and the encode thread (nvn_rec.h) held it for each queue commit. A commit that adds memory takes about 0.04 ms per MB while the GPU is busy (well under a millisecond on an idle one), and the upload batches' completion handlers commit their staging's removal on their own threads. So the submit thread, adding the next textures, waited for those commits. - Fix:
res_addandres_removeonly queue the change, with a reference to its allocation, underg_res_mu;res_committakes the queue and applies and commits it underg_res_commit_mu, which nothing takes insideg_res_mu. Ares_commitreturns once every change queued before it is committed, also one another thread's commit took (that commit holdsg_res_commit_muuntil it is done), and a removed allocation stays alive until the commit that takes it out of the set. The queue commits that heldg_res_muto stay apart from the set's commit (the present snapshot's, and the encode thread's for every command buffer) holdg_res_commit_mu. - Found on: Nintendo Switch Sports Resort (
04008E001F098000, no profile yet), the court's first frame (855 textures, 908 MB) on an M2 Max, with Two source buffers for each staged upload from a large pool fixed: the submit thread'sres_addcalls in that frame went from 42-56 ms in all (the longest 8.8-10.5 ms) to 1.5-1.7 ms (0.08-0.13 ms), and the frame from 242-263 ms to 224-232 ms (two 75 s runs each from the same state). What is left of the frame is mostly the commits themselves (about 150 ms on the submit thread: the textures, their staging and their source buffers made resident while the GPU runs). - Check:
make -C dm/gfx/tests GAME=<id> check_t_res_commit: 200res_add/res_removewhile another thread holds a commit for 100 ms take under a millisecond, and ares_committhen waits for that commit and commits its own changes; a change another thread's commit took is in the set whenres_commitreturns (50 racing rounds); a removed buffer stays alive until its removal is committed, then goes.
Upload retirement can block Metal 4 feedback
- Symptom: a slow residency commit delays the Metal 4 feedback callbacks queued behind an upload. The new diagnostics report completed calls of 100 ms or more as
[RED] slow residency commit:or[RED] slow queue commit:. - Cause: all feedback callbacks share one serial queue (
g_feedback_q). Upload retirement calledres_commiton that queue. It could hold the queue while applying residency changes or waiting forg_res_commit_mu, which the encode thread also takes for queue commits. Feedback-dependent fence and present completions could be delayed. The shared-event fast path can still wake a game SyncWait. - Fix: once Metal reports the upload complete, feedback hands temporary staging to the serial residency worker. The worker queues and commits those removals under one acquisition of
g_res_commit_muand drops the references before clearing the upload slot and decrementingg_up_pending. The three slots still bound staging in flight. A batch with only reusable slot blocks completes in the handler. Host finish and drain wait for pending uploads. GuestnvnQueueFinishkeeps its per-queue GPU wait. External-texture retirement in GL and Vulkan still uses the present feedback path. - Diagnostics:
CLOCK_UPTIME_RAWtimes the main residency set's queued additions, removals and commit, and the Metal 4 queue commits for main command buffers, uploads and snapshot copies in both encoder modes. Timing excludes the lock wait. Logs run outside the commit lock and report what changed or the call site, the thread, and whether it was on the feedback queue. Each kind logs its first 20 slow calls and every 100th thereafter. - Found on: kencalx reported an Ocarina of Time freeze on an iPhone 18 Pro Max in the NX18 fork. A feedback stall was one hypothesis. The freeze's cause remains open.
- Check:
make -C dm/gfx/tests GAME=<id> check_t_res_commitholds the commit lock across real upload feedback. A later callback and an upload with no temporary staging complete while the retiring batch keeps its staging and slot. Releasing the lock lets the worker retire staging and complete that batch. The fixture also checks commit logging and sampling with a lowered threshold.
Per-frame arena blocks made for every submission in flight
- Symptom: graphics memory stays above the earlier steady state after frame-wide command allocator sharing, with many mostly empty 4 MB arena blocks retained.
- Cause: each submission took 4 MB blocks of its own for its argument tables, uniform copies and other scratch (
arena_alloc), held them until the GPU completed it and kept them for the rest of the run; only blocks above 32 MB (ARENA_KEEP) went once idle. So the blocks followed the submissions in flight, not the bytes. Since the submissions of a frame share a command allocator (PR #2090,ALLOC_SHARE), the submit thread no longer waits for one of 8 allocators and up toPOST_RINGsubmissions can be in flight. The extra blocks can remain in use, so idle retirement alone does not address the amplification. - Fix: every NVN game (
arena_begin,arena_commit,arena_triminnvn_mtl.m). A submission goes on in the block the one before it ended in while that has room (g_arena_next). The block's fence becomes the later submission's, so it is reused only once the GPU has completed every submission that wrote it, and the blocks follow the bytes in flight. A new block is taken from those the GPU is done with, the smallest that fits and of those the one used last, so blocks a peak made stay unused. Those above 4 blocks (ARENA_KEEP_BLOCKS) that no submission has used for 600 submissions (ARENA_IDLE) leave the residency set and are freed at a submission's start. A block a pending submission wrote (its fence aboveg_done) or the one the submission being encoded writes is never released. The memory line givesper-frame arena blocks created N in total (alive N, M MB; released when idle N, M MB in total).DM_NVN_ARENA_SHARE=0takes blocks per submission andDM_NVN_ARENA_TRIM=0keeps ordinary blocks, as before; the existing retirement of idle blocks above 32 MB still runs. Release totals include both sizes. Shader argument caches borrow their buffers from the arena instead of retaining them after their pass, so a shader no longer drawn cannot pin retired scratch. Allocation addresses continue to use current main'sarena_takecontract: An argument block points into another arena after a nested allocation. - Found on: NieR:Automata, originally reported by kencalx in NX18 and ported in PR #2862. The game note separates the fork measurements from the current-main comparison. On Apple M4 Pro, macOS 27.2.1, the allocator tests pass in all four modes (25, 25, 22 and 20 checks), and the existing argument-generation tests pass 42 checks. No iPhone run.
- Check:
make -C dm/gfx/tests GAME=<id> check_t_arena_trim, with the encode thread off and on,DM_NVN_ARENA_TRIM=0andDM_NVN_ARENA_SHARE=0, with Metal validation. A zero-age trim exercises the completion guard while 24 blocks are pending; after completion and 604 small submissions the pool falls to four blocks, releasing 80 MB. Shared writers preserve their own bytes, and a filled block whose first writer has completed cannot be reset while its last writer remains gated. A current submission's block remains resident during a trim. A retired block above 32 MB is counted in release totals and its weak reference clears even with its shader cache still alive. The address-rollover regressions stay int_args_gen.
GPU readback without an autorelease pool
- Symptom: GPU memory grows with repeated
nvnTextureReadTexelscalls on a long-lived game thread, even after each readback completes. - Cause: the GPU path in
mtl_read_texelsruns outside a submission's autorelease pool. Metal's temporary command buffer and blit encoder keep the readback buffer alive in the calling thread's undrained pool. - Fix:
mtl_read_texelsencloses texture resolution, readback encoding, the GPU wait and the CPU copy in its own@autoreleasepool. The guest-memory path needs no Metal objects. - Found on: The Legend of Zelda: Breath of the Wild, measured upstream in MacNativeGames commit
635fb31and ported in PR #195: about 130 readbacks a second retained 3.7 GB of GPU memory after 30 minutes. Those game measurements have not been repeated here. - Check:
make -C dm/gfx/tests GAME=010015100B514000 check_t_readbackchecks literal GPU and CPU readback pixels and observes the real readback buffer through a weak reference while the caller's outer pool remains open. Removing only the local pool leaves that buffer alive and fails the lifetime check.
Completion readbacks survive a guest waiter's pool
- Symptom: process footprint and Metal allocation grow during stationary gameplay even after readback fences complete; the deferred-release queue and command allocator sizes remain bounded.
- Cause:
post_runcan execute on a long-lived guest waiter through the GPU-event fast-wake path, not only on Metal's feedback thread.MTLBuffer.contentsreturns an interior pointer (NS_RETURNS_INNER_POINTER), whose receiver may be retained and autoreleased by ARC. Explicit CF readback/visibility ownership is balanced, but those temporary receiver lifetimes escape into the guest thread's undrained outer pool. A submission's pool or a later callback on another thread cannot drain it. - Fix: give the shared
post_runbody its own autorelease pool, ending after its mutex unlock. Guest-storage writes, event effects and existing GPU retirement fences keep their order. This caller drains its temporary completion objects before returning; this is not a new global drain-before-completion synchronization guarantee. - Check:
make -C dm/gfx/tests GAME=<id> check_t_readback(store_completion) gates real GPU feedback and exercises bothDM_NVN_FAST_WAKE=1guest-owned completion and0callback-owned completion, with the guest waiter's outer pool open throughout. It checks literal copied pixels in the storage and event visibility at a successful wait, and delayed-feedback idempotence. Its buffer-lifetime assertion went with the readback into storage (2026-11-10, now stored on the GPU), whose landed buffer it watched; the pool still covers the visibility bufferspost_runreads, which no test watches. - Found on: Tears of the Kingdom, M2 Pro stationary cave route. A bounded paired diagnostic on chain
d1043b780a74showed footprint growth of 617 MiB over about 86 seconds without the pool versus 1 MiB over about 83 seconds with it. This is route-local memory evidence, not an FPS improvement, complete allocation census or verified fix for an iPhone termination.
A pipeline archive on an external drive is read into memory
- Symptom:
footprintshowsMalloc Largeabout the size ofpso_archive/(the log'spipeline archive …: N files, … MB), resident or swapped for the whole run.MallocStackLogging=1withmalloc_history <pid> -allBySizegivesnewArchiveWithURL→MTL4ArchiveImpl::loadFromURL→LoaderGlobalState::loadFile→-[NSData initWithContentsOfFile:options:maxLength:error:]→ malloc. - Cause: where the file is. Metal loads each archive through
NSDatawithNSDataReadingMappedIfSafe, and Foundation counts a file on an external APFS drive on USB (Removable Media: Fixed) as unsafe to map: it reads the whole file into allocated memory. On the internal disk it maps the file.newArchiveWithURL:error:takes only a URL. - Fix:
arch_open_begininnvn_mtl.m, for every game: while the host opens its archives (one window around every open, the archive bundled with the app,Resources/pso/<gpu>.mtl4a, and the device'spso_archive/), it replaces thatNSDatamethod's implementation, and a read of a.mtl4aasks forNSDataReadingMappedAlways. It is a private method, so a system without it reads the files as before. A workaround of the framework's choice, as no public call offers one. The game already runs from that drive, so a drive pulled out ends the run either way. Mapped files are clean pages the system can drop, and they do not count in the footprint. - Check: a 133 MB archive on the external drive: footprint +129 MB without it, +2 MB with it. Ocarina of Time on its walk with a 3.5 GB archive: footprint 15.0 → 11.8 GB, peak 16.7 → 12.8 GB,
Malloc Large3.5 GB → 59 MB, opening 4.6 → 3.0 s. Long frames did not change. The bundled archive first opened before the window, so an app on an external drive still read it whole: Ocarina of Time, app on an external SSD, same save and scene, footprint 19.0 → 12.2 GB,Malloc Large5,032 → 135 MB (one 4.8 GBNSData), 60 fps either way (GitHub PR #1817). - Found on: Kirby Star Allies: the same stage route gave a footprint of 5,109 MB with its 1.13 GB archive on the external drive and 4,013 MB on the internal disk. The Legend of Zelda: Ocarina of Time. iOS was not measured; its files are on the internal disk.
Pipeline archives exhaust a restricted task map
- Symptom: a save load aborts in
pthread_createor a hostreallocwith the footprint far below the memory limit; turning off Metal 4 pipelines lets the save load. The crash's address-space census, rather than the footprint alone, distinguishes this from the physical-memory limit. - Cause: Metal maps each pipeline archive whole and keeps it open for the run. Bundled pair and prewarm archives and the device's own files were all opened without reserving address space for later shader caches, CPU-visible GPU buffers, malloc and stacks. Guest files reduce charged memory but keep the same guest reservation. A task without extended virtual addressing can therefore run out of room for allocations while clean archive pages contribute little to its footprint. Disabling Metal 4 also disables bases and prebuild, so that A/B alone does not isolate the archive mappings from the rest of that path.
- Fix:
arch_planinnvn_mtl.msnapshots the three archive sources before any open.arch_admitsums the validated files' page-rounded sizes (obsolete device indexes are excluded) and scans the task's actual bounds and top-level occupied regions, including reservations and submaps. The entire set and a 2 GiB runtime reserve must fit in the largest free gap; using one gap is conservative about fragmentation and simultaneous opens. The reserve is a host policy estimated from a Mac census's roughly 1.8 GiB of non-guest, non-archive mappings, not a measured minimum for every phone. An unreadable map or an insufficient gap selects the existing MTLDevice path before creating a compiler, opening an archive or starting prebuild/capture; hybrid pipelines are off too. Valid files and prebuild stamps stay in place. Thearchive admissionline records the file bytes, total free space, largest gap, reserve and decision. This is independent of the guest-file memory decision. - Check:
dm/gfx/tests/t_pso_admission.mdrives the real initialization and render/compute fallback with synthetic task maps: aggregate size across all three sources, sufficient total space fragmented into smaller gaps, an empty cache on a tight map, failed task/region queries, an exact fit and ample space, plus the Mac's real map. It checks that rejection never opens an archive or compiler, skips prebuild/hybrids and preserves valid files and stamps.t_pso_bundleandt_pso_archivecover usable archives and the existing reuse/fallback paths. Phone save-load validation remains open. - Found on: Breath of the Wild, issue #2444. The exact introducing commit has not been bisected.
Shader library mappings exhaust a restricted task map
- Symptom: startup's
Preparing shadersaborts after manyfailed to load shader ... mmap failedlines, or an on-demand render-pipeline allocation later aborts withNSMallocException, despite a low physical footprint. Turning off Metal 4 and pipeline prebuild does not disable manifest prewarm;DM_PSO_MANIFEST=offskips startup's list but the reported game still aborted after about 27 minutes. - Cause:
lib_from_fileclosed each loose library's descriptor but handed Metal dispatch data backed by its file mapping, withmunmapdeferred to the data's destruction. Metal retains that input while its library/functions need it, so each distinct input needed a persistent file mapping. Entries in the packed shader image had the same ownership. New mappings require free VM gaps, even when malloc can still allocate from arenas it already manages; a low physical footprint does not establish that another mapping fits. The host tied long-lived compiler input to the file-mapping lifetime instead of giving it allocator-owned storage. - Fix: root-cause fix, general
hostbinding (nvn_mtl.m):lib_from_mapgives Metal owned dispatch data and releases the temporary mapping before entering Metal, for loose and packed libraries alike. Prompt descriptor closure and the digest of the original bytes remain. Prewarm still processes its complete lists: no new row cap, VA cutoff, game setting or cache eviction policy. Existing pipeline-archive admission is unchanged. - Check:
t_library_dataretains every input data object in a synthetic device. It loads 128 libraries with a mapping budget that fits only one source, verifies that the source mapping and loose descriptor are gone before the device call, and checks exact bytes after source deletion, content digests, packed-image offsets, a failed Metal load andENOMEMfrom the source map. A separate real-Metal constrained-VA A/B reserves only free gaps in its own process, leaving 32 MiB for new mappings: the former loader fails withENOMEM; the owned-data loader completes the same library set. The game note records inputs, counts and memory costs. This establishes the loading mechanism on the Mac, not complete resolution on the affected iPhone. - Platform reservations: a minimal C process without nxnative has the same 385 GiB guard total on Apple Silicon: 1 GiB at the commpage and 384 GiB in the GPU carveout. Apple's published XNU VM layout describes those ranges. We should leave them alone. An aggregate phone census does not establish the provenance of every untagged reservation.
- Cost and open validation: owned input increases charged memory compared with reclaimable file pages. Total shader/pipeline cache growth is not newly bounded. Retest the reporter's large startup list and sustained play beyond the prior abort, recording VA and physical-memory headroom; do not claim that both phone failures are resolved from the Mac stress test. No shader-chain change is needed.
- Found on: Tears of the Kingdom, issue #2965. Its note records the reported build, device and crash counts; no patched-phone run is claimed.
Packaged-texture edge snapshot copied into a null allocation
- Symptom:
CRASH sig=11 addr=0 pc=_platform_memmove+… lr=pkg_edges_take+…during gameplay on a tight iOS task map (footprinted headroom still > 1 GB, largest free VA gap ~0–10 MB). A companion run on the same build aborts on_pthread_wqthreadwith uncaughtstd::bad_allocinside<redacted>Apple framework frames. - Cause:
pkg_edges_take(nvn_mtl.m) allocated optional edge-page comparison snapshots withmalloc(or wrote intopk->eb.contents) and calledmemcpywithout checking forNULL. Under VA exhaustion,malloc(0x3000)for edge 1 failed after edge 0 succeeded, dereferencingNULLimmediately; clearing only edge 1 would also leavepkg_edges_cleancomparing only edge 0 and falsely skipping real CPU writes into edge 1. Separately,crash_offandhle_thread.cprinted bare<redacted>+0x…for stripped iOS framework frames,dm_vm_censusrounded free gaps to%.2f GBwithout listing the largestfile/ non-guardotherregions, and neither heap edge snapshots norlib_from_map's owned shader-library copies were counted in the periodic memory log. - Fix: general (
host,nvn_mtl.m,nvn_obj.h,hle_nvn.c,crash.c,hle_thread.c,memstat.m). (1)pkg_edges_takechecks both themallocdestination andpk->eb.contents/length; on failure it records the failed count and bytes, logs once (RED_ONCE), and callspkg_edges_drop(pk)so any partial edge 0 is freed andpkg_edges_cleanreturns0(conservative re-upload path). (2) Heap edge-snapshot live count/bytes/peak andlib_from_mapowned shader-library count/bytes/failures are tracked atomically and reported in the periodic[nvn] packaged texturesand[nvn-mtl] memorylines;crash_offand the host-thread dump preserve<image>+<offset>(<raw_pc>)whendladdrreturns<redacted>or no symbol name;dm_vm_censusprints sub-GB free gaps in MB/KB/B and lists per-class region counts plus the four largestfileand non-guardotherregions. - Check:
t_pkg_edges_oom(50 checks: happy path, edge-1 OOM freeing edge 0 and preserving conservative fallback, edge-0 OOM, null/undersizedpk->eb,pkg_edges_gpuownership transfer,NvPkgdealloc),t_library_data(658 checks including owned-data accounting),t_crash_diag(12 checks: redacted/unnamed image+offset formatting and VM census output),t_nvn, andcheck_t_readback(335 cases with Metal API validation). This fixes the unchecked-NULL crash inpkg_edges_takeand closes the diagnostic gaps; the root cause of the underlying iOS VA exhaustion remains open pending iPhone retest. - Found on: Tears of the Kingdom, issue #3240.
Pool tables and readback buffers made anew each frame
- Symptom: the periodic
residency set up to frameline shows hundreds of allocations added and removed per 300 frames in a scene where nothing loads: Ocarina of Time, 1,500 (pool_gpu900 of 180 KB,mrbuf_get600 of 0.5 MB), and 650 commits. - Cause: a replaced pool table was released and a new buffer made, about 3 a frame. The readback cache turned a buffer away when it was full (16 buffers or 16 MB) and never evicted, so once it held other sizes every readback of a new size was a new buffer.
- Fix:
pool_table_takeandpool_table_giveinnvn_mtl.m, for every game. A replaced table is kept with the fence of the submission that may read it, which the last segment's completion covers, and reused at the same size (rounded up to 64 KB) once that has passed.mrbuf_putevicts its oldest buffers to make room. A walk also skips an ID whose texture type it has seen and which is not the table's (tt1), so that ID is neither looked up nor charged to the budget. The idea of reusing tables and skipping by type comes from PR 1428. - Check:
make -C dm/gfx/tests GAME=<id> check_t_feedback(reuse_tables_case). Ocarina of Time: 11 tables made and 18,990 reused in 11,700 frames; residency per 300 frames, added 1,506 to 6, commits 654 to 12, and 47 to 0.4 ms. Long frames did not change from this alone. Thepool walkline reports the counts. - Found on: The Legend of Zelda: Ocarina of Time.
A texture in a sparse pool came out CPU-written at its first use
- Symptom: with a profile that has
tex_dirty_upload, a texture in a sparse pool that the game draws into or writes as an image logsCPU-written texture ser=…at its first use, and takes its content from its storage.t_sparse_tilescrashed atand unmapped, not drawn: its heap tile goes backwhen built with such a profile, and passed with one without the key. - Cause:
ft_addlisted it for later uploads. A sparse pool's addresses are no rangenvn_dirtytracks, and an untracked range counts as written, sonvn_ft_writtenfound it written at its first use. The list exists for memory the CPU writes, which those addresses are not. - Fix:
ft_addinhle_nvn.c, for every game: a texture in a sparse pool is not listed. What the CPU writes to the physical pages behind one is seen through the page table (sparse textures). A virtual pool aliased onto one physical pool has no sparse state and stays listed. - Check:
make -C dm/gfx/tests GAME=0100F2C0115B6000 check_t_sparse_tilespasses under both kinds of profile. No game was seen drawing wrong from this. - Found on: the unit test, on Tears of the Kingdom's and Ocarina of Time's profiles. Monster Hunter Rise is the other game with the key and a sparse pool.
iOS ends the app once the guest's touched pages reach its memory limit
- Symptom: on an iPhone the app is ended by the system (a jetsam event: no crash report, no
[dm] CRASHline) once its footprint reaches the limit: about 6 GB on a 12 GB iPhone with the increased memory limit (6,143 MiB measured in LiveContainer), 3.3 GB without it. The log stops mid-frame. - Cause: every guest page the game has touched is anonymous memory:
phys_footprintcharges it, and iOS cannot write it out as a Mac swaps it. What the game gives back is charged again as soon as it maps the range anew. - Fix: the guest block in sparse files, unlinked at once, mapped shared over the reservation at the same addresses (
hle_svc.c;DM_GUEST_FILE_DIR, which the iOS app sets toNSTemporaryDirectory()). File pages take the same memory while they stay in it, but they are out of the footprint and the kernel writes them out when it needs the room. The cost is disk (Mario Kart World on a 16 GB Mac: 5.6 GB on disk and 8-10 GB of logical writes in 5.5 minutes), so a game that fits stays anonymous: on iOS the files are on when the game's memory pool and half of it again, for the host's own memory, are larger thanos_proc_available_memory()at start (The guest stayed anonymous when its pool fitted the room but the host's memory did not), and the log's[mem] guest memoryline gives all three; on the Mac only withDM_GUEST_FILE=1, and0keeps them off anywhere. A game whose memory is mostly outside the block is not helped: Unreal's heap is a host malloc zone (Thread stacks from the host's Unreal heap). The files are 1 GB each (DM_GUEST_FILE_CHUNK), since the stall at the system's periodic flush, about every 30 s, grows with the file (on a 16 GB M5 Mac, with 1 GB touched, up to 148 ms with one 20 GB file, 4 ms with 20 files of 1 GB).guest_releasemakes a range the game gives backPROT_NONEthere, since a fresh anonymous mapping would bring it back into the footprint, and its disk blocks are punched out (Guest files keep the blocks of memory the game gave back); a page that keeps its bytes is zeroed byalias_initializeandSetHeapSizewhen it is opened again, leaving the 4 KB pages that already read 0.DM_GUEST_FILE_MIN_FREE(default 2 GB of room after the dirty pages, the same entry) stops the game (exit code 87) before the disk fills; under it at start the guest stays anonymous, and on the Mac, which can swap, under that plus 8 GB.make -C dm/host/tests memory-fileruns the memory SVC tests with the guest in files. - Found on: Mario Kart World 1.0.0 in handheld mode, on the switch2ios fork (a 12 GB iPhone, iOS 27.3, LiveContainer's 6,143 MiB limit; host from nxnative
8c0b8083with that fork's changes): ended at 90 s with the guest anonymous; with one file, 7 min 33 s played, peak 5.56 GiB; with 1 GB files (and a larger texture view cache), a 14-minute session held, peak 5,663 MB, no 30-s stall left. On a 16 GB Mac the peak footprint fell from 11.6 GiB to 5.6. On this host (975bb4c1with this switch, 1 GB files, a larger texture view cache and the profile's map limit), a 16 GB M5 Mac with the iPhone's settings peaked at 4,365 and 4,792 MiB over an 18- and a 30-minute session, and the same build plays on the 12 GB iPhone. On iPhones with an 8 GiB limit (#1184), where the game was ended at course load, or 30 s in at 8.1 GB, the fork's version of this switch merged by hand let it finish races: 4.41 GB at most over 13 minutes and two races on an iPhone 18 Pro with 512 MB files. Those phone runs also had a larger texture view cache (DM_NVN_VC_WAYS=64), which is not on main.
The guest stayed anonymous when its pool fitted the room but the host's memory did not
- Symptom: on an iPad (12 GB limit) the log's start line says
[mem] guest memory: memory pool 9.00 GB, room to the memory limit 11.97 GB, DM_GUEST_FILE unset: anonymous, the footprint climbs over a long session (8.14 GB at 186 s, 10.64 at 1,255 s, 11.94 at 1,711 s), thememory limit … MBlines' room falls under 100 MB, and the log stops mid-line: a jetsam kill. The same game with the guest in files stays near 4.2 GB on an 8 GB iPhone. - Cause: the rule compared only the game's memory pool with the room to the memory limit at start, which the host reads before the game runs. The host's own memory grows beside the guest's pages and comes out of the same room: mostly Metal's copies of the game's textures (Metal cannot sample the guest's block-linear storage), render targets and upload staging. The
[nvn-mtl] memoryline's "GPU allocated" (6.1 → 9.5 GB in that session) does not measure it: Metal's allocated size counts the zero-copy buffers over the guest's own pools too (Finalized pool buffers kept by a guest thread's autorelease pool). - Fix: general (
hle_svc.c,guest_host_margin): the guest goes in files when the pool and a margin of half the pool do not fit the room, and the start line names the margin. What has to fit is the guest's touched pages and the host's own memory together. Measured against the pool on a 16 GB M6 Mac, about 5 minutes each, the guest in files so that the footprint is the host's own (DM_MEMSTAT: footprint less the guest class; the guest's resident pages beside it): The Binding of Isaac 0.21 (host 0.41 GB of a 3.21 GB pool), Mario Golf: Super Rush 1.23 (host 3.22 GB, as much as its pool, 21,514 textures; guest 0.72 GB), Fast Fusion at least 0.77 (host 4.90 GB of 9; guest 2.05), Ocarina of Time about 1.24 (host 5.39 GB at an area load and 4.3–4.8 walking, guest 6.4 GB on that walk), and Mario Kart World at least 1.33 (11.94 GB on the iPad). The host's own share alone runs from a tenth of the pool to all of it, so no smaller margin on the host alone would hold. With half the pool every 9 GB pool goes in files on iOS, and a Switch game's 3.21 GB pool stays anonymous with 6 and 8 GB limits (4.8 GB against about 5.7 and 7.97 of room).DM_GUEST_FILE_HOST=<size>sets the margin (0: the rule before it).DM_MEMSTATandDM_THRCPUnow start from the host's loading rather than a constructor, soDocuments/env.txtturns them on on iOS. - Check:
t_svc_memory(file_rule, undermake -C dm/host/tests memory memory-file): a 9 GB pool goes in files with 11.97 GB of room and did not without the margin; a 3.21 GB pool stays anonymous with 7.97 and 5.8 GB; the switch andDM_GUEST_FILE_HOSToverride it. - Found on: Mario Kart World base v0 on an iPad mini (A20 Pro, iOS 27.2) at
865cc35f(#1184); the measurements on The Binding of Isaac: Rebirth, Mario Golf: Super Rush, Fast Fusion and The Legend of Zelda: Ocarina of Time. Not yet run on the iPad with the margin.
Guest files keep the blocks of memory the game gave back
- Symptom: with the guest in files on an iPad,
[RED] [mem] guest file: 5.0 GB free on its disk, under 5.0: stopping the gameafter a few minutes of play. The files held 6.6 GB on disk (allocated on diskin the[mem] guest fileline) while the heap was 6.2 GB and the alias region had 2.5 GB mapped, though mapped up to +3.8 GB. The disk's free space went from 12.0 to 5.0 GB, almost all of it the files. - Cause: two. (1) What the game gave back only went
PROT_NONE(guest_release): its pages kept their disk blocks for the rest of the run, and a range mapped again elsewhere took new ones. (2) The stop rule readf_bavailalone, which leaves out what the system can purge, against a 5 GB margin far larger than what the files could still take. iOS writes dirty file pages out within seconds of the game touching them (the iPad's files went from 0 to 4 GB on disk in 10 s), so on iOS the files' size follows what the game touches. The Mac writes nothing back unless it needs the room (0 GB allocated after 30 minutes). - Fix: general (
hle_svc.c).guest_file_punchgives a range's blocks back withF_PUNCHHOLE. Over a mapping that also drops the pages, written out or still dirty, and they read 0 again. A wired page, under a Metal no-copy buffer the GPU still holds, keeps its bytes, so ranges are still zeroed when opened again. The heap's given-back ranges are punched at once. The alias region's are only marked: the game unmaps and maps about 0.5 GB of the same ranges a second (Ocarina of Time), and punching those at once makes every page fault back in from a hole. A sweep every 10 s (guest_file_sweep, under the map lock) punches the pages still given back after a whole interval.DM_GUEST_FILE_PUNCH=0keeps the blocks. The stop rule counts the room: free space less the files' dirty pages, counted every 10 s withmincoreover what the game has opened (about 20 ms a gigabyte of address space;SEEK_DATAcannot tell which dirty pages already have blocks, as APFS reports a file with dirty mapped pages as all data). The game stops underDM_GUEST_FILE_MIN_FREE, now 2 GB by default. Whenf_bavailalone is short, the free space with what the system can purge counts (kCFURLVolumeAvailableCapacityForImportantUsageKey, at most every 10 s, as the query goes to a system service), as long asf_bavailkeeps half the minimum, since the system purges only as the disk fills. The 10-s line adds the dirty bytes, what was given back as holes and the purgeable figure.DM_GUEST_FILE_SCAN=1adds the dirty pages by region and how many of them read all 0.t_svc_memory(file_sweep, undermake -C dm/host/tests memory-file) checks that the sweep punches only pages given back over a whole interval and that they read 0 when mapped again. - Why stop at all: a full disk is worse. Measured on the Mac with a 300 MB APFS image and 600 MB of a shared file mapping written,
msyncreturns 0 with 291 MB written, the other 309 MB stay dirty in memory for good (mincore), and every other write to the disk fails withENOSPC. On a phone that is memory taken from everything else until something is killed, and saves, the shader cache and the system's own writes fail. - Result on Ocarina of Time, 5 minutes on an M4 Pro Mac, where the dirty bytes are what the files would hold on an iPad: 7.80 GB without punching, 5.98 GB with the sweep (1.84 GB given back as holes; the alias region's dirty pages 4.56 → 2.87 GB). Punching at once gave 6.32 GB, with 87 GB punched in 3 minutes. Frame time and CPU were the same with the sweep (p50 about 21 ms, GPU-bound). The game's own zeroing leaves about 770 MB of dirty heap pages that read all 0. Punching those would need the write tracker's help (a write between the check and the punch would be lost), so it is not done.
- Open, a GPU hang reported elsewhere: S2Arm, another project running Switch games on Apple hardware, saw Metal report
kIOGPUCommandBufferCallbackErrorHangin 6 of 6 runs of Ocarina of Time on an M1 Pro (16 GB, macOS 27.0.1) when it punched its guest files during play, either each unmapped range in one call or 16 KB at a time from a background thread (S2Arm #258, #305). The punching thread sat infcntl(F_PUNCHHOLE)while Metal's submission thread waited inIOGPUCommandQueueSubmitCommandBuffers, and a 1-s pause after each large unmap made it go away; it now never punches. Not reproduced here (M4 Pro, 48 GB, macOS 27.2, Ocarina of Time idle on the Kokiri Forest deck save, 8 minutes a run). A probe wrote, fsynced and punched 16 MB of alias-region pages the game had not mapped, in the files it uses, every cycle: 36.5 GB in 2.39 million 16 KB punches in one run and 49 GB in 140,000 whole-run punches in another, with no command buffer error. Four runs with the sweep itself had none either, though the game gave memory back only while loading. Under the map lock the probe's 16 KB punches took up to 784 ms a cycle and whole runs up to 53 ms; the sweep punches runs (16–80 ms a sweep, once 162 ms for one 0.7 MB punch). Frames over 1 s came with and without punching. What may differ: the machine and the OS, and that S2Arm's hanging versions punched ranges the moment they were unmapped, where the sweep punches only pages given back a whole interval earlier (the heap's are punched at once). Not run on an iPad or an M1-class Mac;DM_GUEST_FILE_PUNCH=0turns punching off. - Found on: The Legend of Zelda: Ocarina of Time on an iPad Pro (M5, iOS 27, 12.5 GB of guest files). The stop rule and the sweep have not run on an iPad yet. The GPU hang above was reported by S2Arm.
The guest-file watcher could start before guest memory was ready
- Symptom: a startup sweep can read a null alias bitmap in
guest_file_sweep. The watcher's earlier dirty-page scan can also read the guest memory layout before initialization finishes. - Cause:
guest_file_initstarted the watcher after mapping the files, beforemem_init_onceset the heap, stack, and alias ranges and allocated the alias bitmaps. Thread creation only publishes writes that precede it. - Fix:
mem_init_oncecreates the watcher after setting the layout and allocating the bitmaps, and only after file mapping succeeds. Thread creation publishes the initialized state to both watcher paths. - Found on: a Mac, using the startup-order test in
t_svc_memoryand a forced sweep between bitmap allocations. The original null read was reported on NX18's trim path. PR #2870
The residency commit froze over the guest's files
- Symptom: with the guest's memory in files, the game stops presenting for good while sound plays on: a black screen, or the last picture held. A
DM_CTLdumpshows the encode thread in the kernel underres_commit ← gmem_map(iokit_user_client_traporIOGPUResourceGroupUpdateResources), the main fence completed, and at times guest threads at the same guest instruction, loads and stores, dump after dump. On the M1 iPad, Ocarina of Time froze at the title movie (frame 1614) in one run and walking in Link's house (frame ~4755) in another, with 7.6 GB of headroom and 1.6 GB resident: not memory pressure. The app cannot be started again until the device restarts. - Cause: a residency commit wires the pages of each buffer it adds, and pages a file in from the GPU driver's own wiring path (
IOGPUSysMemory::wire → IOGeneralMemoryDescriptor::wireVirtual → apfs_vnop_pagein). A sysdiagnose spindump during the freeze showed that page-in blocked on an APFSkrwlockowned by alaunchdbackground-I/O thread insync() → ubc_msync, itself blocked waiting on a busy page (kThreadWaitPageBusy). Raw pool table pools are added in groups, so a commit can page in hundreds of MB of file at once. - Fix: workaround for an Apple kernel / APFS / IOGPUFamily lock-ordering defect, general in the host (
nvn_mtl.mfile_wire_prep/file_wire_record/file_unwire): a shared buffer whose pages are file-backed (vm_region_recurse_64reports an external pager) is wired withmlockoutsideg_res_mubefore it joins the residency queue, so the pages come in through the ordinary CPU fault path and the commit finds them resident without stalling concurrentres_add/res_removecallers; themlocks are given back right after the commit, which holds the pages for the GPU from then on. Anonymous memory and Metal's own buffers are not touched, so nothing changes with the guest anonymous (every Mac run by default). The residency line every 300 frames counts them:file-backed buffers wired before their commit <n>, <MB>, <ms> (refused <n>); a refusedmlocklogs a red line once and leaves the commit to page them in as before.t_file_wirechecks single, repeated, concurrent, and anonymous ranges. - Result on Ocarina of Time, the M1 iPad, the same route that froze twice: alive past frame 12,900 and two 32-minute Deku Tree runs, no red line; 20 fps in the house, headroom 5.3 GB, residency commits under 2 ms per 300 frames (PR #1971).
- Open, on a Mac with
DM_GUEST_FILE=1: the workaround covers the driver's wire only. Two reports on PR #1971 (16 GB M2 Air, macOS 27.0; 16 GB M4 mini, macOS 27.2) record the same unkillable freeze withDM_GUEST_FILE=1, including one case with no wire on the stack (tex_mtl_ → memmovefaulting on a guest-file page againstlaunchd'ssync() → ubc_msyncAPFS lock), plus 50–110 ms hitches on the 30 s sync grid. Guest files are on by default only on iOS; Mac runs opt in. - Found on: The Legend of Zelda: Ocarina of Time (v131072, 2026-11-08).
Shader-code pools wired by the raw pool table
- Symptom: on an 8 GB iPhone 17 running Ocarina of Time, hundreds of megabytes of shader-code pools stay resident and wired in the raw pool table, starving the guest's file-backed pages: 14–17 fps in Kokiri Forest, 117 ms average frames with 27 ms of GPU, and 6,000–15,600 page-ins every 10 s.
- Cause: the game calls
nvnMemoryPoolGetBufferAddresson eachNVN_MEMORY_POOL_FLAGS_SHADER_CODEpool to pass program addresses tonvnProgramSetShaders. That marked all 223 shader-code pools (317 MB) as addressed for raw global memory (gmem_map), making them resident and wiring their pages even though the GPU never reads guest shader code (shaders run translated offline and constants are copied into host buffers). - Fix: general (
hle_nvn.cnvnMemoryPoolGetBufferAddress): a non-virtual pool withNVN_MEMORY_POOL_FLAGS_SHADER_CODE(0x40) does not mark itself addressed when only its own pool base address is queried. Any buffer created in such a pool (nvnBufferInitialize) or pointer discovered at draw bind still admits it into the raw pool table.t_addr_knownchecks it. - Result on Ocarina of Time, iPhone 17 (8 GB, 30 fps cap, Dynamic resolution on, Kokiri Forest): 223 pools (317 MB) left out of the raw pool table; page-ins fell from 6,000–15,600 to 100–400 per 10 s, and Kokiri Forest rose from 14–17 fps to 27–30 fps (frame p50 36.5 ms, PR #1971).
- Found on: The Legend of Zelda: Ocarina of Time (v131072, 2026-11-09).
GPU-only render-target physical pool wired whole by texture addresses and small lookups
- Symptom: on an 8 GB iPhone 17 walking from Hyrule Field into Kakariko Village, Ocarina of Time's residency set reached 3.9 GB (wired memory 5.7 GB of 7.67 GB, 147 MB free).
DM_CTL restopshowed its 305 MB physical render-target pool (0x18c) wired whole in the residency set even though the GPU only reads its render targets through Metal textures. - Cause: two. (1) Ocarina places its render targets in
CPU_NO_ACCESSvirtual pools over that 305 MB physical pool and queriesnvnTextureGetTextureAddressandnvnMemoryPoolMapVirtual. Both marked the physical pool addressed for raw global memory (gmem_map), even though a block-linearCPU_NO_ACCESStexture's texels live exclusively in its Metal texture here and never in guest RAM. (2) Once removed fromgmem_map, one compute shader still bound a 200 KB storage buffer inside the 305 MB pool every frame, and becauseBIG_MINwas 512 MB, that lookup still created and wired a whole-pool buffer over all 305 MB. - Fix: general (
hle_nvn.c,nvn_obj.h,nvn_mtl.m): (1)nvnTextureGetTextureAddressdoes not admit a pool intogmem_mapfor a block-linear, non-buffer texture inCPU_NO_ACCESSstorage (tex_bytes_elsewhere), andnvnMemoryPoolMapVirtual(aliased mode) admits aCPU_NO_ACCESSvirtual pool only if a reachable address was already handed out (pool_t.asked). Linear textures, buffer textures,nvnBufferInitialize,nvnMemoryPoolGetBufferAddress, CPU-visible pools, and draw-time pointer scans still admit the pool. (2)BIG_MINis lowered from 512 MB to 256 MB so 256–511 MB pools wire only the 16 MB chunks lookups actually reach (~31 MB instead of 305 MB).t_gpu_only_addrandt_pool_chunkscheck both. - Result on Ocarina of Time, iPhone 17 (8 GB, Kakariko Village, PR #2566): cuts ~274 MB of wired memory on the 305 MB physical target pool (with the rest of PR #2566, residency set 3.5 → 3.1 GB, wired 5.3 → 4.9 GB, frame time unchanged).
- Found on: The Legend of Zelda: Ocarina of Time (v131072, 2026-11-13).
Idle uploaded textures, re-upload spares, and memory-pressure trims
- Symptom: on an 8 GB iPhone 17 walking across area transitions (Hyrule Field into Kakariko Village), Ocarina of Time accumulated 0.6–1.0 GB of Metal copies of uploaded textures from areas the player had left and up to 123 MB of re-upload spares, triggering OS memory-pressure warnings and
proc-thrashingtermination at 67 MB free / 5.56 GB wired whileos_proc_available_memorystill reported 2.7 GB. - Cause: on NVN, keeping an old area's texture objects costs nothing beyond their memory pool; on Metal each uploaded
NvPkgkeeps a separate resident GPU copy until finalized, each re-upload kept its replaced texture resident as a spare until finalization, and the host ignoredDISPATCH_SOURCE_TYPE_MEMORYPRESSUREnotifications while retaining waiting recycled render-target heaps and idle upload staging blocks. - Fix: general (
nvn_mtl.m,nvn_owner.h,nvn_owner.m,hle_hid.c): (1) listen toDISPATCH_SOURCE_TYPE_MEMORYPRESSURE(mem_pressure_start) and log system-wide free/wired/compressed/file-backed memory; at the next submission start (mem_trim, triggered at warn+critical on iOS and critical on macOS, or viaDM_NVN_MEM_PRESSURE/DM_CTL memtrim), free all waiting recycled render-target heaps (rh_trim_n), all packaged-texture spares (spare_trim), idle uploaded textures (pkg_evict_idle), idle upload-slot staging blocks, and completed deferred releases. (2)spare_trimretires re-upload spares idle for >3 s (checked every 250 ms) so one-off streamed re-uploads do not pin old copies indefinitely while per-frame movie re-uploads still reuse them. (3)pkg_evict_idleevicts Metal copies of uploadedNvPkgtextures unused for 30 s on the sharedg_tu_now/g_treg[].usedclock (never GPU-written/stored, not sparse, placed, view-bound, pinned, or held) viaown_drop_where_locked, marking their pool IDsevictedso pool walks leave theirpool_standstand-in or dummy until a shader reads or binds them again. On devices with Metal recommended working set< 6 GB(DM_NVN_TEX_EVICT_IDLEoverride),pkg_sweeprunspkg_evict_idleevery 10 s proactively without waiting for memory pressure. Checked byt_rt_recycle,t_pkg_spare,t_pkg_evict, andt_dead_targets. - Result on Ocarina of Time: 16 GB M4 (Hyrule Field route, PR #2270): two trims freed 481 textures (119 MB) and 577 textures (215 MB), residency set 3,487 → 3,163 MB; 8 GB iPhone 17 (Hyrule Field → Kakariko Village, PR #2566): freed 206 MB of old-area uploaded textures on transition with frame time unchanged.
- Found on: The Legend of Zelda: Ocarina of Time (v131072, 2026-11-11).
Memory pools nothing gave an address to stay out of the raw pool table
- Symptom: a Switch 2 game goes past Metal's recommended working set while its first 3D scene loads:
Insufficient Memorycommand buffer errors, then a hung Mac. Ocarina of Time on a 16 GB Mac: 12 GB and more wired, once a kernel panic inIOGPUGroupMemory.cppat 14.7 GB wired. - Cause: a shader that loads or stores through a pointer it read from memory may reach any pool (Global memory at an address loaded from memory), so the raw pool table listed every pool and made each resident. That wires the game's texture-only pools too, gigabytes the GPU reads only through Metal textures that hold their own copy.
- Fix: general (
nvn_mtl.mmtl_pool_addressed,gmem_map).nvnMemoryPoolGetBufferAddress,nvnBufferInitialize,nvnTextureGetTextureAddressand a virtual pool's mapping note their ranges, and the table lists only the pools that meet one. Pointers discovered when a draw is bound also admit their actual target pools: the game can derive a pointer without another address getter. A pool with no addressed range stays out, and a texture upload from it borrows a temporary no-copy buffer that the upload batch holds (up_big_src). Ocarina of Time before its first scene, with the original address filter: 2.9 GB wired against 5.3 GB. - Found on: The Legend of Zelda: Ocarina of Time.
Shaders report which textures they read through a pool
- Symptom: a game whose shaders read texture handles from memory wires far past the working set while a scene loads, with
Insufficient Memoryerrors or a panic, and stutters when new textures stream in. With a limit on how many it makes, surfaces in shadow go near black instead. - Cause: handles read from game memory may name any registered texture, and which ones is known only on the GPU, so the pool walk (
pool_gpu) had to make all of them. On a console that costs nothing: a handle is a number and the data is already in the pool. Here each is a Metal texture beside the pool's copy. Ocarina of Time registers about 33,000 IDs and reads about 300 of them, about 1 GB. The rest were made in case, or, under a budget, exactly the large ones the shaders read were left out, and read the dummy for good. Each upload also reads pages the system may have swapped out and wires them: one 300-frame window spent 8.6 s in residency commits. - Fix: general, in the chain and the host. A read of a texture pool sets the ID's bit in a bitmap (
dmsh_reflect.pypool_arrays,dm_pool_mark; its address in the table's head,DMSH_POOL_HEAD). The word is read first, with a plain load (an atomic one queues the pixels on one word), so nearly every read costs a load, not an atomic. The host folds the bitmap at each submission (pool_seen_scan) and makes those textures whatever the budget, up to 128 MB a frame. It also puts them into the existing tables in place, as a table can stand for a submission once walks have taken their 2 ms: dummy to texture is safe for a draw already encoded. Registering another texture at an ID clears its bit. A render target no pass has written is not made for a read: it holds nothing, and a pass makes it when it renders (pool_unwritten_target). A walk still makes the smallest textures up front, 32 MB a frame up to a twentieth of the working set, as a pass that runs once has no second frame to find its texture in.t_pool_chunkschecks this. - Result on Ocarina of Time, a 16 GB Mac, the village: Metal textures and targets 5.5 → 3.9 GB, physical footprint 14.4 → 13.0 GB, p95 from 42–79 ms (with long frames of 300 ms and more) to 28–32 ms, and the house and bark in shadow lit as on the console.
- Cost: the write makes each such fragment shader one with side effects, which may lose early depth tests. Not measured apart from the other changes: without the bitmap the same textures are missing, so the frames are not comparable.
- Not done: the guest's copy of a texture stays. Only 154 MB of it lies in wired pools on Ocarina of Time, and the system can swap the rest, so releasing it would save swap and no RAM. It would also corrupt a later texture over the same bytes under another description, as those bytes would be gone.
- Reading the numbers:
currentAllocatedSize("GPU allocated") read 16 GB on this game whilevmmapshowed 3.9 GB of Metal textures and targets. Usevmmap -summary(owned unmapped (graphics),IOAccelerator (graphics)) for what memory holds. - Found on: The Legend of Zelda: Ocarina of Time.
Pools that hold shader code made resident to key the shaders
- Symptom: memory pools that hold only shader code are in the residency set, though no shader reads them. In The Great Ace Attorney Chronicles, three shared buffers, about 5 MB: chunks of its 1,000 MB pool (
DM_CTLrestop: shared buffers 241 MB at 30 s, 236 MB with the fix). - Cause:
keys_hash(hle_nvn.c) checks that a shader's code lies in a pool before it hashes it, and it askedmtl_addr, which also makes the pool resident (and, in a pool in chunks, makes the chunk that holds the code). The GPU never reads that code: the shaders run translated, and a shader's c1 constants are copied into the host's own buffers. - Fix: general:
keys_hashasksmtl_addr_known(nvn_mtl.m), the pool lookup with no side effect that texture uploads already used: it makes no pool resident, and in a pool in chunks it makes no chunk (it answers from the pool's range). A pool the GPU does read through a binding or an address is made resident there, as before. Keys are unchanged.t_addr_knownchecks it. - Where it does not help: a game whose shaders read raw global memory has every pool it took an address in made resident by the raw pool table (
gmem_map), shader code pools included. Ocarina of Time is one: on the village walk it kept 4,276 pools resident before the fix and 4,277 after, 2,324 on both at the title. The 222 pools and 334 MB first reported there came from a build with other changes. - Found on: The Legend of Zelda: Ocarina of Time (reported), The Great Ace Attorney Chronicles (measured).
A texture object finalized after its pool kept the pool's memory
- Symptom: the residency set stays high after an area load that finalizes a memory pool, and at the next load that makes the pool's textures again it holds them twice. On the Mac with the iPhone's settings, Ocarina of Time's set stayed about 360 MB higher through Hyrule Field than in Kakariko Village before it, and a large recycled heap was let go only about 20,000 submissions after its pool's Finalize. On the iPhone 17 the game was ended for memory (
JetsamEvent,vm-pageshortage) entering the castle grounds, with two 300 MB heaps in the set. - Cause: on NVN a memory pool's Finalize ends its memory, and with it every texture made on that storage, but the host ended only the pool's entries in the sharing table. A texture object the game finalizes after its pool kept its entry in the serial table, and the entry held the Metal texture: the owner does not retire what an entry holds (
own_retire_locked; GitHub issue #1326 says why). Packaged textures, which the sharing table never names, were kept the same way, and so were finalized serials' entries (the ghost table, kept by use and never trimmed while it is underNGHOST). Ocarina of Time keeps a 12288x12288 Depth16 shadow target alone in a 288 MB GPU-only pool, placed in a 300 MB recycled heap of its own; it finalizes that pool at the load into Hyrule Field and the texture object only at the load back into Kakariko Village (or into the castle grounds), right after making the pool and the target again. - Fix: general (
nvn_owner.mown_pool_finalize_locked). The owner indexes the live texture objects of each pool from their initialization to their Finalize (g_pool_tex, the pool recorded at initialization). A pool's Finalize ends those objects' entries, whatever they hold (a shared texture, a view of one, a packaged texture, the texture the GPU's first write took over from a package), then every live or ghost entry that still names one of those textures, a packaged texture of the pool (g_pkg_share) or a part of one (own_hook_parts), each as a note. The held counts say how many entries name them, so that walk is skipped when none does and stops once it has found them all (drop_entries_naming_locked, which the release of a drawn-over target uses too). Work encoded before the Finalize keeps the textures until it completes (own_hook_drop), and a pin (a queued descriptor or a saved binding) still holds them. A later lookup of such a serial makes nothing and reads as an empty slot (A texture read after its memory pool object was freed); the object's own Finalize finds nothing left to end. The 300-frame memory line counts these entries (evicted with pools N (serial entries that went with them M)). Left as before: a ghost entry that holds a package's texture after the package itself has gone (no table names it any more); the ghost table's own trim lets it go once idle pastNGHOST. - Check:
t_serial_owner(a pool's live object holding a packaged texture and a finalized serial holding the package's texture both lose their entries, each noted, another pool's texture keeps its own, and the object's later Finalize ends nothing;own_check_lockedchecks the pool index against the live texture objects; it fails without the index),t_rt_recycle(a 32 MB target whose pool is finalized while its texture object is live is freed, its heap waits in the recycled list, a lookup makes nothing; 3 checks fail without the fix),t_readback(stale_pools: a live packaged or sparse texture of a finalized pool reads as an empty slot and nothing is uploaded). - Found on: The Legend of Zelda: Ocarina of Time (PR #2775, which found the holder with a trace of every texture of 256 MB or more). On the Mac with the iPhone's settings, Kakariko Village to Hyrule Field and back from the 2026-11-13 save (2026-11-15, the PR's version of the fix, which treats this shared target the same way): the old heap was let go about 330 submissions after the pool's Finalize, the set in the field was 3,850 MB against 4,211 MB, and the peak after a commit at the village load 4,142 MB against 4,375 MB. Whether the iPhone 17 now survives the castle-grounds load is open: no phone run has had the fix.
Large render targets over-allocate recycled heaps
- Symptom: the Ocarina of Time residency census in PR #2566 found a 296 MB shadow target in a 333 MB Metal heap.
- Cause: new recycled heaps kept an eighth of each target's size as headroom for reuse. The resident overhead grew with the target.
- Fix:
rh_heapcaps new heap headroom at 4 MiB. Targets up to 32 MiB still get an eighth, and the existing heap selection and retirement rules apply. - Check:
check_t_rt_recycleverifies the cap and heap reuse.check_t_rt_lifetimeexercises rendering before a target can retire. An isolated iPhone comparison is open. - Found on: The Legend of Zelda: Ocarina of Time.
A full colour texture grew the shared zero buffer
- Symptom: the shared zero buffer stayed at 64 MB in the Ocarina of Time iPhone 17 residency census in PR #2566.
- Cause:
tex_zero_fillcopied a whole colour image at once.clear_rect_zerodid the same for a scissored clear. The shared buffer grew to fit the largest copy. - Fix: both paths copy row bands sized to the shared buffer. They request room for one row, which fits in the 4 MiB buffer at supported widths. The texture-size guard and clear ordering still apply.
- Check:
check_t_zero_colourreads every byte of poisoned colour textures after filling, including mip levels, array layers and 3D slices.check_t_lazy_clear_orderreads back a rectangle larger than one band and checks the surrounding pixels. An isolated iPhone comparison is open. - Found on: The Legend of Zelda: Ocarina of Time.
Guest texture source buffers accumulate within an upload batch
- Symptom: Ocarina of Time's field load on iPhone 17 added 732 MB of zero-copy upload sources to Metal residency within a 300-frame window in PR #2270.
- Cause: the staging budget measures private scratch buffers. It excludes the no-copy buffers that wrap guest pages and stay resident until the upload batch completes.
- Fix:
DM_NVN_UPLOAD_SRC_MBsets an opt-in budget for page-rounded source bytes. A regular upload can start a fresh batch before it wraps the source, and each batch releases its own buffers on completion. A single large texture or a sparse gather can exceed the budget. When staging splits a batch, the upload resolves its source in the new batch or uses the CPU path if wrapping fails. - Check:
check_t_upload_srccompares the batch and buffer counts at 0 and 96 MiB and reads back every texel in both runs. An isolated iPhone comparison is open. - Found on: The Legend of Zelda: Ocarina of Time.
Repeated GPU out-of-memory failures end the game
- Symptom: the Mac grows unresponsive for hours, then panics, with the host still submitting work that fails.
- Cause: a command buffer that fails with
Insufficient Memoryfrees nothing, and the game submits the next one. - Fix: general (
nvn_mtl.mres_top_once): 32 such failures within 60 s end the process with a red line, as the session cannot recover and the machine may not either. - Found on: The Legend of Zelda: Ocarina of Time.
A clear pass on a large depth texture fails with Insufficient Memory
- Symptom: a scene load logs
upload command buffer execution error: … Insufficient Memory (00000008:kIOGPUCommandBufferCallbackErrorOutOfMemory)right after alarge texture … format 0x32 … 296 MBline, thenupload command buffer dropped, then the game's own command buffers fail one after another, up to the 32-failures stop (Repeated GPU out-of-memory failures end the game), with most of the GPU's working set free. - Cause: a new texture is zeroed in the upload batch (New textures start as zero), and a depth one was zeroed by a clear-only render pass. On an M3 Pro (18 GB, macOS 27.3) such a pass on a large depth attachment ends in
kIOGPUCommandBufferCallbackErrorOutOfMemorywhatever memory is free, and the queue then fails every command buffer, trivial ones included, until the texture is freed. A standalone Metal 4 program failed for Depth32Float 4096x4096 and Depth16Unorm from about 5000x5000 up; copying zeros into the same textures, up to 16384x16384, never failed. Not seen on an M4 Pro (48 GB), where Ocarina of Time loads the same textures. Apple's driver is the cause; the host only chooses how it zeroes. - Fix: general (
nvn_mtl.mtex_zero_fill): every single-sample Depth16Unorm or Depth32Float texture, of any size, is zeroed by buffer copies from the shared zero buffer, in pieces of rows that fit it (a row is at most 64 KB, the buffer at least 4 MB, so a depth texture never grows it), in the upload batch as before. Stencil formats and multisample textures keep the clear pass: a plain buffer copy cannot write them. - Where it does not help: a game that renders into a depth attachment this large: the same standalone program fails a load-and-draw pass into 12288x12288, scissored or not. Ocarina of Time only samples its 12288x12288 texture.
- Check:
t_zero_depth(Depth16 and Depth32F from 17x5 to 16384x129, with levels, layers and a cube, poisoned and read back as zero on the GPU, and the number of copies a level takes; under the Metal validation layer). With the clear pass, its copy counts fail. - Found on: The Legend of Zelda: Ocarina of Time (PR #2306: an M3 Pro, where about half the save loads ended at the 32-failures stop; 203 runs on its build with copies for depth textures of 16 MB and more, and a retry throttle not landed here, none failed).