dstorage: size the worker pool to physical cores (copy-back 5.7 -> 2.4-3.5 ms/MB on an 8c/16t machine) #1044

Open
github-bot wants to merge 2 commits from github-bot/gh-1044 into main AGit
Owner

@⁠Key-rs on GitHub · 2026-11-25 17:18 UTC · original
Key-rs:perf/dstorage-workers → main · +86 −1 · 2 files · 2 commits · open

The storage pool starts one worker per logical processor. On a machine with SMT that is twice the physical cores, and those workers compete with the submitting thread, the copies and the title's own threads for cores that do not exist. Size it to physical cores instead, with VICTORY_DSTORAGE_WORKERS to set it outright.

What it measured here

Ryzen 7 8845H (8 cores, 16 threads), RTX 4060 Laptop 8 GB, 0b0074e, same package, same switches (VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024), same scripted input:

workers copies copying back frames
before 16 45.7–143.4 ms / 78–212 MB (0.5–0.7 ms/MB) 87.7 ms / 15.5 MB (5.7 ms/MB) 201–701 ms
after 8 34.1–67.0 ms / 56–151 MB (0.4–0.6 ms/MB) 26.1–92.4 ms / 7–28 MB (2.4–3.5 ms/MB) 221–1980 ms

The per-megabyte cost of the copy-back roughly halves, which is the part of this that is not scene noise (the frame numbers moved with the scene each sample; the copy-back figure is per megabyte and moved consistently).

What changed

  • worker_count(): VICTORY_DSTORAGE_WORKERS if set (1–64), otherwise the physical core count, with the old value as a fallback when the system will not say.
  • physical_cores(): GetLogicalProcessorInformationEx(RelationProcessorCore), one record per core. Adds the Win32_System_SystemInformation feature to victory-hle; no new dependency.
  • Nothing else: the pool, the queues and the scheduler are untouched.

Why physical rather than logical

The pool exists to read, inflate and unpack in parallel, and it is bounded by the staging buffer anyway. SMT twins add little to that kind of throughput, while the thread that submits and copies is the one that stalls when too many workers are resident — slow host submission ms=355 lists=43 on the same runs. If a machine reports one core (or the query fails) the old behaviour is kept, so this cannot reduce the pool below what a machine without SMT had before.

Two things I did not do, in case you would rather they went the other way:

  • No pinning: VICTORY_DISK_CORES already covers leaving the fast cores alone, and I did not want to add a second mechanism for the same thing.
  • No change to the wide workers (shadow.rs, available_parallelism()/4) or the pipeline workers. If the same argument holds there, it is a separate change with its own measurement.
**@⁠Key-rs** on GitHub · 2026-11-25 17:18 UTC · [original](https://github.com/fxceless/victory-fork/pull/1044) `Key-rs:perf/dstorage-workers` → `main` · +86 −1 · 2 files · 2 commits · open The storage pool starts one worker per **logical** processor. On a machine with SMT that is twice the physical cores, and those workers compete with the submitting thread, the copies and the title's own threads for cores that do not exist. Size it to physical cores instead, with `VICTORY_DSTORAGE_WORKERS` to set it outright. ### What it measured here Ryzen 7 8845H (8 cores, 16 threads), RTX 4060 Laptop 8 GB, `0b0074e`, same package, same switches (`VICTORY_RELAY=2 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024`), same scripted input: | | workers | copies | copying back | frames | |---|---|---|---|---| | before | 16 | 45.7–143.4 ms / 78–212 MB (0.5–0.7 ms/MB) | 87.7 ms / 15.5 MB (**5.7 ms/MB**) | 201–701 ms | | after | 8 | 34.1–67.0 ms / 56–151 MB (0.4–0.6 ms/MB) | 26.1–92.4 ms / 7–28 MB (**2.4–3.5 ms/MB**) | 221–1980 ms | The per-megabyte cost of the copy-back roughly halves, which is the part of this that is not scene noise (the frame numbers moved with the scene each sample; the copy-back figure is per megabyte and moved consistently). ### What changed * `worker_count()`: `VICTORY_DSTORAGE_WORKERS` if set (1–64), otherwise the physical core count, with the old value as a fallback when the system will not say. * `physical_cores()`: `GetLogicalProcessorInformationEx(RelationProcessorCore)`, one record per core. Adds the `Win32_System_SystemInformation` feature to `victory-hle`; no new dependency. * Nothing else: the pool, the queues and the scheduler are untouched. ### Why physical rather than logical The pool exists to read, inflate and unpack in parallel, and it is bounded by the staging buffer anyway. SMT twins add little to that kind of throughput, while the thread that submits and copies is the one that stalls when too many workers are resident — `slow host submission ms=355 lists=43` on the same runs. If a machine reports one core (or the query fails) the old behaviour is kept, so this cannot reduce the pool below what a machine without SMT had before. Two things I did not do, in case you would rather they went the other way: * No pinning: `VICTORY_DISK_CORES` already covers leaving the fast cores alone, and I did not want to add a second mechanism for the same thing. * No change to the wide workers (`shadow.rs`, `available_parallelism()/4`) or the pipeline workers. If the same argument holds there, it is a separate change with its own measurement.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:33 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 17:48 UTC · original

Tested this on Linux + Wine 11.22 + RX 7900 XT (8c/16t CPU, RELAY=2, 480 s run into the cell scene).

GetLogicalProcessorInformationEx picked up dstorage: workers=8 cleanly under Wine (instead of 16 logical threads) and the whole 480 s run ran with no hangs, texture streaming issues, or crashes.

**@⁠UwUCammie** on GitHub · 2026-11-25 17:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7170023097) Tested this on Linux + Wine 11.22 + RX 7900 XT (8c/16t CPU, `RELAY=2`, 480 s run into the cell scene). `GetLogicalProcessorInformationEx` picked up `dstorage: workers=8` cleanly under Wine (instead of 16 logical threads) and the whole 480 s run ran with no hangs, texture streaming issues, or crashes.
Author
Owner

