Residency sets are re-wired after the GPU idles: 0.3 s kernel stalls on several queues, about every 25 s #466

Closed
opened 2026-11-27 21:14:07 +00:00 by github-bot · 5 comments
Owner

@⁠lautarocherro on GitHub · 2026-11-27 21:12 UTC · original

What happens

@⁠Olima34 measured it (handoff on #258, M5 Pro 48 GB): about every 25 s, a few command buffers take 0.31 to 0.36 s of kernel time each, on 3 queues at once, and hold the queues for 1.5 to 3.3 s with GPU time near 0. An unchanged set costs 0.03 ms per buffer in an isolated test, so it isn't the set's size alone.

docs/native-host.md ("Why the wired memory flips") already found part of the cause. During CPU stalls (pipeline creation, the title waiting), the system un-wires an idle device's memory, whatever requestResidency asks. The slow residency calls come right after, when the set is made resident again. So the episodes are probably that re-wiring of the ~18 GB heap set after each idle gap.

Plan

  1. Reproduce on an M5 Pro 48 GB (Series X) with VICTORY_TRACE_RESIDENCY=1 and wired memory sampled, and check that each episode follows a gap with nothing committed.
  2. If it does, try to keep the device from counting as idle while the host stalls: a small command buffer with the heap sets attached, committed when nothing has been committed for a while. Measure wired memory, the slow calls and frame times with and without it.

Counts only. This is only the re-wire cost, not the GPU time-outs of #79 (@⁠Tarraga). Say if it overlaps your work.

**@⁠lautarocherro** on GitHub · 2026-11-27 21:12 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462) ## What happens @⁠Olima34 measured it (handoff on #258, M5 Pro 48 GB): about every 25 s, a few command buffers take 0.31 to 0.36 s of kernel time each, on 3 queues at once, and hold the queues for 1.5 to 3.3 s with GPU time near 0. An unchanged set costs 0.03 ms per buffer in an isolated test, so it isn't the set's size alone. docs/native-host.md ("Why the wired memory flips") already found part of the cause. During CPU stalls (pipeline creation, the title waiting), the system un-wires an idle device's memory, whatever `requestResidency` asks. The slow residency calls come right after, when the set is made resident again. So the episodes are probably that re-wiring of the ~18 GB heap set after each idle gap. ## Plan 1. Reproduce on an M5 Pro 48 GB (Series X) with `VICTORY_TRACE_RESIDENCY=1` and wired memory sampled, and check that each episode follows a gap with nothing committed. 2. If it does, try to keep the device from counting as idle while the host stalls: a small command buffer with the heap sets attached, committed when nothing has been committed for a while. Measure wired memory, the slow calls and frame times with and without it. Counts only. This is only the re-wire cost, not the GPU time-outs of #79 (@⁠Tarraga). Say if it overlaps your work.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:14:07 +00:00
Author
Owner

@⁠lautarocherro on GitHub · 2026-11-27 21:12 UTC · original

/claim

**@⁠lautarocherro** on GitHub · 2026-11-27 21:12 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462#issuecomment-7228232779) /claim
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-27 21:12 UTC · original

Claimed by @⁠lautarocherro. Open a draft pull request with Refs #462 in its description within 24 hours, or the claim expires.

**@⁠github-actions[bot]** on GitHub · 2026-11-27 21:12 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462#issuecomment-7228235389) Claimed by @⁠lautarocherro. Open a draft pull request with `Refs #462` in its description within 24 hours, or the claim expires.
Author
Owner

@⁠lautarocherro on GitHub · 2026-11-27 22:22 UTC · original

Results. M5 Pro 48 GB, macOS 27.2.1, Series X, headless, 300 s each, main b998bb65 plus one trace change: the commit trace's cb done line also gives kernel time. Four runs with each setting, alternated.

The churn is real. In the world, an allocation leaves the heap's set with a commit of its own each time its last entry is overwritten. That is about 5,000 commits a second (2,900 to 5,800), with the set at 24 GB and 50,000 to 90,000 allocations.

It is not what stalls. I tried keeping unnamed allocations in the set and removing them in one commit every 2 s (a local switch). That cut the commits to about 24 a second, but nothing else moved:

removed at once (4 runs) lingering (4 runs)
GPU time-outs 8, 11, 0, 0 3, 0, 0, 3
Title fault at image+0x55e56f8 1 run 1 run
World frames from 100 s to the end 43 (fault), 221, 226, 253 240, 247, 237, 128 (fault)
Kernel time above GPU time, from 100 s 54, 4, 25, 30 s 27, 26, 48, 27 s

So I won't open a PR for it.

What the kernel time likely is. Many command buffers show gpu_ms=0.0 with 100 to 280 ms of kernel time. Metal's kernel start and end times cover scheduling, so this is probably time spent waiting for other queues' shared events (title fences, order events), not residency work. The idle un-wiring in docs/native-host.md isn't involved either: no episode followed a gap of more than 1.9 s in commits.

I'm releasing this issue. If the kernel time on the cb done line is useful to someone (it measures it without VICTORY_TRACE_GPU_FAILS), I can open that as a small PR.

**@⁠lautarocherro** on GitHub · 2026-11-27 22:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462#issuecomment-7229272184) Results. M5 Pro 48 GB, macOS 27.2.1, Series X, headless, 300 s each, main `b998bb65` plus one trace change: the commit trace's `cb done` line also gives kernel time. Four runs with each setting, alternated. **The churn is real.** In the world, an allocation leaves the heap's set with a commit of its own each time its last entry is overwritten. That is about 5,000 commits a second (2,900 to 5,800), with the set at 24 GB and 50,000 to 90,000 allocations. **It is not what stalls.** I tried keeping unnamed allocations in the set and removing them in one commit every 2 s (a local switch). That cut the commits to about 24 a second, but nothing else moved: | | removed at once (4 runs) | lingering (4 runs) | |---|---|---| | GPU time-outs | 8, 11, 0, 0 | 3, 0, 0, 3 | | Title fault at image+0x55e56f8 | 1 run | 1 run | | World frames from 100 s to the end | 43 (fault), 221, 226, 253 | 240, 247, 237, 128 (fault) | | Kernel time above GPU time, from 100 s | 54, 4, 25, 30 s | 27, 26, 48, 27 s | So I won't open a PR for it. **What the kernel time likely is.** Many command buffers show `gpu_ms=0.0` with 100 to 280 ms of kernel time. Metal's kernel start and end times cover scheduling, so this is probably time spent waiting for other queues' shared events (title fences, order events), not residency work. The idle un-wiring in docs/native-host.md isn't involved either: no episode followed a gap of more than 1.9 s in commits. I'm releasing this issue. If the kernel time on the `cb done` line is useful to someone (it measures it without `VICTORY_TRACE_GPU_FAILS`), I can open that as a small PR.
Author
Owner

@⁠lautarocherro on GitHub · 2026-11-27 22:22 UTC · original

/release

**@⁠lautarocherro** on GitHub · 2026-11-27 22:22 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462#issuecomment-7229272537) /release
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-29 00:42 UTC · original

The claim by @⁠lautarocherro has expired: no pull request referenced it within 24 hours. This issue is free to claim.

**@⁠github-actions[bot]** on GitHub · 2026-11-29 00:42 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/462#issuecomment-7248294079) The claim by @⁠lautarocherro has expired: no pull request referenced it within 24 hours. This issue is free to claim.
This discussion has been locked. Commenting is limited to contributors.
No description provided.