Hi, In <53d02a9c-c26a-4a6a-b62b-603d8a6c3...@python.org> "Re: [Discuss][C++] Switch to mimalloc by default?" on Tue, 11 Jun 2024 10:45:12 +0200, Antoine Pitrou <anto...@python.org> wrote:
>> mimalloc doesn't override malloc()/free() as long as we >> don't include mimalloc-override.h: >> https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-override.h > > I see malloc() defined by libmimalloc.so.2 here (Ubuntu 22.04): I think that it's not used because malloc() in libc.so is used. But I was wrong... a.c: ---- #include <stdlib.h> int main(void) { free(malloc(2 * 1024L * 1024L * 1024L)); return 0; } ---- malloc() of mimalloc is used: ---- $ gcc -o a a.c -lmimalloc && MIMALLOC_SHOW_STATS=1 ./a heap stats: peak total freed current unit count reserved: 2.0 GiB 4.0 GiB 4.0 GiB 0 ok committed: 2.0 GiB 4.0 GiB 4.0 GiB 0 ok reset: 0 purged: 0 touched: 64.2 KiB 64.2 KiB 2.0 GiB -2.0 GiB ok segments: 1 1 1 0 ok -abandoned: 0 0 0 0 ok -cached: 0 0 0 0 ok pages: 0 0 1 -1 ok -abandoned: 0 0 0 0 ok -extended: 0 -noretire: 0 arenas: 0 -crossover: 0 -rollback: 0 mmaps: 0 commits: 0 resets: 0 purges: 0 threads: 0 0 0 0 ok searches: 0.0 avg numa nodes: 1 elapsed: 0.001 s process: user: 0.000 s, system: 0.001 s, faults: 0, rss: 18.2 MiB, commit: 2.0 GiB ---- If we link to libc.so explicitly, malloc() of mimalloc is not used: ---- $ gcc -o a a.c -lc -lmimalloc && MIMALLOC_SHOW_STATS=1 ./a ---- It seems that we need to disable MI_OVERRIDE explicitly to not define malloc() in libmimalloc.so: https://github.com/microsoft/mimalloc/blob/03020fbf81541651e24289d2f7033a772a50f480/CMakeLists.txt#L10 But we can't use LD_PRELOAD with the option. So system mimalloc will not disable MI_OVERRIDE. Can we use "-lc -lmimalloc" for system mimalloc? Or should we keep using bundled mimalloc? Thanks, -- kou