Fix/streaming pool and guards lock #334
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!334
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-334"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@delacor on GitHub · 2026-12-03 16:13 UTC · original
delacor:fix/streaming-pool-and-guards-lock→main· +22 −4 · 2 files · 3 commits · merged 2026-12-03 16:55 UTCStreaming and guard-fault waits during load
Two waits stall frames while the world streams in. Neither is I/O and neither is
the GPU: both are a thread waiting for a lock, or for a worker.
The machine and the conditions
One machine only: Ryzen 7 3700X (8 cores, 16 threads), Radeon RX 7800 XT under
RADV 26.3.1 with Resizable BAR on (BAR0 16 GiB), Wine 11.22, Xbox Series X
profile, ray tracing off, 2560×1440 output. The frame clock followed the title's
own interval, 33.333 ms in the world, so a frame's budget is 33.3 ms.
Where every number below comes from
The emulator's own counters, printed once a second and once every five seconds:
dstorage: last <n> sbusy_workers,waiting, staging waitsRlines,VICTORY_DSTORAGE_LOG=<file>Submittimestamp, the worker's start, its endbusy_workersis the sum of the per-read worker durations divided by the windowlength: the average number of workers running a read at once.
waitingis thenumber of reads the title has submitted that no worker has begun.
Fix 1 —
dstorage: the pool was eight workers, whatever the machineWhat was wrong
const WORKERS: usize = 8sized the DirectStorage worker pool independently ofthe host. On this 16-thread machine, eight was the ceiling.
What it costs
A read is short. From the per-read log, the read itself, from a worker
starting it to its end:
The wait for a worker, from the title's
Submitcall to a worker beginningthe read, is what costs:
With eight workers the pool ran 7.5 of 8 busy (93 %) in its busiest sampled
five-second window, with 883 reads queued behind it. Two other suspects were
measured and cleared first:
workers, 7.4 ms for the title's own thread;
start()refusing work: it never returns nothing while reads wait(
starts_with_reads_waiting = 0).So the limit was the number of workers. At sixteen the same windows show
13.3 of 16 busy (83 %).
The median does not move, and that is expected: the title delivers about 4,000
reads a second of 12 KiB median (90th percentile 128 KiB), so the queue is
never empty. This change removes the tail, not the average.
What it does
The pool is the machine's own core count, capped at 64, by default.
VICTORY_DSTORAGE_WORKERS=<n>asks for another count. The 64 cap mattersbecause each worker keeps a read-back buffer of up to 4 MiB.
Fix 2 —
gpu: a remap took the guards whole, under one holdWhat was wrong
guard_sharedtook the guards' write lock and, while still holding it, removedevery block the remap had brought from the two sets that record where title
memory is. A large remap brings thousands of blocks.
What it costs
The guard-fault handler must take that same lock. Its own instrumentation
(
VICTORY_FAULT_SLOW_MS) splits the handler into parts, and the parts say whichone waits:
14.2 of 14.3 ms is the wait for the guards lock, with the texture write and
the descriptor fallback at 0.02 ms in the same faults.
That wait lands inside a frame: one measured frame took 144.0 ms, of which
100.8 ms was the guard-fault handler's span (
a fault looked at) and 25.0 mstexture refresh.
The holder was named by a hold timer (
VICTORY_GUARD_SLOW_MS):guard_shared'sper-block walk, with one hold of 167.5 ms measured and 126 holds over 3 ms
per run.
What it does
The blocks are taken 256 at a time, with the lock released between parts.
Guards-lock time per run fell from 3027 ms to 907 ms, and holds over 3 ms
from 126 to 52.
It is safe to split: the walk changes no block's protection, and a block is only
touched by the thread mapping it, so a fault that finds the lock between two
parts never looks at a half-changed state of its own block.
What is left
The holds that remain are the card writing and title memory changing, not this
walk. In a 100-second run after the fix: 2 holds over 2 ms, longest 195 ms, and
41 guard faults over 2 ms. That is about 1 ms of a second's work, not a
frame-rate problem.
Also measured and cleared
VICTORY_DSTORAGE_STAGING_MB=128against thetitle's 32 MiB made the median wait worse, 25 → 37 ms. Not the limit.
about 2 GB/s, and the read is 0.09 ms per frame of texture-refresh time.
Texture refreshes are already run in parallel at submission
(
refresh_texturesspreads the due textures over the worker threads andreports the wall time), so a prefetch bought nothing: the wall time is
0.1–2.3 ms per frame, while detiling (1.59 ms) and hashing (0.69 ms) of
thread time already overlap.
What this does not fix
Steady state was already at the title's own cap: median 30.0 fps, 90th
percentile 30.1 fps, mean frame 33.0 ms, with the frame clock following the
title. The remaining stalls are about one frame a second, and after both fixes
these two waits contribute well under a frame's budget. Further frame-rate work
has to attack the title's own recording, not these waits.
Reproducing
With this PR alone, the streaming-pool figures:
Read
dstorage: lastforbusy_workersandwaiting, theRlines forsubmit → start, and
started → done.The guards-lock figures need the investigation branch, which carries the hold
timer and the fault handler's parts:
github-bot referenced this pull request2026-12-05 11:23:55 +00:00
github-bot referenced this pull request2026-12-05 11:35:00 +00:00