DirectStorage: a zlib request that fails is tried again, the last time past the file cache #3245

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

@⁠ve3xone on GitHub · 2026-11-29 20:59 UTC · original
ve3xone:dstorage-zlib-retry → main · +121 −2 · 1 files · 1 commits · open

Mitigates #1272 (root cause still open; evidence in the comment there).

What

When a zlib request fails to inflate (0x8007000d), execute now tries again before the title is told, instead of failing the request:

  1. The same source bytes, inflated into a buffer of ours. If that works, the destination changed under the in-place inflate.
  2. The source read once more.
  3. The source read through a handle reopened with FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING (the existing read_direct), past the host's file cache.

The result is copied into the destination in one go. Each rescue logs which step worked and how the reads differed (differ: how many bytes, first/last offset, first byte before and after). If all three fail, the request fails as before. The happy path is untouched: no extra copy and no extra read unless a chunk has already failed.

Why

On one PC with the packs on a local SSD, 7 of 9 runs crashed within about 2 minutes, 1 to 3 s after 2 to 8 such failures (an access at null, or the title's own break). The failed chunks inflate fine offline, and reads outside the runtime never mismatch. See #1272 for the full evidence.

Measured

Same PC, same settings (io=Handles), 6-minute run with this change:

bad reads rescued 85
…by reading again 43
…only past the file cache 42
requests failed 0
title crashes 0

Before: crashes in 7 of 9 runs.

Tests

  • New a_failed_zlib_request_is_tried_again. It covers three paths: the same-source retry, a wrong first read with the file right on re-read, and bad on disk too, where the request still fails. It also checks read_uncached at an offset and size that are not sector multiples, None for a memory source, and the differ text.
  • cargo test -p victory-hle --lib dstorage: 30 passed.
  • cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings: nothing in dstorage.rs. The workspace clippy gate is already red on main, independent of this change: gameinput.rs (unnecessary_lazy_evaluations), lifecycle.rs (items_after_test_module), and unused items in victory-shader and victory-loader.
  • cargo xtask policy --staged: ok.

Not in this PR

  • Making VICTORY_DSTORAGE_IO=direct the default for victory play. It may avoid the bad cache pages entirely, but I have not measured a run with it yet.
  • The root cause: whatever overwrites the cached pages.
**@⁠ve3xone** on GitHub · 2026-11-29 20:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3245) `ve3xone:dstorage-zlib-retry` → `main` · +121 −2 · 1 files · 1 commits · open Mitigates #1272 (root cause still open; evidence in the comment there). ## What When a zlib request fails to inflate (`0x8007000d`), `execute` now tries again before the title is told, instead of failing the request: 1. The same source bytes, inflated into a buffer of ours. If that works, the destination changed under the in-place inflate. 2. The source read once more. 3. The source read through a handle reopened with `FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING` (the existing `read_direct`), past the host's file cache. The result is copied into the destination in one go. Each rescue logs which step worked and how the reads differed (`differ`: how many bytes, first/last offset, first byte before and after). If all three fail, the request fails as before. The happy path is untouched: no extra copy and no extra read unless a chunk has already failed. ## Why On one PC with the packs on a local SSD, 7 of 9 runs crashed within about 2 minutes, 1 to 3 s after 2 to 8 such failures (an access at null, or the title's own break). The failed chunks inflate fine offline, and reads outside the runtime never mismatch. See #1272 for the full evidence. ## Measured Same PC, same settings (`io=Handles`), 6-minute run with this change: | | | |---|---| | bad reads rescued | 85 | | …by reading again | 43 | | …only past the file cache | 42 | | requests failed | 0 | | title crashes | 0 | Before: crashes in 7 of 9 runs. ## Tests - New `a_failed_zlib_request_is_tried_again`. It covers three paths: the same-source retry, a wrong first read with the file right on re-read, and bad on disk too, where the request still fails. It also checks `read_uncached` at an offset and size that are not sector multiples, `None` for a memory source, and the `differ` text. - `cargo test -p victory-hle --lib dstorage`: 30 passed. - `cargo clippy -p victory-hle --all-targets --no-deps -- -D warnings`: nothing in `dstorage.rs`. The workspace clippy gate is already red on `main`, independent of this change: `gameinput.rs` (`unnecessary_lazy_evaluations`), `lifecycle.rs` (`items_after_test_module`), and unused items in `victory-shader` and `victory-loader`. - `cargo xtask policy --staged`: ok. ## Not in this PR - Making `VICTORY_DSTORAGE_IO=direct` the default for `victory play`. It may avoid the bad cache pages entirely, but I have not measured a run with it yet. - The root cause: whatever overwrites the cached pages.
A chunk that failed to inflate (0x8007000d) failed the request, and the
title crashed a few seconds later on what it should have loaded (an
access at null, or its own break). The failure path now tries again
before the title is told: the same source bytes into a buffer of ours,
then the source read once more, then read through a handle opened with
FILE_FLAG_NO_BUFFERING. The happy path is unchanged.

Measured on one PC with the packs on a local SSD (2026-11-29): seven of
nine runs crashed within two minutes after 2 to 8 such failures. All 13
failed chunks inflate offline, and 40,000 chunks read twice by 28
threads outside the runtime matched. With the retry, a 6-minute run had
85 bad reads, 0 failed requests and no crash: 43 came right read again,
42 only past the file cache. In each comparison the differing bytes
lay in one run (2% to 100% of the chunk, all of it in 54 of 97, the
0x78 zlib header overwritten in 75): runs of other data in the cached
pages, not scattered flipped bits. The warning says how many bytes
differed and where.

Mitigates #1272.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 21:03:23 +00:00
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/3245/head:github-bot/gh-3245'
git switch 'github-bot/gh-3245'

Merge

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