Repository navigation
Ocarina of Time with guest files on held 54–56 fps in 20 of 20 runs with DM_RES_CB=1 (the residency set named per command buffer); without it 9 of 20 fell to 23–36 fps - #2715
Conversation
…nstead of attached to the queues: Ocarina of Time's wiring state with guest files on, on a 16 GB M4, in 0 of 20 runs against 10 of 20 While g_res sits on both queues, Ocarina of Time on a 16 GB M4 (macOS 27.2, guest files on) falls in about half its launches into a state where the driver wires memory 53,000-93,000 times a second on the game's threads (Wire <size> System Memory in a Metal System Trace; 18-1,552 in the other runs) and the room runs at 23-36 fps in nine such runs of ten. Kernel stacks of two such runs put 27-28 % of the submission thread's kernel samples in IOGPUScheduler::freeToWireSysMemory, all under the queue's event signal, and 62-63 % in IOGPUMemory::prepare_memory_slow, nearly all under the commit. Why the attachment matters is not known. Now DM_RES_CB=1 (off by default) leaves g_res off g_q and g_q4 and names it with useResidencySet just before each endCommandBuffer (a begin drops a command buffer's sets), and on a classic command buffer when it is made; the residency line counts the namings and their time with the wait for g_res_commit_mu. Unset, nothing changes. Main 0c07813 with an earlier form of the switch (the same call sites), encode thread off, 20 runs a side on one host, order shuffled, a 4 s trace in each: the wiring state in 10 runs without it and 0 with it (Fisher's exact, p = 0.00044). Kernel stacks without a trace on e19bcd6 with 14 open pull requests, encode thread on: 2 of 3 against 0 of 4. t_res_cb (18 checks, run with the switch unset and set, the encode thread off and on; Metal's commits, begins and useResidencySet wrapped): with the switch neither queue holds g_res and every command buffer committed by a submission with a cut and an upload batch, a present snapshot, a display-link present, an offscreen present and a classic command buffer (three, then one each) names it; unset, both queues hold it and none names it. Each of the upload batch's, the encode thread's and the snapshot's namings taken out fails it in the mode that runs it. The gfx suite passes with the switch unset and with DM_RES_CB=1 set. Reference entry, game note, switch row, symptom index. Not checked: this commit in the game on plain main, guest files off beyond six traced runs that were not in the state, frame hold on, play, area loads, other games and Macs, sparse mapping updates (they name no set).
|
Results on a base M2 (MacBook Air, 10-core GPU, 16 GB, macOS 27.0) This PR, applied as host code only on main b06f4e0. Ocarina of Time on a scripted Kokiri Forest route from a fixed save, at a 30 fps cap, handheld 1440x810, MetalFX upscaling, guest files on. Launches alternated with the switch off and on, each to frame 6000, read from frame 1500:
On this machine the state looks a bit different from the M4 description. Instead of a steady 23–36 fps, a launch in the state runs at 13–16 fps throughout. The deepest moments are episodes of 400 ms+ frames, with the GPU near idle and 80–96 % of the frame in the sync wait. A kernel trace in that state showed work held after the submit with the GPU idle 70–87 %, which fits the driver re-wiring you describe. Without the switch, the state also appeared on old main (rarely) and on newer mains (most launches). With the switch on, it didn't appear in any run. Runs at a 60 fps cap follow, and we'll add them here. 🤖 Generated with Claude Code |
|
Follow-up on the base M2: cap 60, a long run, and a hang we've seen twice with the switch on Same machine and route as the earlier comment (M2 MacBook Air, 16 GB, Ocarina of Time, Kokiri Forest, handheld 1440x810, MetalFX, guest files on). At a 60 fps cap (main b06f4e0 with this PR, launches alternating, to frame 6000, read from frame 1000):
That's 2 launches per arm, so it adds to the cap-30 result rather than standing alone. The cost matches cap 30: about 305k namings a run, about 200 ms in total, longest 0.05 ms. Frame times outside the slow state are unchanged. A 25-minute run at cap 30 on our next build (this PR plus our other carries, A hang, seen twice, cause unknown. On two builds based on that one, both with In one, the call comes from the queue's replay thread ( 🤖 Generated with Claude Code |
… attached to a queue (PR #2715) With g_res attached to both queues, Ocarina of Time with guest files on fell in about half its launches on 16 GB Macs into a state where the driver wired memory 53,000-93,000 times a second (IOGPUScheduler::freeToWireSysMemory under the queues' event signals, IOGPUMemory::prepare_memory_slow under their commits): 23-36 fps on an M4 in 10 runs of 20, 13.6 fps median on an M2 in 5 of 5 (issue #2751). Named on each command buffer instead (the PR's opt-in switch), in none of 20 and none of 4. Apple documents the two routes as the same, so this is a route around the driver's state; its cause is open. Now the only route, with no switch: res_name names g_res and the present snapshots' set (made at start) on every command buffer under g_res_commit_mu; every Metal 4 command buffer ends through cb_end (the encode thread's RO_CB_END too), every classic one is made by cl_cb, and the present also names its drawable's layer set. The residency line counts the namings and their time. t_res_cb (encode thread off and on): no set on a queue; a submission with a cut and an upload batch, a present snapshot, a display-link present, an offscreen present and a classic command buffer each name both sets, the present its layer set too. test_residency_naming.py: no addResidencySet, endCommandBuffer only in cb_end, [g_q commandBuffer] only in cl_cb. gfx checks pass (t_dlss_scaler does not build on main since 23790f8). regress.py check PASS on Octopath II (59.7 -> 59.8 fps) and Mario Kart World (58.8 -> 59.8), and a quick Octopath II run with DM_GUEST_FILE=1; namings about 0.7 us each (211 ms over a 440 s run, longest 0.31 ms). Not run: Ocarina of Time (its build is at an older chain), a 16 GB Mac, the iPhone. Co-authored-by: bettterlabs <279109819+bettterlabs@users.noreply.github.com>
|
Landed as 83a74d7, with you as co-author. Thank you for the measurements and the kernel stacks. They made the case. It landed reworked: the naming is now the only route, with no switch.
Checked:
Not run: Ocarina of Time on a 16 GB Mac, and the iPhone. A few launches on main with guest files on would confirm it on your M4. |
|
iPad Pro 11" (M5), iOS 27.2: 6 + 6 alternating launches on Ocarina of Time with Seedds noted on #2715 that Ocarina of Time on a 16 GB Mac and the iPhone were not run. This is an iPad, on the opt-in switch as it was in the PR, before 83a74d7. Build and setup. NX2Apple v1.5.0-rc2's engine (
What this does not show. There is no kernel trace or Metal System Trace on the iPad here, so I cannot say the slow launches are the wiring state in this PR; I classify them only by frame and GPU time. The launches are few and the draws differ a little between the arms. One thing to report, not attributed. After launch 2 of the off arm, which ended with a forced exit ("graceful exit not done in 1.5 seconds, exiting at once"), the next launches of the app stayed on a black screen and Logs of the 12 launches (host logs as copied from the app, unedited; checked for device ids and paths): https://gist.github.com/williamstonef/277b0532610e092224302547e0db93a6. I can repeat this on the first NX2Apple build that carries 83a74d7. Written with AI: Claude · Responsibility: williamstonef |
|
I've experienced 3 like yours on my base M4 Mac mini, with the set on the queues @dpadr, your two hangs look like a freeze I've had three times on a base M4 Mac mini (16 GB, macOS 27.2, IOGPUFamily 162.16.1, apfs 3288.41.1). All three of mine ran with the residency set attached to the queues; yours ran with it named per command buffer. So a hang like this predates the naming. Whether yours is the same one, and whether the naming changes how often it happens, is still open.
As in yours, my process couldn't be killed ( The kernel stacks come from whole-system spindumps for 2 and 3 and from the power-button panic stackshot for 1 (its raw offsets match the symbolized ones). The stuck thread ( It waits on a lock held by a launchd thread in My freeze dumps have no user frames for that thread ( So a set commit that goes into Where the page-in comes from, in main's code: zero-copy buffers over guest memory go into I'm running the launches seedds asked for now: 10 on main d20e9e7 and, alternated with them, 10 on the same main with 83a74d7 reverted (only the host differs; both use the same game build, which carries the prewarm lists and game-profile PRs I merge), in Link's room with guest files on. 16 of the 20 were done at 19:57; I'll post the result here when all are in. In collaboration with Claude Code (Claude Opus 5.5); outside review by Codex (gpt-6.1-sol). |
|
Main d20e9e7 with guest files on: 10 launches on a base M4 Mac mini, none slow, no hang @seedds, here are the launches you asked for. Main d20e9e7 with
|
…uffer Upstream seedds#2715 attaches no residency set to the queue any more; the test's own command buffer read textures that were not resident and its present never completed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016qteK4T7SLBnbRPXQUVaNR
What and why
With guest files on (
DM_GUEST_FILE=1, off by default on the Mac), Ocarina of Time on a 16 GB M4 falls in about half its launches into a state where the driver wires memory 53,000–93,000 times a second on the game's threads (Wire <size> System Memoryin a Metal System Trace), against 18–1,552 in the other runs; in it, Link's room runs at 23–36 fps (one run of ten averaged 50). Six traced runs without guest files, on another day, were never in it. Possibly the state in #2277; not checked.Kernel stacks of two such runs put 27–28 % of the submission thread's kernel samples in
IOGPUScheduler::freeToWireSysMemory, all under the queue's event signal (IOGPUDeviceUserClient::t_signal_shared_event), and 62–63 % inIOGPUMemory::prepare_memory_slow, nearly all under the commit. A run outside the state has 0–1 samples there.g_res, the host's main residency set, is attached to both queues. The change:DM_RES_CB=1(off by default) leaves it offg_qandg_q4and names it withuseResidencySetjust before eachendCommandBuffer, and on a classic command buffer when it is made. With it, the state did not appear: all 20 runs held 54–56 fps, against 23–36 fps in nine of the ten that fell into it without the switch. Why the two differ is not known (Apple documents a queue's sets as attached to every command buffer committed on it), so this is a switch to test, not a fix. KhronosGroup/MoltenVK#2890 and trymirai/uzu#988 report the same kernel functions with a set attached to a queue; Apple's guide calls the queue attachment the more efficient way. Related: #1394 (fewer pools in the set), #2566 (what the set holds).Checked
Measured: OoT 0400486024DEC000 v131072, Link's room standing still, fullscreen, dynamic resolution on, frame hold off, guest files on; the bench route's 85–145 s window. Main 0c07813 with an earlier form of the same switch (the same call sites; its namings counted, not timed), encode thread off; 20 pairs, order shuffled, a 4 s trace in each; declared before run 1, read once; "in the state" = 10,000 game wires a second or more.
DM_RES_CB=1Fisher's exact, two-sided: p = 0.00044. The share without the switch moves between blocks (4 of 12 that morning, 10 of 20 here).
Kernel stacks, no trace, main e19bcd6 + 14 open PRs incl. replay ahead (nvn/queue: translate a frame parked on a CPU event before its signal #2341), encode thread on: 2 of 3 runs in the state without the switch, 0 of 4 with it. The namings took 1–8 ms per 300 frames with their lock wait (longest recorded 0.57 ms).
Tests (Mac mini M4, 16 GB, macOS 27.2): new
t_res_cb(18 checks; the switch unset and set, the encode thread off and on) wraps Metal's commits anduseResidencySetcalls. With the switch, each command buffer a submission, a cut, an upload batch, a snapshot and a present commit names the set (counted per path); each of three namings taken out fails it in the mode that runs it. Unset, the queues hold the set and none is named.make -C dm/gfx/tests GAME=0400486024DEC000 runpasses with the switch unset and set;test_docs.py,test_env_switches.pypass. No test reproduces the state itself.regress.py:impactreaches every game (the submission path); no other game is built here, so nocheck.System-wide wired memory stayed at 7.6–9.8 GiB in both states, under
vm.global_user_wire_limit(12.16 GiB; sampled every 5 s); the driver's own limits were not compared.requestResidencyon the set: not shown to help (four traced runs still in the state).Not checked: why it differs; this commit in the game on plain main (the runs above are on the builds named); frame hold on, play, area loads (the naming's lock wait), other scenes, games and Macs; a game whose sparse textures map pages (a mapping update names no set).
Next: a few launches with
DM_RES_CB=1on the #2277 Macs.Docs
docs/reference/frame-rate.md, game note lines, switch row;python3 dm/tools/docs_symptoms.pyrunIn collaboration with Claude Code.