Created
November 12, 2021 03:16
-
-
Save ddwolf/4f78ffc740e6b555a1bf24f30ed9cca3 to your computer and use it in GitHub Desktop.
using jemalloc 5.2.1 and memory seems not being released to the operation system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// COMPILE: g++ a.cpp -g -Wall -std=c++11 -I./jemalloc/include/ -ljemalloc -L./jemalloc/lib/ | |
// jemalloc version: 5.2.1 | |
// TEST: | |
// $ export MALLOC_CONF="prof:true,prof_active:true,prof_prefix:jeprof.out,stats_print:true,muzzy_decay_ms:3000,dirty_decay_ms:3000" | |
// $ cat > test.sh << EOF | |
// > a.out & | |
// > top -p $! | grep $USER | |
// EOF | |
// $ sh test.sh | |
/** | |
* this programe can allocate 62 gigabytes virtual memory at most, and after it reached its peak, it never falls, even after I had | |
* released all the allocated memory, the amount of virtual memory keeps not changed. | |
*/ | |
#include <iostream> | |
#include <memory> | |
#include <map> | |
#include <unistd.h> | |
using namespace std; | |
constexpr int SIZE = 1024 * 50; | |
int i = 0; | |
int main() | |
{ | |
{ | |
std::map<int, std::unique_ptr<char[]>> map1; | |
int i = 0; | |
cout << "before allocate" << endl; | |
while (i < SIZE) { | |
map1.emplace_hint(map1.end(), i, new char[rand() % (2 * 1024 * 1024) + 1]()); | |
++i; | |
} | |
cout << "All allocated" << endl; | |
while (i >= 0) { | |
map1.erase(i); | |
--i; | |
} | |
cout << "All freed" << endl; | |
while (i < SIZE) { | |
map1.emplace_hint(map1.end(), i, new char[rand() % (2 * 1024 * 1024) + 1]()); | |
++i; | |
} | |
cout << "All reallocated" << endl; | |
} | |
cout << "map deallocated" << endl; | |
sleep(30); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment