Skip to content

Question about releasing memory #383

Open
@elgatito

Description

@elgatito

Hello,

I'm trying to use mimalloc with my binary. And have questions about memory release to OS.
I have a memory storage, it allocates 300MB of memory.
Then I destroy it.
And expect to return memory back to OS, but instead I see memory is not returned.
Then I init another storage and memory grows by another 300MB.

Compiling mimalloc:

cmake -B cmake-build-dir/release -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17

Compiling my binary with:

/usr/x86_64-linux-musl-cross/lib/mimalloc-1.7/libmimalloc.a

Added to main.cxx:

#include <mimalloc.h>
#include <mimalloc-override.h>

Compiling everything with Release build type.

What I see in process stats:

Started:
elgato    2429  2.0  0.1 272984  8808 pts/3    Sl+  17:57   0:00 build/linux_x64/lt2http

Storage init:
elgato    2429  1.4  4.0 797568 322636 pts/3   Sl+  17:57   0:00 build/linux_x64/lt2http

Storage destroyed:
elgato    2429  1.0  4.0 797712 322900 pts/3   Sl+  17:57   0:00 build/linux_x64/lt2http

Storage re-init:
elgato    2429  1.0  4.7 797712 381244 pts/3   Sl+  17:57   0:00 build/linux_x64/lt2http

Storage re-destroyed:
elgato    2429  0.8  4.7 797712 381244 pts/3   Sl+  17:57   0:01 build/linux_x64/lt2http

Stats after closing:

heap stats:     peak      total      freed    current       unit      count  
  reserved:   768.0 mb   768.0 mb   512.0 mb   256.0 mb       1 b              not all freed!
 committed:   745.9 mb   745.9 mb   512.0 mb   233.9 mb       1 b              not all freed!
     reset:     4.2 mb     5.4 mb     1.1 mb     4.2 mb       1 b              not all freed!
   touched:       0 b        0 b    606.3 mb  -606.3 mb       1 b              ok
  segments:      16        318        314          4                           not all freed!
-abandoned:       5          5          5          0                           ok
   -cached:       0          0          0          0                           ok
     pages:     300        353        325         28                           not all freed!
-abandoned:      30         30         30          0                           ok
 -extended:       0   
 -noretire:       0   
     mmaps:       0   
   commits:     198   
   threads:       7          7         12         -5                           ok
  searches:     0.0 avg
numa nodes:       1
   elapsed:     144.618 s
   process: user: 0.610 s, system: 0.552 s, faults: 0, rss: 372.6 mb, commit: 745.9 mb

I understand that mimalloc is probably keeping memory for re-use in future.
But is there any configuration, that can be changed to force memory release?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions