DirectStorage: the decode workers read their requests, each on its own handle #3364
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3364"
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 ivall/xcl. Originally posted by Prime1997 on 2026-11-29T10:29:23Z.
Requested by Prime
A pooled request was read on its queue's thread, one at a time, before a worker decoded it: the queue thread waited for every read (queue depth 1), and the workers waited for the queue thread. Now the queue thread checks the request and reserves its buffers, and the worker reads the compressed bytes and decodes them; retirement stays in queue order on the queue thread.
Reads of one file on one synchronous handle still go one at a time, so each worker opens the file again by its path (up to 16 files per worker) and reads on its own handle: with four workers, up to four reads are in flight. If the file cannot be opened again, the request's handle is used, as before. On
mainthe pool is opt-in (XCL_DSTORAGE_PARALLEL_DECOMPRESS=1), so without it this changes nothing.What is in it
crates/xcl/src/hle/dstorage/parallel.rs(first commit): the worker reads a pooled request on a handle of its own (re-opened by path, up to 16 per worker, the request's handle as the fallback); testa_worker_reads_a_file_on_a_handle_of_its_owninparallel_tests.rscrates/xcl/src/hle/dstorage/parallel.rs(second commit): a request whose range runs past the end of its file fails on the queue thread (file length, no read) before a worker takes it, as when the queue thread read it itself; testa_range_past_the_end_of_its_file_fails_before_a_worker_takes_it. Without it, in a local build with ten other changes,completion_event_waits_for_parallel_retirement_and_keeps_its_handlefailed 1 of 3 library runs (Prepared(2)beforeBeforeDecode(1)). To be squashed into the first before reviewTested
cargo test --workspace --no-fail-fast -- --test-threads=4with the threeuma_drivertests below skipped, on8e133ef15e: 2607 passed, 0 failed, 49 ignored (SKIPPED GPU tests: 28 lines: 21no wave64(this card runs wave32), 3 a wave32 per-lane form refused by the translator (#1426), 2no heap windows(opt-inXCL_HEAP_WINDOWS=1), 1no dxc.exe, 1cannot disable the driver cache(needs Windows Developer Mode))cargo test -p xcl --lib -- --test-threads=1 uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window): 3 passed, 0 failed. They are left out of the whole run because on this PC's driver they can end the library test process (exit 0x7c10003, "coherent window could not be restored"), onmaintoocargo test -p xcl --lib -- --test-threads=4, same skips): 2467 passed, 1 failed (hle::d3d12x::list_x::tests::cross_queue_wait64_before_signal_does_not_deadlock_submit_thread); 2468 passed, 0 failedE_OUTOFMEMORY(0x8007000E) while the run shared the 8 GB card with the other tests and the desktop; this branch changes no D3D12 code, and a siblinglist_xtest failed the same way once on another branch of this set; it passed in the other runs heremainfa204595a4: 2605 passed, 0 failed, 49 ignored, 28SKIPPEDlines (own-prs-20261129 run, same command)scripts/smoke.ps1, no input, copied profile and shader cache): blocks belowRegression run
Not tested
main, so they do not reach this code. Read throughput in a retail world was not measured.AI use
Optional temporary Discord for coordinating contributor work, testing and comparing results.
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-29T13:47:46Z.
Reviewed and tested at
8e133ef1.Code review findings
IDStorageFile::Close()(OWNincrates/xcl/src/hle/dstorage/parallel.rs):OWNis athread_local! HashMap<u32, Option<Arc<std::fs::File>>>on long-livedDECOMPRESS_POOLworker threads. When a title callsIDStorageFile::Close()(file_close),FileInner.filedrops itsArc, but each worker'sOWNmap keeps its own OS handle open indefinitely (up to16 × workershandles) until that worker happens to touch 16 otherFileInner::ids and callsown.clear(). On Windows this leaves closed files locked against deletion/replacement. (The new unit test only avoided failingremove_filebecause it ranread_sourceon a one-shot thread that exited before cleanup.)if !own.contains_key(&source.file.id) && own.len() >= OWN_HANDLES { own.clear(); }drops all 16 cached handles on a single miss. A title streaming from 17+ pack files in round-robin will repeatedly close and reopen all handles instead of evicting a single oldest/LRU entry.metadata()syscall on the queue thread:handle.metadata()(GetFileInformationByHandle) now runs synchronously on the queue thread for every enqueued request; caching the file length onFileInner(or updating it only when needed) would avoid a kernel call per request.Tested locally
32.0.16.2140), AMD Ryzen 7 7800X3D,rustc 1.100.0.cargo test -p xcl --lib hle::dstorage:: -- --test-threads=1: 40 passed, 0 failed.AI use
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-29T22:39:36Z.
Review: COMMENTED
Static review of
8e133ef1for the stack in the #3041 comparison.A worker can decode data from a different file than the title opened. The queue validates the request against the original handle, then the worker opens the stored pathname. If the name is renamed and reused before a worker first opens it, that worker reads the replacement. A worker with a cached handle can still read the original for the same title handle. Reopening from the original file handle preserves file identity while giving the worker its own handle. Worker open ?? Windows
ReOpenFileReview assisted by Codex (GPT-6, exact variant unavailable). No new build or GPU run for this review.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:43:24Z.
Review: COMMENTED
Critical review of current head
8e133ef1. Changes needed before default-on use:read_sourcereopens the stored pathname, so a rename/replacement between the title's open and a worker's first open can make the worker decode a different file than the validated request handle. Reopen/duplicate by file identity or retain the original handle's semantics. The thread-localOWNmap also keeps reopened handles on long-lived workers afterIDStorageFile::Close; this can prevent deleting/replacing a title file until eviction or process exit. Add a close/rename/replacement test. These risks are also documented in the prior discussion. I did not run Windows tests.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:41:22Z.
Review (head
8e133ef1, diff read, not a merge-check; draft, so not built or run):parallel.rs~153), not when the title opened it. If the title renamed or replaced the file in between, or changed directory for a relative path, the open succeeds on a different file and requests decode its bytes with no fallback, while the end-of-file check (~470) still uses the original handle's length.ReOpenFileon the request's handle gives a new handle to the same file without resolving the path again.IDStorageFile::Closeno longer releases the file, and up to 16 workers x 16 files stay open.clear()drops every cached handle, so each new file is opened again through the VFS hook, the cost this PR is meant to remove.read_sourcedirectly), and the smoke runs don't reach the pool (it needsXCL_DSTORAGE_PARALLEL_DECOMPRESS=1).Fine: reads still go through the VFS hooks (KERNELBASE, process-wide), share mode and synchronous flags match
factory_open_file, retirement stays in queue order, a failed read on a worker comes back as anErrundercatch_unwind, and cancellation, the memory budget and queue close are unchanged. Nothing changes by default.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T17:25:54Z.
Test report (not a merge-check: draft)
base:
b2b1f109d2head:
8e133ef15emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3364#issuecomment-7299963239, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. The first run of this merge lost the lib test binary to a test race on main (a fake pipeline pointer built ahead of first use, unrelated to this PR); this is the rerun.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.