@⁠Key-rs on GitHub · 2026-11-25 17:54 UTC · original

That is the part of this I could not test myself — thank you. I have Windows only, so I had no idea whether GetLogicalProcessorInformationEx(RelationProcessorCore) would answer at all under Wine; if it had not, the fallback (vailable_parallelism() / 2) would have quietly given the same 8 on an 8c/16t machine and the change would have looked fine while doing nothing on Linux. Seeing it report the physical cores there, and 480 s of cell scene with no streaming regressions, is a better test than the one in the description.

For the record on my side: 8c/16t Zen 4, RTX 4060 Laptop, copying back went from 5.7 ms/MB (16 workers) to 2.4-3.5 ms/MB (8), and the same run with VICTORY_DSTORAGE_WORKERS=16 puts it back, which is how I convinced myself the change and not the scene was doing it.

If you still have that Wine box, the one thing worth a look is a machine whose cores the query reports oddly (containers or VMs that claim many logical processors and few cores): VICTORY_DSTORAGE_WORKERS is the way out, and I would rather hear about it before the default is trusted on Linux than after.

**@⁠Key-rs** on GitHub · 2026-11-25 17:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7170158731) That is the part of this I could not test myself — thank you. I have Windows only, so I had no idea whether GetLogicalProcessorInformationEx(RelationProcessorCore) would answer at all under Wine; if it had not, the fallback (vailable_parallelism() / 2) would have quietly given the same 8 on an 8c/16t machine and the change would have looked fine while doing nothing on Linux. Seeing it report the physical cores there, and 480 s of cell scene with no streaming regressions, is a better test than the one in the description. For the record on my side: 8c/16t Zen 4, RTX 4060 Laptop, copying back went from 5.7 ms/MB (16 workers) to 2.4-3.5 ms/MB (8), and the same run with VICTORY_DSTORAGE_WORKERS=16 puts it back, which is how I convinced myself the change and not the scene was doing it. If you still have that Wine box, the one thing worth a look is a machine whose cores the query reports oddly (containers or VMs that claim many logical processors and few cores): VICTORY_DSTORAGE_WORKERS is the way out, and I would rather hear about it before the default is trusted on Linux than after.
Author
Owner

@⁠SkillIssueXO on GitHub · 2026-11-25 21:38 UTC · original

I checked the topology walk at 0bba762 on Windows. SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX starts with Relationship, followed by Size. The first two DWORDs returned for RelationProcessorCore here are 0 and 48. The current loop reads that 0 as the record length and exits, so workers=8 on an 8c/16t machine can come from the fallback.

Reading Size at offset_of!(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, Size) and bounding the walk by the returned byte length counted 8 physical cores from the API (384 bytes). I also checked that the corrected walk rejects a truncated record. Windows SDK record layout

