fix(hle): retry transient physical destination writes in DirectStorage #3282

Open
github-bot wants to merge 1 commit from github-bot/gh-3282 into main AGit
Owner

@⁠legayclightning22 on GitHub · 2026-11-26 15:41 UTC · original
legayclightning22:fix/dstorage-destination-write-retries → main · +171 −1 · 1 files · 1 commits · open

Summary

Adds bounded retries with capped exponential backoff to DirectStorage physical destination writes in crates/victory-hle/src/modules/dstorage.rs so transient page/view refusals during launch and streaming recover cleanly instead of dropping reads.

Changes

  • Retry transient xmem::write_physical failures up to 12 times by default (VICTORY_DSTORAGE_RETRIES override capped at 64) with capped exponential backoff (1–100 ms).
  • Track retried writes with an atomic counter surfaced in debug summaries and log exhausted failures clearly without panicking.
  • Add unit tests covering transient retry recovery, exhaustion handling, and environment override limits.

Verification

  • cargo test -p victory-hle --lib
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings
  • cargo xtask policy
**@⁠legayclightning22** on GitHub · 2026-11-26 15:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3282) `legayclightning22:fix/dstorage-destination-write-retries` → `main` · +171 −1 · 1 files · 1 commits · open ## Summary Adds bounded retries with capped exponential backoff to DirectStorage physical destination writes in `crates/victory-hle/src/modules/dstorage.rs` so transient page/view refusals during launch and streaming recover cleanly instead of dropping reads. ## Changes - Retry transient `xmem::write_physical` failures up to 12 times by default (`VICTORY_DSTORAGE_RETRIES` override capped at 64) with capped exponential backoff (`1–100 ms`). - Track retried writes with an atomic counter surfaced in debug summaries and log exhausted failures clearly without panicking. - Add unit tests covering transient retry recovery, exhaustion handling, and environment override limits. ## Verification - `cargo test -p victory-hle --lib` - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` - `cargo xtask policy`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:42:21 +00:00
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-26 15:46 UTC · original · reviewed

The retry treats every write_physical failure as transient, but into_destination already handles a known permanent one right after it (page number 0, "no page"). With this change, that case and any other bad destination now sleep through 12 attempts (about 0.6 s: 1+2+…+64 ms, then 100 ms × 5) on a DirectStorage worker before reaching the same fallback, with the worker blocked the whole time. A title issuing several such requests would stall the queue.

What makes a refusal transient here? If there's a log showing write_physical failing and then succeeding for the same pages (e.g. a mapping racing the read), please link it. Otherwise, retrying only when the pages exist but aren't mapped yet, and failing at once for page 0 or unknown pages, would keep the bad cases fast.

**@⁠AurumCarlos** on GitHub · 2026-11-26 15:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6076992702) · **reviewed** The retry treats every `write_physical` failure as transient, but `into_destination` already handles a known permanent one right after it (page number 0, "no page"). With this change, that case and any other bad destination now sleep through 12 attempts (about 0.6 s: 1+2+…+64 ms, then 100 ms × 5) on a DirectStorage worker before reaching the same fallback, with the worker blocked the whole time. A title issuing several such requests would stall the queue. What makes a refusal transient here? If there's a log showing `write_physical` failing and then succeeding for the same pages (e.g. a mapping racing the read), please link it. Otherwise, retrying only when the pages exist but aren't mapped yet, and failing at once for page 0 or unknown pages, would keep the bad cases fast.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 15:47 UTC · original · approved these changes

