From 9da8788daeb43c3cb796ac8d6cbfef7574211a97 Mon Sep 17 00:00:00 2001 From: Michael Clark Date: Wed, 19 Jan 2022 08:03:39 +1300 Subject: [PATCH 1/5] mimalloc-types: amend comment adding medium to list of page kinds --- include/mimalloc-types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index c9f399df..d8985385 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -313,7 +313,7 @@ typedef struct mi_segment_s { // layout like this to optimize access in `mi_free` size_t page_shift; // `1 << page_shift` == the page sizes == `page->block_size * page->reserved` (unless the first page, then `-segment_info_size`). _Atomic(mi_threadid_t) thread_id; // unique id of the thread owning this segment - mi_page_kind_t page_kind; // kind of pages: small, large, or huge + mi_page_kind_t page_kind; // kind of pages: small, medium, large, or huge mi_page_t pages[1]; // up to `MI_SMALL_PAGES_PER_SEGMENT` pages } mi_segment_t; From d2e727f0e871cd35305bdb7bc3983cf607441752 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 18 Jan 2022 21:11:12 -0800 Subject: [PATCH 2/5] Add MI_SKIP_COLLECT_ON_EXIT flag --- CMakeLists.txt | 5 +++++ src/init.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b56953c4..76c26666 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF) option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF) option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF) option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF) +option(MI_SKIP_COLLECT_ON_EXIT, "Skip collecting memory on exit" OFF) include("cmake/mimalloc-config-version.cmake") @@ -102,6 +103,10 @@ if(MI_CHECK_FULL) set(MI_DEBUG_FULL "ON") endif() +if (MI_SKIP_COLLECT_ON_EXIT) + list(APPEND mi_defines MI_SKIP_COLLECT_ON_EXIT=1) +endif() + if(MI_DEBUG_FULL) message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)") list(APPEND mi_defines MI_DEBUG=3) # full invariant checking diff --git a/src/init.c b/src/init.c index c0f09b5e..998649e3 100644 --- a/src/init.c +++ b/src/init.c @@ -516,11 +516,13 @@ static void mi_process_done(void) { FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208 #endif - #if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB) - // free all memory if possible on process exit. This is not needed for a stand-alone process - // but should be done if mimalloc is statically linked into another shared library which - // is repeatedly loaded/unloaded, see issue #281. - mi_collect(true /* force */ ); + #ifndef MI_SKIP_COLLECT_ON_EXIT + #if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB) + // free all memory if possible on process exit. This is not needed for a stand-alone process + // but should be done if mimalloc is statically linked into another shared library which + // is repeatedly loaded/unloaded, see issue #281. + mi_collect(true /* force */ ); + #endif #endif if (mi_option_is_enabled(mi_option_show_stats) || mi_option_is_enabled(mi_option_verbose)) { From a5a87a109b07a7b66b3ff2b24ea54da5c1013c82 Mon Sep 17 00:00:00 2001 From: Hans Loeblich Date: Wed, 26 Jan 2022 17:39:58 -0600 Subject: [PATCH 3/5] Include mimalloc-redirect.dll with cmake install --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93686cef..c0eee92e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -303,6 +303,7 @@ if(MI_BUILD_SHARED) add_custom_command(TARGET mimalloc POST_BUILD COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" $ COMMENT "Copy mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll to output directory") + install(FILES "$/mimalloc-redirect${MIMALLOC_REDIRECT_SUFFIX}.dll" DESTINATION ${mi_install_libdir}) endif() install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_libdir} LIBRARY) From b1e1b0573cde26d4540e39efd6436efcb8ee57b3 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 27 Jan 2022 07:01:32 +0000 Subject: [PATCH 4/5] tls revives inline asm for openbsd --- include/mimalloc-internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index b90595ba..16be1251 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -722,6 +722,7 @@ static inline mi_threadid_t _mi_thread_id(void) mi_attr_noexcept { || (defined(__APPLE__) && (defined(__x86_64__) || defined(__aarch64__))) \ || (defined(__BIONIC__) && (defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__))) \ || (defined(__FreeBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \ + || (defined(__OpenBSD__) && (defined(__x86_64__) || defined(__i386__) || defined(__aarch64__))) \ ) static inline void* mi_tls_slot(size_t slot) mi_attr_noexcept { From 3e05c64d8b829106bfb81e08478d65c01d32b246 Mon Sep 17 00:00:00 2001 From: Daan Date: Wed, 2 Feb 2022 20:12:26 -0800 Subject: [PATCH 5/5] fix compile error on macOS 10.13 for claimed_address; fix by @michaeljclark, issue #527 --- src/alloc-override-osx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index 34cde0b4..a88186bc 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -217,7 +217,7 @@ static malloc_zone_t mi_malloc_zone = { .batch_free = &zone_batch_free, .introspect = &mi_introspect, #if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) - #if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + #if defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) .version = 10, #else .version = 9, @@ -226,7 +226,7 @@ static malloc_zone_t mi_malloc_zone = { .memalign = &zone_memalign, .free_definite_size = &zone_free_definite_size, .pressure_relief = &zone_pressure_relief, - #if defined(MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7) + #if defined(MAC_OS_X_VERSION_10_14) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14) .claimed_address = &zone_claimed_address, #endif #else