DirectStorage: a request's source and zlib intermediate are not zeroed before they are written over #3607

Closed
github-bot wants to merge 1 commit from github-bot/gh-3607 into main AGit
Owner

@⁠tphira612 on GitHub · 2026-11-30 01:39 UTC · original
perf/dstorage-read-no-zero → main · +90 −4 · 1 files · 1 commits · closed without merging

What it changes

Every compressed DirectStorage request zeroed its source buffer, and then the file read wrote every byte of it again. The zlib intermediate (zlib then BCPack) was zeroed too, then cut to what the stream wrote. Every byte was written twice, on the workers that stream textures in.

Scratch::for_overwrite takes a spare buffer as it is and zeroes only a part past what it held before. It is used for those two buffers only:

  • the source: read_into fills it whole, or the request fails and the buffer is never read;
  • the intermediate: inflate writes n bytes and the buffer is truncated to n before BCPack reads it.

The buffer of a write to scattered pages stays zeroed, since all of it goes to the pages even when a zlib stream ends short. With VICTORY_DSTORAGE_BUFFERS=0, or above SPARE_MAX, buffers are vec![0; len] as before.

How it was tested

  • Cached file reads into a reused buffer, zeroed first vs not (Ryzen 9 5900X, release build): 64 KiB 8.6 → 8.0 µs, 1 MiB 112 → 100 µs, 8 MiB 1,559 → 845 µs. Load times and pop-in in the title not measured.
  • New tests: a_buffer_to_write_over_is_reused_without_zeroing (same memory reused, only the new part zeroed, zeroed() unchanged) and a_source_read_into_a_reused_buffer_is_the_file (a read into a buffer holding other bytes gives exactly the file). The existing spare-buffer tests pass.
  • cargo test --locked -p victory-hle --lib: 424 passed (main 422, plus the two new ones). The one failure, xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it, also fails on main in the full run and passes alone.
  • cargo build --release --locked -p victory and cargo xtask policy --staged pass. Clippy adds no warnings to victory-hle.
**@⁠tphira612** on GitHub · 2026-11-30 01:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3607) `perf/dstorage-read-no-zero` → `main` · +90 −4 · 1 files · 1 commits · closed without merging ## What it changes Every compressed DirectStorage request zeroed its source buffer, and then the file read wrote every byte of it again. The zlib intermediate (zlib then BCPack) was zeroed too, then cut to what the stream wrote. Every byte was written twice, on the workers that stream textures in. `Scratch::for_overwrite` takes a spare buffer as it is and zeroes only a part past what it held before. It is used for those two buffers only: - the source: `read_into` fills it whole, or the request fails and the buffer is never read; - the intermediate: `inflate` writes `n` bytes and the buffer is truncated to `n` before BCPack reads it. The buffer of a write to scattered pages stays zeroed, since all of it goes to the pages even when a zlib stream ends short. With `VICTORY_DSTORAGE_BUFFERS=0`, or above `SPARE_MAX`, buffers are `vec![0; len]` as before. ## How it was tested - Cached file reads into a reused buffer, zeroed first vs not (Ryzen 9 5900X, release build): **64 KiB 8.6 → 8.0 µs, 1 MiB 112 → 100 µs, 8 MiB 1,559 → 845 µs**. Load times and pop-in in the title not measured. - New tests: `a_buffer_to_write_over_is_reused_without_zeroing` (same memory reused, only the new part zeroed, `zeroed()` unchanged) and `a_source_read_into_a_reused_buffer_is_the_file` (a read into a buffer holding other bytes gives exactly the file). The existing spare-buffer tests pass. - `cargo test --locked -p victory-hle --lib`: 424 passed (main 422, plus the two new ones). The one failure, `xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`, also fails on `main` in the full run and passes alone. - `cargo build --release --locked -p victory` and `cargo xtask policy --staged` pass. Clippy adds no warnings to `victory-hle`.
read_source zeroed its buffer (Scratch::zeroed) and the read then wrote
every byte of it, or the request failed; the zlib intermediate was zeroed
and then cut to what the stream wrote. Every byte was written twice.

Scratch::for_overwrite takes a spare buffer as it is and zeroes only a
part past what it held before; the buffer of a write to scattered pages
stays zeroed, since all of it goes to the pages. A read from the file
cache, zeroed first and not (Ryzen 9 5900X, release build): 64 KiB 8.6
and 8.0 us, 1 MiB 112 and 100 us, 8 MiB 1,559 and 845 us.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:42:56 +00:00
github-bot closed this pull request 2026-11-30 18:10:37 +00:00

Pull request closed

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!3607
No description provided.