File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed
Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change 2929# include < jemalloc/jemalloc.h>
3030#endif
3131
32+ #if defined(SPADES_USE_MIMALLOC)
33+ extern " C" {
34+ void mi_collect (bool );
35+ size_t mi_stats_total_mem ();
36+ int mi_reserve_os_memory (size_t size, bool commit, bool allow_large);
37+ void mi_debug_show_arenas ();
38+
39+ };
40+ #endif
41+
3242namespace utils {
3343
3444void limit_memory (size_t limit) {
@@ -54,6 +64,15 @@ void limit_memory(size_t limit) {
5464 } else {
5565 INFO (" Memory limit set to " << GB << " Gb" );
5666 }
67+
68+ #if defined(SPADES_USE_MIMALLOC)
69+ // Reserve half of the limit memory
70+ res = mi_reserve_os_memory (rl.rlim_cur / 2 , false , true );
71+ if (res != 0 ) {
72+ WARN (" Failed to reserve OS memory of " << GB << " Gb, mi_reserve_os_memory() call failed, errno = "
73+ << errno << " (" << strerror (errno) << " ). Watch your memory consumption!" );
74+ }
75+ #endif
5776}
5877
5978size_t get_memory_limit () {
@@ -88,13 +107,6 @@ size_t get_max_rss() {
88107
89108#endif
90109
91- #if defined(SPADES_USE_MIMALLOC)
92- extern " C" {
93- void mi_collect (bool );
94- size_t mi_stats_total_mem ();
95- };
96- #endif
97-
98110size_t get_used_memory () {
99111#if defined(SPADES_USE_JEMALLOC)
100112 // Update statistics cached by mallctl
You can’t perform that action at this time.
0 commit comments