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

Closed
github-bot wants to merge 1 commit from github-bot/gh-3586 into main AGit
Owner

@⁠fl4rion on GitHub · 2026-11-30 01:23 UTC · original
fl4rion:dstorage-released-file → main · +72 −13 · 1 files · 1 commits · closed without merging

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.
**@⁠fl4rion** on GitHub · 2026-11-30 01:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3586) `fl4rion:dstorage-released-file` → `main` · +72 −13 · 1 files · 1 commits · closed without merging ## 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.
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 workers: their reads failed with "The handle is
invalid", or crashed in the freed object.

Now each read 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. A read of a memory source holds none. The worker drops its reference
after the read and before it takes the scheduler's lock again, so a file
whose last reference that was closes outside the lock.

Seen with a test title that releases a file right after submitting eight
reads of it: on main it died in that check in most runs on one console
model and some on the other (an access violation, or a panic in the title's
thread amid invalid-handle read errors). With this change all 12 runs of it
(two builds, three runs, both models) finished, and the check passed in
every one.

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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:26:03 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:50 UTC · original

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.

**@⁠trustno1-coder** on GitHub · 2026-12-01 18:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3586#issuecomment-7321661290) 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.
github-bot closed this pull request 2026-12-01 18:58:15 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3586
No description provided.