Immediately release memory to OS with jemalloc

62 Views Asked by At

I'm implementing a memory monitor which observes current memory used by my application / docker container by observing cgroups' memory.current.

Now when my application exceeds a high memory setting I want it to go into memory saving mode, pause some processes, attempt to release as much memory immediately back to the OS and then unpause those internal processes.

When initially starting the app with jemalloc's default memory strategy, will the calls shown below immediately release previously allocated and freed memory back to the OS? Or will this affect only newly allocated and afterwards freed memory?

Is there a better strategy to force release as much memory at once and go back to the default performance mode afterwards?

    void force_memory_reclaim() {
    // Set decay time for dirty pages to 0
    ssize_t decay_time = 0; // Immediate decay
    mallctl("arena.0.dirty_decay_ms", NULL, NULL, &decay_time, sizeof(decay_time));
    mallctl("arena.0.muzzy_decay_ms", NULL, NULL, &decay_time, sizeof(decay_time));
}
0

There are 0 best solutions below