Reviewed the diff and verified locally on Windows 11 x64:

  • Retrying transient xmem::write_physical refusals with capped exponential backoff (VICTORY_DSTORAGE_RETRIES, capped at 64, max 100 ms backoff) and surfacing destination_retries in the periodic debug line is clean and bounded.
  • cargo test -p victory-hle --lib modules::dstorage:: -- --test-threads=1: 19 passed, 0 failed (including destination_retry_setting_is_bounded, physical_writes_retry_transient_refusals, and physical_writes_report_exhausted_retries_without_panicking).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 15:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6077015563) · **approved these changes** Reviewed the diff and verified locally on Windows 11 x64: - Retrying transient `xmem::write_physical` refusals with capped exponential backoff (`VICTORY_DSTORAGE_RETRIES`, capped at 64, max 100 ms backoff) and surfacing `destination_retries` in the periodic debug line is clean and bounded. - `cargo test -p victory-hle --lib modules::dstorage:: -- --test-threads=1`: 19 passed, 0 failed (including `destination_retry_setting_is_bounded`, `physical_writes_retry_transient_refusals`, and `physical_writes_report_exhausted_retries_without_panicking`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github-bot force-pushed github-bot/gh-3282 from 5bbed0f1b9 to 891dfa023c 2026-11-26 16:04:40 +00:00 Compare
Author
Owner

@⁠legayclightning22 on GitHub · 2026-11-26 16:20 UTC · original

Pushed 891dfa0 adding an immediate fail-fast check for page 0 / unknown or unmapped destination addresses before retrying so bad addresses don't incur retry backoff, along with a unit test asserting zero retry attempts. Re-verified dstorage tests (20/20 passing), clippy -- -D warnings, and cargo xtask policy.

**@⁠legayclightning22** on GitHub · 2026-11-26 16:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/3282#issuecomment-7197524488) Pushed `891dfa0` adding an immediate fail-fast check for page `0` / unknown or unmapped destination addresses before retrying so bad addresses don't incur retry backoff, along with a unit test asserting zero retry attempts. Re-verified `dstorage` tests (20/20 passing), `clippy -- -D warnings`, and `cargo xtask policy`.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 20:24 UTC · original · requested changes

Thanks for adding the fail-fast precheck in 891dfa0. Local tests pass (victory-hle: 156 lib + 2 integration tests, dstorage::: 20 passed), and clippy (default & --all-features) is clean, but a few issues in into_destination / retry_physical_write still need attention before merge:

Requested changes

  1. Race between the zero-page precheck and the late page-list fallback (crates/victory-hle/src/modules/dstorage.rs:1057-1067, 1143-1161):
    pages views title memory directly (1113). If retry_physical_write observes 0 at 1057 and returns Err(E_INVALIDARG), and the title finishes populating the page list before 1143 (if pages.contains(&0)), 1143 sees false, skips LATE_LIST_TRIES and the write, and fails the request with E_INVALIDARG. Even without the race, 1059 also logs "dstorage: physical destination has no allocated pages" at warn! before LATE_LIST_TRIES gets a chance to succeed.
  2. Short zlib output can be rejected due to unused trailing pages (dstorage.rs:909-918, 1113-1131):
    inflate (912) accepts outputs shorter than len (n < len), and into_destination only writes &data[..n] (1129). However, pages is sliced for (offset + len).div_ceil(PAGE) (1116), so pages.contains(&0) and unknown_pages(pages) inspect trailing pages past offset + n that will not be written. If any unused trailing page is 0 or unknown, the precheck rejects a write that fits cleanly in the leading pages. Slicing pages to (offset + n).div_ceil(PAGE) before calling retry_physical_write would avoid this.
  3. Worker/staging stall and transient failure rationale (dstorage.rs:459, 523, 669, 1086):
    Retrying with std::thread::sleep (up to ~627 ms at the default 12 retries, or ~5.8 s at the cap of 64) holds the worker thread, self.staged quota, queue status flushing, and close_lane without checking lane.closed. Also, as asked earlier, once zero == false && unknown == 0, it would be helpful to clarify what concrete transient condition makes write_physical succeed after sleeping.

Minor nits

  • DESTINATION_RETRIES is a process-wide static read by Lanes::count (497, swap(0)) and asserted in physical_writes_retry_transient_refusals (1928) / physical_writes_fail_fast_on_page_zero_or_unknown_pages (1962), which can race if tests run concurrently or with debug logging enabled.
  • allocated_page() (1346) does not free its allocated physical page via XMemFreePhysicalPages at the end of those two tests.
  • rustfmt --edition 2024 diffs appear in the PR hunks at dstorage.rs:1038 and 1910.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 20:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6080118547) · **requested changes** Thanks for adding the fail-fast precheck in `891dfa0`. Local tests pass (`victory-hle`: 156 lib + 2 integration tests, `dstorage::`: 20 passed), and `clippy` (default & `--all-features`) is clean, but a few issues in `into_destination` / `retry_physical_write` still need attention before merge: ### Requested changes 1. **Race between the zero-page precheck and the late page-list fallback (`crates/victory-hle/src/modules/dstorage.rs:1057-1067`, `1143-1161`):** `pages` views title memory directly (`1113`). If `retry_physical_write` observes `0` at `1057` and returns `Err(E_INVALIDARG)`, and the title finishes populating the page list before `1143` (`if pages.contains(&0)`), `1143` sees `false`, skips `LATE_LIST_TRIES` and the write, and fails the request with `E_INVALIDARG`. Even without the race, `1059` also logs `"dstorage: physical destination has no allocated pages"` at `warn!` before `LATE_LIST_TRIES` gets a chance to succeed. 2. **Short zlib output can be rejected due to unused trailing pages (`dstorage.rs:909-918`, `1113-1131`):** `inflate` (`912`) accepts outputs shorter than `len` (`n < len`), and `into_destination` only writes `&data[..n]` (`1129`). However, `pages` is sliced for `(offset + len).div_ceil(PAGE)` (`1116`), so `pages.contains(&0)` and `unknown_pages(pages)` inspect trailing pages past `offset + n` that will not be written. If any unused trailing page is `0` or unknown, the precheck rejects a write that fits cleanly in the leading pages. Slicing `pages` to `(offset + n).div_ceil(PAGE)` before calling `retry_physical_write` would avoid this. 3. **Worker/staging stall and transient failure rationale (`dstorage.rs:459`, `523`, `669`, `1086`):** Retrying with `std::thread::sleep` (up to ~627 ms at the default 12 retries, or ~5.8 s at the cap of 64) holds the worker thread, `self.staged` quota, queue status flushing, and `close_lane` without checking `lane.closed`. Also, as asked earlier, once `zero == false && unknown == 0`, it would be helpful to clarify what concrete transient condition makes `write_physical` succeed after sleeping. ### Minor nits - `DESTINATION_RETRIES` is a process-wide static read by `Lanes::count` (`497`, `swap(0)`) and asserted in `physical_writes_retry_transient_refusals` (`1928`) / `physical_writes_fail_fast_on_page_zero_or_unknown_pages` (`1962`), which can race if tests run concurrently or with debug logging enabled. - `allocated_page()` (`1346`) does not free its allocated physical page via `XMemFreePhysicalPages` at the end of those two tests. - `rustfmt --edition 2024` diffs appear in the PR hunks at `dstorage.rs:1038` and `1910`.
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/3282/head:github-bot/gh-3282'
git switch 'github-bot/gh-3282'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3282'
git switch 'github-bot/gh-3282'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3282'
git switch 'github-bot/gh-3282'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3282'
git switch 'main'
git merge --squash 'github-bot/gh-3282'
git switch 'main'
git merge --ff-only 'github-bot/gh-3282'
git switch 'main'
git merge 'github-bot/gh-3282'
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!3282
No description provided.