xmem: lazily reserve below-40 startup blocks and reclaim empty slabs #2762
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2770"
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 R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T07:26:04Z.
Extends the opt-in lazy commit and physical-page slab paths so large
< 2^40startup pools stay reserved until touched and freed physical-page slabs return system commit to the OS. Refs #1199.What changed
src/xmem_mapped_pages.cpp(commit_startup_block): removes&& !below_40fromlazyand assignsblock = keep_startup_block_below_40(...)instead of returning early, so0x283blocks>= 32 MiBwhen bothX2W_XMEM_LAZY_STARTUP=1andX2W_XMEM_STARTUP_BELOW_40=1are set are placed below2^40asMEM_RESERVEand registered inlazy_blocks(committing 256 KiB chunks on first touch /x2w_xmem_commit_range, while preserving the< 2^40validation and exhaustion refusal). Runs withoutX2W_XMEM_LAZY_STARTUP=1are unchanged.src/xmem_slab_slots.h&src/xmem_mapped_pages.cpp(slab reclamation): tracksslab_used_,open_slabs_, andtotal_used_inSlabSlots<Handle>and adds explicitreclaim_empty_slabs(Close&&)(keepingrelease()non-closing on its own, preservingfreeing_everything_keeps_the_slabs). Non-trailing empty slabs leaveHandle{}tombstones so active slab indices remain stable; trailing empty slabs are popped cleanly. Infree_pagesandunpin_slot/x2w_xmem_release_section, empty slab sectionHANDLEs are collected undermemory.mutexand closed viaCloseHandleoutsidememory.mutex, returning their committed slab memory to the OS.tools/startup/run.ps1&docs/startup-runtime.md: adds[switch]$LazyMemory(settingX2W_XMEM_LAZY_COMMIT=1,X2W_XMEM_LAZY_STARTUP=1,X2W_XMEM_SHARED_VIEWS=1) and documents the updated below-2^40lazy behavior and slab reclamation.tests/xmem_slab_slots_check.cpp(reclaiming_empty_slabs_closes_handles),tests/xmem_lazy_startup_check.py(combinedbelow_40+lazy_startupreserve-until-touch + 64 MiB slab alloc/map/unmap/free OSCommitTotaldrop, withRUN_SERIAL TRUEinCMakeLists.txt), andtests/xmem_page_stats_check.py(partial slab retention(1, 1, 4095)and full reclamation(0, 0, 0)).Verified (
bcfebe7brebased on currentmain)Fail-first mutants (temporary, reverted on
183185ed):reclaim_empty_slabsincollect_empty_slabs: failsxmem_page_stats(slabs, in use, free = (1, 0, 4096), expected (0, 0, 0)) andxmem_lazy_startup(empty slab was not reclaimed: (1, 0, 4096)).&& !below_40incommit_startup_block: failsxmem_lazy_startup(AssertionError: below40 block was committed up front).NOT established
4096 × 64 KiBslots); a slab closes only when all 4096 slots in that slab are freed and unpinned (a single lingering allocation keeps its slab open).CommitTotalinxmem_lazy_startupis a global host metric; the new CTest case carriesRUN_SERIAL TRUEto isolate it from parallel tests.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:31:52Z.
Review: COMMENTED
Review of
bcfebe7b(comment only).Checked:
xmem_slab_slots.handxmem_mapped_pages.cpp. Per-slab counters, tombstones, popping of trailing empty slabs, andfresh_used_after a pop are consistent. Slab handles are closed outsidememory.mutex.commit_startup_block: the below-40 block now keeps its< 2^40validation and exhaustion refusal, and is registered as lazy only whenX2W_XMEM_LAZY_STARTUP=1. Runs without it are unchanged.xmem_slab_slots_check.cppand the extended Python checks cover tombstones, trailing reclaim and the lazy below-40 path.git diff --check,tests/docs_links_check.py,tests/bidi_controls_check.py: clean. CI on the head is green.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
bcfebe7b4f76d1ef20add417cf06bf2e4fb4aea5:--preset dev):cmake --build --preset dev --target xmem_slab_slots_check xmem_shim -- -j 2):2.20s(configure1.96s)ctest --preset dev -R 'xmem' --parallel 3 --no-tests=error --output-on-failure): 56/59 passed (10.76s:cpu_native_xmem_pool_commit2.44s,xmem_page_stats0.09s,cpu_native_xmem_default_pair3.12s,xmem_startup_below_400.03s,xmem_startup_below_40_mutant_no_limit0.03s,xmem_startup_below_40_deployed_ignores_mutants0.02s,xmem_startup_below_40_mutant_no_limit_no_release0.02s,xmem_startup_below_40_mutant_no_limit_no_check0.03s,xmem_shim_mapped_pages0.25s,startup_indirect_mesh_xmem_arguments_skip_wait_warp0.15s,startup_indirect_mesh_xmem_arguments_warp0.17s,xmem_slab_slots0.04s,startup_mesh_xmem_writer_warp0.05s,xmem_committed_memory0.02s,xmem_shim_exports0.03s,xmem_shim_allocation0.01s,xmem_shim_default_allocation0.01s,cpu_native_xmem_physical_pair1.51s,xmem_shim_tools_memory0.01s,xmem_shim_transfer_memory0.02s,xmem_shim_query0.01s,xmem_shim_working_set0.02s,xmem_shim_working_set_aggregation0.01s,xmem_shim_working_set_warp0.13s,xmem_shim_working_set_hardware0.06s,xmem_commit_protection0.02s,xmem_lazy_startup_off0.08s,xmem_commit_protection_mutate_xva_positive_refused0.01s,xmem_commit_protection_mutate_xva_commit_accepted0.01s,xmem_commit_protection_mutate_xva_readonly_accepted0.01s,xmem_commit_protection_mutate_xva_state_dependent0.01s,xmem_commit_protection_mutate_private_second_va_aliases0.01s,xmem_commit_protection_mutate_private_type_mapped0.01s,xmem_commit_protection_mutate_mapped_decommit_succeeds0.01s,xmem_lazy_imports0.02s,xmem_lazy_handler_failure0.01s,xmem_section_lease_single_page0.02s,xmem_section_lease_warp0.11s,xmem_page_batch_inflight_warp0.04s,xmem_shim_physical_pages0.74s,xmem_section_lease_mesh_warp0.05s,xmem_section_lease_vertex_warp0.05s,xmem_section_lease_hardware0.05s,xmem_page_batch_inflight_hardware0.04s,xmem_section_lease_mesh_hardware0.05s,xmem_section_lease_vertex_hardware0.05s,xmem_page_runs_device_warp0.16s,xmem_page_runs_device_hardware0.14s,startup_indirect_mesh_xmem_arguments_hardware0.03s,startup_indirect_mesh_xmem_arguments_skip_wait_hardware0.03s,startup_mesh_xmem_writer_hardware0.03s,xmem_attribute_scan3.09s,xmem_attribute_scan_cli_check3.34s,xmem_shim_page_runs10.14s,xmem_mapped_pages_commit0.07s,xmem_mapped_pages_commit_failure0.07s,xmem_lazy_commit0.13s,xmem_lazy_commit_off0.10s,xmem_lazy_startup0.12s); skipped (capability, not a pass):startup_indirect_mesh_xmem_arguments_hardware,startup_indirect_mesh_xmem_arguments_skip_wait_hardware,startup_mesh_xmem_writer_hardware/O2(--preset release):cmake --build --preset release --target xmem_slab_slots_check xmem_shim -- -j 2):10.77s(configure1.98s)ctest --preset release -R 'xmem' --parallel 3 --no-tests=error --output-on-failure): 56/59 passed (11.26s:startup_mesh_xmem_writer_warp0.06s,xmem_committed_memory0.01s,xmem_shim_exports0.01s,xmem_shim_allocation0.01s,xmem_shim_default_allocation0.01s,startup_indirect_mesh_xmem_arguments_skip_wait_warp0.12s,xmem_shim_tools_memory0.01s,xmem_shim_transfer_memory0.02s,xmem_shim_query0.01s,startup_indirect_mesh_xmem_arguments_warp0.19s,xmem_shim_working_set_aggregation0.01s,xmem_shim_working_set0.02s,xmem_shim_physical_pages0.15s,xmem_commit_protection0.02s,xmem_slab_slots0.01s,xmem_shim_working_set_warp0.12s,xmem_page_stats0.07s,xmem_commit_protection_mutate_xva_positive_refused0.01s,xmem_commit_protection_mutate_xva_commit_accepted0.01s,xmem_lazy_startup_off0.09s,xmem_shim_working_set_hardware0.21s,xmem_commit_protection_mutate_xva_readonly_accepted0.02s,xmem_commit_protection_mutate_xva_state_dependent0.02s,xmem_commit_protection_mutate_private_second_va_aliases0.02s,xmem_commit_protection_mutate_private_type_mapped0.02s,xmem_commit_protection_mutate_mapped_decommit_succeeds0.02s,xmem_lazy_imports0.02s,xmem_lazy_handler_failure0.02s,xmem_section_lease_single_page0.02s,xmem_section_lease_warp0.11s,xmem_section_lease_vertex_warp0.05s,xmem_section_lease_mesh_warp0.18s,xmem_section_lease_hardware0.06s,xmem_page_batch_inflight_warp0.25s,xmem_page_batch_inflight_hardware0.07s,xmem_section_lease_mesh_hardware0.06s,xmem_startup_below_400.03s,xmem_startup_below_40_deployed_ignores_mutants0.02s,xmem_section_lease_vertex_hardware0.05s,xmem_startup_below_40_mutant_no_limit0.02s,xmem_startup_below_40_mutant_no_limit_no_check0.03s,xmem_startup_below_40_mutant_no_limit_no_release0.03s,startup_indirect_mesh_xmem_arguments_hardware0.02s,startup_indirect_mesh_xmem_arguments_skip_wait_hardware0.02s,startup_mesh_xmem_writer_hardware0.02s,xmem_page_runs_device_hardware0.16s,xmem_page_runs_device_warp0.18s,xmem_shim_mapped_pages0.22s,xmem_attribute_scan3.11s,xmem_attribute_scan_cli_check3.39s,cpu_native_xmem_physical_pair1.19s,cpu_native_xmem_pool_commit1.87s,cpu_native_xmem_default_pair2.29s,xmem_shim_page_runs9.75s,xmem_mapped_pages_commit0.07s,xmem_mapped_pages_commit_failure0.07s,xmem_lazy_commit0.10s,xmem_lazy_commit_off0.09s,xmem_lazy_startup0.10s); skipped (capability, not a pass):startup_indirect_mesh_xmem_arguments_hardware,startup_indirect_mesh_xmem_arguments_skip_wait_hardware,startup_mesh_xmem_writer_hardwareAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T07:26:11Z.
Codex Review Summary: ❌ Failed
This comment shows the latest Codex review activity on this pull request.
We couldn’t complete this review. Comment
@codex reviewto try again.bcfebe7ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T07:26:16Z.
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:31:57Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
bcfebe7b4f76d1ef20add417cf06bf2e4fb4aea5:--preset dev):cmake --build --preset dev --target xmem_slab_slots_check xmem_shim -- -j 2):2.20s(configure1.96s)ctest --preset dev -R 'xmem' --parallel 3 --no-tests=error --output-on-failure): 56/59 passed (10.76s:cpu_native_xmem_pool_commit2.44s,xmem_page_stats0.09s,cpu_native_xmem_default_pair3.12s,xmem_startup_below_400.03s,xmem_startup_below_40_mutant_no_limit0.03s,xmem_startup_below_40_deployed_ignores_mutants0.02s,xmem_startup_below_40_mutant_no_limit_no_rel0.02s,xmem_startup_below_40_mutant_no_limit_no_check0.03s,xmem_shim_mapped_pages0.25s,startup_indirect_mesh_xmem_arguments_skip_wait_warp0.15s,startup_indirect_mesh_xmem_arguments_warp0.17s,xmem_slab_slots0.04s,startup_mesh_xmem_writer_warp0.05s,xmem_committed_memory0.02s,xmem_shim_exports0.03s,xmem_shim_allocation0.01s,xmem_shim_default_allocation0.01s,cpu_native_xmem_physical_pair1.51s,xmem_shim_tools_memory0.01s,xmem_shim_transfer_memory0.02s,xmem_shim_query0.01s,xmem_shim_working_set0.02s,xmem_shim_working_set_aggregation0.01s,xmem_shim_working_set_warp0.13s,xmem_shim_working_set_hardware0.06s,xmem_commit_protection0.02s,xmem_lazy_startup_off0.08s,xmem_commit_protection_mutate_xva_positive_refused0.01s,xmem_commit_protection_mutate_xva_commit_accepted0.01s,xmem_commit_protection_mutate_xva_readonly_accepted0.01s,xmem_commit_protection_mutate_xva_state_dependent0.01s,xmem_commit_protection_mutate_private_second_va_aliases0.01s,xmem_commit_protection_mutate_private_type_mapped0.01s,xmem_commit_protection_mutate_mapped_decommit_succeeds0.01s,xmem_lazy_imports0.02s,xmem_lazy_handler_failure0.01s,xmem_section_lease_single_page0.02s,xmem_section_lease_warp0.11s,xmem_page_batch_inflight_warp0.04s,xmem_shim_physical_pages0.74s,xmem_section_lease_mesh_warp0.05s,xmem_section_lease_vertex_warp0.05s,xmem_section_lease_hardware0.05s,xmem_page_batch_inflight_hardware0.04s,xmem_section_lease_mesh_hardware0.05s,xmem_section_lease_vertex_hardware0.05s,xmem_page_runs_device_warp0.16s,xmem_page_runs_device_hardware0.14s,startup_indirect_mesh_xmem_arguments_hardware0.03s,startup_indirect_mesh_xmem_arguments_skip_wait_hardware0.03s,startup_mesh_xmem_writer_hardware0.03s,xmem_attribute_scan3.09s,xmem_attribute_scan_cli_check3.34s,xmem_shim_page_runs10.14s,xmem_mapped_pages_commit0.07s,xmem_mapped_pages_commit_failure0.07s,xmem_lazy_commit0.13s,xmem_lazy_commit_off0.10s,xmem_lazy_startup0.12s); skipped (capability, not a pass):startup_indirect_mesh_xmem_arguments_hardware,startup_indirect_mesh_xmem_arguments_skip_wait_hardware,startup_mesh_xmem_writer_hardware/O2(--preset release):cmake --build --preset release --target xmem_slab_slots_check xmem_shim -- -j 2):10.77s(configure1.98s)ctest --preset release -R 'xmem' --parallel 3 --no-tests=error --output-on-failure): 56/59 passed (11.26s:startup_mesh_xmem_writer_warp0.06s,xmem_committed_memory0.01s,xmem_shim_exports0.01s,xmem_shim_allocation0.01s,xmem_shim_default_allocation0.01s,startup_indirect_mesh_xmem_arguments_skip_wait_warp0.12s,xmem_shim_tools_memory0.01s,xmem_shim_transfer_memory0.02s,xmem_shim_query0.01s,startup_indirect_mesh_xmem_arguments_warp0.19s,xmem_shim_working_set_aggregation0.01s,xmem_shim_working_set0.02s,xmem_shim_physical_pages0.15s,xmem_commit_protection0.02s,xmem_slab_slots0.01s,xmem_shim_working_set_warp0.12s,xmem_page_stats0.07s,xmem_commit_protection_mutate_xva_positive_refused0.01s,xmem_commit_protection_mutate_xva_commit_accepted0.01s,xmem_lazy_startup_off0.09s,xmem_shim_working_set_hardware0.21s,xmem_commit_protection_mutate_xva_readonly_accepted0.02s,xmem_commit_protection_mutate_xva_state_dependent0.02s,xmem_commit_protection_mutate_private_second_va_aliases0.02s,xmem_commit_protection_mutate_private_type_mapped0.02s,xmem_commit_protection_mutate_mapped_decommit_succeeds0.02s,xmem_lazy_imports0.02s,xmem_lazy_handler_failure0.02s,xmem_section_lease_single_page0.02s,xmem_section_lease_warp0.11s,xmem_section_lease_vertex_warp0.05s,xmem_section_lease_mesh_warp0.18s,xmem_section_lease_hardware0.06s,xmem_page_batch_inflight_warp0.25s,xmem_page_batch_inflight_hardware0.07s,xmem_section_lease_mesh_hardware0.06s,xmem_startup_below_400.03s,xmem_startup_below_40_deployed_ignores_mutants0.02s,xmem_section_lease_vertex_hardware0.05s,xmem_startup_below_40_mutant_no_limit0.02s,xmem_startup_below_40_mutant_no_limit_no_check0.03s,xmem_startup_below_40_mutant_no_limit_no_rel0.03s,startup_indirect_mesh_xmem_arguments_hardware0.02s,startup_indirect_mesh_xmem_arguments_skip_wait_hardware0.02s,startup_mesh_xmem_writer_hardware0.02s,xmem_page_runs_device_hardware0.16s,xmem_page_runs_device_warp0.18s,xmem_shim_mapped_pages0.22s,xmem_attribute_scan3.11s,xmem_attribute_scan_cli_check3.39s,cpu_native_xmem_physical_pair1.19s,cpu_native_xmem_pool_commit1.87s,cpu_native_xmem_default_pair2.29s,xmem_shim_page_runs9.75s,xmem_mapped_pages_commit0.07s,xmem_mapped_pages_commit_failure0.07s,xmem_lazy_commit0.10s,xmem_lazy_commit_off0.09s,xmem_lazy_startup0.10s); skipped (capability, not a pass):startup_indirect_mesh_xmem_arguments_hardware,startup_indirect_mesh_xmem_arguments_skip_wait_hardware,startup_mesh_xmem_writer_hardwareAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:35:04Z.
Independent Windows Release receipt on
bcfebe7b. The source-built below-40 block remained reserved before touch. Reclaiming the synthetic slab returned 64 MiB of system commit in this serial run. The 13 adjacent mapping and lease checks all passed. I also ran the three hardware cases the Win2025 receipt skipped: startup_indirect_mesh_xmem_arguments_hardware, startup_indirect_mesh_xmem_arguments_skip_wait_hardware, and startup_mesh_xmem_writer_hardware. All passed on RTX 4060 Laptop 32.0.16.1656, Windows 11 build 26200, debug layer enabled and no warnings or errors. This fills the physical-adapter coverage in the existing review. The matched original-executable replay for #1199 is still open.