DirectStorage: physical pages the host refused a view of are written on a retry #2883

Open
github-bot wants to merge 3 commits from github-bot/gh-2883 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:01 UTC · original
0xkn0wh3r3:hle/dstorage-page-writes-retry-host-refusals → main · +181 −38 · 2 files · 3 commits · open

What

A DirectStorage request whose destination is physical pages writes them through views of their sections (xmem::write_physical). If every page is known but the host refuses a view, the request used to fail at once. The refusal comes from MapViewOfFile, or from committing the view, failing while commit or address space is short, for example while a load maps many pages at once. The title never reads a request's result, so the model or texture just kept whatever its pages held. The only case retried was a page list still naming page 0 (#1726).

Now View::map returns the Windows error when the host refuses, and write_physical passes it on. When the error is a memory shortage (ERROR_NOT_ENOUGH_MEMORY, ERROR_NO_SYSTEM_RESOURCES or ERROR_COMMITMENT_LIMIT), the write is tried again up to seven times, waiting 2, 4, … 128 ms before each (254 ms in all), before the request fails. Any other error, or a retry that meets one, fails the request at once, and so do requests that name pages xmem doesn't know, so a bad list or a refusal that can't pass doesn't hold up its queue.

The warning for a request that fails now includes the error (error = … (os error N)), and the info line for a write that succeeded on a retry includes the code it first met.

Where it came from

From DexNom's fork, DexNom/VIctory@570a941 (into_destination's retries, VICTORY_DSTORAGE_RETRIES). Their version retries every failure for about 1.5 s. This one only retries known pages refused for lack of memory, and waits less in total. Credited with Co-authored-by: DexNom.

Tested

  • dstorage::tests::host_refusals_are_retried_with_longer_waits: a write refused for lack of memory that succeeds on its third retry waited 2, 4 and 8 ms. One that never succeeds waited 2 … 128 ms and fails with the last error.
  • dstorage::tests::other_refusals_are_not_retried: unknown pages and other errors (access denied) aren't retried, and a retry that meets an error that can't pass stops there.
  • cargo test -p victory-hle --lib: 154 passed. Windows 11. a_page_list_filled_after_its_request_starts (from #1726, unchanged here) failed once out of six full runs. It's timing-based: a filler thread has to write the list within the 8 ms the request re-reads it for.
  • cargo clippy -p victory-hle --all-targets: 0 warnings. cargo xtask policy: ok.

Not tested

  • The refusal itself isn't reproduced. There's no fault injection in View::map, and I haven't run the title under commit pressure, so I don't know which error code it actually returns. The warning now names it, so a log from a tester who hits it will show the failure mode.

Changes after review

  • 8ad1371 (was 4e89780 before the rebase): if a list naming page 0 gets filled in while the request reads it again, but the write then meets a host refusal, the retries and the failure's log line now use the list as last read, not the first reading.
  • 5c87644 (triage): View::map reports the Windows error, the failure warning includes it, and retries happen only for memory-shortage errors.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2883) `0xkn0wh3r3:hle/dstorage-page-writes-retry-host-refusals` → `main` · +181 −38 · 2 files · 3 commits · open ## What A DirectStorage request whose destination is physical pages writes them through views of their sections (`xmem::write_physical`). If every page is known but the host refuses a view, the request used to fail at once. The refusal comes from `MapViewOfFile`, or from committing the view, failing while commit or address space is short, for example while a load maps many pages at once. The title never reads a request's result, so the model or texture just kept whatever its pages held. The only case retried was a page list still naming page 0 (#1726). Now `View::map` returns the Windows error when the host refuses, and `write_physical` passes it on. When the error is a memory shortage (`ERROR_NOT_ENOUGH_MEMORY`, `ERROR_NO_SYSTEM_RESOURCES` or `ERROR_COMMITMENT_LIMIT`), the write is tried again up to seven times, waiting 2, 4, … 128 ms before each (254 ms in all), before the request fails. Any other error, or a retry that meets one, fails the request at once, and so do requests that name pages xmem doesn't know, so a bad list or a refusal that can't pass doesn't hold up its queue. The warning for a request that fails now includes the error (`error = … (os error N)`), and the info line for a write that succeeded on a retry includes the code it first met. ## Where it came from From DexNom's fork, [DexNom/VIctory@570a941](https://github.com/DexNom/VIctory/commit/570a941e9b4e945121c26eb30dfc10c126845207) (`into_destination`'s retries, `VICTORY_DSTORAGE_RETRIES`). Their version retries every failure for about 1.5 s. This one only retries known pages refused for lack of memory, and waits less in total. Credited with `Co-authored-by: DexNom`. ## Tested - `dstorage::tests::host_refusals_are_retried_with_longer_waits`: a write refused for lack of memory that succeeds on its third retry waited 2, 4 and 8 ms. One that never succeeds waited 2 … 128 ms and fails with the last error. - `dstorage::tests::other_refusals_are_not_retried`: unknown pages and other errors (access denied) aren't retried, and a retry that meets an error that can't pass stops there. - `cargo test -p victory-hle --lib`: 154 passed. Windows 11. `a_page_list_filled_after_its_request_starts` (from #1726, unchanged here) failed once out of six full runs. It's timing-based: a filler thread has to write the list within the 8 ms the request re-reads it for. - `cargo clippy -p victory-hle --all-targets`: 0 warnings. `cargo xtask policy`: ok. ## Not tested - The refusal itself isn't reproduced. There's no fault injection in `View::map`, and I haven't run the title under commit pressure, so I don't know which error code it actually returns. The warning now names it, so a log from a tester who hits it will show the failure mode. ## Changes after review - 8ad1371 (was 4e89780 before the rebase): if a list naming page 0 gets filled in while the request reads it again, but the write then meets a host refusal, the retries and the failure's log line now use the list as last read, not the first reading. - 5c87644 (triage): `View::map` reports the Windows error, the failure warning includes it, and retries happen only for memory-shortage errors.
