perf(libc): keep no per-page physical state for resident guest pages on Windows #11152

Merged
thuanquang merged 1 commit from upstream-pr/11152 into main 2026-10-27 11:00:40 +00:00
thuanquang commented 2026-10-25 19:46:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-25T19:46:55Z.


What

On Windows, WindowsMappings::Map gives each 16 KiB page of a resident run (singly mapped private direct memory) five heap objects: a View, a SharedPage, a Physical, the physical map node for it, and an aliases buffer. That is about 480 bytes per page, or 30.9 MiB of private memory per GiB mapped. A title that maps its whole direct-memory pool pays about 0.4 GiB for this.

For a page that is never mapped at a second address, evicted, re-protected or pinned, the SharedPage, the Physical and the aliases hold only default values.

This change keeps only the View for a resident page. Its pin count and compare mark move into padding in the View, which stays 128 bytes. Resident runs of a physical page are found through a per-run index keyed by section and offset. The other objects are created only when needed:

  • demote creates the SharedPage and Physical when a page becomes shared.
  • evict creates a Physical only for pages that hold data or carry a compare mark.
  • ForgetSection drops the section's entries from the index.

Demoting a run creates its two objects per 16 KiB page at that point, for example 65,536 pairs for a 1 GiB run, so the cost moves from every resident mapping to the mappings that become shared. demote and evict erase a run's index entry only after their per-page loops, and demote adds its new physical entries only after the run's private pages are released.

