Skip to content

GPU: a pipeline library save the host has no memory for waits, not aborts (1.7 GB library on NVIDIA) - #2007

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
KevinPratap:gpu/library-save-fallible
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
KevinPratap:gpu/library-save-fallible

Conversation

@KevinPratap

Copy link
Copy Markdown
Contributor

Problem

library::save serialises the pipeline library with vec![0u8; GetSerializedSize()]. On NVIDIA the library holds each pipeline's machine code: after translate --cache --pipelines it is about 1.7 GB on an RTX 4050 Laptop, where the README mentions about 4 MB on AMD. A save in the world then aborted the whole process:

memory allocation of 2650101862 bytes failed

(32 GB RAM, about 21 GB committed by the process at that point.)

Fix

The buffer is reserved with try_reserve_exact. Without memory, the save logs a warning and returns. The pipelines stay counted as added, so the next save tries again.

Verified

  • New test a_save_buffer_the_host_cannot_give_is_refused; the pipeline::library tests pass (9).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean.

Related: the size itself (one blob rewritten whole every 20 s) is worth splitting on NVIDIA, but that is a larger change.

Only crates/victory-gpu/src/pipeline/library.rs changes.

AI-assisted.

🤖 Generated with Claude Code

…orts

The library is serialised into one buffer of its whole size, allocated infallibly. On NVIDIA the library holds each pipeline's machine code, about 1.7 GB after translate --cache --pipelines, and a save in the world aborted the process: 'memory allocation of 2650101862 bytes failed' (RTX 4050 Laptop, 32 GB). The buffer is now reserved fallibly; without memory the save is left for later (the pipelines stay counted as added).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Pipeline-library save with insufficient host memory waits instead of aborting — OOM-path hardening; correct fail-slow behavior for an emulator.

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep the fallible allocation; preserve early-list retries (54b994d)

Evidence

  • The reservation failure now returns without aborting. There is one save path where leaving l.added intact is insufficient. When l.added == 0, prebuilt_changed is false, and the early list alone is dirty, the entry check consumes USED_CHANGED with swap(false, …) before calling zeroed. The new failure return leaves no dirty flag for a later retry. The existing serializer-error path has the same bookkeeping gap.

Checks and limits

  • The allocation helper test covers rejecting an unallocatable size and producing zero bytes for a small size. It does not go through save with only the early list dirty. The exact-head Windows check passed. I reviewed the source and CI without inducing host memory pressure.

Next step

  • Retain or restore the early-list dirty state when an allocation or serialization failure interrupts a save, without overwriting concurrent usage updates. A synthetic failed allocation with no new pipelines, followed by a successful retry, would pin the behavior. GPU: retry pipeline cache saves after write failures #72’s retry bookkeeping is a useful comparator for the broader save path.

This verification was AI-assisted.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate.

crates/victory-gpu/src/pipeline/library.rs::save now allocates the serialisation buffer with try_reserve_exact (new helper zeroed) instead of vec[0u8; GetSerializedSize()], so a library too large for the host's free memory logs a warning and is retried on a later save instead of aborting the process. l.added/prebuilt_changed are left untouched on that path, so the retry does happen; on Windows the allocator reports failure rather than overcommitting, so try_reserve_exact is the right tool here. Small, focused, merges cleanly.

Optional follow-up, also raised in the earlier review comment: when only the early list is dirty, USED_CHANGED has already been swapped to false before the allocation, so a failed allocation (like the existing serialiser-error path) drops that pending early-list save until something else changes; restoring the flag on both failure returns would close that. #2129 contains the same fallible helper inside a much larger rework of the library file; this PR is the smaller way to land just the abort fix. Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

juanfariasdev pushed a commit to juanfariasdev/VIctory that referenced this pull request Nov 25, 2026
The host pipeline library was read into a buffer at start and kept for
the whole run, because the host reads the bytes a library was made from
for as long as it lives; a save serialised the whole library into a
second buffer and wrote it out. On fxceless/victory-fork a world run's
library was 1,352 MB, all of it in the process's own memory; a save of
a 1.7 GB library failing for lack of memory is what Marvisak#2007 handles.

