victory-gpu: split the pipeline library into shards so a save writes only what changed (was 600 MB per save) #1653
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1653
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1653"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@pes7 on GitHub · 2026-11-24 20:29 UTC · original
pes7:perf/pipeline-library-shards→main· +261 −131 · 1 files · 3 commits · openEvery save writes the whole 600 MB pipeline library. The host can only serialise a library whole, so splitting it into shards - one file each, chosen by the pipeline's name hash - lets a save write only the shards that gained pipelines.
owner:GPU-PIPELINE-LIBRARY-SIZEin #1633. ## The problem, as the task states it The host pipeline library is one serialised blob, over 600 MB in the world, andID3D12PipelineLibrary::Serializehas no per-entry form: the whole thing is copied into one buffer and written, every time a save happens (every 20 s while new pipelines are still being made, and at shutdown).Serializeitself copies 600 MB, thenwrite_atomicallywrites 600 MB to a temp file and renames it. ## What changes The library becomes 16 shards,host-pipelines.00.bin...host-pipelines.15.bin: -shard_of(name)hashes the pipeline's name (already a hash of its whole host description) and picks a shard. Stable across runs, so a pipeline always lands in the same file - that is what makes a partial save correct. -libraries()opens every shard from its own file; a missing file is an empty library, a rejected blob is an empty library, exactly as the single file behaved. -pipeline()looks a pipeline up in its own shard only (no extra lookups: the routing is deterministic) and stores it there on a miss. The per-shard mutex also means pipeline creation contends 16 ways instead of one. -save()serialises and writes only the shards withadded > 0, and writes the early list only when it changed. The log line reportsshards = K, bytes = Binstead of one blob's size. A save that adds pipelines spread over K shards writesK/16of the library instead of all of it. In the steady state a run touches one or two shards, so a 600 MB write becomes roughly 40-75 MB. ## Measured What I can measure here, without the title: -a_pipeline_lands_in_one_shard_and_the_shards_spread: the same name always maps to the same shard, and 4 096 names reach all 16 shards, so a save is a fraction rather than all or nothing. - The bytes a save writes are printed by the existing log line (host pipeline library saved), which now carriesshardsandbytes- so the first run in the world gives the number directly: the old line reportedbytes тХд╨ТтХи╨йтХи╨и 600 MB, the new one reports the sum of the changed shards. Not measured: the wall time of a save in the world. It isSerialize+ one write per changed shard, so it scales with the same fraction. ## Correctness Rewritten ontomain940d32f, where this module gained the pre-build'sprebuiltlist. That list is now one file per shard (prebuilt-pipelines.NN.txt), each tagged with its own shard's bytes: a single list tagged with the whole library would be invalidated by any shard's write, which would undo the point of sharding. The concurrency added upstream at the same time is kept as it is: one thread at a time per pipeline name (Names/Held), the interface cloned out of the lock so loads do not hold it, and theSAVElock insidewrite_atomically- the sharding only decides which of the sixteen libraries a name is looked up in.a_rejected_blob_gives_an_empty_librarystill passes, and the existing name test is unchanged. - One-time cost on upgrade: the old singlehost-pipelines.binis no longer read, so the first run after this rebuilds the library once (and the old file can be deleted).cargo test --workspace --locked, both clippy configurations with-D warnings,cargo xtask policy. No game data used.Correction, from aycow's control
Sharding wins only while few shards are dirty. aycow measured a 16 MiB synthetic payload through the same publisher:
So the first run after this lands - every shard new, i.e. all sixteen dirty - is worse than one blob, because each shard pays its own serialisation. Every save after that, in the steady state of one to four dirty shards, is 1.4x to 5.3x better. Native PSO serialisation is unmeasured in both directions.
Two persistence holes aycow found are fixed in the current head (
9c60694): a shard's dirty count is cleared only after its file is published (a failed write retries instead of losing the pipelines), and oneSAVINGlock covers serialisation and publication together (two saves cannot publish an older snapshot over a newer one).What it gives (to decide the merge): a save writes only the library shards that gained pipelines, instead of the whole 926 MB (1.7 GB on NVIDIA) every 20 s while holding the library's lock; a cache made before the split is still read, and what it holds moves into the shards as it is used.
State: MERGEABLE, CI
checkgreen, rebased onto today'smain(f3578e3).Risk: the library format moves from one file to 16; a rejected blob still gives an empty shard, and a failed write leaves the shard dirty for the next save.
The host serialises a whole pipeline library and nothing less, so every save wrote all of it: 926 MB here, 1.7 GB on NVIDIA (`host pipeline library saved bytes=970507898`), every 20 seconds, and a save holds the library's lock for as long as it serialises. The library is kept in 16 files now, `host-pipelines.NN.bin`, one per hash of the pipeline's name (`shard_of`). The name is a hash already, so a pipeline always lands in the same shard across runs, and a save serialises and writes only the shards that gained pipelines since the last one (`Library::dirty`). A shard is left dirty if its write fails, so the next save writes it. The early list stays one file and is written when it changed (or on a shutdown save, which passes `now`). A cache made before the shards is not thrown away: `host-pipelines.bin` is still read (never written), and a pipeline found there is stored into its shard, so a warm run fills the shards and the old file can then be deleted. The log says so once, and the load line now reports the shards and their total bytes instead of one file. Measured before this (retail title, `O:\tmp\victory-cache\pipelines`): host pipeline library loaded bytes=970507898 ms=57 (926 MB, 27 160 pipelines) with a save every 20 s writing the same 926 MB back; a run that made three pipelines paid it. After the split, the same save writes one shard of that structure (a sixteenth of the names) plus the early list. Rebased onto today's `main`: `write_atomically`, `zeroed` (a 1.7 GB allocation is not infallible), `Shared { loads, state }` (loads take no lock) and the pre-build's list tagged with the translator hash are all kept; the shard structure is applied on top, and `pipeline`'s `load` is `Fn` rather than `FnOnce` because a name may now be tried in its shard and in the one-file library. cargo test --release -p victory-gpu (229 tests, one new: names spread over the shards and keep their shard); clippy clean; both `victory` configurations build.@aycow on GitHub · 2026-11-24 20:57 UTC · original
Independent checks on exact 88b678b found two persistence concerns. Dirty flags are cleared before successful file publication, and its save-order lock does not cover serialization and publication together. The former can lose retries and the latter allows an older complete snapshot to replace a newer one. #1660's unique temporary paths address a separate failure: the unchanged #1653 writer failed 35/256 concurrent synthetic replacements on Windows, while the #1660 writer passed 256/256.
For a 16 MiB synthetic serialized-payload control using the same atomic publisher in both modes, one dirty shard took median 1.56 ms versus 8.21 ms whole-file, four took 5.59 ms versus 7.85 ms, and all 16 took 24.15 ms versus 8.55 ms. These timings isolate payload preparation and publication. Native PSO serialization and title performance are unmeasured. I also reran all seven #1651 tests, including a real WARP PSO cache round-trip. Those comparisons may help your save-order and fallback choices.
AI-assisted using Codex.
@pes7 on GitHub · 2026-11-24 21:05 UTC · original
Thanks - both are real, and fixed in
f26e6ae:addedis cleared only afterwrite_atomicallysucceeded, by the count that was serialised, so a failed write leaves the shard dirty and the next save retries it (and pipelines stored while the write ran stay dirty too).SAVINGmutex now spans serialisation and publication, so two saves cannot interleave and publish an older snapshot over a newer one.Your control also changes the claim in this description, so I have corrected it rather than leaving "K/16" standing as if it held everywhere:
So sharding wins in the steady state - one to four dirty shards - and loses when every shard is dirty, which is exactly the first world load, because each shard pays its own serialisation. Anyone reading this should expect the first run after the upgrade to be worse and every later save to be better; the sentence in the description now says that.
On the
#1660point: each shard publishes through its own temporary path (host-pipelines.NN.tmp) and theSAVINGlock serialises writers inside the process, so the fixed-path concurrent-replacement failure you measured should not reach this code. If you can point your 256-replacement test at this branch it would settle it rather than my assuming it - I would rather have the number.@pes7 on GitHub · 2026-11-24 22:03 UTC · original
@aycow - your two findings are still addressed, and the branch is rewritten on today's
main(70564ae), which changed this module underneath it (prebuiltlists keyed by a tag of the library bytes,Usedsplit into before/now). The rebase conflicted in seven places, so rather than resolving a three-way merge I re-applied the sharding to the current file; head is1e79f14.Both of your concerns, on the new code:
addedcounter andprebuilt_changedflag are cleared only afterwrite_atomicallyreturnedOk, by what was serialised (l.added -= added; l.prebuilt_changed &= !marked;), so a failed write leaves the shard dirty for the next save and a store during the write keeps it dirty;SAVINGis held across serialising and publishing every shard, so two saves cannot interleave and publish an older complete snapshot over a newer one.Two changes from the revision you reviewed, both because the file moved:
prebuilt-pipelines.NN.txt), each tagged with its own shard's bytes - a single list tagged with the whole library would be invalidated by any shard's write, which would undo the point of sharding;host-pipelines.NN.tmp) stays as it was.Your control still decides the shape of the claim, and the description now says it plainly: 1.56 / 5.59 / 24.15 ms for 1 / 4 / 16 dirty shards against 8.21 / 7.85 / 8.55 ms for one blob, so sharding wins in the steady state and loses on the first save after the upgrade, when every shard is dirty.
cargo test --workspace --locked(79 tests in this crate, including a new one that a corpus of names spreads over allSHARDS), both clippy configurations with-D warnings,cargo xtask policy. Native PSO serialisation and title performance are still unmeasured - no game copy here.@pes7 on GitHub · 2026-11-24 22:41 UTC · original
@catminou4 - good catch, and they do not compose: #1651 (
avt0m4t48) and this one are two takes on the same change, both splittingpipeline/library.rsinto sixteen files and both writing only the shards that gained pipelines. Only one can land. The differences, so the owner can pick:shard_of(name)over the name's bytes (same idea, one small function)host-pipelines.binCONFLICTING, +506/-95, newlibrary/disk.rs, and it lists #275/#1041/#640 conflicts in this fileMERGEABLE, +146/-65, one fileSo: #1651 is the more thorough one (legacy fallback, cross-process note, a dedicated module), mine is the smaller one that applies today. I am not going to argue for mine - if you would rather have the legacy fallback, take #1651 and say so, and I will close this one the same way I closed #1556 and #1656 when
mainhad moved past them.What I would keep from this one either way, since #1651's description does not mention it: the per-shard pre-build list. A single list tagged with the whole library is invalidated by any shard's write, so after sharding it would be rewritten almost every save and would undo part of the win. It is a small change on top of whichever version lands.
@Marvisak on GitHub · 2026-11-25 01:33 UTC · original · edited 2026-11-26 00:25 UTC
Automated triage for the maintainers.
Needs work. The re-application onto current
main(crates/victory-gpu/src/pipeline/library.rs) keepsShared,zeroedandwrite_atomically, and it adds a read-only fallback to the one-file library, which is a good idea. But it loses the fix this PR had at013da61:saveserialises a shard under its lock (serialise), releases the lock to write the file, and then setsl.added = 0; l.prebuilt_changed = false;unconditionally. A pipeline stored, or a pre-build key noted, in that window is cleared without being in the published bytes. Unless that shard gains another pipeline, it is never written, not even at the shutdown save. This is the race andrewpozdnakov7-jpg reproduced. Please acknowledge only what was serialised (subtract theaddedcount you took, and compareprebuilt.len()with the snapshot), and bring back hissave_shardregression test, which is also no longer in the branch.USED_CHANGEDis swapped to false before the early list is written. If that write fails, the change is not retried.mainhad the same shape, but the generation check you described for013da61is not in this head either.libraries()returnsNonewith no warning, wheremainlogged "no host pipeline library".The choice between this PR and #1651 (the same sharding) is still open for the maintainers. Push the fix and this will be reviewed again.
CI: passing (
check).Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 08:04 UTC · original
I reproduced a remaining publication race at 1e79f14. The shard snapshots its prebuilt keys and releases the mutex to write the files. If a new key is recorded during that write while the dirty flag was already true, acknowledging the first snapshot clears the flag for the new key too. A second save can then skip that shard even though its prebuilt file is missing the new key.
Fix and regression on the exact PR head. It compares the current number of prebuilt keys with the snapshot count after both files publish. The test inserts a key at the start of the write, checks that the first sidecar contains just the original key, then verifies that the second save writes both.
On native Windows/WARP the same test failed before the fix and passed after it. The GPU library suite went from 81 passed, 2 failed, 1 ignored to 82 passed, 1 failed, 1 ignored. The placed-view texture-format test failed in both runs. Clippy passed with diagnostics and warnings denied.
If you fold the fix or test into your commit, please retain this trailer.
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted. Synthetic data only.
@pes7 on GitHub · 2026-11-25 12:12 UTC · original
Re-applied onto
main940d32f, which changed this file again:Names/Held(one thread at a time per name) and aSAVElock insidewrite_atomically. Head is9c60694; the diff is still one file.Two conflicts, both resolved by keeping your code and routing it through a shard:
so the per-name hold, the clone-out-of-the-lock trick and the
SAVElock all still do what you made them do; the only change is which of the sixteen libraries a name is looked up in.libraries()opens one file per shard andsave()serialises and writes only the shards that gained pipelines, clearingaddedby what was serialised after the bytes are published.cargo test --workspace --lockedpasses, including your three new concurrency tests (different_names_are_held_at_the_same_time,one_name_is_held_by_one_thread_at_a_time,pipelines_load_on_many_threads_at_once) and the new one here (a_pipeline_lands_in_one_shard_and_the_shards_spread). Both clippy configurations with-D warnings,cargo xtask policy.Still the open question from the description: #1651 is the same change from another author, so this one only needs a decision, not more work.
@pes7 on GitHub · 2026-11-25 12:49 UTC · original
@andrewpozdnakov7-jpg @Marvisak - taken, with the trailer, at
013da61.The race was real and I had introduced it rewriting
save()for shards: acknowledging "was the flag set when I snapshotted" instead of "is what I published still everything". Fixed the way you wrote it - the shard stays dirty when its key count changed while the write ran:Your
save_shard(.., write)split is what makes it testable, so I kept it verbatim; your test is in the PR as sent. I also checked it can fail: with the old check put back it panics onassert!(second.is_some(), ...)and with the fix it passes, so it is a regression test and not just documentation.USED_CHANGEDhad the same shape, as the triage said, so the early list is acknowledged the same way -note_usedbumps a generation counter and a save clears the flag only if the generation it wrote is still current. Missing that one only costs a rewrite of the early list, not a lost pipeline, but it is the same bug.cargo test --workspace --locked(10 library tests, including yours), both clippy configurations with-D warnings,cargo xtask policy.@pes7 on GitHub · 2026-11-25 17:09 UTC · original
Measured on the title, and it is the case this PR was written for - with a bigger number than the description had.
The Xbox build's own pipelines, warmed by
translate --cache --pipelines: 27 160 pipelines, and the library they make is 970 507 898 bytes (926 MB), not the 600 MB the README estimates. Every pipeline is ~28 KB of serialised state on average.Two lines from one
run --execute, two seconds apart:The load is cheap (57 ms: the driver maps it). The save is not: the whole 926 MB was written again with
made=0- no pipeline was added, the pre-build's early list changed by one entry, and the writer had no way to write less than the whole blob. That is the 20-second save onmaindoing 926 MB of I/O for nothing, at every start and every time the early list moves.With the shards in this PR that save writes no library bytes at all: every shard has
added == 0 && !prebuilt_changed, sosave_shardreturnsNonefor all sixteen and only the early list is published. The 926 MB is not rewritten; the same run writes a few kilobytes.The rest of the launch, for context: the first frame still takes 21 s of
preparing, but the shader cache is not what it waits for (hits=7 misses=0, the warm-up does reach the cache the run reads), and the copies in it are 25 ms for 91 MB - so the wait is pipeline making and the first title-memory snapshots, not translation and not this.Caveat unchanged from the description: the first save after the upgrade is still the slow one (all sixteen shards dirty), and the native PSO serialisation itself is not what these numbers measure - they are the payload and the I/O around it.
@pes7 on GitHub · 2026-11-25 18:26 UTC · original
A device removal costs more than the session: it takes the pipeline library with it, and the next run starts from nothing.
Measured on this machine just now. The library was 970 507 898 bytes (926 MB) and loaded in 57-73 ms. After the removal that every run ends in (a TDR, #1633), the next run says:
i.e. the blob is 627 KB - the write of the new library at that start-up never finished, and what is on disk is a fragment. From there, every pipeline the title needs is translated and compiled again: the warm-up that took
translate --cache --pipelines7.5 minutes for 27 160 of them (shaders_cached=52496 shaders_translated=0on a warm one), andmade=23057on a cold one.Two things about that for this PR:
USED_GENERATION/SAVINGbookkeeping that is already in the branch is exactly the "which of these are from the crash" question.made=0; after a removal, the entire library is rebuilt, which is minutes rather than seconds.If a "the library on disk is smaller than what the load reported" line is cheap (
bytesat the load,bytesat the save), that would name this in one line instead of a 627 KB number noticed by accident - the crash path never reaches the save that would have written the full blob, so nothing in the log says so today.@pes7 on GitHub · 2026-11-25 18:33 UTC · original
Correction to what I wrote above, after reading
library::save: the 612 KB is not a truncated write.write_atomically(temp file, then rename) is already there and correct. The small number is a legitimate library that is small: the pipelines in it are named after the shaders they were made from, so a translator change gives every pipeline a new name, the old 926 MB library holds nothing the run can load, and the save writesGetSerializedSize()of what this run made (612 KB) over the file. Atomic, and still a 926 MB / 7.5 minute cache destroyed.The fix for that is #2706: the library lives in
dir/<SOURCE_HASH>, two newest kept, so a run writes only its own directory and bisecting between two builds finds both libraries warm. Measured: run 1saved bytes=3086then7488with no load; run 2loaded bytes=7488 ms=0, inpipelines/94ef170ae2f5e8da/.So the shards in this PR are still right for the "926 MB per save" cost, and no longer need to carry the crash-durability argument - the crash durability is real (
Addedaccumulations are lost with the process, not the file).@pes7 on GitHub · 2026-11-25 22:27 UTC · original
Status of this branch against today's
main(f3578e3), and what porting it needs.mainreworked the two ends of this file since the branch was written:write_atomically(a save writes a temporary and renames),tag()+prebuilt-pipelines.txt(the pre-build's list holds the translator hash, so a list from another build is ignored),zeroed(a library of 1.7 GB on NVIDIA is not an infallible allocation), the USED/created counters, andlibrary()now hands out aShared { loads, state }so a pipeline load does not take the library's lock.The shards themselves are the part that is not in
main: nothing there writes only what changed, so every save still serialises the whole library and writes it whole (926 MB here,host pipeline library saved bytes=...every 20 s; on NVIDIA closer to 1.7 GB).Porting is therefore not a rebase but a re-application of the shard structure onto
Shared:libraries() -> &'static [Shared; SHARDS], one shard file each (host-pipelines.NN.bin,prebuilt-pipelines.NN.txt), opened per shard;shard_of(name)unchanged (a hash of the pipeline name, so a pipeline always lands in the same file);pipeline,prebuilt,note_prebuiltpick the shard;saveserialises and writes only the shards that gained pipelines (USED_CHANGED/early list once, as now), throughzeroed+write_atomically.Two things to settle while porting: a
StorePipelineinto a shard that the host refuses (it stays dirty for the next save), and the early list, which is per library rather than per shard - it can stay one file.Also worth saying: #2706 (a library per translation) removes part of the reason this was written - a translator edit no longer overwrites another build's library - so the remaining cost this PR addresses is the write volume of a run's own saves. If the maintainers would rather have the smaller change first, "save only after N new pipelines or on exit" is a few lines and gets most of the I/O, but it loses the crash-safety of a periodic save; the shard design keeps both.
I have not ported it here: 200 lines through a file whose save/load changed twice since, without a run to check the library still loads, is not something to push tonight. Happy to do it as the next piece of work if it is wanted.
@pes7 on GitHub · 2026-11-25 22:39 UTC · original
Ported onto today's
main(f3578e3) as a re-application rather than a rebase, sincemainreworked both ends of this file meanwhile (write_atomically,zeroed,Shared { loads, state }so loads take no lock, and the pre-build's list tagged with the translator hash). One commit,3b1cda6.What it does now:
SHARDS = 16files,host-pipelines.NN.bin, chosen byshard_of(name)(a hash of the pipeline's name, so a pipeline keeps its shard across runs);saveserialises and writes only the shards that gained pipelines (Library::dirty), leaves a shard dirty if its write fails, and writes the early list (still one file) when it changed or on a shutdown save;prebuilt/note_prebuilt/pipelinepick the shard;host-pipelines.binis still read (never written) and a pipeline found there is stored into its shard, so a warm run fills the shards and the file can then be deleted (one log line says so);pipeline'sloadisFnrather thanFnOnce, because a name may now be looked for in its shard and then in the one-file library.Checked:
cargo test --release -p victory-gpu229 pass (one new: names spread over the shards and keep their shard), clippy clean, bothvictoryconfigurations build.Note for whoever merges: this and #2706 touch the same file but different parts (this one the library/save/load, #2706 the cache directory), so whichever goes second needs a trivial rebase.
@catminou4 on GitHub · 2026-11-24 22:19 UTC · original · reviewed
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Pipeline library split into shards: only shards that gained pipelines are serialised and written on save; shard_file() maps shard→file. 1 test. Pairs with #1651 (save only changed shards) — check whether these two conflict or compose.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 08:35 UTC · original
@pes7 I reran the shard-save regression on the current
3b1cda6. The fix and regression test are in5236270oncodex2/pr1653-save-race, directly on that head.The WARP test stores a second named compute PSO and its prebuilt key after the first save has taken its snapshot, just before the file write. It reopens the shard and reads the sidecar after each write.
3b1cda65236270The third save skips the clean shard. All 13 pipeline-library tests passed on Windows with WARP, and strict GPU Clippy passed with all features.
The patch restores acknowledgement of just the saved snapshot and keeps overlapping saves from acknowledging or replacing each other's snapshots. If you fold the fix or test into your commit, please retain
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted.
@fuzeofficlal on GitHub · 2026-11-26 09:17 UTC · original · requested changes
Verified
3b1cda6blocally on Windows 11 x64 (git merge-treeagainst63bcca43is conflict-free):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default and--all-features): clean (9.16s/4.19s).cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed (0.35s).cargo test -p victory-gpu --lib --locked pipeline::library:: -- --test-threads=1: 12 passed, 0 failed on both RTX 5090 (0.61s) andVICTORY_WARP=1(0.52s).Two save-concurrency bugs are present in
3b1cda6b:save()(library.rs:428-443):serialise(shared)releases the shard mutex beforewrite_atomically, and on successsave()unconditionally setsl.added = 0; l.prebuilt_changed = false;. Any pipeline stored ornote_prebuiltkey inserted during that I/O window is wiped from the dirty state and skipped by subsequent saves (includingsave(true)). Please acknowledge only the snapshot count/length (l.added -= added,l.prebuilt_changed = l.prebuilt.len() != prebuilt_count) and include a regression test for concurrent store/prebuilt updates during shard write.library.rs:407-445):LASTonly guards the throttle timestamp whileWRITINGinsidewrite_atomicallyonly serializes individual file renames, so a periodic save andsave(true)can interleave and let an older snapshot overwrite a newer shard/sidecar. Please serialize the entire snapshot-and-publish transaction acrosssave().Two non-blocking notes as well:
prebuilt/note_prebuiltshard by title key whilepipeline()shards by host PSO name (so partial cross-shard failures can leave a prebuilt entry without its PSO on restart), andUSED_CHANGED.swap(false)before writingEARLY_FILEdrops retries on write failure.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 09:57 UTC · original
@fuzeofficlal 5236270, directly on
3b1cda6, addresses both races in your review. It acknowledges only the published snapshot, leaving concurrent stores and prebuilt keys pending, and holds the save lock through publication and acknowledgement so an older snapshot cannot overwrite a newer one. The WARP regression verifies that a PSO and key added during the first write are present after the second save.Please retain the Git author on cherry-pick or rebase. If folded into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.3b1cda6b26to013da6195d@pes7 on GitHub · 2026-11-26 13:39 UTC · original
The two races the review found are fixed on the branch, which was also rebased onto current
main(it was 74 files behind, which is why the diff looked enormous; the force-push makes CI run against the current tree).Race 1 - a pipeline added during the write was lost.
save_shardacknowledged by resetting the dirty flags after the bytes were written, unconditionally:A pipeline that arrived while the shard was being serialised and written is in neither the file nor the dirty flags, so it was never saved. Now (
013da619) the save records what it snapped (added,prebuilt.len()), and on the way back subtracts exactly that and recomputesprebuilt_changedfrom whether the set grew in the meantime, so late arrivals stay dirty for the next save.Race 2 - an older snapshot could be published over a newer one. Two saves (a worker's and the shutdown's) could serialise at T1 and T2 and publish in the opposite order. Snapshot and publish are now one transaction under
SAVING(save), so the last publisher holds the newest snapshot;write_atomicallykeeps a reader from ever seeing a part.Also in the same area, since the review listed it: the early-pipeline list is now published with a generation check (
USED_GENERATIONis compared after the write, andUSED_CHANGEDcleared only if no key arrived meanwhile), so keys added during that write are written by the next save instead of being acknowledged away.Still open here, and not fixed in this push:
prebuiltis sharded by the title key whilepipeline()looks a shard up by the host name (shard_of(key)vsshard_of(name)) - the two only line up if those strings are the same, and the review says they are not for every path;None(awarnonce would do);Verification:
cargo test --release -p victory-gpu- 228 passed, 1 ignored; clippy-D warningsclean. No frame-time claim: this changes what a save writes, not what a frame does.@pes7 on GitHub · 2026-11-26 13:43 UTC · original
Correction to my last comment, and the exact state of this branch.
The two races are fixed (
9c606942+013da619on top of940d32f6), as described: the save acknowledges only what it snapped, and snapshot+publish are one transaction underSAVING; the early list is published with a generation check."Rebased onto current main" was wrong - I wrote that before doing it, and doing it shows the branch needs a port, not a rebase.
mainhas moved 160 commits, and three of them changepipeline/library.rs, the very file this PR rewrites:321a4bc1zeroed), so a save without memory waits instead of aborting the process (1.7 GB on NVIDIA)save_shardallocatesvec![0u8; size]infallibly today: the samezeroed+ the test that comes with it555c112eShared { loads, state }) beside the lock a save holds while it serialises hundreds of megabyteslibraries()returns[Mutex<Library>; SHARDS], so each shard needs itsSharedandpipeline()must load through ite9ea9a45Used::read,used()), so a full list drops the oldest runs' keys and a save before any read keeps the saved listUsed::list+savewriteused()as a set; the ordered form has to come in with itI tried the rebase and backed it out: the only way through in one step was to take my side of the file wholesale, which reverts all three of the above - a regression dressed as a merge. The branch is therefore still
013da619(conflicting, as GitHub says) rather than silently dropping threemainfixes.What finishing this means, concretely: port those three onto the sharded code (
Sharedper shard,zeroedinsave_shard,Usedas an ordered map), thencargo test --release -p victory-gpu(228 tests) and the pipeline-library tests inlibrary.rs'smod tests, which cover the shard round trip.013da6195dtobf43b8068e@pes7 on GitHub · 2026-11-26 14:49 UTC · original
Rebased onto current
mainand the three fixesmainhad landed in this file are ported onto the sharded code — so the branch is nowMERGEABLEwith a one-file diff again (+261/−131), CI running.For the record of what happened: the rebase itself only goes through by taking this side of
pipeline/library.rswhole, which would have dropped321a4bc1,555c112eande9ea9a45(the "rebase" I backed out earlier). This time the rebase was done and then each fix was ported deliberately, one section at a time:main's fix321a4bc1— a library save the host has no memory for waits, not aborts (Kevin Pratap)zeroed(n)withtry_reserve_exact, used bysave_shard; without the memory the shard stays dirty and a later save writes it555c112e— pipeline library loads do not wait for a save (winne42)Shared { loads, state }:pipeline()loads through the second interface with no lock at all, where this branch still cloned it under the lock; ported with its teste9ea9a45— a full early pipeline list drops the oldest runs' keys (Danilo Mori Schuler)Used::beforeisHashMap<key, place>withUsed::read/Used::listsorting by place, so the oldest runs' keys make room, and a list saved in no order still readsThis branch's own two races are untouched: a save acknowledges only what it snapped (
d09b71bf), snapshot and publish are one transaction underSAVING, and the early list is published with a generation check.Verification (
cargo test --release -p victory-gpu, all 231 tests; the module's 11 alone in a filter):a_pipeline_loads_while_a_save_holds_the_libraryholds a shard's lock, then requires a stored pipeline to load within 30 s — with the cloning version it times out, which is what made the port worth doing rather than trusting.the_early_list_keeps_this_run_firstnow asserts both ends of the order: the most recent earlier key is kept and the oldest is the one that made room.Clippy
--all-targets -D warningsclean.Still open, deliberately not in this PR (they are separate questions, not merge blockers): a shard file that fails to open is a silent
None(awarnonce would do), and the legacy single-file library stays mapped for the whole run (926 MB observed). Theprebuilt-keyed-by-title-key versuspipeline()-keyed-by-host-name question from the review is settled here by keeping one shard function (shard_of) for both, which is what the shard round-trip test pins.@pes7 on GitHub · 2026-11-26 15:06 UTC · original
Where this PR stands, and the one cross-PR dependency among our open PRs.
All nine open PRs by
pes7areMERGEABLE/CLEANwith green CI and none is a draft:I checked every pair that touches the same file with
git merge-tree—2936×2848,2936×2696,2936×1623,2848×2696,2848×2683,2848×2634,2683×2634,1653×2706— and none conflicts textually.The one that matters is
1653 × 2706: they both rewritepipeline/library.rs, and although git merges them cleanly the result does not compile, because2706'sis_translationlooks forhost-pipelines.binand this PR removes it (LIBRARY_FILEbecomeshost-pipelines.NN.bin). That is the worst shape of conflict — clean to git, broken to the build.Handled:
2706now counts a directory as a library when it holds the file or its first shard (b621621fd), so it builds onmaintoday and after this PR. The combination was then verified for real:cargo test --release -p victory-gpu pipeline::library— 11 passed; clippy--all-targets -D warningsclean; CI green.2706: builds after a 6-line resolution,pipeline::24 passed (both the shard round-trip tests andpruning_leaves_foreign_directories_alone). The resolved tree is pushed asperf/library-per-translation-on-shards(e60d4cbb3).So: merge in either order, and whoever lands second takes that resolution. If this PR lands first, the update to
2706is that single commit rather than a re-derivation.Nothing else is pending here — the three
main-side fixes are ported and tested, the two races this branch fixed are untouched, and the diff is one file.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 15:34 UTC · original
@pes7 I reproduced a remaining race in the early-list acknowledgement on
bf43b80. A test-only hook let a second thread callnote_used("late")after the save compared the generation and before it cleared the dirty flag. The first save correctly wrote justinitial. The next forced save also left justinitial, since the acknowledgement had cleared the new key's dirty flag.The follow-up captures the list and its generation together under
USED. The existing save mutex remembers the generation actually published. The same forced schedule then wroteinitialon the first save and both keys on the second. With the test-only hook removed, the patch passed all 26 pipeline tests, the full WARP GPU lib suite (246 passed, 1 ignored), strict GPU Clippy and policy. Follow-up onbf43b80Please retain
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if you fold the fix into your commit. AI-assisted with Codex.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.