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

Merged
mizzied merged 1 commit from upstream-pr/1596 into main 2026-11-29 08:16:56 +00:00
mizzied commented 2026-11-28 22:10:57 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mizzied on 2026-11-28T22:10:57Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5545063213 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1596). Originally posted by [mizzied](https://github.com/mizzied) on 2026-11-28T22:10:57Z. --- **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.
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
trustno1-coder/VIctory-NVIDIA!1596
No description provided.