mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

Different output when overriding from `static.c` vs. `mimalloc.o` from cmake

Open jberryman opened this issue 2 years ago • 2 comments

compiling with:

  • gcc -c -DMI_MALLOC_OVERRIDE -Iinclude -o mimalloc.o src/static.c (is that right? it's not documented well)
  • vs. the mimalloc.o produced from cmake, I get different results from MIMALLOC_SHOW_STATS=1.

I get different stats results for the same source:

e.g. for the latter I get the line:

    touched:   128.5 KiB   192.7 KiB   212.1 MiB  -211.9 MiB                          ok

and for the former:

   touched:   192.1 MiB   212.1 MiB   212.1 MiB    69.2 KiB                          not all freed

for the same mimalloc version the numbers are otherwise consistent across runs and recompilations

jberryman avatar Jun 27 '23 19:06 jberryman

My goal is to validate that I'm compiling and overriding malloc correctly

jberryman avatar Jun 27 '23 19:06 jberryman

Okay it's also clear I don't know how to build static.c

What I find is that if I link against the mimalloc.o built using the cmake process, things seem to work as expected (I both see mimalloc stats at the end, but also i see a dramatic improvement to memory usage, and obvious effects of the more eager memory decommit behavior).

I've tried compiling static.c in several different ways, and linking it as above, but it hasn't been successful: I do always see output from mimalloc at the end, and it seems to be using the library, But the memory behavior of my program still looks like what I observed with glibc (high memory usage, RSS never shrinks after a pause as it does with mimalloc)

I’ve tried compiling static.c with flags it seems cmake configures for me:

-DMI_MALLOC_OVERRIDE
-DMI_STATIC_LIB
-O3 -DNDEBUG -fPIC   -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden -Wstrict-prototypes -ftls-model=initial-exec -fno-builtin-malloc -std=gnu11

…in various combinations, but no luck

I'm hoping to be able to avoid cmake because integration with my project will be much much simpler.

jberryman avatar Jun 29 '23 15:06 jberryman