Tested

Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release. Head 83c8315d70, rebased onto main be9effaeb0, which includes #9505.

  • A new check in guest_memory maps 1 GiB with protection 0x33. It requires less than 16 MiB per GiB of private bytes beyond the mapped bytes. It then maps one 64 KiB slice at a second address and one 2 MiB run as an alias, checks the data in both directions, unmaps and releases everything, and requires private bytes to return to within 4 MiB of where they started. With main's WindowsMappings.hpp and this change's tests it fails at the bound in 3 of 3 runs, at 30.90, 30.87 and 30.92 MiB per GiB. With this change it passes in 3 of 3 runs, at 13.40 MiB per GiB.

  • Five new checks in windows_write_watch cover the new index. They pass with main's WindowsMappings.hpp too (2 of 2 runs), since they test behaviour that main gets from the per-page objects:

    • a pinned page of a resident run stays writable after a second mapping makes the run shared, and is reported as written until it is unpinned;
    • ForgetSection does not report a section as blank while a resident run of it is still mapped;
    • after ForgetSection, a second resident run of the same physical pages replaces the first in the index; releasing the first run, all of it or one page of it, leaves the second run's data visible to a third mapping, and writes through that mapping reach the second run.
    • a resident run of 0x40000 bytes, collected with All, Fresh and Armed, reports exactly its two written pages, once.

    With the run-identity check in the index lookup removed, the replaced-run check fails in 2 of 2 runs.

  • ^(guest_memory|windows_write_watch.*|windows_mappings_release.*|agc_write_tracking.*|agc_write_watch_coverage|agc_.*host_import.*)$, 3 rounds: 21 pass and agc_host_import_sparse skips. agc_host_import_cut_lifetime fails, as it does on main (#10746).

  • ^guest_: 788 of 788 pass.

  • Independent run by ycbuzi (Windows 11 Home 26200, WinLibs GCC 15.2.0 r7): this head merged onto main 35ac3402c8 builds without warnings; guest_memory, guest_mmap_fixed_anonymous and windows_write_watch pass 2 of 2, and with main's WindowsMappings.hpp guest_memory fails at GuestMemory.cpp:2202.

  • PPSA05110 (own dump), memory only, no speed claim. Base: main 61fc572cee + #10614, #10913, #7844, #9181 and a local equivalent of #10887, which the title needs to load and run. Change: the same base plus this change at an earlier review state (the same data structures; later commits moved two steps in demote and added the null check and tests). Each run follows the same scripted route (boot, title, New Game, opening) for 330 s on a shared GPU, with no stop. Private bytes are sampled from outside the process. The runs went base, change, change, base. The two runs of each pair rendered at about the same rate: pair 1 at 500-600 presents per 10 s, pair 2 at 40-80.

run peak private peak working set private at 45 / 90 / 150 / 290 s (MiB)
pair 1, base 18.12 GiB 15.70 GiB 16912 / 18246 / 18432 / 18550
pair 1, change 17.85 GiB 15.47 GiB 16569 / 17950 / 18155 / 18276
pair 2, change 18.10 GiB 15.56 GiB 16512 / 18232 / 18432 / 18530
pair 2, base 18.38 GiB 15.84 GiB 16764 / 18339 / 18712 / 18823

Within each pair the change saves 274 and 293 MiB of private bytes at 290 s, and 0.27 and 0.28 GiB of peak private bytes. The unit check predicts about 237 MiB for the 13,793 MiB of direct memory the title maps (17.6 MiB per GiB × 13.5 GiB).

Summary lines at about 290 s, pair 1 (shared GPU; frame times are not compared)
{"commit":"f4f0c7acec08","dirty":false,"env":{"APS5_DUMP_FRAMES":"4000","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA05110","title":"Persona 5 Royal","content_version":"01.000.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":11380,"ms":10011.192},"interval_start_s":279.811,"interval_end_s":289.822,"presents":550,"frame_ms":{"p50":16.695,"p90":19.855,"p99":30.097,"max":438.329},"gpu_busy_ms_per_present":10.519,"worker_busy_pct":{"queue worker 0x0":97.404},"top_phases_ms_per_frame":{"VideoOut.Flip":17.758,"Driver.Packet":17.675,"VideoOut.Flip.present":8.735,"Driver.Present":8.719,"VideoOut.Flip.vblank_wait":8.328,"Driver.Packet.pipeline_drain":6.881,"Driver.Packet.rendering_wait":5.411,"Driver.Present.render_fence_wait":5.126},"trace_dropped":false,"trace":""}
{"commit":"f32f0493e004","dirty":false,"env":{"APS5_DUMP_FRAMES":"4000","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA05110","title":"Persona 5 Royal","content_version":"01.000.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":10708,"ms":10010.208},"interval_start_s":283.420,"interval_end_s":293.431,"presents":600,"frame_ms":{"p50":16.682,"p90":16.934,"p99":20.763,"max":25.735},"gpu_busy_ms_per_present":10.884,"worker_busy_pct":{"queue worker 0x0":98.514},"top_phases_ms_per_frame":{"VideoOut.Flip":16.473,"Driver.Packet":16.400,"VideoOut.Flip.vblank_wait":10.993,"Driver.Packet.rendering_wait":7.346,"VideoOut.Flip.present":4.972,"Driver.Packet.pipeline_drain":4.968,"Driver.Present":4.966,"Graphics.Draw":3.315},"trace_dropped":false,"trace":""}

Overlap: #9505 has merged, and this change is rebased onto it. In #9505's run mapping, a resident run is now demoted through the new index before slotOf, because resident pages are no longer in a SharedPage's aliases. #9505's View initializers carry the two new fields, and its unmap loop skips the null page of a resident view. #9098 (on #9505) still changes the same loops; whichever of #9098 and this PR merges second takes the same resolution.

Not tested: Linux and macOS (WindowsMappings is Windows-only), and titles other than PPSA05110.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5008065723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11152). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-25T19:46:55Z. --- ### What On Windows, `WindowsMappings::Map` gives each 16 KiB page of a resident run (singly mapped private direct memory) five heap objects: a `View`, a `SharedPage`, a `Physical`, the `physical` map node for it, and an aliases buffer. That is about 480 bytes per page, or 30.9 MiB of private memory per GiB mapped. A title that maps its whole direct-memory pool pays about 0.4 GiB for this. For a page that is never mapped at a second address, evicted, re-protected or pinned, the `SharedPage`, the `Physical` and the aliases hold only default values. This change keeps only the `View` for a resident page. Its pin count and compare mark move into padding in the `View`, which stays 128 bytes. Resident runs of a physical page are found through a per-run index keyed by section and offset. The other objects are created only when needed: - `demote` creates the `SharedPage` and `Physical` when a page becomes shared. - `evict` creates a `Physical` only for pages that hold data or carry a compare mark. - `ForgetSection` drops the section's entries from the index. Demoting a run creates its two objects per 16 KiB page at that point, for example 65,536 pairs for a 1 GiB run, so the cost moves from every resident mapping to the mappings that become shared. `demote` and `evict` erase a run's index entry only after their per-page loops, and `demote` adds its new `physical` entries only after the run's private pages are released. ### Tested Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release. Head `83c8315d70`, rebased onto `main` `be9effaeb0`, which includes #9505. - A new check in `guest_memory` maps 1 GiB with protection `0x33`. It requires less than 16 MiB per GiB of private bytes beyond the mapped bytes. It then maps one 64 KiB slice at a second address and one 2 MiB run as an alias, checks the data in both directions, unmaps and releases everything, and requires private bytes to return to within 4 MiB of where they started. With `main`'s `WindowsMappings.hpp` and this change's tests it fails at the bound in 3 of 3 runs, at 30.90, 30.87 and 30.92 MiB per GiB. With this change it passes in 3 of 3 runs, at 13.40 MiB per GiB. - Five new checks in `windows_write_watch` cover the new index. They pass with `main`'s `WindowsMappings.hpp` too (2 of 2 runs), since they test behaviour that `main` gets from the per-page objects: - a pinned page of a resident run stays writable after a second mapping makes the run shared, and is reported as written until it is unpinned; - `ForgetSection` does not report a section as blank while a resident run of it is still mapped; - after `ForgetSection`, a second resident run of the same physical pages replaces the first in the index; releasing the first run, all of it or one page of it, leaves the second run's data visible to a third mapping, and writes through that mapping reach the second run. - a resident run of 0x40000 bytes, collected with `All`, `Fresh` and `Armed`, reports exactly its two written pages, once. With the run-identity check in the index lookup removed, the replaced-run check fails in 2 of 2 runs. - `^(guest_memory|windows_write_watch.*|windows_mappings_release.*|agc_write_tracking.*|agc_write_watch_coverage|agc_.*host_import.*)$`, 3 rounds: 21 pass and `agc_host_import_sparse` skips. `agc_host_import_cut_lifetime` fails, as it does on `main` (#10746). - `^guest_`: 788 of 788 pass. - Independent run by [ycbuzi](https://github.com/boykopovar/AnyPS5/pull/11152#issuecomment-6411012697) (Windows 11 Home 26200, WinLibs GCC 15.2.0 r7): this head merged onto `main` `35ac3402c8` builds without warnings; `guest_memory`, `guest_mmap_fixed_anonymous` and `windows_write_watch` pass 2 of 2, and with `main`'s `WindowsMappings.hpp` `guest_memory` fails at `GuestMemory.cpp:2202`. - **PPSA05110** (own dump), memory only, no speed claim. Base: `main` `61fc572cee` + #10614, #10913, #7844, #9181 and a local equivalent of #10887, which the title needs to load and run. Change: the same base plus this change at an earlier review state (the same data structures; later commits moved two steps in `demote` and added the null check and tests). Each run follows the same scripted route (boot, title, New Game, opening) for 330 s on a shared GPU, with no stop. Private bytes are sampled from outside the process. The runs went base, change, change, base. The two runs of each pair rendered at about the same rate: pair 1 at 500-600 presents per 10 s, pair 2 at 40-80. | run | peak private | peak working set | private at 45 / 90 / 150 / 290 s (MiB) | |---|---|---|---| | pair 1, base | 18.12 GiB | 15.70 GiB | 16912 / 18246 / 18432 / 18550 | | pair 1, change | 17.85 GiB | 15.47 GiB | 16569 / 17950 / 18155 / 18276 | | pair 2, change | 18.10 GiB | 15.56 GiB | 16512 / 18232 / 18432 / 18530 | | pair 2, base | 18.38 GiB | 15.84 GiB | 16764 / 18339 / 18712 / 18823 | Within each pair the change saves 274 and 293 MiB of private bytes at 290 s, and 0.27 and 0.28 GiB of peak private bytes. The unit check predicts about 237 MiB for the 13,793 MiB of direct memory the title maps (17.6 MiB per GiB × 13.5 GiB). <details><summary>Summary lines at about 290 s, pair 1 (shared GPU; frame times are not compared)</summary> ``` {"commit":"f4f0c7acec08","dirty":false,"env":{"APS5_DUMP_FRAMES":"4000","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA05110","title":"Persona 5 Royal","content_version":"01.000.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":11380,"ms":10011.192},"interval_start_s":279.811,"interval_end_s":289.822,"presents":550,"frame_ms":{"p50":16.695,"p90":19.855,"p99":30.097,"max":438.329},"gpu_busy_ms_per_present":10.519,"worker_busy_pct":{"queue worker 0x0":97.404},"top_phases_ms_per_frame":{"VideoOut.Flip":17.758,"Driver.Packet":17.675,"VideoOut.Flip.present":8.735,"Driver.Present":8.719,"VideoOut.Flip.vblank_wait":8.328,"Driver.Packet.pipeline_drain":6.881,"Driver.Packet.rendering_wait":5.411,"Driver.Present.render_fence_wait":5.126},"trace_dropped":false,"trace":""} {"commit":"f32f0493e004","dirty":false,"env":{"APS5_DUMP_FRAMES":"4000","APS5_DUMP_FRAMES_EVERY":"30","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA05110","title":"Persona 5 Royal","content_version":"01.000.000","resolution":"3840x2160","window":{"spec":"summary_every 10","first_present":10708,"ms":10010.208},"interval_start_s":283.420,"interval_end_s":293.431,"presents":600,"frame_ms":{"p50":16.682,"p90":16.934,"p99":20.763,"max":25.735},"gpu_busy_ms_per_present":10.884,"worker_busy_pct":{"queue worker 0x0":98.514},"top_phases_ms_per_frame":{"VideoOut.Flip":16.473,"Driver.Packet":16.400,"VideoOut.Flip.vblank_wait":10.993,"Driver.Packet.rendering_wait":7.346,"VideoOut.Flip.present":4.972,"Driver.Packet.pipeline_drain":4.968,"Driver.Present":4.966,"Graphics.Draw":3.315},"trace_dropped":false,"trace":""} ``` </details> **Overlap:** #9505 has merged, and this change is rebased onto it. In #9505's run mapping, a resident run is now demoted through the new index before `slotOf`, because resident pages are no longer in a `SharedPage`'s aliases. #9505's `View` initializers carry the two new fields, and its unmap loop skips the null `page` of a resident view. #9098 (on #9505) still changes the same loops; whichever of #9098 and this PR merges second takes the same resolution. Not tested: Linux and macOS (`WindowsMappings` is Windows-only), and titles other than PPSA05110. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 19:53:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:53:59Z.

