Probabilistic boot hang: UnmapMemory waits for a full GPU drain while holding the memory-operation mutex (regression from #135) #149
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!149
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/149/head"
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?
@Stepz97 on GitHub · 2026-08-01 15:40 UTC · original
Stepz97:fix-unmap-gpu-drain-deadlock→main· +36 −0 · 2 files · 1 commits · closed without mergingSymptom
Roughly one in three boots (measured on a commercial title on macOS, but the mechanism is platform-independent) freezes at a wandering point: the process stays alive at low CPU, the log stops advancing, no crash. Sampling the live process shows a three-way stall:
GpuResourceManager::UnmapMemory, which takesGpu::SubmissionLock(PauseSubmissions: grabs the submission mutex) and then waits for a full GPU drain (WaitLocked).WaitRegMem64on a label that a guest thread is supposed to write.GpuState::Submiton the submission mutex held by the pauser, the rest block on the memory-operation mutex held by thread 1.Since the memory rework (#135),
MapGpuRange/UnmapGpuRangerun inside the memory paths that hold the global mutex, so any unmap pays the pause + full-drain price there — and GPU progress can depend on guest threads that need that same mutex. The specific caller caught in the sample wasAllocateGuestRuntimeMemoryconsuming a reserved span: a range that had never been GPU-mapped at all, paying a full GPU drain as a defensive no-op.Fix
If the range has no intersection with the GPU-mapped set (
m_mapped_ranges), take the same no-pause local path the pre-renderer branch (m_gpu == nullptr) already uses.RangeSetgrows anIntersectsquery — intersection, not containment, so partially mapped ranges still go through the full drain. The short path also verifies the "never mapped => nothing cached" invariant against both caches (BufferCache::HasPageOverlap,TextureCache::QueryRegion().image_pages) and fails loud on a violation instead of silently re-creating the cross-thread wait.This narrows the window rather than restructuring the locking: unmaps of ranges that really are GPU-mapped still drain as before. A follow-up could revisit whether the full drain under the memory mutex is avoidable in general.
Validation
a65d17a. Independent of the relocation-livelock fix submitted separately; boot-level validation on macOS ran with both applied (the livelock otherwise blocks boot there).Disclosure (README § AI Use): this fix was developed with AI assistance. I reviewed the analysis and the code, ran the validation on my machine, and take responsibility for this submission.
@Nmzik on GitHub · 2026-08-02 11:34 UTC · original
@Stepz97 This should be fixed by
github.com/KytyPS5/KytyPS5@fc8d2a3b83. Please retest.Pull request closed