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

Open
legayclightning22 wants to merge 1 commit from upstream-pr/3282 into main
legayclightning22 commented 2026-11-26 15:41:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T15:41:06Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:issue:5512981341 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T15:41:06Z. --- ## 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`
AurumCarlos commented 2026-11-26 15:46:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-26T15:46:13Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6076992702 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6076992702). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-26T15:46:13Z. **Review:** COMMENTED --- 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.
Dukestar69 commented 2026-11-26 15:47:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:47:55Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6077015563 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6077015563). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T15:47:55Z. **Review:** APPROVED --- 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).
legayclightning22 commented 2026-11-26 16:20:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T16:20:59Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197524488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282#issuecomment-7197524488). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T16:20:59Z. --- 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`.
fuzeofficlal commented 2026-11-26 20:24:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T20:24:28Z.

Review: CHANGES_REQUESTED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6080118547 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282#pullrequestreview-6080118547). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T20:24:28Z. **Review:** CHANGES_REQUESTED --- 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`.
legayclightning22 commented 2026-11-28 04:41:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-28T04:41:25Z.


Thanks @fuzeofficlal — pushed an updated commit in crates/victory-hle/src/modules/dstorage.rs slicing pages by actual inflated bytes n, running LATE_LIST_TRIES before warning on zero pages, aborting the retry sleep early when lane.closed is set, isolating DESTINATION_RETRIES in tests, freeing test physical pages, and running rustfmt.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234197489 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3282#issuecomment-7234197489). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-28T04:41:25Z. --- Thanks @fuzeofficlal — pushed an updated commit in `crates/victory-hle/src/modules/dstorage.rs` slicing `pages` by actual inflated bytes `n`, running `LATE_LIST_TRIES` before warning on zero pages, aborting the retry sleep early when `lane.closed` is set, isolating `DESTINATION_RETRIES` in tests, freeing test physical pages, and running `rustfmt`.
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/3282:upstream-pr/3282'
git switch 'upstream-pr/3282'

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/3282'
git switch 'upstream-pr/3282'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3282'
git switch 'upstream-pr/3282'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3282'
git switch 'main'
git merge --squash 'upstream-pr/3282'
git switch 'main'
git merge --ff-only 'upstream-pr/3282'
git switch 'main'
git merge 'upstream-pr/3282'
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
Marvisak/VIctory!3280
No description provided.