fix Windows fixed placeholder reservations below allocation granularity #101
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!101
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/101/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?
@Digote on GitHub · 2026-07-22 17:30 UTC · original
fix/windows-subgranularity-placeholder→main· +455 −29 · 4 files · 4 commits · closed without mergingWhat changed
FixedSub64KDirectMapUsesExactAddress, covering fixed reservation, exact direct-memory mapping, shared-backing aliasing, unmap, placeholder restoration, and release of the neighboring host ranges.Why
UFC 5 fails early in #100 while mapping
EAOSGlobalat0xfbffffc000with a size of0x4000.VirtualAlloc2requires a non-null fixed base address to be aligned to the system allocation granularity. The affected address is a valid 16 KiB PS5-page address but is offset within a 64 KiB Windows allocation-granularity range.The fix reserves an aligned placeholder container and uses placeholder splitting so that
MapViewOfFile3(..., MEM_REPLACE_PLACEHOLDER)receives a placeholder whose base address and size exactly match the requested mapping.Documentation
Validation
cmake --build Build\windows --target kyty_emulator virtual_memory_allocation_testsvirtual_memory_allocation_tests: 27/27 cases passed.git diff --checkpassed.src/kernel/memoryAddressSpace.inc.PPSA03541): the originalplaceholder-reserve-failed/ fatal error no longer occurs.EAOSGlobalnow maps at0xfbffffc000withshared = yes.Scope
This partially addresses #100. The new UFC 5 log proceeds far beyond the original memory failure but later stops on an unrelated
unsupported storage texturerenderer error, so this PR should not close #100.AI assistance disclosure
AI assistance was used for investigation, implementation support, test design, and documentation research. I have reviewed the final diff and validation results and remain responsible for this contribution.
@chatgpt-codex-connector[bot] on GitHub · 2026-07-22 17:35 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
ebe84caa72ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@chatgpt-codex-connector[bot] on GitHub · 2026-07-22 17:35 UTC · original
On
src/kernel/memoryAddressSpace.incline 1161 (outdated):On Windows, after reserving one fixed 16 KiB placeholder inside a 64 KiB allocation-granularity block, these calls release the other pages in that block. If the guest then reserves or maps another 16 KiB page in the same block before unmapping the first,
ReserveFixedcan no longer recreate a placeholder for it: the enclosingVirtualAlloc2conflicts with the existing placeholder, and the fallbackReserveFixedHostRange/VirtualAllocpath is rounded to the same occupied container. This makes valid adjacent PS5-page fixed reservations fail with ENOMEM; keep the sibling placeholders tracked or otherwise handle partially occupied containers.Useful? React with 👍 / 👎.
@Digote on GitHub · 2026-07-22 18:15 UTC · original
On
src/kernel/memoryAddressSpace.incline 1161 (outdated):Thanks, good catch! 👍
I fixed this in
a5637b3.The old code was releasing the neighboring placeholder ranges too early. Now it keeps the full 64 KiB placeholder reserved, so another adjacent 16 KiB reservation can still use the same block.
I also added a regression test for that adjacent 16 KiB case. All Windows virtual-memory tests are passing (27/27).
@Nmzik on GitHub · 2026-07-29 06:12 UTC · original · reviewed
The adjacent-page fix addresses the earlier review finding, but there is one remaining non-blocking resource-lifetime issue in the retained sibling placeholders. CI could not be inspected because the workflow stopped before creating any jobs.
@Nmzik on GitHub · 2026-07-29 06:12 UTC · original
On
src/kernel/memoryAddressSpace.incline 1150 (outdated):This retains the entire aligned container in
m_free, but the virtual-range layer records only the requested 16 KiB range. When that range is later released,ReleaseFree(vaddr, size)frees only those 16 KiB; the unowned sibling placeholders remain reserved and tracked for the rest of the process. Repeating isolated sub-granularity reservations therefore leaks up to 48 KiB of host address space per 16 KiB guest range and can block unrelated host reservations in those gaps. Please release the enclosing container once none of its subranges are owned, and extend the test to verify all sibling addresses become unmapped after the requested ranges are released.@Digote on GitHub · 2026-07-29 13:29 UTC · original
Thanks for the detailed explanation. I've addressed the container lifetime issue in
399dc7f.Fixed allocation-granularity containers are now tracked separately from their individual guest ranges. When a range gets released, we check the virtual-range ownership of each 64 KiB container:
Same cleanup applies to the unmap and rollback paths too, so a failed mapping can't leave an unowned container behind.
I extended FixedSub64KDirectMapUsesExactAddress to check that:
Validation:
Also reproduced UFC 5 again — EAOSGlobal still maps fine at 0xfbffffc000 with shared backing, no placeholder reservation or container-release errors.
@Nmzik on GitHub · 2026-07-29 14:07 UTC · original · requested changes
The new container-lifetime cleanup addresses the previously reported sibling-placeholder leak, but valid fixed reservations can still fail when they cross from an existing tracked 64 KiB container into an unreserved one. CI could not be inspected because the workflow stopped before creating any jobs.
@Nmzik on GitHub · 2026-07-29 14:07 UTC · original
On
src/kernel/memoryAddressSpace.incline 1141 (outdated):ReserveFixedreturns early only when onem_freeentry contains the entire request. For example, after reserving[base, base + 0x4000), a valid non-overlapping reserve of[base + 0x4000, base + 0x14000)spans the remainder of that tracked 64 KiB container and the first page of the next container.FindContainingfails, then this call tries to reserve both aligned containers at once; Windows rejects it because the first container is already reserved, so the guest request incorrectly returnsENOMEM. Please combine existing tracked placeholder containers with reservations for only the missing containers, and add a regression covering a cross-container request with the first container already present.@Digote on GitHub · 2026-07-29 15:02 UTC · original
Thanks, fixed in
2c41030. ReserveFixed now reuses tracked 64 KiB containers, reserves only missing ones, and rolls back newly created containers on failure. I added the exact cross-container regression case; all 28 Windows virtual-memory tests pass, and UFC 5 still maps EAOSGlobal correctly without placeholder errors.@Digote on GitHub · 2026-07-31 02:33 UTC · original
It looks like the UFC 5 issue has already been resolved with #135
Closing.
@Nmzik on GitHub · 2026-07-31 03:59 UTC · original
@Digote Didnt expect that change to fix UFC5 memory allocation bug. Thanks for reporting
@Digote on GitHub · 2026-07-31 11:14 UTC · original
@Nmzik test

github.com/KytyPS5/KytyPS5@d8a4c83cc7Pull request closed