feat(libc): track guest memory with windows write-watch tokens #13784
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13784"
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 Celegans12 on 2026-10-31T06:10:13Z.
What
libc has no host-side token for checking whether cached guest bytes changed. Add
GuestArenaArmOwned_nid_no_patchandGuestArenaOwnedUnchanged_nid_no_patchover whole 64 KiB blocks, using Windows GetWriteWatch.Arming preserves consumed dirty pages for collection and eviction. Mapping changes, pins, host access, protection notifications and clearing collections invalidate tokens under the mapping mutex. Guest page protection stays unchanged. Linux and other unsupported platforms return false; private memory requires flag 1. Pending and newly reported pages are merged using a sorted lookup before collection returns them. The token and pending maps are capped independently at 65,536 blocks. Token pressure invalidates lowest-address proofs; pending pressure refuses new blocks before resetting their writes. Existing pending blocks can still be armed. The byte-only contract and unmeasured title impact are recorded in libc debt.
This rebase incorporates merged #13220's standalone write-watch registration fix, which addresses the inherited configure failure in the old macOS jobs. Token behavior is unchanged. Driver consumers, GPU stamps and epochs remain separate; no title performance claim. #11552 and #6926 supply different APIs. Adjacent libc debt entries from #12184/#12849 must be retained together. The current overlap scan left 20 shared-file comparisons unresolved. #10025 adds zero-page mapping and must preserve token invalidation; #5021 changes test registration. The other unresolved changes concern independent platform, registration or debt work.
Tested
Based on
main66e1f7f993. Windows 11, MinGW-w64 GCC 15.2.0, Release,-DBUILD_TESTING=ON: eight mapping tests passed three times, includingguest_owned_memory_limits. Its eight-entry fixture checks pending saturation, refusal before reset, reuse after collection and token eviction; removing either bound made it fail. A synthetic 512-block workload reproduced unbounded growth on the previous head. A separate 8,192-page collection improved from 6.1–6.4 ms to 0.35–0.37 ms before the rebase.A current-main merge with the dependent draw and storage changes passed 10 selected Windows tests and seven Linux tests three times each. Linux does not exercise Windows write-watch. Earlier Ubuntu 24.04/GCC 13.3 host tests passed three times; unsupported platforms refuse ownership. Not tested: macOS, titles, console behavior or title performance. These synthetic results do not establish frame impact.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:47:48Z.
Review: COMMENTED
Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows
Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.Three things before this can be judged.
No title ID and no consumer. "Unblocks: none", "no performance claim", and the only caller is the stacked #13793 (and later #13809). A new libc export pair with no title reaching it on main is the export-only shape the maintainers close. If the point is to make draw-input copies skippable, the evidence has to be on the consumer PR (trace_digest of main vs change, same scene), and this one should say which title/scene makes
GuestArenaArmOwnedhot.Linux gets nothing. "Linux native tokens are unsupported", so on Linux both functions return false and the consumer always falls back to the copy. Everything the PR adds is a Windows-only code path (
GetWriteWatch), plus the same two exports being callable on every platform. Please state that in the PR title/What so nobody reads it as a general facility.Cost and growth in
WindowsMappings.hpp:ArmOwnedandOwnedUnchangedtake the mappingmutex, the same lock the map/unmap/protect paths use, and callGetWriteWatch(a syscall) once per 64 KiB block per call. For a draw that touches many blocks this is a syscall per block per draw on a lock shared with the allocator. Is there a number for how many blocks and calls per frame in a real scene?collectOwnedWritesrunsstd::find(pages, pages + *count, pointer)for every pending bit, so merging pending pages into the result is O(pending x reported) inside the collection path that previously was a singleGetWriteWatch. With a large dirty set that is quadratic work under the mapping mutex.ownedWords/ownedPendingonly shrink ondisown/unmap/pin. A title that arms many distinct blocks and never unmaps them keeps one map node per 64 KiB block forever. What bounds it?nextOwned++hands out tokens from a 64-bit counter; fine, butArmOwnedfails oncecount > UINT64_MAX - nextOwned + 1, and that failure is silent to the caller (justfalse).Please add a counter or a trace phase for arm/check/refuse so the reuse rate can be read in a trace_digest, otherwise nobody can tell whether the feature fires.