Repository navigation
Conversation
WindowsMappings::Collect handed GetWriteWatch the caller's whole remaining capacity (65536 entries for the write tracker) for every private piece it collects. The call's cost follows the entry count it is given, not the pages of the range: about 7 us for a 64 KiB range with 65536 entries, against 0.5 us with the 16 the range can actually report. Most collects are small ranges that find nothing written, so this fixed cost was most of each walk. The count passed is now the smaller of the remaining capacity and the range's 4 KiB pages. A range cannot report more pages than it has, so the results are the same; a full buffer still returns early for the caller to continue as before. As suggested by exiled96 in discussion boykopovar#357, who measured the per-call cost on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A queue worker walks the write-watch state of every range it collects, once per collect epoch, and there are 18 epochs per frame in Astro Bot (one per ordering point). About 1,400 GetWriteWatch calls per frame land on the worker that records the draws, at a fixed cost of about 10 us each, and almost none of them finds a written page (about 30 dirty pages per frame). Mechanism. A worker's memoized walks of one epoch are logged under the address of the epoch's first walk. When a later epoch starts with a walk of that address, a helper thread of the worker (on the efficiency cores of a hybrid CPU) looks at the ranges logged last time while the worker records: GetWriteWatch without reset, holding no lock across the call (WindowsMappings::ProbeClean resolves the range under the mappings mutex and calls GetWriteWatch after releasing it). A range found clean has its 64 KiB blocks marked in walkedBlocks with a tracker generation taken before the look, under the tracker mutex; a completed resetting walk marks the blocks it covered whole the same way. A memoized collect of a queue worker skips the blocks marked after its epoch began and walks only the rest. Safety, under the epoch contract of GuestMemory.hpp. The look starts after the worker's ordering point, since a walk of the new epoch posts it, so its generation is newer than the worker's epoch generation. A CPU write made before that point either still has its dirty bit at the look (the range is not marked and the worker walks it) or had it cleared by a resetting walk, which stamps the block under the tracker mutex before releasing it; the mark is made under that mutex after the look, so the stamp is already in. A mark only serves epochs that began before its generation was taken, so it expires at the next ordering point. A commit, release or mapping change (new mapping serial) or an unwatch between the look and the mark drops the mark. Shared views, uncommitted and non-watched memory are never marked. Uncached collects always walk. Measured on Astro Bot (PPSA21564) at the Crash Site, Windows 11, Core Ultra 9 285K, RTX 5080, 150 s runs: worker walks 156,000 -> 53,000 per 10 s, 33.9 -> 29.1 us per draw packet, 9.6 -> 10.9 FPS. That run had direct memory backed by write-watched private pages (boykopovar#637); on main direct memory is mapped as shared views, which this leaves to the existing per-view tracking, so the gain there is limited to private memory until direct memory is watched the same way. APS5_NO_PREWALK=1 disables it. The helper is started on the first epoch that repeats a key and is stopped and joined when its worker returns. The [guestmem] line (APS5_PROFILE_DRAW) counts looks, clean looks and trimmed collects. agc_write_tracking covers a clean range being skipped, a page written before the ordering point never being marked clean, and a write after a look being seen at the next epoch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The repository allows comments only for documented technical debt. The mechanism and its safety argument stay in the commit message of the prewalk and in the pull request description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriadam10
left a comment
There was a problem hiding this comment.
Following up on @oneandonlydean's request, which is still open:
- Split the
GetWriteWatchbuffer sizing (WindowsMappings::Collect,core/libs/prx/libc/include/WindowsMappings.hpp:270) into its own PR. It is small, exact and independent of the prewalk. - The prewalk numbers (9.6 → 10.9 FPS, 156,000 → 53,000 walks) were measured with direct memory as private watched pages (#637). On
maindirect memory is mapped as shared views, which the prewalk leaves alone, so the gain onmainis not shown. Either post before/after numbers onmain, or declareDepends on: #637(or #2054) instead ofnone, and rebase once that lands (#218). - Please add the prewalk helper thread and the "gain limited to private memory" caveat to
docs/dev/TechnicalDebt.md, under an accurate section (not at the end of one).
Checked: the diff builds and the Linux ctest scope is green. The prewalk code is _WIN32 only, so we could not run CheckPrewalk here; the Windows result rests on your run.
|
Windows run, since the PR has no Intel or Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
Full AI-assisted (Claude Code); I ran this on my machine. |
|
Additional platform validation of standalone PR head Linux: passed with skips — Arch Linux in WSL2 (kernel 6.6.87.2), GCC 16.2.1 20260810; CMake 4.3.1 / Ninja; Release, 3 checks, 0 failures, 1 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run. Checks: Command after building: This scope checks CPU-side behavior; no GPU execution result is claimed. Internal limitation: heap-mirror subcases returned early because the guest arena was not write-watched in WSL. Zero CTest skips does not include that early return. No title/gameplay validation. These results cover the standalone head, not a merge with current main. |
|
Rebase handoff — rebased onto current Two test-file conflicts with main's newer write-tracking tests, resolved by keeping both sides: main's Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
|
Closing: the 2026-10-10 request for numbers on |
What
Problem
On Windows a queue worker walks the write-watch state of every range it collects, once per collect epoch. Astro Bot has 18 epochs per frame (one per ordering point), and the worker that records the draws makes about 1,400
GetWriteWatchcalls per frame at a fixed cost of about 10 us each. Almost none of them finds a written page (about 30 dirty pages per frame).Change
Two commits:
GetWriteWatchbuffer to the range (WindowsMappings::Collect). The call was given the whole remaining capacity (65,536 entries) for every piece. Its cost follows the entry count, so a 64 KiB range cost about 7 us instead of 0.5 us. The count is now the smaller of the capacity and the range's pages, which gives the same results. As suggested by @exiled96 in discussion Astro Bot (PPSA21564) #357.GetWriteWatchwithout reset and outside every lock (WindowsMappings::ProbeClean). A clean range has its 64 KiB blocks marked inwalkedBlocks, under the tracker mutex, with a generation taken before the look. A completed resetting walk marks the blocks it covered whole.Safety (epoch contract of
GuestMemory.hpp)Measurement
Host: Windows 11, Core Ultra 9 285K, RTX 5080. Astro Bot (PPSA21564) at the Crash Site, 150 s runs:
Caveat: these runs had direct memory backed by write-watched private pages (#637). On
main, direct memory is mapped as shared views. The prewalk leaves views to their existing per-view tracking, so its gain onmainis limited to private memory until direct memory is watched the same way (#637 or #2054). Neither commit depends on those PRs. The buffer sizing (commit 1) was not measured separately here; the 7 to 0.5 us figure is @exiled96's.Disabling
APS5_NO_PREWALK=1. The helper starts on the first epoch that repeats a key and is stopped and joined when its worker returns. UnderAPS5_PROFILE_DRAWthe[guestmem]line counts looks, clean looks and trimmed collects.Tested
Windows 11, MinGW GCC 15.2 Release, Astro Bot (PPSA21564) for the measurement above.
agc_write_trackinggainsCheckPrewalk(Windows), which checks three cases:cteston Windows (MinGW GCC 15.2, Release): 709/709 passed.agc_write_tracking,agc_shared_writeand the graphics tests also pass withAPS5_NO_PREWALK=1.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)Discussion: #357. Written with AI assistance (Claude Code).
🤖 Generated with Claude Code