fix(agc): keep the pipeline journal's newest pipelines when it is full #9440
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9440"
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?
Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-21T22:09:40Z.
What
The pipeline journal could lose the pipelines a title needs most, in two ways.
APS5_PIPELINE_JOURNAL_ENTRIESentries of the file, so a title with more pipelines than the bound never replayed the ones it built last: the pipelines of the level the save was in were compiled again at every level entry, under the GPU mutex.APS5_PIPELINE_JOURNAL_MAX_MIBthe writer refused every later record, so a level that loaded after the cap was reached was never recorded at all and paid its builds on every boot (#8309).This change:
The rewrite happens in the journal's writer thread, under the file lock it already holds, and the counters report what it dropped:
APS5_PIPELINE_JOURNAL_MAX_MIBandAPS5_PIPELINE_JOURNAL_ENTRIESkeep their meaning (the size cap and the number of entries replayed); the debt entry andENVIRONMENT.mddescribe the new behaviour.Tested
Linux (Ubuntu 24.04), GCC 16.2.1, NVIDIA GTX 1660 SUPER, driver 590.48.01, Vulkan 1.4.313.
agc_driver_pipeline_journalgains four cases:APS5_PIPELINE_JOURNAL_ENTRIES=2builds the two newest entries and not the graphics entry of the first level; the newest program is then found in the store at its dispatch and the oldest is built there. Withmain's replay code it fails:the replay did not build the two newest entries: built 3 compute and 1 graphics, 0 rejected, 0 present, 0 skipped.main's writer the file keeps growing and the record is refused (the journal was not rewritten when it reached its cap).the record written after the eviction was not replayed: 0 graphics built, 1 rejectedand the load line readsloaded 1 pipelines and 0 modules.the oversized record emptied the journal: 39888 bytes became 32) and the record is lost; with the fix the file keeps its size, the skipped record is counted as a write failure and the pipeline that was in the journal still replays.agc_driver_pipeline_journal,agc_pipeline_journalandagc_pipeline_journal_long_pathspass (3 of 3), as doagc_driver_graphicsandagc_driver_graphics_maps_fallback.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R 'agc_driver_pipeline_journal|agc_pipeline_journal' -V): 3 of 3 pass onmaina6dcea9279and on this branch. Neither log reports the layer missing, and neither has aVUID-error.tools/check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-22T00:06:59Z.
The overlap bot is right about #8542 and #9401: this branch changes the same lines that bound the replay, the same two rows of
docs/dev/ENVIRONMENT.mdand the same debt entry. Here is what each of them touches here and how the three reconcile.PipelineJournal.cpp, the bound (L917-918 onmain). #8542 counts graphics and compute entries against two bounds, #9401 raises the bound and grows the store. This branch keeps the last entries instead of the first, so the pipelines a title built last are the ones the replay builds. The three compose: take the entries this branch keeps, then apply whichever bound is in force.PipelineJournal.cpp, the parse (L585 onmain). This branch hands the record spans to the writer, which needs them to rewrite the file at the size cap. #8213 and #8365 rewrite the same function to read the modules from the file instead of holding it; the spans are a small addition on top of that, and this branch rebases onto it without a conflict.docs/dev/ENVIRONMENT.md(L338-339) anddocs/dev/debt/libSceAgcDriver.md(L100). The two bound rows and the journal's debt entry, one line each.The branch is rebased onto the current
main(a6dcea9279), and the focused tests pass on it and onmainwith the Khronos validation layer (3 of 3 each, noVUID-error on either side).Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-22T00:20:15Z.
@milescoviello — this changes the journal's record reading and the bound that #8213, #8365 and #8542 also change, so it is probably yours to look at. It is two parts: the replay keeps the last entries instead of the first (a title's newest pipelines are the ones its current level needs), and the writer rewrites the file at
APS5_PIPELINE_JOURNAL_MAX_MIBinstead of refusing the record, which is the "later pipelines are never recorded" half of #8309.The record spans the writer needs are a small addition to the parse that #8213 rewrites, and the branch is rebased onto the current
main; what is left to reconcile with #8542 and #9401 is the bound line and the two documentation rows.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T00:25:06Z.
Review: COMMENTED
@00xDisaster thanks for the ping. I read the eviction against #8213, #8365 and #8542. One thing looks wrong to me, plus a note.
The record that triggers an eviction can lose its modules. In
append,newModulesandbatchare built at the top, againstwrittenModules. A module that is already in the file isn't put in the batch. Then, whenoverCap,evictUnderLock(batch.size())rebuilds the file around the records it keeps, and keeps only the modules those records need. The pending record isn't in the file yet, so any module it shares with an evicted older record is dropped, andwrittenModulesis reset tokeptModules.appendthen writes the batch built before the eviction, which doesn't contain that module. So the newest record, the one the eviction is meant to make room for, is written without one of its modules.writtenRecordsnow holds its hash, so it is never written again, and at replay it can't be built.A way to close it: after a successful
evictUnderLock,return false, so the caller rebuilds the batch against the newwrittenModules. That's the same path as when the file was cut. Or rebuildnewModulesandbatchin place. A test case would be a record whose stage module was first written by an older record that the eviction drops; the test could check that the record replays after the rewrite.A note on #8213: it keeps the journal open for the replay and reads module payloads by offset: an fd on Linux, a handle with
FILE_SHARE_DELETEon Windows. On Linux the rename leaves that fd on the old inode, so a rewrite in the middle of a replay is safe. On WindowsMoveFileExWover a file that's still open may fail; you already handle that by falling back to "not recorded". So the two compose. Whichever lands second only re-addsRecordSpancollection to the streaming parse.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-22T01:13:53Z.
You are right, and thank you for reading it that closely. The record that triggers the eviction did lose its modules: the batch was built before the eviction, so it held no module the file already had, while the file the eviction wrote had none either, and
writtenModuleswas reset to the modules the kept records needed. The record was then written with its hash inwrittenRecordsand could never be replayed.The fix follows the path you named, with one addition:
The test you asked for is in
agc_driver_pipeline_journal: a record whose stage module was first written by an older record that the eviction drops. The journal is filled past its cap with records no pipeline needs, a second draw with the same shaders and a different blend state writes a record that shares the older record's modules, and the replay after the rewrite must build it. Without the fix the run reportsthe record written after the eviction was not replayed: 0 graphics built, 1 rejectedand the load line showsloaded 1 pipelines and 0 modules; with the fix it loads1 pipelines and 2 modulesand the pipeline is built.On #8213: the rewrite goes through
MoveFileExWwithMOVEFILE_REPLACE_EXISTINGon Windows, so it replaces the file that #8213 keeps open withFILE_SHARE_DELETE, and the fd on Linux stays on the old inode. When the replacement fails, the eviction reports that the journal is full and the record is not recorded, as you described.The branch is rebased onto the current
main(a6dcea9279), the focused tests pass on it and onmainwith the validation layer (3 of 3 each, noVUID-), andtools/check_conventions.py --base upstream/mainis clean.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T01:24:18Z.
@00xDisaster thanks, I read
4472daa36a(not built or run here yet). Reserving the whole record and returning false after the eviction closes the loss I described: the rebuilt batch is taken against the rewritten file, so the dropped modules come back, andneededalready covers them.Two smaller points, neither blocking:
appendnow encodes every module of every record before the cap check, including the ones the file already holds. Before, only the missing ones were encoded. That's only needed to size an eviction. It's on the writer thread, so it's off the game's path, but the encode could happen only whenoverCapis true.write's two attempts. If the same write first cuts a torn tail (attempt 0 returns false), then needs an eviction (attempt 1 returns false), it throws "the journal keeps changing under this run" and drops the record. A third attempt, or not counting the eviction's retry, would cover that. It's rare: a torn tail and a full journal in the same write.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:33:54Z.
Code review location:
core/libs/prx/libSceAgcDriver/Graphics/src/PipelineJournal.cpp; line 802If one pending record and its modules require at least the configured cap, this budget is zero or below the header size. The loop then keeps no existing records, rewrites the journal to just its header, and returns for a retry; the same oversized record still cannot fit, so it is dropped after the retry. For example, with
APS5_PIPELINE_JOURNAL_MAX_MIB=1, a record larger than 1 MiB can erase previously usable journal entries even though that incoming record is never saved. Please detect an intrinsically oversized batch before eviction, preserve the existing journal, count/report the skipped record, and add a regression that proves the previous records survive.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:33:55Z.
Code review location:
core/libs/prx/libSceAgcDriver/tests/execution/PipelineJournal.cpp; line 547This is a new C++ source comment, while the workspace review instructions prohibit code comments except
#endifand namespace endings. The PR also changes technical debt, but the local AGENTS rule is stricter. Please move this rationale to the PR description or debt entry and remove the test-source comment.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:33:56Z.
Review: CHANGES_REQUESTED
The reported validation-layer comparisons and focused tests are detailed, and the reviewer’s latest comment confirms the previously found pending-module loss is fixed. Hosted checks currently show conventions and labels passing; the full CI matrix is not present on this head, so I am relying on the reported same-GPU main/change runs rather than claiming additional tests here. I found one remaining data-loss case in the eviction path: if the incoming record plus its modules exceeds the configured journal cap,
evictUnderLockreduces the budget below the header, rewrites away all existing records, then the retry still cannot fit the incoming record. With a valid small cap such as 1 MiB, a larger encoded record therefore wipes the useful journal and is still dropped. Please reject an intrinsically oversized batch before eviction, preserve existing entries, and add a regression for that case. Also remove the added test-source comment, which conflicts with the workspace AGENTS rule prohibiting code comments except#endifand namespace endings.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:44:23Z.
Review: CHANGES_REQUESTED
I rechecked head
4472daa36aafter the pending-module fix. That fix addresses the earlier record/module loss, but the oversized-record data-loss case from my prior review remains.needednow reserves the entire incoming pipeline plus module records. InevictUnderLock, whenheaderBytes + reserveis greater than the configured cap,budgetbecomes zero andusedstarts atheaderBytes; the reverse scan keeps no records, then replaces the existing journal with a header-only file. The retry cannot fit that incoming batch either, so the write is ultimately dropped after the existing valuable journal has already been erased. This can also happen when the batch is smaller than the cap but leaves less thanheaderBytesavailable. Please reject a batch that cannot fit alongside the header before calling eviction, preserve the existing journal in that case, and add a regression that verifies both the rejected batch and byte-for-byte preservation of the prior journal.The new test also adds a C++ explanatory comment, which conflicts with the workspace review instruction prohibiting code comments except
#endifand namespace endings; please remove it. Finally, this branch is based ona6dcea9279b53b3a39c13695eac66f7c8b5b503c, while currentmainis94fbb8cea80af91db62ab6ee7e4da23341675c40; please update/rebase and rerun the relevant validation. The latest hosted checks show conventions and labels passing, but do not show the author-reported Vulkan validation or focused test suite for this new head; I did not run a local build.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:50:29Z.
Review: CHANGES_REQUESTED
I rechecked the new head
a92fd3f824. The addedbudget < headerBytesguard returns before replacement, andOversizedRecordKeepsTheJournalchecks the existing file size and replay after an oversized write; the prohibited test comment is also removed. That resolves the journal-erasure and comment findings from my prior review.Two validation items remain. This head is still based on
a6dcea9279b53b3a39c13695eac66f7c8b5b503c; currentmainisdf2569d2c5fc6adb68f6eb8b56ad0d0ddf35686b, so it does not meet the current-main rule. Please rebase/update and rerun the focused journal tests. Also, the PR’sTestedsection still lists only the prior three cases and does not report running the new oversized-record regression on this head. Since this changes AGC journal behavior, please include that test in the same-machinemain/branch Vulkan-validation comparison and report the missing-layer/VUID result for the updated head. The current hosted checks show conventions and labels passing; product build jobs are not present. I have not run a local build.Imported from boykopovar/AnyPS5. Originally posted by 00xDisaster on 2026-10-22T01:51:08Z.
Both points are fixed in
a92fd3f82.The oversized record: the writer measures the whole record, the modules it names included, before it touches the file, and when the record cannot fit under the cap it leaves the journal as it is, counts the skipped record as a write failure and says so:
The eviction itself now refuses a budget below the header size, so the file can no longer be rewritten to nothing. The regression is in
agc_driver_pipeline_journal: a compute program whose result carries 1.6 MB of user words is recorded into a journal that already holds a pipeline. Without the fix the journal shrinks to its 32-byte header (the oversized record emptied the journal: 39888 bytes became 32) and the record is lost withthe journal keeps changing under this run; with the fix the file keeps its size, the write failure is counted, and the pipeline that was in the journal still replays.The comment in the test source is gone; the rationale is in this pull request's description.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:39:59Z.
Thanks for adding the oversized-record regression and the paired Khronos validation run; the current report now covers the missing test and confirms the layer load and matching VUID results. Since that run, upstream main has advanced from
a6dcea927to110a18ba01. Please update/rebase onto current main and rerun the focused journal/Vulkan comparison and conventions/overlap checks so the prior requested validation applies to the current base. The earlier #8542/#9401/#8213/#8365 merge coordination remains documented in your overlap explanation.Pull request closed