Skip to content

Update mimalloc to 3.6.1 - #28121

Merged
sbc100 merged 9 commits into
emscripten-core:mainfrom
kleisauke:mimalloc-update-3.6.1
Oct 31, 2026
Merged

sbc100 merged 9 commits into
emscripten-core:mainfrom
kleisauke:mimalloc-update-3.6.1

Conversation

@kleisauke

Copy link
Copy Markdown
Collaborator

No description provided.

@kleisauke

Copy link
Copy Markdown
Collaborator Author

A trivial patch update. All existing patches are reapplied as-is (see e.g. commit 724728a were these patches were removed and commit affa429 were they were reapplied). However, some of these changes have since been upstreamed (or backported):

I also had to revert the mi_prim_heap_has_room() logic introduced in commit microsoft/mimalloc@0fec3da, as we should forward users to build with -sABORTING_MALLOC=0 instead (which is already done in the test_wrap_malloc_mimalloc test and when building with -sALLOW_MEMORY_GROWTH). As possible follow-up, we could make -sABORTING_MALLOC=0 the default when building with -sMALLOC=mimalloc.

Note that upstream now always uses a 2-level page map (see commit microsoft/mimalloc@cbd6dce), which seems to work OK with our default INITIAL_HEAP of 16 MiB. So, perhaps my analysis in #27982 (comment) was incorrect after all.

Tested with:

$ ./test/runner {core2,wasmfs,wasm64_4gb}.test_wrap_malloc_mimalloc other.test_malloc_size_mimalloc* other.test_malloc_multithreading_mimalloc* other.test_mimalloc_options
Running 8 tests
Using 8 parallel test processes
[8/8] test_malloc_size_mimalloc_O2 (test_other.other.test_malloc_size_mimalloc_O2) ... ok

----------------------------------------------------------------------
Ran 8 tests in 1.142s

OK
Total core time: 3.706s. Wallclock time: 1.142s. Parallelization: 3.25x.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates mimalloc to version 3.6.1, introducing several key architectural, security, and compatibility enhancements. Notably, it consolidates almost all static and global variables into a single, guarded mi_process_t structure (_mi_process) to protect allocator metadata. It also transitions to always using a 2-level page map for simplicity and security, adds support for C23 free_sized and free_aligned_sized overrides, and introduces experimental support for CHERI platforms. Additionally, it improves fork support (particularly on macOS), optimizes the STL allocator trait, and enhances WebAssembly/Emscripten/WASI compatibility. There are no review comments to address, and I have no further feedback to provide.

@sbc100 sbc100 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like system/lib/mimalloc/README.emscripten is missing from this change?

Otherwise lgtm

@kleisauke

Copy link
Copy Markdown
Collaborator Author

Looks like system/lib/mimalloc/README.emscripten is missing from this change?

Ah, my bad. Forgot to update that file, fixed with commit 1b8015b.

@sbc100
sbc100 enabled auto-merge (squash) October 31, 2026 17:58
@sbc100
sbc100 merged commit 51ed955 into emscripten-core:main Oct 31, 2026
42 checks passed
@kleisauke
kleisauke deleted the mimalloc-update-3.6.1 branch October 31, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants