kernel: retry a guest address hole that another thread took first (ASTRO BOT) #2143
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!2143
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2143"
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?
@Nawid3333 on GitHub · 2026-11-06 23:53 UTC · original
Nawid3333:fix/guest-reserve-retry→main· +79 −3 · 4 files · 2 commits · openReserveGuestRegions(Windows) reserves the aligned free holes larger than 16 MiB in the guest ranges in two steps:VirtualQueryfinds aMEM_FREEhole, thenVirtualAlloc2(MEM_RESERVE | MEM_RESERVE_PLACEHOLDER)reserves it at that fixed base. The two calls are not atomic. With the Tracy profiler on (--profile), its threads are already running when Memory starts; when an allocation lands in a hole between the two calls, the fixed reservation fails (error 487,ERROR_INVALID_ADDRESS) and the emulator exits withfailed to reserve guest address space at ....Measured on my PC (Windows 11) with ASTRO BOT and
--profile: each start was stopped as soon as the reservation finished or failed, main and this change alternated, and both builds had a lab-only printout of what occupied the hole.failed to reserve guest address space, in four different holes.--profile: 0 of 500.Both reservation failures in our earlier full ASTRO BOT runs had the profiler on and ended with
failed to reserve guest address space at 0x000000007fff0000.Change. When the fixed reservation fails, query the same address again: the walk sees the hole's new shape, skips the new block and reserves the aligned free parts larger than 16 MiB around it. At most
MaxReserveAttempts(16) tries per address, then the same exit as before. A fixed-baseVirtualAlloc2that fails reserves nothing, so there is nothing to release.Test.
GuestReservationRace(VirtualMemoryAllocationTests, Windows only) uses a one-shot test hook, likeTestBeforeNextBackingMap, that runs between the query and the reservation and places a small block inside the hole. The address space must finish initializing, leave the block alone and own the free parts before and after it; the test then frees the block and re-initializes Memory for the following tests.virtual_memory_allocation_testspass and two are skipped (PackedBitFieldExtract/Insert, native SSE4a host); with the retry removed (hook kept) the run exits at this test withfailed to reserve guest address space at 0x0000000000040000, size 0x0000000064900000.Fork CI on the PR head (
0b745ff2d): the Linux, Windows and macOS builds and tests pass.Written with Claude Code and OpenAI Codex (AI): the fix, the test and the measurements, run on my PC; reviewed by me.
589bd14a9into fix/guest-reserve-retry d5c9575cfe@coderabbitai[bot] on GitHub · 2026-11-06 23:58 UTC · original · edited 2026-11-07 16:54 UTC
Walkthrough
The change adds a test-only callback that runs before a guest reservation. On Windows, failed reservations retry up to 16 times per region. A new test injects a host-memory blocker and checks ownership of the blocked range and the free ranges beside it.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
d5c95The reservation retry and race test have no established merge-blocking issue. Merge after normal checks.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 3 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@coderabbitai[bot] on GitHub · 2026-11-06 23:58 UTC · original · reviewed
02792f13-e49d-4d2a-8251-e5a723ed2af7Reviewing files that changed from the base of the PR and between
182161eb3eand0b745ff2d9.src/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.inctests/VirtualMemoryAllocationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-07 16:54 UTC · original · reviewed
e0be1f63-29d4-4f9a-99ff-02c3b72622ecReviewing files that changed from the base of the PR and between
0b745ff2d9andd5c9575cfe.src/kernel/memory.cppsrc/kernel/memory.hsrc/kernel/memoryAddressSpace.inctests/VirtualMemoryAllocationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.