Commit only payload pages for ERA heap alignments above a page #181
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/182"
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 Vonsek on 2026-11-21T18:07:07Z.
Change
era_heap::allocatepassed every alignment exponent (bits 24–28, up to 31) to_aligned_malloc. The CRT over-allocates by the alignment and commits that padding as heap memory, so a 257-byte request with exponent 31 committed more than 2 GiB, and exponent 20 committed 1 MiB.src/era_heap.cpp: alignments above the page size get their own reservation. The allocator reservespayload + alignmentaddress space, releases it, and reserves and commits only the page-rounded payload at the aligned address inside it, retrying up to eight times if another thread takes the range.VirtualAllocmemory is already zero, so nomemsettouches it. Alignments up to one page keep the_aligned_mallocpath unchanged.releasefrees a block withVirtualFree(MEM_RELEASE)when it is aligned to the allocation granularity andVirtualQueryreports it as theAllocationBase. A CRT block cannot pass this test:_aligned_mallocstores its base pointer below the returned address, so the block never starts its own allocation. Other pointers go to_aligned_freeas before.tests/era_heap_check.cpp,CMakeLists.txt: newera_heap_large_alignmentscenario. Exponents 13, 16, 17, 20 and 31 with payloads of 1, 257, one page, one page + 1 and three pages − 1 bytes. Each block must be aligned and zeroed.VirtualQuerymust reportAllocationBase == BaseAddress == block,MEM_COMMIT,PAGE_READWRITE,MEM_PRIVATEandRegionSizeequal to the page-rounded payload. After release the address must beMEM_FREE.docs/experiments.md: notes the deviation from SlimEra'sXMemAllocDefault, which uses_aligned_mallocfor all heap requests, and adds the test row.tools/pe_inventory.py: linksXMemAlloc/XMemFreeto the new test.Attribute decoding is unchanged. The accepted attribute set, the 16-byte minimum alignment and the failure policy are the same as before.
Verification
src/era_heap.cppandtests/era_heap_check.cppcompiled with clang++ 18 (-std=c++20 -Wall -Wextra, no warnings) against awindows.h/malloc.hstand-in mappingVirtualAlloc/VirtualFree/VirtualQueryontommap(4 KiB pages, 64 KiB granularity) and_aligned_mallocontoposix_memalign.exponent=13 bytes=1 base_matches=0 state=1000.large_alignment_cases=25 committed_bytes=163840 alignment_bytes=10743685120, PASS.allocation,failure,concurrency,caller_layoutandreusepass both before and after.ctest --preset dev --no-tests=error -R 'era_heap|desktop_memory_query' -Vat3928f00(rebased on main1485f17, with the memory-type handling from #134 and the xmem shim; earlier runs at 7d0a713 and 9a09357 gave the same output) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100: passed in Debug (thedevpreset) and in Release (cmake --preset dev -B out/build/rel -DCMAKE_BUILD_TYPE=Release, thenctest --test-dir out/build/rel). Both configurations printlarge_alignment_cases=25 committed_bytes=163840 alignment_bytes=10743685120andreuse_cases=9 recycled_address=9. The full Debugctest --preset dev --no-tests=errorpassed 120/120, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.Evidence and follow-up
+alignmentprobe reservation is released before the aligned commit.VirtualAlloc2withMEM_ADDRESS_REQUIREMENTSwould avoid the retry, but it requiresonecore.lib.VirtualAllocpath, andrelease_with_attributesroutes heap blocks throughrelease.era_heap_observed_wordspasses unchanged.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T18:16:29Z.
GitHub reports a conflict on
7d0a713c. Please reconcile the high-alignment path with the current ERA heap attribute decoder. Retain the Bink-sized heap and graphics allocation cases alongside the new payload commit test before marking ready.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:22:28Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
3928f00ℹ️ 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.