GPU: dropping the old title memory layout inside the rewrite costs about 5 ms each time here (and a marks lock hazard in copy_back_marks) #3137

Open
opened 2026-11-26 11:08:18 +00:00 by github-bot · 1 comment
Owner

@⁠Machad3x on GitHub · 2026-11-26 09:52 UTC · original

Shared::rewrite (memory.rs) assigns self.layout = Arc::new(Layout { .. }), so the layout it replaces is dropped right there: on the submitting thread, with the heaps locked, with one Arc<Shadow> per copy (about 15,000 here) and the last reference of copies released since the previous rewrite among them.

Measured (cell window, Ryzen 7 5700X, RTX 3080 Ti, a fork with other changes on top of main; the fork's table builder differs from main's):

  • Temporary timers: about 9 ms per rewrite, about two rewrites a frame. The part from building the new Layout to dropping the old one was about 4.8 ms of it.
  • With the old layout sent to the release thread (release_later), that part was 0.15 ms, and the title memory step of preparing went from 19 to 7 ms a frame (one 5-minute run each, medians). Frame time also fell (398 to 359 ms), but the earlier run was uneven, so I would not read that figure as the change's alone.
crate::host::release_later(Box::new(std::mem::replace(&mut self.layout, layout)));

Related, found in review and fixed along with it: the page_of closure of copy_back_marks (shadow.rs) calls upgrade() on the owners' weak references while holding the marks lock. If another thread drops the other references meanwhile, the copy can be dropped inside the closure (the discarded tuple, or the then that rejects a bit past the copy's pages), and Shadow::drop takes the same lock: a deadlock. This is from reading the code; I have not seen it happen. Collecting the upgraded copies under the lock and looking at them after releasing it avoids it. Dropping layouts on another thread makes the window larger, so the two belong together.

Not tried: other scenes or hardware, main itself.

AI-assisted.

**@⁠Machad3x** on GitHub · 2026-11-26 09:52 UTC · [original](https://github.com/Marvisak/VIctory/issues/3137) `Shared::rewrite` (memory.rs) assigns `self.layout = Arc::new(Layout { .. })`, so the layout it replaces is dropped right there: on the submitting thread, with the heaps locked, with one `Arc<Shadow>` per copy (about 15,000 here) and the last reference of copies released since the previous rewrite among them. **Measured** (cell window, Ryzen 7 5700X, RTX 3080 Ti, a fork with other changes on top of `main`; the fork's table builder differs from `main`'s): - Temporary timers: about 9 ms per rewrite, about two rewrites a frame. The part from building the new `Layout` to dropping the old one was about 4.8 ms of it. - With the old layout sent to the release thread (`release_later`), that part was 0.15 ms, and the title memory step of preparing went from 19 to 7 ms a frame (one 5-minute run each, medians). Frame time also fell (398 to 359 ms), but the earlier run was uneven, so I would not read that figure as the change's alone. ```rust crate::host::release_later(Box::new(std::mem::replace(&mut self.layout, layout))); ``` **Related, found in review and fixed along with it:** the `page_of` closure of `copy_back_marks` (shadow.rs) calls `upgrade()` on the owners' weak references while holding the marks lock. If another thread drops the other references meanwhile, the copy can be dropped inside the closure (the discarded tuple, or the `then` that rejects a bit past the copy's pages), and `Shadow::drop` takes the same lock: a deadlock. This is from reading the code; I have not seen it happen. Collecting the upgraded copies under the lock and looking at them after releasing it avoids it. Dropping layouts on another thread makes the window larger, so the two belong together. Not tried: other scenes or hardware, `main` itself. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:08:18 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:15 UTC · original

@⁠Machad3x I tested the mark-owner part of this report on 63bcca4 and opened #3145.

The synthetic WARP case confirms that lookup used to release an out-of-range candidate before leaving the marks lock. The patch carries the owner out, then rejects that page and drops the reference. The valid-page control and all 247 app-local WARP GPU tests passed, with one test ignored.

This provides the lock fix independently of the deferred-layout performance measurement. If you reuse the fix or its fixture in another commit, please preserve the Git author or keep Co-authored-by: andrewpozdnakov7-jpg <[email protected]> when folding the changes.

AI-assisted.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 10:15 UTC · [original](https://github.com/Marvisak/VIctory/issues/3137#issuecomment-7189120662) @⁠Machad3x I tested the mark-owner part of this report on `63bcca4` and opened [#3145](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3145). The synthetic WARP case confirms that lookup used to release an out-of-range candidate before leaving the marks lock. The patch carries the owner out, then rejects that page and drops the reference. The valid-page control and all 247 app-local WARP GPU tests passed, with one test ignored. This provides the lock fix independently of the deferred-layout performance measurement. If you reuse the fix or its fixture in another commit, please preserve the Git author or keep `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` when folding the changes. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
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/Marvisak--VIctory#3137
No description provided.