From 72a33c37ef14abc24d3a5cdbb2be806fd24cb382 Mon Sep 17 00:00:00 2001 From: daan Date: Sat, 18 Dec 2021 11:34:02 -0800 Subject: [PATCH 1/3] merge from dev --- include/mimalloc-types.h | 4 ++-- src/segment.c | 2 +- test/test-api.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index 9f97f8f5..957115c8 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -172,13 +172,13 @@ typedef int32_t mi_ssize_t; #endif // Maximum slice offset (15) -#define MI_MAX_SLICE_OFFSET ((MI_ALIGNED_MAX / MI_SEGMENT_SLICE_SIZE) - 1) +#define MI_MAX_SLICE_OFFSET ((MI_ALIGNMENT_MAX / MI_SEGMENT_SLICE_SIZE) - 1) // Used as a special value to encode block sizes in 32 bits. #define MI_HUGE_BLOCK_SIZE ((uint32_t)MI_HUGE_OBJ_SIZE_MAX) // blocks up to this size are always allocated aligned -#define MI_MAX_ALIGN_GUARANTEE (8*MI_MAX_ALIGN_SIZE) +#define MI_MAX_ALIGN_GUARANTEE (8*MI_MAX_ALIGN_SIZE) diff --git a/src/segment.c b/src/segment.c index 7b2fa28e..3001f160 100644 --- a/src/segment.c +++ b/src/segment.c @@ -317,7 +317,7 @@ static uint8_t* _mi_segment_page_start_from_slice(const mi_segment_t* segment, c size_t psize = (size_t)slice->slice_count * MI_SEGMENT_SLICE_SIZE; // make the start not OS page aligned for smaller blocks to avoid page/cache effects size_t start_offset = (xblock_size >= MI_INTPTR_SIZE && xblock_size <= 1024 ? MI_MAX_ALIGN_GUARANTEE : 0); - if (page_size != NULL) *page_size = psize - start_offset; + if (page_size != NULL) { *page_size = psize - start_offset; } return (uint8_t*)segment + ((idx*MI_SEGMENT_SLICE_SIZE) + start_offset); } diff --git a/test/test-api.c b/test/test-api.c index 96817337..f057799a 100644 --- a/test/test-api.c +++ b/test/test-api.c @@ -163,7 +163,7 @@ int main(void) { for (size_t align = 1; align <= MI_ALIGNMENT_MAX && ok; align *= 2) { void* ps[8]; for (int i = 0; i < 8 && ok; i++) { - ps[i] = mi_malloc_aligned(align/2 /*size*/, align); + ps[i] = mi_malloc_aligned(align*13 /*size*/, align); if (ps[i] == NULL || (uintptr_t)(ps[i]) % align != 0) { ok = false; } From 397f44c9573d762364e6fe77d5dae16c2003489b Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 10 Jan 2022 12:04:24 -0800 Subject: [PATCH 2/3] nicefy --- src/alloc-override-osx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/alloc-override-osx.c b/src/alloc-override-osx.c index b53032e2..edd93b37 100644 --- a/src/alloc-override-osx.c +++ b/src/alloc-override-osx.c @@ -32,8 +32,7 @@ terms of the MIT license. A copy of the license can be found in the file extern "C" { #endif -#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_6) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6) // only available from OSX 10.6 extern malloc_zone_t* malloc_default_purgeable_zone(void) __attribute__((weak_import)); #endif From f317225a70929fea9be62e15945c2e8890cf6a1a Mon Sep 17 00:00:00 2001 From: Daan Date: Mon, 10 Jan 2022 12:10:18 -0800 Subject: [PATCH 3/3] ignore reset_decommits option in the 2.x / dev-slice version --- include/mimalloc-internal.h | 2 +- src/options.c | 2 +- src/os.c | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h index 348bef4b..45775df4 100644 --- a/include/mimalloc-internal.h +++ b/include/mimalloc-internal.h @@ -83,7 +83,7 @@ bool _mi_os_unprotect(void* addr, size_t size); bool _mi_os_commit(void* addr, size_t size, bool* is_zero, mi_stats_t* stats); bool _mi_os_decommit(void* p, size_t size, mi_stats_t* stats); bool _mi_os_reset(void* p, size_t size, mi_stats_t* stats); -bool _mi_os_unreset(void* p, size_t size, bool* is_zero, mi_stats_t* stats); +// bool _mi_os_unreset(void* p, size_t size, bool* is_zero, mi_stats_t* stats); size_t _mi_os_good_alloc_size(size_t size); bool _mi_os_has_overcommit(void); diff --git a/src/options.c b/src/options.c index f7dbc620..b8bac750 100644 --- a/src/options.c +++ b/src/options.c @@ -72,7 +72,7 @@ static mi_option_desc_t options[_mi_option_last] = { 0, UNINIT, MI_OPTION(reset_decommits) }, // reset decommits memory #else { 1, UNINIT, MI_OPTION(eager_region_commit) }, - { 0, UNINIT, MI_OPTION(reset_decommits) }, // reset uses MADV_FREE/MADV_DONTNEED + { 0, UNINIT, MI_OPTION(reset_decommits) }, // legacy; ignored now and reset always uses MADV_FREE/MADV_DONTNEED (issue #518) #endif { 0, UNINIT, MI_OPTION(large_os_pages) }, // use large OS pages, use only with eager commit to prevent fragmentation of VMA's { 0, UNINIT, MI_OPTION(reserve_huge_os_pages) }, // per 1GiB huge pages diff --git a/src/os.c b/src/os.c index 8aac3845..ac2d73d1 100644 --- a/src/os.c +++ b/src/os.c @@ -938,9 +938,12 @@ bool _mi_os_decommit(void* addr, size_t size, mi_stats_t* tld_stats) { return mi_os_commitx(addr, size, false, true /* conservative */, &is_zero, stats); } +/* static bool mi_os_commit_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* stats) { - return mi_os_commitx(addr, size, true, true /* conservative */, is_zero, stats); + return mi_os_commitx(addr, size, true, true // conservative + , is_zero, stats); } +*/ // Signal to the OS that the address range is no longer in use // but may be used later again. This will release physical memory @@ -1003,14 +1006,10 @@ static bool mi_os_resetx(void* addr, size_t size, bool reset, mi_stats_t* stats) bool _mi_os_reset(void* addr, size_t size, mi_stats_t* tld_stats) { MI_UNUSED(tld_stats); mi_stats_t* stats = &_mi_stats_main; - if (mi_option_is_enabled(mi_option_reset_decommits)) { - return _mi_os_decommit(addr, size, stats); - } - else { - return mi_os_resetx(addr, size, true, stats); - } + return mi_os_resetx(addr, size, true, stats); } +/* bool _mi_os_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* tld_stats) { MI_UNUSED(tld_stats); mi_stats_t* stats = &_mi_stats_main; @@ -1022,7 +1021,7 @@ bool _mi_os_unreset(void* addr, size_t size, bool* is_zero, mi_stats_t* tld_stat return mi_os_resetx(addr, size, false, stats); } } - +*/ // Protect a region in memory to be not accessible. static bool mi_os_protectx(void* addr, size_t size, bool protect) {