Conversation
This reverts commit a4e07d4. In preparation for the next commit.
Resolves: emscripten-core#23090.
|
|
||
| This contains mimalloc 8c532c32c3c96e5ba1f2283e032f69ead8add00f (v2.1.7) with | ||
| This contains mimalloc 0ddf397796fbefa35b3278bd4431c2913a9892eb (v3.3.0) with | ||
| Emscripten-specific changes. |
There was a problem hiding this comment.
Are we tracking these emscripten-specific changes?
Was it easy enough for you to port them to the new version?
There was a problem hiding this comment.
Emscripten-specific changes are tracked in commit 8f4d480, which was created via:
- Replace
system/lib/mimalloc/with original mimalloc v2.1.7. - Commit those changes.
- Upgrade to mimalloc v3.3.0.
- Revert the changes from step 2.
There was a problem hiding this comment.
Nice. I wonder if its worth forking mimalloc in the emscripten-core org like we do for llvm and musl in order to keep track of these changes.
Perhaps not worth it as the changes are so small and we have the option to upstream most of them (I think?)
There was a problem hiding this comment.
It's probably not worth creating a fork for these small changes. The changes to src/prim/emscripten/prim.c could likely be upstreamed, but I'm less certain about those in src/alloc-override.c (although commit microsoft/mimalloc@a9b895e introduced a similar Emscripten-specific change to that file). I attempted to revert those weak decls with commit a4e07d4 but it was needed for test_wrap_malloc_mimalloc.
Commit 9e64b24 may also qualify as an Emscripten-specific change, but I'm not sure whether it should be documented (I've opened PR microsoft/mimalloc#1264 for this).
| @@ -8654,8 +8654,7 @@ def test_mallinfo(self): | |||
| @parameterized({ | |||
| '': ([],), | |||
| 'emmalloc': (['-sMALLOC=emmalloc'],), | |||
| # FIXME(https://github.com/emscripten-core/emscripten/issues/23090) | |||
| # 'mimalloc': (['-sMALLOC=mimalloc'],), | |||
| 'mimalloc': (['-sMALLOC=mimalloc', '-sABORTING_MALLOC=0'],), | |||
There was a problem hiding this comment.
Why is ABORTING_MALLOC=0 needed here bit not for the other variants of this test?
There was a problem hiding this comment.
It was somehow necessary for wasm64_4gb.test_wrap_malloc_mimalloc. mimalloc was likely over-allocating internally, and this change prevented an abort().
There was a problem hiding this comment.
Maybe worth a TODO to investigate?
| # https://github.com/emscripten-core/emscripten/issues/20645#issuecomment-1962964755 | ||
| '-DMI_ARENA_SLICE_SHIFT=(12 + MI_SIZE_SHIFT)', | ||
| # `malloc`ed pointers must be aligned at least as strictly as max_align_t | ||
| '-DMI_MAX_ALIGN_SIZE=8', |
There was a problem hiding this comment.
Is this somehow not the default?
There was a problem hiding this comment.
It's not the default. See:
emscripten/system/lib/mimalloc/include/mimalloc/types.h
Lines 35 to 39 in 094d31e
There was a problem hiding this comment.
I synced this with:
emscripten/system/lib/emmalloc.c
Lines 74 to 77 in 094d31e
There was a problem hiding this comment.
Can we patch emscripten/system/lib/mimalloc/include/mimalloc/types.h to use alignof(max_align_t) directly maybe? Do you know why it doesn't already? Maybe because its C11?
But we could use the __alignof GCC/clang builtin when available?
How about:
#ifndef MI_MAX_ALIGN_SIZE
#ifdef __GNUC__
#define MI_MAX_ALIGN_SIZE __alignof__(max_align_t)
#else
#define MI_MAX_ALIGN_SIZE 16 // sizeof(max_align_t)
#endif
#endif
?
There was a problem hiding this comment.
MI_MAX_ALIGN_SIZE is also used in pre-processor checks, which prevents the use of function-like macros (such as _Alignof(), __alignof__() or alignof()), see:
emscripten/system/lib/mimalloc/src/page-queue.c
Lines 24 to 32 in 094d31e
| '-DMI_MAX_ALIGN_SIZE=8', | ||
| # reserve memory in 64 MiB chunks (internally divided by 4) | ||
| # Note: keep in sync with the -sINITIAL_HEAP default | ||
| '-DMI_DEFAULT_ARENA_RESERVE=65536', |
There was a problem hiding this comment.
It's in KiB.
emscripten/system/lib/mimalloc/src/options.c
Line 148 in 094d31e
The / 4 happens here:
emscripten/system/lib/mimalloc/src/arena.c
Lines 319 to 321 in 094d31e
| # build mimalloc with an override of malloc/free | ||
| '-DMI_MALLOC_OVERRIDE', | ||
| # TODO: add build modes that include debug checks 1,2,3 | ||
| '-DMI_DEBUG=0', | ||
| # disable `assert()` in the underlying emmalloc allocator | ||
| '-DNDEBUG', | ||
| # avoid use of `__builtin_thread_pointer()` | ||
| '-DMI_LIBC_MUSL', | ||
| # enable use of `__builtin_thread_pointer()` |
There was a problem hiding this comment.
Why did this change from avoid => enable? Is it somehow OK to use now?
There was a problem hiding this comment.
It can be enabled after commit llvm/llvm-project@ea58410.
| # build mimalloc with an override of malloc/free | ||
| '-DMI_MALLOC_OVERRIDE', | ||
| # TODO: add build modes that include debug checks 1,2,3 | ||
| '-DMI_DEBUG=0', | ||
| # disable `assert()` in the underlying emmalloc allocator | ||
| '-DNDEBUG', | ||
| # avoid use of `__builtin_thread_pointer()` | ||
| '-DMI_LIBC_MUSL', |
There was a problem hiding this comment.
We are using musl so wouldn't we want to continue to define this?
There was a problem hiding this comment.
The MI_LIBC_MUSL definition is only used by:
emscripten/system/lib/mimalloc/include/mimalloc/prim.h
Lines 252 to 265 in 094d31e
Looking at commit microsoft/mimalloc@e46c114 and the linked issue, I don't think it applies to Emscripten.
|
Thanks for working on this! Lgtm but let's wait for @kripken to chime in |
Resolves: #23090.
Supersedes: #23037.
Supersedes: #24542.