diff --git a/cmake/JoinPaths.cmake b/cmake/JoinPaths.cmake deleted file mode 100644 index c68d91b8..00000000 --- a/cmake/JoinPaths.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# This module provides function for joining paths -# known from most languages -# -# SPDX-License-Identifier: (MIT OR CC0-1.0) -# Copyright 2020 Jan Tojnar -# https://github.com/jtojnar/cmake-snips -# -# Modelled after Python’s os.path.join -# https://docs.python.org/3.7/library/os.path.html#os.path.join -# Windows not supported -function(join_paths joined_path first_path_segment) - set(temp_path "${first_path_segment}") - foreach(current_segment IN LISTS ARGN) - if(NOT ("${current_segment}" STREQUAL "")) - if(IS_ABSOLUTE "${current_segment}") - set(temp_path "${current_segment}") - else() - set(temp_path "${temp_path}/${current_segment}") - endif() - endif() - endforeach() - set(${joined_path} "${temp_path}" PARENT_SCOPE) -endfunction() diff --git a/cmake/mimalloc-config-version.cmake b/cmake/mimalloc-config-version.cmake deleted file mode 100644 index a44c121d..00000000 --- a/cmake/mimalloc-config-version.cmake +++ /dev/null @@ -1,19 +0,0 @@ -set(mi_version_major 2) -set(mi_version_minor 1) -set(mi_version_patch 2) -set(mi_version ${mi_version_major}.${mi_version_minor}) - -set(PACKAGE_VERSION ${mi_version}) -if(PACKAGE_FIND_VERSION_MAJOR) - if("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "${mi_version_major}") - if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL "${mi_version_minor}") - set(PACKAGE_VERSION_EXACT TRUE) - elseif("${PACKAGE_FIND_VERSION_MINOR}" LESS "${mi_version_minor}") - set(PACKAGE_VERSION_COMPATIBLE TRUE) - else() - set(PACKAGE_VERSION_UNSUITABLE TRUE) - endif() - else() - set(PACKAGE_VERSION_UNSUITABLE TRUE) - endif() -endif() diff --git a/cmake/mimalloc-config.cmake b/cmake/mimalloc-config.cmake deleted file mode 100644 index a49b02a2..00000000 --- a/cmake/mimalloc-config.cmake +++ /dev/null @@ -1,14 +0,0 @@ -include(${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake) -get_filename_component(MIMALLOC_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH) # one up from the cmake dir, e.g. /usr/local/lib/cmake/mimalloc-2.0 -get_filename_component(MIMALLOC_VERSION_DIR "${CMAKE_CURRENT_LIST_DIR}" NAME) -string(REPLACE "/lib/cmake" "/lib" MIMALLOC_LIBRARY_DIR "${MIMALLOC_CMAKE_DIR}") -if("${MIMALLOC_VERSION_DIR}" EQUAL "mimalloc") - # top level install - string(REPLACE "/lib/cmake" "/include" MIMALLOC_INCLUDE_DIR "${MIMALLOC_CMAKE_DIR}") - set(MIMALLOC_OBJECT_DIR "${MIMALLOC_LIBRARY_DIR}") -else() - # versioned - string(REPLACE "/lib/cmake/" "/include/" MIMALLOC_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}") - string(REPLACE "/lib/cmake/" "/lib/" MIMALLOC_OBJECT_DIR "${CMAKE_CURRENT_LIST_DIR}") -endif() -set(MIMALLOC_TARGET_DIR "${MIMALLOC_LIBRARY_DIR}") # legacy diff --git a/include/mimalloc.h b/include/mimalloc.h index c6ef6aaa..e4e9ee8e 100644 --- a/include/mimalloc.h +++ b/include/mimalloc.h @@ -330,7 +330,7 @@ typedef enum mi_option_e { mi_option_reserve_huge_os_pages_at, // reserve huge OS pages at a specific NUMA node mi_option_reserve_os_memory, // reserve specified amount of OS memory at startup mi_option_deprecated_segment_cache, - mi_option_page_reset, + mi_option_deprecated_page_reset, mi_option_abandoned_page_purge, mi_option_deprecated_segment_reset, mi_option_eager_commit_delay, @@ -343,7 +343,7 @@ typedef enum mi_option_e { mi_option_max_segment_reclaim, mi_option_destroy_on_exit, mi_option_arena_reserve, - mi_option_arena_purge_delay, + mi_option_arena_purge_mult, mi_option_allow_purge, mi_option_purge_extend_delay, _mi_option_last, diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index 7164df1e..42d033be 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -291,8 +291,7 @@ typedef uintptr_t mi_thread_free_t; typedef struct mi_page_s { // "owned" by the segment uint32_t slice_count; // slices in this page (0 if not a page) - uint32_t slice_offset; // distance from the actual page data slice (0 if a page) - uint8_t is_reset : 1; // `true` if the page memory was reset + uint32_t slice_offset; // distance from the actual page data slice (0 if a page) uint8_t is_committed : 1; // `true` if the page virtual memory is committed uint8_t is_zero_init : 1; // `true` if the page was zero initialized diff --git a/src/alloc-aligned.c b/src/alloc-aligned.c index 59f5a524..a0e60efd 100644 --- a/src/alloc-aligned.c +++ b/src/alloc-aligned.c @@ -165,6 +165,11 @@ mi_decl_nodiscard mi_decl_restrict inline void* mi_heap_malloc_aligned(mi_heap_t } } +// ensure a definition is emitted +#if defined(__cplusplus) +static void* _mi_heap_malloc_aligned = (void*)&mi_heap_malloc_aligned; +#endif + // ------------------------------------------------------ // Aligned Allocation // ------------------------------------------------------ diff --git a/src/alloc.c b/src/alloc.c index da6608bb..1bab41fa 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1031,7 +1031,7 @@ void* _mi_externs[] = { (void*)&mi_zalloc_small, (void*)&mi_heap_malloc, (void*)&mi_heap_zalloc, - (void*)&mi_heap_malloc_small + (void*)&mi_heap_malloc_small, // (void*)&mi_heap_alloc_new, // (void*)&mi_heap_alloc_new_n }; diff --git a/src/arena.c b/src/arena.c index 13768016..172453bd 100644 --- a/src/arena.c +++ b/src/arena.c @@ -411,7 +411,7 @@ static void mi_arena_schedule_purge(mi_arena_t* arena, size_t bitmap_idx, size_t mi_assert_internal(arena->blocks_purge != NULL); if (!mi_option_is_enabled(mi_option_allow_purge)) return; - const long delay = mi_option_get(mi_option_arena_purge_delay); + const long delay = mi_option_get(mi_option_purge_delay) * mi_option_get(mi_option_arena_purge_mult); if (_mi_preloading() || delay == 0) { // decommit directly mi_arena_purge(arena, bitmap_idx, blocks, stats); @@ -501,7 +501,7 @@ static bool mi_arena_try_purge(mi_arena_t* arena, mi_msecs_t now, bool force, mi } // if not fully purged, make sure to purge again in the future if (!full_purge) { - const long delay = mi_option_get(mi_option_arena_purge_delay); + const long delay = mi_option_get(mi_option_purge_delay) * mi_option_get(mi_option_arena_purge_mult); mi_msecs_t expected = 0; mi_atomic_cas_strong_acq_rel(&arena->purge_expire,&expected,_mi_clock_now() + delay); } @@ -509,7 +509,7 @@ static bool mi_arena_try_purge(mi_arena_t* arena, mi_msecs_t now, bool force, mi } static void mi_arenas_try_purge( bool force, bool visit_all, mi_stats_t* stats ) { - const long delay = mi_option_get(mi_option_arena_purge_delay); + const long delay = mi_option_get(mi_option_purge_delay) * mi_option_get(mi_option_arena_purge_mult); if (_mi_preloading() || delay == 0 || !mi_option_is_enabled(mi_option_allow_purge)) return; // nothing will be scheduled const size_t max_arena = mi_atomic_load_acquire(&mi_arena_count); diff --git a/src/init.c b/src/init.c index 3badaba7..c9bbc689 100644 --- a/src/init.c +++ b/src/init.c @@ -14,7 +14,7 @@ terms of the MIT license. A copy of the license can be found in the file // Empty page used to initialize the small free pages array const mi_page_t _mi_page_empty = { - 0, false, false, false, false, + 0, false, false, false, 0, // capacity 0, // reserved capacity { 0 }, // flags diff --git a/src/options.c b/src/options.c index 3c687b09..7d5362ae 100644 --- a/src/options.c +++ b/src/options.c @@ -67,7 +67,7 @@ static mi_option_desc_t options[_mi_option_last] = {-1, UNINIT, MI_OPTION(reserve_huge_os_pages_at) }, // reserve huge pages at node N { 0, UNINIT, MI_OPTION(reserve_os_memory) }, { 0, UNINIT, MI_OPTION(deprecated_segment_cache) }, // cache N segments per thread - { 0, UNINIT, MI_OPTION(page_reset) }, // reset page memory on free + { 0, UNINIT, MI_OPTION(deprecated_page_reset) }, // reset page memory on free { 0, UNINIT, MI_OPTION_LEGACY(abandoned_page_purge,abandoned_page_reset) }, // reset free page memory when a thread terminates { 0, UNINIT, MI_OPTION(deprecated_segment_reset) }, // reset segment memory on free (needs eager commit) #if defined(__NetBSD__) @@ -88,7 +88,7 @@ static mi_option_desc_t options[_mi_option_last] = #else { 128L * 1024L, UNINIT, MI_OPTION(arena_reserve) }, #endif - { 100, UNINIT, MI_OPTION(arena_purge_delay) }, // reset/decommit delay in milli-seconds for arena allocation + { 10, UNINIT, MI_OPTION(arena_purge_mult) }, // purge delay multiplier for arena's { 1, UNINIT, MI_OPTION(allow_purge) }, // allow decommit/reset to free (physical) memory back to the OS { 1, UNINIT, MI_OPTION_LEGACY(purge_extend_delay, decommit_extend_delay) }, }; diff --git a/src/page.c b/src/page.c index cae6b581..9943739f 100644 --- a/src/page.c +++ b/src/page.c @@ -255,7 +255,7 @@ void _mi_page_reclaim(mi_heap_t* heap, mi_page_t* page) { #if MI_HUGE_PAGE_ABANDON mi_assert_internal(_mi_page_segment(page)->kind != MI_SEGMENT_HUGE); #endif - mi_assert_internal(!page->is_reset); + // TODO: push on full queue immediately if it is full? mi_page_queue_t* pq = mi_page_queue(heap, mi_page_block_size(page)); mi_page_queue_push(heap, pq, page); diff --git a/src/segment-cache.c b/src/segment-cache.c index 16ddaf5c..c2e7a05a 100644 --- a/src/segment-cache.c +++ b/src/segment-cache.c @@ -259,7 +259,7 @@ mi_decl_noinline bool _mi_segment_cache_push(void* start, size_t size, size_t me slot->commit_mask = *commit_mask; slot->purge_mask = *purge_mask; if (!mi_commit_mask_is_empty(commit_mask) && !is_large && !is_pinned && mi_option_is_enabled(mi_option_allow_purge)) { - long delay = mi_option_get(mi_option_arena_purge_delay); + long delay = mi_option_get(mi_option_purge_delay) * mi_option_get(mi_option_arena_purge_mult); if (delay == 0) { _mi_abandoned_await_readers(); // wait until safe to decommit mi_commit_mask_decommit(&slot->commit_mask, start, MI_SEGMENT_SIZE, tld->stats); diff --git a/src/segment.c b/src/segment.c index 7cc1f10d..b86cb486 100644 --- a/src/segment.c +++ b/src/segment.c @@ -757,7 +757,6 @@ static mi_page_t* mi_segment_span_allocate(mi_segment_t* segment, size_t slice_i } // and initialize the page - page->is_reset = false; page->is_committed = true; segment->used++; return page; @@ -1051,10 +1050,9 @@ static mi_slice_t* mi_segment_page_clear(mi_page_t* page, mi_segments_tld_t* tld _mi_stat_decrease(&tld->stats->pages, 1); // reset the page memory to reduce memory pressure? - if (!segment->mem_is_pinned && !page->is_reset && mi_option_is_enabled(mi_option_page_reset)) { + if (segment->allow_decommit && mi_option_is_enabled(mi_option_deprecated_page_reset)) { size_t psize; - uint8_t* start = _mi_page_start(segment, page, &psize); - page->is_reset = true; + uint8_t* start = _mi_page_start(segment, page, &psize); _mi_os_reset(start, psize, tld->stats); }