**@⁠SkillIssueXO** on GitHub · 2026-11-25 21:38 UTC · [original](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7175355355) I checked the topology walk at `0bba762` on Windows. `SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX` starts with `Relationship`, followed by `Size`. The first two DWORDs returned for `RelationProcessorCore` here are `0` and `48`. The current loop reads that `0` as the record length and exits, so `workers=8` on an 8c/16t machine can come from the fallback. Reading `Size` at `offset_of!(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, Size)` and bounding the walk by the returned byte length counted 8 physical cores from the API (384 bytes). I also checked that the corrected walk rejects a truncated record. [Windows SDK record layout](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-system_logical_processor_information_ex)
Author
Owner

@⁠Key-rs on GitHub · 2026-11-26 01:38 UTC · original

You are right, and thank you — that is a bug in the change, not a stylistic point.

SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX starts with Relationship (which is RelationProcessorCore == 0 for every record this walk asks for) and only then Size, so reading the first dword as the length always got 0, the loop broke on size < 8, physical_cores() returned None, and workers=8 came from the fallback vailable_parallelism() / 2. On an 8c/16t machine the two paths agree, which is exactly why it looked correct — your ␀ and 48 pair is the giveaway I should have caught.

Fixed in 4d1bf6b: the length is read at offset_of!(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, Size), the walk is still bounded by the byte length the API returned, and it now logs which of the two paths produced the number, so the next reader can tell an API answer from a fallback without a debugger:

dstorage: physical cores, from the system cores=8 logical=16 dstorage: workers workers=8

On this machine (Ryzen 7 8845H, 8c/16t) the API path reports 8 cores, matching your 384-byte walk.

Two things worth saying plainly:

  • The measurement in the description survives the bug — 16 workers to 8 is what was compared, and VICTORY_DSTORAGE_WORKERS=16 puts the old numbers back. But the reason workers=8 appeared was the fallback, so anyone reading the first version as "the API works" was reading it wrong. Your correction is the difference between a patch that happens to work on SMT machines and one that does what it says.
  • If you have the harness you used for the truncated-record check, the case I would most like covered is a machine whose API answer and fallback disagree — a 6c/12t or a 4c/8t part, where logical / 2 and the real core count can differ from a VM's claim. On this box they cannot.
**@⁠Key-rs** on GitHub · 2026-11-26 01:38 UTC · [original](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7179969490) You are right, and thank you — that is a bug in the change, not a stylistic point. SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX starts with Relationship (which is RelationProcessorCore == 0 for every record this walk asks for) and only then Size, so reading the first dword as the length always got 0, the loop broke on size < 8, physical_cores() returned None, and workers=8 came from the fallback vailable_parallelism() / 2. On an 8c/16t machine the two paths agree, which is exactly why it looked correct — your ␀ and 48 pair is the giveaway I should have caught. Fixed in 4d1bf6b: the length is read at offset_of!(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, Size), the walk is still bounded by the byte length the API returned, and it now logs which of the two paths produced the number, so the next reader can tell an API answer from a fallback without a debugger: ` dstorage: physical cores, from the system cores=8 logical=16 dstorage: workers workers=8 ` On this machine (Ryzen 7 8845H, 8c/16t) the API path reports 8 cores, matching your 384-byte walk. Two things worth saying plainly: * **The measurement in the description survives the bug** — 16 workers to 8 is what was compared, and VICTORY_DSTORAGE_WORKERS=16 puts the old numbers back. But the *reason* workers=8 appeared was the fallback, so anyone reading the first version as "the API works" was reading it wrong. Your correction is the difference between a patch that happens to work on SMT machines and one that does what it says. * If you have the harness you used for the truncated-record check, the case I would most like covered is a machine whose API answer and fallback disagree — a 6c/12t or a 4c/8t part, where logical / 2 and the real core count can differ from a VM's claim. On this box they cannot.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1044/head:github-bot/gh-1044'
git switch 'github-bot/gh-1044'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1044'
git switch 'github-bot/gh-1044'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1044'
git switch 'github-bot/gh-1044'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1044'
git switch 'main'
git merge --squash 'github-bot/gh-1044'
git switch 'main'
git merge --ff-only 'github-bot/gh-1044'
git switch 'main'
git merge 'github-bot/gh-1044'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.