DirectStorage: requests reuse a worker's buffers, within one budget #1596

Manually merged
github merged 1 commit from github-bot/gh-1596 into main 2026-11-29 08:21:21 +00:00 AGit
Owner

@⁠mizzied on GitHub · 2026-11-28 22:10 UTC · original
mizzied:up/dstorage-buffers → main · +254 −8 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC

What was wrong. Each DirectStorage request allocated its source buffer, its zlib intermediate and the buffer for a write to scattered pages with vec![0; size]. That faulted in every page again for every request.

The fix. A worker now keeps up to three spare buffers of at most 32 MiB each (VICTORY_DSTORAGE_BUFFERS, on by default), zeroed before reuse. All workers together keep at most 256 MB of them (VICTORY_DSTORAGE_BUFFER_BUDGET, in MB, 0 for no bound). Without that bound, 16 workers × 3 × 32 MiB could hold 1.5 GB for the whole run, in a process that's often short of memory. A buffer that doesn't fit is freed at the end of its request.

How it was tested. RTX 5070, Windows 11. New tests cover the following:

  • A spare buffer is reused (same memory) and zeroed again.
  • It's counted while kept, and not kept past what a worker keeps.
  • A worker keeps three spare buffers at most.
  • The budget bounds what all workers keep, counts a buffer again when it leaves, and is no bound when 0.

cargo test --workspace passes apart from repository_passes_policy, which already fails on main: lower.rs is over the 640 KiB file-size limit there (#1493 raises it). Clippy reports only the 16 findings already on main, none on lines this PR changes.

**@⁠mizzied** on GitHub · 2026-11-28 22:10 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1596) `mizzied:up/dstorage-buffers` → `main` · +254 −8 · 1 files · 1 commits · merged 2026-11-29 08:16 UTC **What was wrong.** Each DirectStorage request allocated its source buffer, its zlib intermediate and the buffer for a write to scattered pages with `vec![0; size]`. That faulted in every page again for every request. **The fix.** A worker now keeps up to three spare buffers of at most 32 MiB each (`VICTORY_DSTORAGE_BUFFERS`, on by default), zeroed before reuse. All workers together keep at most 256 MB of them (`VICTORY_DSTORAGE_BUFFER_BUDGET`, in MB, `0` for no bound). Without that bound, 16 workers × 3 × 32 MiB could hold 1.5 GB for the whole run, in a process that's often short of memory. A buffer that doesn't fit is freed at the end of its request. **How it was tested.** RTX 5070, Windows 11. New tests cover the following: - A spare buffer is reused (same memory) and zeroed again. - It's counted while kept, and not kept past what a worker keeps. - A worker keeps three spare buffers at most. - The budget bounds what all workers keep, counts a buffer again when it leaves, and is no bound when 0. `cargo test --workspace` passes apart from `repository_passes_policy`, which already fails on `main`: `lower.rs` is over the 640 KiB file-size limit there (#1493 raises it). Clippy reports only the 16 findings already on `main`, none on lines this PR changes.
A request's source, its zlib intermediate and the buffer of a write to
scattered pages were each vec![0; size], faulting in all their pages again
for every request. A worker now keeps up to three spare buffers of at most
32 MiB (VICTORY_DSTORAGE_BUFFERS, on), zeroed before reuse, and all workers
together keep at most 256 MB of them (VICTORY_DSTORAGE_BUFFER_BUDGET, in
megabytes, 0 for no bound): 16 workers by 3 by 32 MiB could hold 1.5 GB for
the run in a process the PC has little memory left for. A buffer that does
not fit is freed at the end of its request.

Tests: a spare buffer is reused (same memory), zeroed again, counted while
kept and not kept past the most a worker keeps; a worker keeps three spare
buffers at most; the budget bounds what all workers keep, counts a buffer
again when it leaves, and is no bound when 0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 22:13:05 +00:00
github manually merged commit a68640af72 into main 2026-11-29 08:21:21 +00:00
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!1596
No description provided.