[Bf-blender-cvs] [d2da3af073a] master: Fix T54287: memory not freed after rendering on Linux.

Brecht Van Lommel noreply at git.blender.org
Wed Oct 3 12:11:50 CEST 2018


Commit: d2da3af073a63b6ae25119ebbd2e0d3c9a1b6823
Author: Brecht Van Lommel
Date:   Wed Oct 3 11:10:08 2018 +0200
Branches: master
https://developer.blender.org/rBd2da3af073a63b6ae25119ebbd2e0d3c9a1b6823

Fix T54287: memory not freed after rendering on Linux.

With new jemalloc versions memory allocated by threads that then become
inactive is not longer automatically freed. Instead we have to enable a
background thread to do it.

Some testing is needed to find out of this is sufficient, because the
background thread only runs periodically.

===================================================================

M	build_files/cmake/Modules/FindJeMalloc.cmake
M	intern/guardedalloc/CMakeLists.txt
M	intern/guardedalloc/intern/mallocn.c

===================================================================

diff --git a/build_files/cmake/Modules/FindJeMalloc.cmake b/build_files/cmake/Modules/FindJeMalloc.cmake
index 506892b34ba..0abe103cd2e 100644
--- a/build_files/cmake/Modules/FindJeMalloc.cmake
+++ b/build_files/cmake/Modules/FindJeMalloc.cmake
@@ -53,6 +53,15 @@ FIND_LIBRARY(JEMALLOC_LIBRARY
     lib64 lib
   )
 
+if(JEMALLOC_INCLUDE_DIR)
+  SET(_version_regex "^#define[ \t]+JEMALLOC_VERSION[ \t]+\"([^\"]+)\".*")
+  file(STRINGS "${JEMALLOC_INCLUDE_DIR}/jemalloc.h"
+    JEMALLOC_VERSION REGEX "${_version_regex}")
+  string(REGEX REPLACE "${_version_regex}" "\\1"
+    JEMALLOC_VERSION "${JEMALLOC_VERSION}")
+  unset(_version_regex)
+endif()
+
 # handle the QUIETLY and REQUIRED arguments and set JEMALLOC_FOUND to TRUE if
 # all listed variables are TRUE
 INCLUDE(FindPackageHandleStandardArgs)
diff --git a/intern/guardedalloc/CMakeLists.txt b/intern/guardedalloc/CMakeLists.txt
index 10ed4287185..7f648cff27c 100644
--- a/intern/guardedalloc/CMakeLists.txt
+++ b/intern/guardedalloc/CMakeLists.txt
@@ -53,6 +53,11 @@ if(WIN32 AND NOT UNIX)
 	)
 endif()
 
+# Jemalloc 5.0.0+ needs extra configuration.
+if(WITH_MEM_JEMALLOC AND ("${JEMALLOC_VERSION}" VERSION_GREATER_EQUAL "5.0.0"))
+	add_definitions(-DWITH_JEMALLOC_CONF)
+endif()
+
 blender_add_lib(bf_intern_guardedalloc "${SRC}" "${INC}" "${INC_SYS}")
 
 # Override C++ alloc, optional.
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index a95cc9163c4..8c17da853e5 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -37,6 +37,13 @@
 
 #include "mallocn_intern.h"
 
+#ifdef WITH_JEMALLOC_CONF
+/* If jemalloc is used, it reads this global variable and enables background
+ * threads to purge dirty pages. Otherwise we release memory too slowly or not
+ * at all if the thread that did the allocation stays inactive. */
+const char *malloc_conf = "background_thread:true,dirty_decay_ms:4000";
+#endif
+
 size_t (*MEM_allocN_len)(const void *vmemh) = MEM_lockfree_allocN_len;
 void (*MEM_freeN)(void *vmemh) = MEM_lockfree_freeN;
 void *(*MEM_dupallocN)(const void *vmemh) = MEM_lockfree_dupallocN;



More information about the Bf-blender-cvs mailing list