Skip to content

Commit 4d72d24

Browse files
committed
mimalloc: remove alignment size workaround (#20645)
1 parent 8453098 commit 4d72d24

File tree

1 file changed

+3
-19
lines changed
  • system/lib/mimalloc/src/prim/emscripten

1 file changed

+3
-19
lines changed

system/lib/mimalloc/src/prim/emscripten/prim.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,14 @@ extern void* emmalloc_memalign(size_t, size_t);
7272

7373
// Note: the `try_alignment` is just a hint and the returned pointer is not guaranteed to be aligned.
7474
int _mi_prim_alloc(size_t size, size_t try_alignment, bool commit, bool allow_large, bool* is_large, bool* is_zero, void** addr) {
75-
MI_UNUSED(try_alignment); MI_UNUSED(allow_large); MI_UNUSED(commit);
75+
MI_UNUSED(allow_large); MI_UNUSED(commit);
7676
*is_large = false;
7777
// TODO: Track the highest address ever seen; first uses of it are zeroes.
7878
// That assumes no one else uses sbrk but us (they could go up,
7979
// scribble, and then down), but we could assert on that perhaps.
8080
*is_zero = false;
81-
// emmalloc has some limitations on alignment size.
82-
// TODO: Why does mimalloc ask for an align of 4MB? that ends up allocating
83-
// 8, which wastes quite a lot for us in wasm. If that is unavoidable,
84-
// we may want to improve emmalloc to support such alignment. See also
85-
// https://github.com/emscripten-core/emscripten/issues/20645
86-
#define MIN_EMMALLOC_ALIGN 8
87-
#define MAX_EMMALLOC_ALIGN (1024*1024)
88-
if (try_alignment < MIN_EMMALLOC_ALIGN) {
89-
try_alignment = MIN_EMMALLOC_ALIGN;
90-
} else if (try_alignment > MAX_EMMALLOC_ALIGN) {
91-
try_alignment = MAX_EMMALLOC_ALIGN;
92-
}
93-
void* p = emmalloc_memalign(try_alignment, size);
94-
*addr = p;
95-
if (p == 0) {
96-
return ENOMEM;
97-
}
98-
return 0;
81+
*addr = emmalloc_memalign(try_alignment, size);
82+
return (*addr != NULL ? 0 : ENOMEM);
9983
}
10084

10185

0 commit comments

Comments
 (0)