Review: DISMISSED


The implementation and the memory-footprint measurements are clearly scoped, and the PR explicitly avoids claiming a speedup. The perf label still needs the artifacts requested by the repository's Performance report form: the body includes two aps5-summary.jsonl lines from the same title and machine, but both have "trace":"", the recorded switches only include APS5_TRACE_SUMMARY_EVERY, and no trace files or tools/trace_digest.py output are attached. Please add paired main and change trace captures from the same scene/machine and include both digests, or get maintainer confirmation that a memory-only change is exempt before treating the performance evidence as complete.

I could not run the reported Windows tests locally. The available MinGW compiler successfully syntax-checked WindowsMappings.hpp after defining the placeholder-allocation constants missing from its older Windows headers; this is compile-only coverage, not a Windows runtime test. Hosted Windows/product tests are skipped by repository policy; the Windows relinker remains pending.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5644959428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11152#pullrequestreview-5644959428). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T19:53:59Z. **Review:** DISMISSED --- The implementation and the memory-footprint measurements are clearly scoped, and the PR explicitly avoids claiming a speedup. The `perf` label still needs the artifacts requested by the repository's Performance report form: the body includes two `aps5-summary.jsonl` lines from the same title and machine, but both have `"trace":""`, the recorded switches only include `APS5_TRACE_SUMMARY_EVERY`, and no trace files or `tools/trace_digest.py` output are attached. Please add paired `main` and change trace captures from the same scene/machine and include both digests, or get maintainer confirmation that a memory-only change is exempt before treating the performance evidence as complete. I could not run the reported Windows tests locally. The available MinGW compiler successfully syntax-checked `WindowsMappings.hpp` after defining the placeholder-allocation constants missing from its older Windows headers; this is compile-only coverage, not a Windows runtime test. Hosted Windows/product tests are skipped by repository policy; the Windows relinker remains pending.
klosixgaming-arch commented 2026-10-25 21:45:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-25T21:45:47Z.