The file is now mapped: its pages are the file's, only those the host
reads are in memory, and the system can drop them without writing them
anywhere. A save serialises the library straight into a mapping of a
uniquely named staging file and renames it over the library.

The mapped file's handle stays open while it is mapped. A save renames
over the file this run has mapped, and with the handle closed Windows
gives up the old file's contents, so pages of the mapping not in memory
then read as zeros, which the host would take for stored pipelines (the
fork lost the device that way). Where a system refuses to replace a
mapped file, the new library waits as `host-pipelines.next` and takes
the old one's place at the next start. `VICTORY_LIBRARY_MAP=0` reads and
writes through buffers, as before; that buffer, and the one used where a
staging file cannot be mapped, is asked for fallibly, so a save the host
has no memory for is left for later instead of aborting (as Marvisak#2007 does
for today's buffer).

Ported from fxceless/victory-fork (commit 578d459): the mapping only, on
top of upstream's concurrent loads, unique staging files and pre-build
list (not that commit's other library changes).

Tests:
- `the_library_file_is_mapped_and_replaced`: a mapped file reads as its
  bytes; a save through a mapped staging file replaces the mapped
  library, the old mapping still reads the old bytes, the next start
  reads the new ones, the returned tag is the new bytes', no staging
  file is left, and a failed serialisation leaves the library as it was.
- `a_replaced_library_file_still_reads_from_the_disk`: an 8 MiB file
  written past the system cache, mapped, then replaced by a save; every
  page still reads as the old file. With the handle closed it fails
  (page 16 reads zeros on an RTX 5070 Ti host).
- `pipelines_load_on_many_threads_at_once` now opens its library from a
  mapped file.
- `a_save_buffer_the_host_cannot_give_is_an_error`.

Co-authored-by: fxceless <36782933+fxceless@users.noreply.github.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
…ory for waits, not aborts (1.7 GB library on NVIDIA)
@Marvisak
Marvisak merged commit 321a4bc into Marvisak:main Nov 25, 2026
1 check passed
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 25, 2026
The host pipeline library was read into a buffer at start and kept for
the whole run, because the host reads the bytes a library was made from
for as long as it lives; a save serialised the whole library into a
second buffer and wrote it out. On fxceless/victory-fork a world run's
library was 1,352 MB, all of it in the process's own memory; a save of
a 1.7 GB library failing for lack of memory is what Marvisak#2007 handles.

The file is now mapped: its pages are the file's, only those the host
reads are in memory, and the system can drop them without writing them
anywhere. A save serialises the library straight into a mapping of a
uniquely named staging file and renames it over the library.

The mapped file's handle stays open while it is mapped. A save renames
over the file this run has mapped, and with the handle closed Windows
gives up the old file's contents, so pages of the mapping not in memory
then read as zeros, which the host would take for stored pipelines (the
fork lost the device that way). Where a system refuses to replace a
mapped file, the new library waits as `host-pipelines.next` and takes
the old one's place at the next start. `VICTORY_LIBRARY_MAP=0` reads and
writes through buffers, as before; that buffer, and the one used where a
staging file cannot be mapped, is Marvisak#2007's fallible one, so a save the
host has no memory for is still left for later instead of aborting.

Ported from fxceless/victory-fork (commit 578d459): the mapping only, on
top of upstream's concurrent loads, unique staging files and pre-build
list (not that commit's other library changes).

Tests:
- `the_library_file_is_mapped_and_replaced`: a mapped file reads as its
  bytes; a save through a mapped staging file replaces the mapped
  library, the old mapping still reads the old bytes, the next start
  reads the new ones, the returned tag is the new bytes', no staging
  file is left, and a failed serialisation leaves the library as it was.
- `a_replaced_library_file_still_reads_from_the_disk`: an 8 MiB file
  written past the system cache, mapped, then replaced by a save; every
  page still reads as the old file. With the handle closed it fails
  (page 16 reads zeros on an RTX 5070 Ti host).
- `pipelines_load_on_many_threads_at_once` now opens its library from a
  mapped file.

Co-authored-by: fxceless <36782933+fxceless@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants