DirectStorage: a file released with reads of it in flight stays open until they are done #3586

Closed
fl4rion wants to merge 1 commit from upstream-pr/3586 into main
fl4rion commented 2026-11-30 01:23:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fl4rion on 2026-11-30T01:23:56Z.


What it changes

A title may release its last reference on an IDStorageFileX right after submitting reads of it. On the console that last release (Close) waits for the file's reads, and they complete with the file's bytes. Here it freed the file object under the scheduler's workers: their reads failed with "The handle is invalid", or crashed in the freed object.

Each read now holds a reference on its file object (FileHold), taken at enqueue and dropped once a worker has read it, or when the read is dropped unrun. Reads from a memory source hold none. The worker drops its reference after the read and before it retakes the scheduler's lock, so a final close happens outside the lock. FileHold is a new name because FileRef is already the file pointer's type alias. In the stuck-read warning, the one place that copied a queued Read now borrows it, since Read holds a reference and is no longer Copy.

How it was tested

  • GPU and profile: RTX 5070 Ti; a test title that releases a file right after submitting eight reads of it, on both the Series X and Series S profiles. DLSS, frame generation and ray tracing don't apply: the change is DirectStorage only.
  • Before (main, 3 runs per profile): it died in that check in most Series S runs and some Series X runs, with an access violation or a panic on the title's thread amid invalid-handle read errors.
  • After (3 runs per profile, on main with this change and on main with this change plus another GPU change): all 12 runs finished, and the check passed in every one. All other results were identical between the two builds.
  • New test a_file_released_with_reads_in_flight_is_read: eight 64 KiB reads, the file released right after the submit; the reads complete with S_OK and the file's bytes.
  • cargo test -p victory-hle --lib: 423 passed, 1 failed. The failure, xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it, fails the same way on main in every full run and passes alone. cargo build --release -p victory and clippy: nothing new.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. None found for releasing a file with reads in flight.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5557319055 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3586). Originally posted by [fl4rion](https://github.com/fl4rion) on 2026-11-30T01:23:56Z. --- ## What it changes A title may release its last reference on an `IDStorageFileX` right after submitting reads of it. On the console that last release (Close) waits for the file's reads, and they complete with the file's bytes. Here it freed the file object under the scheduler's workers: their reads failed with "The handle is invalid", or crashed in the freed object. Each read now holds a reference on its file object (`FileHold`), taken at enqueue and dropped once a worker has read it, or when the read is dropped unrun. Reads from a memory source hold none. The worker drops its reference after the read and before it retakes the scheduler's lock, so a final close happens outside the lock. `FileHold` is a new name because `FileRef` is already the file pointer's type alias. In the stuck-read warning, the one place that copied a queued `Read` now borrows it, since `Read` holds a reference and is no longer `Copy`. ## How it was tested - GPU and profile: RTX 5070 Ti; a test title that releases a file right after submitting eight reads of it, on both the Series X and Series S profiles. DLSS, frame generation and ray tracing don't apply: the change is DirectStorage only. - Before (main, 3 runs per profile): it died in that check in most Series S runs and some Series X runs, with an access violation or a panic on the title's thread amid invalid-handle read errors. - After (3 runs per profile, on main with this change and on main with this change plus another GPU change): all 12 runs finished, and the check passed in every one. All other results were identical between the two builds. - New test `a_file_released_with_reads_in_flight_is_read`: eight 64 KiB reads, the file released right after the submit; the reads complete with S_OK and the file's bytes. - `cargo test -p victory-hle --lib`: 423 passed, 1 failed. The failure, `xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`, fails the same way on main in every full run and passes alone. `cargo build --release -p victory` and clippy: nothing new. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. None found for releasing a file with reads in flight.
trustno1-coder commented 2026-12-01 18:50:47 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:50:47Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321661290 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3586#issuecomment-7321661290). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:50:47Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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!3586
No description provided.