Review: CHANGES_REQUESTED


Reviewed head 65720d76ab by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine.

Requesting changes. I think there is a null dereference in a path this PR makes reachable, and the PR is not mergeable as it stands.

What it does. Resident runs (large private mappings that stand in for section views) no longer get a SharedPage and a Physical slot per 16 KiB page up front. Resident views are created with page == nullptr, a residentIndex finds the run for a (section, offset), and the per-page state is created lazily in demote. The memory numbers (a 1 GiB mapping staying under 16 MiB of bookkeeping) are a real improvement, and the PR is careful to say it does not claim a speed-up.

The concern. After this change, every resident View has a null page. I applied the PR's WindowsMappings.hpp hunks to the current file and then searched for remaining dereferences. The PR guards invalidate, Pin, Unpin, Collect and the unmap path, but armResident is not touched:

if (!it->second.resident || ... || it->second.page->pins != 0) return false;

That loop only continues past the first test when the view is resident, so it evaluates page->pins on exactly the views whose page is now null. armResident is called from the collect path for a run of at least 0x40000 bytes (run.end - start >= 0x40000). The PR uses view.pins for residents in Pin/Unpin, so the intended replacement is clearly it->second.pins. If I am wrong, tell me where page is set for resident views; if I am right, the new tests (which use Bytes-sized runs) may simply not reach a run that large.

