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

Open
Key-rs wants to merge 2 commits from upstream-pr/1044 into main
Key-rs commented 2026-11-25 17:18:39 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Key-rs on 2026-11-25T17:18:39Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:issue:6609839715 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1044). Originally posted by [Key-rs](https://github.com/Key-rs) on 2026-11-25T17:18:39Z. --- 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.
UwUCammie commented 2026-11-25 18:05:13 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by UwUCammie on 2026-11-25T17:48:17Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7170023097 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7170023097). Originally posted by [UwUCammie](https://github.com/UwUCammie) on 2026-11-25T17:48:17Z. --- 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.
Key-rs commented 2026-11-25 18:05:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Key-rs on 2026-11-25T17:54:09Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7170158731 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7170158731). Originally posted by [Key-rs](https://github.com/Key-rs) on 2026-11-25T17:54:09Z. --- 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.
SkillIssueXO commented 2026-11-25 22:07:24 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by SkillIssueXO on 2026-11-25T21:38:49Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7175355355 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7175355355). Originally posted by [SkillIssueXO](https://github.com/SkillIssueXO) on 2026-11-25T21:38:49Z. --- 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)
Key-rs commented 2026-11-26 02:08:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Key-rs on 2026-11-26T01:38:03Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7179969490 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1044#issuecomment-7179969490). Originally posted by [Key-rs](https://github.com/Key-rs) on 2026-11-26T01:38:03Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1044:upstream-pr/1044'
git switch 'upstream-pr/1044'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1044'
git switch 'upstream-pr/1044'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1044'
git switch 'upstream-pr/1044'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1044'
git switch 'main'
git merge --squash 'upstream-pr/1044'
git switch 'main'
git merge --ff-only 'upstream-pr/1044'
git switch 'main'
git merge 'upstream-pr/1044'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
fxceless/victory-fork!1042
No description provided.