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) #3135

Open
opened 2026-11-26 09:52:23 +00:00 by Machad3x · 1 comment
Machad3x commented 2026-11-26 09:52:23 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-26T09:52:23Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6624006145 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/3137). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-26T09:52:23Z. --- `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.
andrewpozdnakov7-jpg commented 2026-11-26 11:03:59 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T10:15:32Z.


@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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7189120662 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/3137#issuecomment-7189120662). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T10:15:32Z. --- @Machad3x I tested the mark-owner part of this report on `63bcca4` and opened [#3145](https://github.com/Marvisak/VIctory/pull/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.
Sign in to join this conversation.
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
Marvisak/VIctory#3135
No description provided.