Other points:

  1. Merge state is DIRTY. The thread agrees the order is #9505, then #9098, then this PR rebasing. Until then this cannot be validated against the final shape of the file, which also touches WindowsWriteWatch.cpp.
  2. demote allocates before it mutates. The created vector (a SharedPage and a Physical per page) is built, and physical.insert_or_assign is called, before the VirtualProtect that can fail(). If that throws, physical has entries for a run that is still resident. Insert into physical only after the protection and mapping steps succeed.
  3. For a 1 GiB run demote now creates 65,536 pairs of shared_ptr allocations in one go. That is the cost moved from "always" to "on demote", which is the right trade, but the spike is worth one line.
  4. The perf label still needs the artifacts MarcZX10 asked for.

The idea is sound. Please fix armResident, add a test with a resident run of at least 0x40000 bytes that goes through Collect with Armed or All, and rebase.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645479849 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11152#pullrequestreview-5645479849). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-25T21:45:47Z. **Review:** CHANGES_REQUESTED --- Reviewed head `65720d76ab` by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine. **Requesting changes. I think there is a null dereference in a path this PR makes reachable, and the PR is not mergeable as it stands.** **What it does.** Resident runs (large private mappings that stand in for section views) no longer get a `SharedPage` and a `Physical` slot per 16 KiB page up front. Resident views are created with `page == nullptr`, a `residentIndex` finds the run for a (section, offset), and the per-page state is created lazily in `demote`. The memory numbers (a 1 GiB mapping staying under 16 MiB of bookkeeping) are a real improvement, and the PR is careful to say it does not claim a speed-up. **The concern.** After this change, every resident `View` has a null `page`. I applied the PR's `WindowsMappings.hpp` hunks to the current file and then searched for remaining dereferences. The PR guards `invalidate`, `Pin`, `Unpin`, `Collect` and the unmap path, but `armResident` is not touched: `if (!it->second.resident || ... || it->second.page->pins != 0) return false;` That loop only continues past the first test when the view *is* resident, so it evaluates `page->pins` on exactly the views whose `page` is now null. `armResident` is called from the collect path for a run of at least 0x40000 bytes (`run.end - start >= 0x40000`). The PR uses `view.pins` for residents in `Pin`/`Unpin`, so the intended replacement is clearly `it->second.pins`. If I am wrong, tell me where `page` is set for resident views; if I am right, the new tests (which use `Bytes`-sized runs) may simply not reach a run that large. **Other points:** 1. **Merge state is DIRTY.** The thread agrees the order is #9505, then #9098, then this PR rebasing. Until then this cannot be validated against the final shape of the file, which also touches `WindowsWriteWatch.cpp`. 2. **`demote` allocates before it mutates.** The `created` vector (a `SharedPage` and a `Physical` per page) is built, and `physical.insert_or_assign` is called, before the `VirtualProtect` that can `fail()`. If that throws, `physical` has entries for a run that is still resident. Insert into `physical` only after the protection and mapping steps succeed. 3. For a 1 GiB run `demote` now creates 65,536 pairs of `shared_ptr` allocations in one go. That is the cost moved from "always" to "on demote", which is the right trade, but the spike is worth one line. 4. The `perf` label still needs the artifacts MarcZX10 asked for. The idea is sound. Please fix `armResident`, add a test with a resident run of at least 0x40000 bytes that goes through `Collect` with `Armed` or `All`, and rebase. AI-assisted: yes. Written with AI assistance and reviewed by me.
klosixgaming-arch commented 2026-10-26 07:21:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-26T07:21:20Z.

Review: APPROVED


Re-reviewed head 83c8315d70 by reading the diff and the thread. I did not build or run it.

My main objection was wrong: armResident does not exist on this head or on current main, so there is no null dereference there (I said so in my earlier comment). The other points are addressed in the code: demote stages the new Physical entries and does physical.merge(staged) only after the VirtualFree step, CheckLargeResidentRunCollects now covers a 0x40000-byte resident run, and the allocation spike is in the description. Replacing my request for changes with an approval.

AI-assisted: yes. Written with AI assistance and reviewed by me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5648623983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11152#pullrequestreview-5648623983). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-26T07:21:20Z. **Review:** APPROVED --- Re-reviewed head `83c8315d70` by reading the diff and the thread. I did not build or run it. My main objection was wrong: `armResident` does not exist on this head or on current `main`, so there is no null dereference there (I said so in my earlier comment). The other points are addressed in the code: `demote` stages the new `Physical` entries and does `physical.merge(staged)` only after the `VirtualFree` step, `CheckLargeResidentRunCollects` now covers a 0x40000-byte resident run, and the allocation spike is in the description. Replacing my request for changes with an approval. AI-assisted: yes. Written with AI assistance and reviewed by me.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11152
No description provided.