Repository navigation
feat(libc): track guest memory with windows write-watch tokens - #13784
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
bd01f8d to
adfa2c9
Compare
There was a problem hiding this comment.
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.
adfa2c9 to
3a3c1ca
Compare
|
@CnRJay I investigated the pending-page merge you called out and changed it in I also made the Windows-only token support explicit in the title and description. The updated head passed the seven Windows mapping and write-watch tests three times each, including new overlapping and disjoint page checks with partial collection. I also measured the per-block calls in a synthetic private-memory run: arming 64 blocks averaged about 204 µs and checking them about 21 µs. I still need a title trace and the requested reuse counters to say what that costs in practice. There is no fixed entry cap on the two maps: token entries can remain for armed blocks until invalidated, and pending dirty-page bits remain until collection or removal. Their growth follows the blocks involved, so long-lived mappings can retain entries; I haven't established a title-level bound. Token exhaustion returns false and stops new arms rather than wrapping; there is currently no separate diagnostic for it. Would you take a look at the collection change when you have a chance? I'm continuing with the remaining concerns and the dependent branches. MeasurementBefore rebasing, I allocated watched private memory, dirtied each page, armed the blocks, dirtied the pages again and collected without reset, checking every page was returned once in order. Three runs at 8,192 pages took 6.116–6.354 ms before and 0.354–0.373 ms after. This measures collection in a synthetic all-overlap workload. In a separate clean private-memory workload, three batches of 100 arms and checks averaged 1.63–1.66 / 0.27 µs for one block and 203.96–204.23 / 20.73–20.76 µs for 64 blocks. Each operation currently calls GetWriteWatch once per block. |
Expose internal proofs for fully writable, write-watched guest blocks. Keep mapping changes, pins, host accesses and collect resets serialized with token queries, without changing guest page protection. Retain writes consumed during arming for later collection and eviction. Refuse unsupported mappings and platforms conservatively; defer driver consumers, GPU write stamps and epoch caching to subsequent changes. Cover private and resident lifetimes, aliases and concurrent collection. AI-assisted: yes
3a3c1ca to
4b26f5d
Compare
|
@CnRJay I addressed the unbounded maps in A standalone Windows fixture with an eight-entry limit covers saturation, mixed existing/new ranges, preserved dirty pages, collection, and token eviction. It and seven related mapping tests passed three times; disabling either limit made the fixture fail. A current-main merge of the full stack passed 10 selected Windows tests and seven Linux tests three times each. Linux cannot exercise the Windows write-watch implementation. I also restacked the draw and storage follow-ups. Their trace counters report requested blocks and outcomes, but not a saturation reason or measured per-frame cost. Would this bound and fallback policy address your growth concern? |
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
main66e1f7f. 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)