A request whose destination is physical pages writes them through views
of their sections (xmem::write_physical). When every page is known but
the host refuses a view (MapViewOfFile, or committing the view, failing
while commit or address space is short, as when a load maps many at
once), the request failed at once; the title never looks at a request's
result, so the model or texture stayed whatever its pages held. Only a
page list still naming page 0 was read again.

Such a write is now tried again up to seven times, after 2, 4, ... 128
ms (254 ms in all), before the request fails; requests naming pages
xmem does not know still fail at once, so a bad list does not hold its
queue.

Test: host_refusals_are_retried_with_longer_waits (the retry helper's
waits and outcome).

From DexNom/VIctory@570a941e9b
(into_destination's retries, VICTORY_DSTORAGE_RETRIES), narrowed to
known pages and to a shorter total wait.

Co-authored-by: DexNom <[email protected]>
Review: when a request's page list named page 0 and the title filled it
while the request read it again, but the write then met a host refusal,
the retries looked at the first reading (with its 0), found an unknown
page and failed at once. They, and the failure's log line, now take the
list as last read.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:39 +00:00
github-bot force-pushed github-bot/gh-2883 from 4e897803d1 to 5c87644762 2026-11-26 07:28:08 +00:00 Compare
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 23:10 UTC · original

Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup.

  • cargo test --locked -p victory-hle --lib host_refusals_are_retried_with_longer_waits --quiet -> 1 passed, 0 failed (152 filtered out).
  • cargo test --locked -p victory-hle --quiet -> 153 passed, 0 failed, plus doctests.
  • Diff vs merge-base 842b0cb: 1 file +61/-0; git diff --check clean.
  • Negative control: host_refusals_are_retried_with_longer_waits is absent from the base commit, so the coverage is new here.
  • Only pre-existing deprecation warnings in victory-gpu/src/object.rs and victory-hle/src/modules/xmem.rs.

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2883#issuecomment-7177229721) Local verification on Windows / rustc 1.100.0 / MSVC, no game data, no GPU, no clippy/rustup. - `cargo test --locked -p victory-hle --lib host_refusals_are_retried_with_longer_waits --quiet` -> 1 passed, 0 failed (152 filtered out). - `cargo test --locked -p victory-hle --quiet` -> 153 passed, 0 failed, plus doctests. - Diff vs merge-base 842b0cb: 1 file +61/-0; `git diff --check` clean. - Negative control: `host_refusals_are_retried_with_longer_waits` is absent from the base commit, so the coverage is new here. - Only pre-existing deprecation warnings in `victory-gpu/src/object.rs` and `victory-hle/src/modules/xmem.rs`. AI-assisted (Hy4 flash).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:18 UTC · original

Reviewed and verified fda4a63d on Windows 11 against main (842b0cb):

  • Local checks: victory-hle dstorage 17/17 (including host_refusals_are_retried_with_longer_waits) and xmem 14/14 passed, cargo clippy --locked -p victory-hle --all-targets -- -D warnings 0 warnings, cargo xtask policy (191 files ok).
  • Concurrency/safety audit looks clean: xmem::write_physical only holds physical() briefly in runs(), never across sleep backoff or MapViewOfFile, freeing a page mid-retry terminates cleanly via runs() -> None, and retries are idempotent before report_written.
  • One minor edge case to note (non-blocking): if the initial pages slice contains 0 (entering the LATE_LIST_TRIES loop) and the title finishes filling the list (!again.contains(&0)), but that write is then refused by the host, line 1070 checks xmem::unknown_pages(pages) == 0 against the original snapshot containing 0 and skips HOST_RETRIES. Passing the refreshed slice (again) into unknown_pages and the retry closure would cover that combined case too.

Looks solid and ready to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2883#issuecomment-7177390729) Reviewed and verified `fda4a63d` on Windows 11 against `main` (`842b0cb`): - Local checks: `victory-hle` `dstorage` 17/17 (including `host_refusals_are_retried_with_longer_waits`) and `xmem` 14/14 passed, `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` 0 warnings, `cargo xtask policy` (`191 files ok`). - Concurrency/safety audit looks clean: `xmem::write_physical` only holds `physical()` briefly in `runs()`, never across sleep backoff or `MapViewOfFile`, freeing a page mid-retry terminates cleanly via `runs() -> None`, and retries are idempotent before `report_written`. - One minor edge case to note (non-blocking): if the initial `pages` slice contains `0` (entering the `LATE_LIST_TRIES` loop) and the title finishes filling the list (`!again.contains(&0)`), but that write is then refused by the host, line 1070 checks `xmem::unknown_pages(pages) == 0` against the original snapshot containing `0` and skips `HOST_RETRIES`. Passing the refreshed slice (`again`) into `unknown_pages` and the retry closure would cover that combined case too. Looks solid and ready to merge.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:26 UTC · original

Automated triage for the maintainers.

Needs work. This retries xmem::write_physical in into_destination (victory-hle/src/modules/dstorage.rs) up to seven times with doubling waits (254 ms total) when all pages are known but the host refused a view. The code is sound, but the PR says the refusal has never been reproduced or logged, and if it is persistent (for example commit exhaustion) each such request now holds its queue for a quarter second without succeeding. Please attach a log showing the warning with unknown = 0 followed by a successful retry, or first make View::map report the Windows error so the failure mode is known.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 04:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2883#issuecomment-7182602978) <!-- victory-triage v1 head=4e897803d10cb1be1891ce03e466ada7ffa5cdb9 verdict=needs-work at=2026-11-26T04:26:45Z --> Automated triage for the maintainers. **Needs work.** This retries `xmem::write_physical` in `into_destination` (`victory-hle/src/modules/dstorage.rs`) up to seven times with doubling waits (254 ms total) when all pages are known but the host refused a view. The code is sound, but the PR says the refusal has never been reproduced or logged, and if it is persistent (for example commit exhaustion) each such request now holds its queue for a quarter second without succeeding. Please attach a log showing the warning with `unknown = 0` followed by a successful retry, or first make `View::map` report the Windows error so the failure mode is known. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 07:22 UTC · original

I can't run the title, so I can't attach a log. I went with the second option in 5c87644 (rebased onto main):

  • View::map now returns the Windows error, using GetLastError() right after MapViewOfFile, or the error from committing the view. write_physical passes it through. When a request fails, the warning now includes error = <message> (os error N) next to unknown. The info line for a write that succeeded on a retry includes the code it first hit.
  • Retries now happen only for memory-shortage errors: ERROR_NOT_ENOUGH_MEMORY, ERROR_NO_SYSTEM_RESOURCES and ERROR_COMMITMENT_LIMIT. Any other error, or a retry that hits one, fails the request right away without waiting. I kept the commit limit in the retry set because it can rise while Windows grows a system-managed page file. When the limit is persistent, commit_refused already writes it to crashes.log, since the title usually faults soon after. New test: other_refusals_are_not_retried.

If anyone hits this, please post the dstorage: a destination's physical pages could not be written warning line (or the written after the host refused a view info line) along with the error field.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 07:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2883#issuecomment-7185382835) I can't run the title, so I can't attach a log. I went with the second option in 5c87644 (rebased onto main): - `View::map` now returns the Windows error, using `GetLastError()` right after `MapViewOfFile`, or the error from committing the view. `write_physical` passes it through. When a request fails, the warning now includes `error = <message> (os error N)` next to `unknown`. The info line for a write that succeeded on a retry includes the code it first hit. - Retries now happen only for memory-shortage errors: `ERROR_NOT_ENOUGH_MEMORY`, `ERROR_NO_SYSTEM_RESOURCES` and `ERROR_COMMITMENT_LIMIT`. Any other error, or a retry that hits one, fails the request right away without waiting. I kept the commit limit in the retry set because it can rise while Windows grows a system-managed page file. When the limit is persistent, `commit_refused` already writes it to `crashes.log`, since the title usually faults soon after. New test: `other_refusals_are_not_retried`. If anyone hits this, please post the `dstorage: a destination's physical pages could not be written` warning line (or the `written after the host refused a view` info line) along with the `error` field.
This pull request can be merged automatically.
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/2883/head:github-bot/gh-2883'
git switch 'github-bot/gh-2883'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2883'
git switch 'github-bot/gh-2883'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2883'
git switch 'github-bot/gh-2883'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2883'
git switch 'main'
git merge --squash 'github-bot/gh-2883'
git switch 'main'
git merge --ff-only 'github-bot/gh-2883'
git switch 'main'
git merge 'github-bot/gh-2883'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2883
No description provided.