fix(libkernel): map direct memory as write-watched private pages until it is aliased #2054
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2054"
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?
Imported from boykopovar/AnyPS5. Originally posted by esatturan on 2026-10-09T06:01:00Z.
What
On Windows, direct memory was always mapped as views of a section. Views have no page write watch, so the GPU driver tracked CPU writes to them by arming pages read-only and taking a write fault. With live AVX state, the exception frame Windows builds for such a fault overwrites the stack from RSP-0x20 down: most of the System V red zone, where guest leaf functions keep live values. Measured on Windows 11 with AVX2; without live AVX state the frame starts at RSP-0x120.
PPSA29141 took about 5,000 such faults a second and crashed in roughly a quarter of 90-second runs, in a Unity job, on a red-zone slot read back as 0.
MEM_WRITE_WATCHmemory, one allocation per mapping, with the section as its store.GuestArenaAwaitRetarget) and retry.WindowsMappings::Collectfinds Commit's write-watched allocations withoutVirtualQuery.HostWritealso refuses private pages the guest left read-only (reads into them returnEFAULT).Tested
Windows 11, i7-13650HX, RTX 4070 Laptop, MinGW-w64 GCC 15.2.
guest_memorygains tests for: a page mapped once is private and never armed; content survives an unmap and remap; a second mapping converts to views while another thread keeps writing; a partial unmap while another thread writes. The writer waits are bounded (5 s) andguest_memoryhas a 20 s CTest timeout. The existing view tests now alias their pages.cteston currentmain(c6e3aa76) merged with this branch, the other LEGO Party! PRs and #1482: 547/547 pass. On Windows,main'slibsstep currently fails withduplicate patched export name: LibwuIonIBw: #1714 addedAPS5_EXPORTs forsceVideoOutAddVrrActiveStatusEventandsceVideoOutAddVrrStatusFlagsPrivilege, whose names the NID table already maps. Those two lines were removed locally for the run.--module-dirfor its plugins, and #846 no longer merges with today'smain, so the title was not converted and run again on it.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:12:36Z.
Review: COMMENTED
I reviewed the retargeting and direct-memory changes. One CI-blocking test issue: the new Windows-only writer tests have unbounded
while (stores.load() < ...) std::this_thread::yield()waits (GuestMemory.cpp around lines 801/804 and 876/880). If a regression leaves a writer waiting in the AV handler, the test can hang indefinitely, contrary to CONTRIBUTING.md’s 30-second per-test limit. Please giveguest_memorya hard CTest timeout below 30 seconds (and bound the progress waits where possible), so a regression fails the job instead of occupying a runner indefinitely. I have not approved this head; I could not independently run the Windows-only path here.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T06:13:25Z.
Review: COMMENTED
One contribution-policy issue as well: this diff adds many explanatory comments in code (
WindowsMappings.hpp,DirectMemory.cpp,CrashReport.cpp, andGuestMemory.cpp).docs/dev/CONVENTIONS.mdallows code comments only for technical-debt notes,#endif, or namespace endings. The new TechnicalDebt entry is appropriate, but it does not make the implementation walkthroughs and test comments compliant. Please remove those comments or keep only comments that point to the specific documented debt; the PR checklist currently says there are no code comments, which does not match the diff.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:23:01Z.
Two things before this can go in:
WindowsMappings.hpp,DirectMemory.cpp,CrashReport.cpp,GuestMemory.cpp) as MarcZX100 said; only technical-debt markers are allowed, and the TechnicalDebt entry already covers this. The bounded waits he asked for in the writer tests too.APS5_DIRECT_MEMORY_VIEWS. TheAPS5_TRACE_FAULTScounter and the crash-report register dump are separate topics; send them in their own PR if you want them.It conflicts with main in TechnicalDebt now, so please rebase when you push.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-09T17:14:01Z.
Tested this PR on Arch Linux in WSL2 on Windows 11 (Intel Core i7-13700K), using GCC 16.2.1 20260810, CMake 4.4.4, Ninja, Python 3.14.7 and Mesa lavapipe (
VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json). This is software Vulkan validation, not a native Linux hardware-GPU result.I applied head
46d6acb8a641a17bd92b57ec4ccdb3427e397f22to main0fdda7bein an isolated native WSL checkout. There was a documentation-only conflict in TechnicalDebt, resolved by retaining both entries; the code was unchanged. Release,BUILD_TESTING=ON, SPIRV-Tools disabled; built the default target and explicitly builtlibs.guest_memorypassed. The skips are feature-dependent GPU tests on lavapipe.agc_driver_flat_storetimed out at 30 s; an isolated retry also timed out. I checked out unchanged main0fdda7be, rebuilt both the default target andlibs, and reran that test: the same timeout, with the batch still running at 25 s. This failure reproduces without this PR; I am not reporting a clean full suite.Additional Windows integration check (WinLibs GCC 15.2.0 r7, Release with
-g, SPIRV-Tools disabled):guest_memory,fiber, andwindows_exceptionsall passed, 3/3. That branch also includes #2310 and #1477, so this is an integration result rather than isolated Windows validation of this PR. A Demon's Souls dump still faults during startup with those changes; this is not a title compatibility success claim.Validation performed with OpenAI Codex assistance. No game binaries or proprietary code are attached.
Imported from boykopovar/AnyPS5. Originally posted by esatturan on 2026-10-09T23:36:49Z.
Done, rebased on current
main:WindowsMappings.hpp,DirectMemory.cpp,CrashReport.cppandGuestMemory.cpp.APS5_DIRECT_MEMORY_VIEWSis gone.APS5_TRACE_FAULTSand the crash-report stack and register dumps are out too, soCrashReport.cpponly adds theGuestArenaAwaitRetargetcheck now.Require, andguest_memoryhas a 20 s CTest timeout.guest_memory,windows_exceptions,fiberand the full suite pass on Windows 11. @Mouhand-Kaddo, thanks for the Linux run.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:46:50Z.
Please rebase onto current main:
core/libs/tests/GuestMemory.cppconflicts after #2236 and #2328.#2236 changed
sceKernelReleaseDirectMemoryandsceKernelCheckedReleaseDirectMemoryto unmap the released memory's mappings afterDirectMemoryFree. With a page mapped once now being private, check that this unmap doesn't write the page back into a section range that was just freed, and add a case that releases a page mapped once.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:49:13Z.
Review: CHANGES_REQUESTED
Thanks for the updates. Still open:
main:core/libs/tests/GuestMemory.cppconflicts after #2236 and #2328.DirectMemoryFreeinsceKernelReleaseDirectMemory/sceKernelCheckedReleaseDirectMemory. A page mapped once is now private, and its content goes back to the section when the mapping ends: please check that this doesn't write into a section range that was just freed.Since PR CI no longer builds Windows, please also post a Windows run of the rebased head (
guest_memoryand the title run if possible).Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T16:39:47Z.
Windows data point for this PR from a retail Unreal title, Taxi Chaos 2 (PPSA30279).
Without the PR (
maincf8b129eplus unrelated local patches), the title stalls while it loads its menu:WindowsMappings::Mapmaps direct memory as oneMapViewOfFile3view per 16 KiB page. By the menu that is ~165,000 views for 2.6 GB.sceKernelMapDirectMemoryof 64-155 MiB took 8.8 s and 17.2 s in two measured calls, and up to minutes in others.RHISubmissionThreadblocks in it and flips stop. Eventually UE fatals withGameThread timed out waiting for RenderThread after 120.00 secs.WindowsMappings::Map→MapViewOfFile3while a driver thread waits on the mapping lock inCollect.With this PR cherry-picked (two trivial conflicts, both sides kept), the same run maps 2.4 GB in about 2.3 s in total. The title then goes on to build its first menu frame and stops later on an unrelated depth-surface issue (#1409).
Windows 11 26200, Radeon 880M (
ANYPS5_GPU=AMD), WinLibs GCC 15.2.0 r7, Release. Dump from my own copy; no game files are shared.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T17:25:25Z.
@esatturan I retested the current head (
630b18f0) against the crash I described on #361 (RetroArch's Dolphin core, a red-zone clobber during write-watch faults on direct memory).Startup works again. An earlier version of this PR stopped RetroArch at startup with
a heap mirror's range is no longer write-watched(RADV's read+execute shader range). With630b18f0that's gone: Dolphin boots the GameCube 240p Suite and renders its menu. Three 150 s runs with shader compilation mode 0 had no crash.The red-zone crash: I can't tell whether this fixes it. On my current base the
adler32crash no longer happens even without this PR. The crash used to need shader compilation mode 2. In that mode, all three runs with the PR and all three without it now stop at an unrelated recompiler error (GetImageResource dword 0 is not a valid runtime value), and none of them hitadler32before that. So these runs don't show anything either way about the fix.One test interaction with
main.CheckFailedCollectKeepsWrites(added inbbdb35b1, after this PR's base) fails with the PR merged:Its second half:
PROT_NONE;With this PR that mapping is a private write-watched allocation, and the collect over both pages succeeds. Without the PR, on the same build, the whole
guest_memorytest passes. Since a collect that fails is supposed to keep the writes for the next one, a no-access page in the range now gets the opposite result from before. If the private path is meant to tolerate that, the test should probably say so; if not, the private path may need the same range check.How I ran it:
guest_memorystops earlier on my machine atCheckGuestModuleImageProtection(adlopenthat fails here, onmaintoo). I skipped that one check locally for both runs so the later checks would run. Your two new checks (CheckDirectMemoryMappedOnceIsPrivate,CheckPartialUnmapOfPrivateDirectMemory) run afterCheckFailedCollectKeepsWrites, so I couldn't see their result.Caveats:
main: this is my integration branch, amainfrom 2026-10-07 plus my open PRs, #423 and a few local spikes.630b18f0was cherry-picked onto it, with conflicts inDirectMemory.cpp(static_cast<void>(start)next to yourheld.assign) and theGuestMemory.cpptest list, resolved by keeping both sides.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T18:36:00Z.
Tested head
630b18f04applied to current main7159f7f34(local validation commit0c4ef6a09). The cherry-pick required two mechanical conflict resolutions: retain both constructor initializers and retain both main'sCheckFailedCollectKeepsWritescall and this PR's added test calls.Windows 11, MinGW-w64 GCC 15.2.0, Release:
windows_exceptionsandfiberpassed.guest_memoryfailed atGuestMemory.cpp:1024, inCheckFailedCollectKeepsWrites: after mapping direct memory once, writing its first half, and changing the second half to no access,Require(!collect(mapped, page * 2, count))fails. Collection returns success for the mixed-protection private mapping.guest_memoryon unchanged main7159f7f34: passed (1.29 s).Arch Linux under WSL2, GCC 16.2.1, Release:
guest_memoryandfiberpassed, 2/2. The Windows-only private-page checks are not exercised by that Linux result.This is focused validation, not a full-suite or game compatibility claim. The new main regression appears to need reconciliation with private direct-memory collection before merging.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T18:45:52Z.
Follow-up to my Windows result above: the failure comes from private-region collection accepting
PAGE_NOACCESSduring preflight. The same issue also occurs on main for an ordinary private allocation with an inaccessible middle region.I prepared a separate focused fix and regression in the fork: https://github.com/Mouhand-Kaddo/AnyPS5/tree/prep/private-write-watch-inaccessible (commit
82336b697). It rejects inaccessible private regions before any write-watch reset, and the regression verifies that a failed collection preserves earlier writes. The existing direct-memory assertion also distinguishes the 4 KiB private write-watch granularity from shared-view tracking.With this PR's head
630b18f04applied on top of that fix and main29380369a(local validation commit1fa8ba9a2), Windows 11 / MinGW-w64 GCC 15.2.0 Release passedguest_memory,fiber, andwindows_exceptions: 3/3, 1.48 s. This reconciles the focused failure I reported; it is not a full-suite validation. The generic fix alone also passedguest_memoryandfiberon Arch WSL2 (2/2); those Linux results do not exercise the Windows-only checks.No upstream PR opened for the separate fix while intake is paused.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T19:26:46Z.
Additional Windows runtime evidence, separate from the isolated regression checks reported above:
I tested a local integration of current main
4a747c487, the #757/#758 shader-table stack, the focused shader-stack and private-range collection fixes, and this PR's head630b18f04.guest_memory,fiber, andwindows_exceptionspassed 3/3 (1.98 s).During the bounded runtime comparison, host committed memory rose from 24.68 GB to 46.23 GB in 9.5 s; the commit limit was 46.99 GB at that point. I stopped the process when headroom fell below 1 GB. The process had about 7.51 GB of private committed memory then. This run ended before the engine loop, so it does not establish a boot or rendering result.
The physical allocator had also created a shared pagefile-backed section for a 12 GiB physical allocation. The implementation currently creates that section eagerly, before private views are mapped. I am investigating delaying shared backing creation until a shared view or retained private data needs it, and will keep that separate from this PR's mapping behavior. No payloads or executable data are attached.
Windows 11 x64, GCC 15.2.0 / MinGW-w64, Release; original pagefile settings retained. This is a commit-pressure observation on an integration, not an isolated functional failure of the PR.
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-10T20:44:05Z.
Follow-up on the host-commit observation: I prepared a separate, single-topic fork change that defers Windows shared backing creation until it is first mapped:
https://github.com/Mouhand-Kaddo/AnyPS5/tree/prep/lazy-direct-memory-backing
On main
262c03169, the focused memory/fiber/exception checks passed 3/3 on Windows and memory/fiber passed 2/2 on Arch WSL2. A local 1 GiB allocation probe confirms that an unmapped allocation creates no section handle or approximately-1-GiB commit charge, while shared aliases still preserve writes in both directions and release returns the handle count to baseline.I also tested a local integration with this PR's head
630b18f04plus the previously reported inaccessible-range collection fix. The Windows checks passed 3/3 (1.74 s). Its first private mapping leaves the backing section uncreated; creating an alias then materializes the section and preserves both views' contents. Adapting the lazy helper requires using it inMapViewand theWindowcopy paths.Bounded runtime probes of the combined changes progress through substantially more shader work than the earlier run and now stop at an unsupported depth-maintenance draw. This does not isolate the earlier startup fault's cause or establish rendering success, since the integration also includes newer main and shader work. No new upstream PR or payload upload.
Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-10T22:51:02Z.
Runtime result on Windows 11 10.0.26300, i7-13700K, RTX 4080, WinLibs GCC 15.2.0 r7: with
630b18f0cherry-picked, Disney Epic Mickey: Rebrushed (PPSA15657) no longer hits the #361 null write at eboot0x55eac49(a red-zone pointer in a leaf function) and ran more than 14 minutes past that point. Details on #361.On my branch
CheckFailedCollectKeepsWritesneeded its expectation changed for the private pages, the same failure @Mouhand-Kaddo reported above; their separate fix looks like the cleaner way to handle it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:23:31Z.
Review: CHANGES_REQUESTED
Thanks for the updates. Still open:
CheckFailedCollectKeepsWrites(already onmain) fails on Windows with this PR, as reported by @Mouhand-Kaddo and @johnmaia: private-region collection acceptsPAGE_NOACCESSin preflight, so a failed collect no longer preserves earlier writes. The fix is the separate change @Mouhand-Kaddo prepared (reject inaccessible private regions before any write-watch reset, https://github.com/Mouhand-Kaddo/AnyPS5/tree/prep/private-write-watch-inaccessible); please include it here or land it first, and keep the test expectation asmainhas it.main(DirectMemory.cppconstructor andGuestMemory.cpptest list conflict). It rebases cleanly apart from those two spots.ForgetDirectMemoryerasesg_physPagesand the mappings beforeUnmapDirectMemoryViews, soEraseMappingsfinds no private mapping andSavePrivateis not called on the freed range. Please add a test for it: map once, write,sceKernelReleaseDirectMemory, allocate the same range again, map it, and require zeroes (the old address must no longer be committed).guest_memoryrun of the rebased head with the first point fixed.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T20:37:56Z.
Test data for this PR with DREDGE (PPSA09076, Unity), which showed the red-zone crash described in #361 and #3915 on
maina11c8f7f7(Windows 10, Ryzen 7 5800X3D).Rebase.
630b18f04cherry-picked ontomaina11c8f7f7has two small conflicts, both from tests thatmaingained after this PR was written: inDirectMemory.cpp(PhysicalBacking,mainhasstatic_cast<void>(start);, this PR hasheld.assign(...); I kept both) and inGuestMemory.cpp(the call list inmain; I keptmain'sCheckFailedCollectKeepsWrites()and this PR's two new checks). After thatlibsbuilds, butctest -R "^guest_memory$"fails on that rebase:Line 1159 is
Require(collect(mapped, page, count) && count == 4)inCheckFailedCollectKeepsWrites, a check on a direct mapping that is mapped once (sceKernelMapDirectMemoryof one range, thensceKernelMprotectof its second page, thenGuestArenaCollectWrites). With this PR such a mapping is private write-watched memory, so the number of pagescollectreturns may differ from what that test, written for views, expects. I did not look at whether the test or the PR is wrong;guest_memorypasses on plainmain.Crash rate (inconclusive). 10 alternating pairs of 120 s runs, plain
mainlibs againstmain+ this commit, same relinkedapp.exe: 0 of 10 faults on either side (noFATALin any of the 20). The same title faulted in 2 of 8 earlier runs onmain(see #3915), so the rate was lower in this batch and these 20 runs cannot show whether the PR removes the crash. A second batch with 60 s runs is running.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T21:04:10Z.
Second batch for the DREDGE comparison above, same method: 10 alternating pairs, 60 s each, the same relinked
app.exeandrun_title(Windows 10, Ryzen 7 5800X3D,maina11c8f7f7libs against the same libs plus the rebased630b18f04; no other change).mainmain+ this PRThe three faults on
mainare all in aJob.Workerthread (Job.Worker 1,10,8), atapp.exe+0x17f05ed(twice, a read of0x00007ff74d268000, an address inside the executable's own mapping) and+0x17f0843(a read of0x40), in the same routine area as the faults in #3915 (+0x17f0796,+0x17efe13). None of the 20 runs with this PR faulted.What this does and does not show: a one-sided Fisher exact test on 3 of 20 against 0 of 20 gives p of about 0.12, so it is consistent with the PR removing the crash but is not significant, and the rate on
mainwas clearly not constant (2 of 8 earlier, then 0 of 10 at 120 s, then 3 of 10 at 60 s), so the groups are not equally exposed. More runs on both sides would be needed. The unit test failure of the rebase (GuestMemory.cpp:1159, above) is separate and unresolved.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T21:07:23Z.
@esatturanthanks for this PR. On theguest_memoryfailure after rebasing it onto currentmain(a11c8f7f7), which I reported above: it is not a mistake in the rebase, and it has two separate causes. This is from reading and building only; I changed nothing in the PR and did not push anything.CheckFailedCollectKeepsWriteswas added tomainbybbdb35b19after this PR was written. It maps a direct-memory range once (sceKernelMapDirectMemory, two 0x4000 pages), writes one byte in the first page, makes the second page inaccessible withsceKernelMprotect(..., 0), and then expects (a) acollectover both pages to fail without losing the write, and (b) acollectof the first page to return 4 four-KiB pages. With this PR such a mapping is privateMEM_WRITE_WATCHmemory, not shared views, and:Require(!collect(mapped, page * 2, count)). The whole-range pre-checkcollectable()returns false for aPAGE_NOACCESSview, but for private memory it only testsMEM_COMMITandMEM_PRIVATE, so the inaccessible private page passes andcollectreturns true. A one-line local change ((memory.Protect & 0xffu) == PAGE_NOACCESSalso returns false in the private branch ofcollectable()) makes line 1159 pass. Without it, a caller that getstruefor such a range would go on to read a page the guest made inaccessible.count == 4. With that change,collect(mapped, page, count)returnsok = 1, count = 1:GetWriteWatchreports the one 4 KiB page that was written, while shared views report the whole 16 KiB guest page as 4 pages. So this expectation describes views only. Since a once-mapped range is private now, the test would need to alias the mapping (map the same physical range a second time) to keep exercising the view path, or the expected count has to depend on the mapping kind.I did not run anything beyond
guest_memoryfor this. Whether (2) matters to the GPU side, which is the consumer of the collected page list, I do not know.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-11T21:09:56Z.
@esatturan a rendering regression with this PR under host import, found and bisected together with @parl0v.
What we see. Sword of the Sea (PPSA25344, Unreal Engine 5) on Windows. Our integration branch is
maina11c8f7fplus #2054 (0f25943c7) plus a stack of other open PRs. With host import on, its main menu renders saturated red with tiled garbage rectangles. Two changes bring back a correct menu on the same branch:APS5_NO_HOST_IMPORT=1, or keeping direct memory as shared views by forcingprivatePages = falseinAddMapping(libkernel/DirectMemory/DirectMemory.cpp) and changing nothing else.privatePages = falseAPS5_NO_HOST_IMPORT=1Reverting the R_X XOR fixes, #3372 and #3425 left it red (#3425 is a separate slowdown).
Mechanism. @parl0v traced it in the code.
ShareMappedPages(DirectMemory.cpp:436) runs when a new mapping aliases a private range. It callsSavePrivate, remaps the VA as shared section views and setsprivatePages = false(lines 455–462), but nothing re-imports host memory. AVkDeviceMemoryimported while the range was still private keeps the old pages, so the GPU reads pages the title no longer writes. That gives stale tiles, and the same stale data feeds UE's colour-grading LUT, hence the red.Possible fixes. Invalidate and re-import any host import over the range in
ShareMappedPages, or don't keep host-imported direct memory private. I haven't tried either yet.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T21:24:47Z.
Second 60 s batch of the DREDGE comparison (10 more alternating pairs, same setup as the two comments above). The result is less clear than the first batch:
mainmain+ this PROne-sided Fisher exact test: p of about 0.09 for 5 of 20 against 1 of 20, and about 0.10 for 5 of 30 against 1 of 30. So the rate with this PR was lower in these runs but the difference is not significant, and the crash did not go away: the one fault with this PR is in
Job.Worker 4atapp.exe+0x17efe13with a read of0x0000000600000004, the same site and the same bad value as one of the original faults onmain(#3915). Themainfaults in this batch were both atapp.exe+0x17f0796, a read of0x0000000600000030, again the site and value from #3915.So this data does not support "this PR removes the DREDGE crash"; it is compatible with it removing some of the write faults that overwrite the red zone while others remain. A guess that I did not check: write-watched memory that is not direct memory mapped once (the guest arena's watched commits, or direct memory that is aliased) still takes resumed write faults. I did not check which memory the faulting write in DREDGE targets.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T09:23:49Z.
@esatturan a correction to our red-menu report above (Sword of the Sea, PPSA25344): the mechanism we gave there is wrong for this title. The red is real and comes with this PR plus host import, but it is not caused by
ShareMappedPages.What we got wrong. We said
ShareMappedPagesturns a private range into views and leaves an import of the old pages behind. This title never takes that path. WithAPS5_TRACE_MEMORY=1, a 180 s menu run logs 3708[memory]lines and noshared ... (mapped again)line, so no direct memory range is mapped a second time. We also wrote a fix for that path (wait for GPU work and retire the imports before the switch). On one build with that fix switchable, the menu is just as red with it as without it:ShareMappedPagesfixWhat it is instead, as far as we can tell. The last row keeps Windows host imports write-watched. That takes a local switch of ours (
APS5_WRITE_WATCH_IMPORTS=watch, not onmain), and with it the menu is correct. On Windows the driver unwatches every range it imports ([write-watch] Windows direct host imports use comparisons; separate shared aliases retain guest write tracking):main, direct memory is shared views, so an import goes through a separate alias and the guest's own views keep their write tracking.So some CPU write that the driver relies on write tracking to see is missed. That fits both changes from our first report:
APS5_NO_HOST_IMPORT=1, and forcingprivatePages = false. I haven't found yet which consumer misses the write.Cost. The comparisons are also expensive. In the four red rows
mem.compareis a top cost at 215-231 ms per frame, with about 1 TB compared per run. Keeping the imports watched cuts that to 22 GB, and our shared-view rows on the same base compare 3-5 GB per run at 289-332 ms per frame.The gap we described in
ShareMappedPagesis still there in the code: an import made over private pages outlives a second mapping of the same memory. A mock test shows it, but this title doesn't reach it. I can send that fix and its test separately if you want them. Sorry for the wrong lead.Windows 11, RTX 5070 Laptop (616.92). The base is
maina11c8f7f7plus this PR (rebased, 02c898e65) and our local patches for this title, upstream default env (APS5_RESOURCE_CACHE_ENTRIES=8192,APS5_PROFILE_DRAW=1).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T14:06:52Z.
Question on testing: DREDGE (PPSA09076, Windows) faults intermittently in a function whose loop variables live below
rsp(details and offsets in https://github.com/boykopovar/AnyPS5/issues/3915 , comment of today), which looks like the red-zone case of #361. Should I run DREDGE with this PR branch (5 runs of 150 s against plain main, library hash checked) to see whether the fault rate changes? In my earlier test of this approach on this title (#3915) the fault rate dropped but the fault did not disappear. I will not start it until someone says it is wanted.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T00:10:40Z.
Thanks for this. Closing in favour of #637, which handles singly mapped direct memory the same way and is being ported onto main. The points from the 10-11 review (inaccessible private pages in collect, the release test) apply there too. If you want to continue this design, please reopen.
Pull request closed