Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/mimalloc/mimalloc/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ static inline void mi_atomic_yield_sleep( size_t* ticks, const size_t ticks_unti
// These should be light-weight in-process only locks.
// Only used for reserving arena's and to maintain the abandoned list.
// ----------------------------------------------------------------------
#if _MSC_VER
#if defined(_MSC_VER)
#pragma warning(disable:26110) // unlock with holding lock
#endif

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/mimalloc/mimalloc/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void _mi_segment_page_abandon(mi_page_t* page, mi_segments_tld_t* tld);
bool _mi_segment_try_reclaim_abandoned( mi_heap_t* heap, bool try_all, mi_segments_tld_t* tld);
void _mi_segment_collect(mi_segment_t* segment, bool force);

#if MI_HUGE_PAGE_ABANDON
#if defined(MI_HUGE_PAGE_ABANDON)
void _mi_segment_huge_page_free(mi_segment_t* segment, mi_page_t* page, mi_block_t* block);
#else
void _mi_segment_huge_page_reset(mi_segment_t* segment, mi_page_t* page, mi_block_t* block);
Expand Down
2 changes: 1 addition & 1 deletion Include/internal/mimalloc/mimalloc/prim.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static inline mi_heap_t* mi_prim_get_default_heap(void);
#endif


#if MI_TLS_SLOT
#ifdef MI_TLS_SLOT
# if !defined(MI_HAS_TLS_SLOT)
# error "trying to use a TLS slot for the default heap, but the mi_prim_tls_slot primitives are not defined"
# endif
Expand Down
6 changes: 3 additions & 3 deletions Include/internal/mimalloc/mimalloc/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ defined, undefined, or not accessible at all:

-------------------------------------------------------------------------------------------------------*/

#if MI_TRACK_VALGRIND
#if defined(MI_TRACK_VALGRIND)
// valgrind tool

#define MI_TRACK_ENABLED 1
Expand All @@ -60,7 +60,7 @@ defined, undefined, or not accessible at all:
#define mi_track_mem_undefined(p,size) VALGRIND_MAKE_MEM_UNDEFINED(p,size)
#define mi_track_mem_noaccess(p,size) VALGRIND_MAKE_MEM_NOACCESS(p,size)

#elif MI_TRACK_ASAN
#elif defined(MI_TRACK_ASAN)
// address sanitizer

#define MI_TRACK_ENABLED 1
Expand All @@ -75,7 +75,7 @@ defined, undefined, or not accessible at all:
#define mi_track_mem_undefined(p,size) ASAN_UNPOISON_MEMORY_REGION(p,size)
#define mi_track_mem_noaccess(p,size) ASAN_POISON_MEMORY_REGION(p,size)

#elif MI_TRACK_ETW
#elif defined(MI_TRACK_ETW)
// windows event tracing

#define MI_TRACK_ENABLED 1
Expand Down
4 changes: 2 additions & 2 deletions Include/internal/mimalloc/mimalloc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ typedef int32_t mi_ssize_t;

// we never allocate more than PTRDIFF_MAX (see also <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
// on 64-bit+ systems we also limit the maximum allocation size such that the slice count fits in 32-bits. (issue #877)
#if (PTRDIFF_MAX > INT32_MAX) && (PTRDIFF_MAX >= (MI_SEGMENT_SLIZE_SIZE * UINT32_MAX))
#if (PTRDIFF_MAX > INT32_MAX) && (PTRDIFF_MAX >= (MI_SEGMENT_SLICE_SIZE * UINT32_MAX))
#define MI_MAX_ALLOC_SIZE (MI_SEGMENT_SLICE_SIZE * (UINT32_MAX-1))
#else
#define MI_MAX_ALLOC_SIZE PTRDIFF_MAX
Expand Down Expand Up @@ -270,7 +270,7 @@ typedef enum mi_delayed_e {

// The `in_full` and `has_aligned` page flags are put in a union to efficiently
// test if both are false (`full_aligned == 0`) in the `mi_free` routine.
#if !MI_TSAN
#if !defined(MI_TSAN)
typedef union mi_page_flags_s {
uint8_t full_aligned;
struct {
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern inline void* _mi_page_malloc_zero(mi_heap_t* heap, mi_page_t* page, size_
}
}

#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !MI_TSAN
#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !defined(MI_TSAN)
if (!zero && !mi_page_is_huge(page)) {
mi_debug_fill(page, block, MI_DEBUG_UNINIT, mi_page_usable_block_size(page));
}
Expand Down
8 changes: 4 additions & 4 deletions Objects/mimalloc/free.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static inline void mi_free_block_local(mi_page_t* page, mi_block_t* block, bool
if mi_unlikely(mi_check_is_double_free(page, block)) return;
if (!was_guarded) { mi_check_padding(page, block); }
if (track_stats) { mi_stat_free(page, block); }
#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !MI_TSAN
#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !defined(MI_TSAN)
if (!mi_page_is_huge(page)) { // huge page content may be already decommitted
size_t dbgsize = mi_page_block_size(page); if (dbgsize > 1*MI_MiB) { dbgsize = 1*MI_MiB; }
mi_debug_fill(page, block, MI_DEBUG_FREED, dbgsize);
Expand Down Expand Up @@ -302,7 +302,7 @@ static void mi_decl_noinline mi_free_block_mt(mi_page_t* page, mi_segment_t* seg

// first see if the segment was abandoned and if we can reclaim it into our thread
if (_mi_option_get_fast(mi_option_abandoned_reclaim_on_free) != 0 &&
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
segment->page_kind != MI_PAGE_HUGE &&
#endif
mi_atomic_load_relaxed(&segment->thread_id) == 0 && // segment is abandoned?
Expand All @@ -329,7 +329,7 @@ static void mi_decl_noinline mi_free_block_mt(mi_page_t* page, mi_segment_t* seg
_mi_padding_shrink(page, block, sizeof(mi_block_t));

if (segment->kind == MI_SEGMENT_HUGE) {
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
// huge page segments are always abandoned and can be freed immediately
_mi_segment_huge_page_free(segment, page, block);
return;
Expand All @@ -341,7 +341,7 @@ static void mi_decl_noinline mi_free_block_mt(mi_page_t* page, mi_segment_t* seg
#endif
}
else {
#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !MI_TSAN // note: when tracking, cannot use mi_usable_size with multi-threading
#if (MI_DEBUG>0) && !MI_TRACK_ENABLED && !defined(MI_TSAN) // note: when tracking, cannot use mi_usable_size with multi-threading
size_t dbgsize = mi_usable_size(block); if (dbgsize > 1*MI_MiB) { dbgsize = 1*MI_MiB; }
mi_debug_fill(page, block, MI_DEBUG_FREED, dbgsize);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ static void mi_process_init_once(void) mi_attr_noexcept {

// Initialize the process; called by thread_init or the process loader
void mi_process_init(void) mi_attr_noexcept {
#if _MSC_VER < 1920
#if defined(_MSC_VER) && _MSC_VER < 1920
mi_heap_main_init(); // vs2017 can dynamically re-initialize _mi_heap_main
#endif
mi_atomic_do_once {
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void mi_options_print(void) mi_attr_noexcept
#if MI_GUARDED
_mi_message("guarded build: %s\n", mi_option_get(mi_option_guarded_sample_rate) != 0 ? "enabled" : "disabled");
#endif
#if MI_TSAN
#ifdef MI_TSAN
_mi_message("thread santizer enabled\n");
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void* mi_os_prim_alloc_aligned(size_t size, size_t alignment, bool commit
}
else {
// if not aligned, free it, overallocate, and unmap around it
#if !MI_TRACK_ASAN
#if !defined(MI_TRACK_ASAN)
// CPython: downgraded from _mi_warning_message, the warning is noisy in the test suite (gh-112027)
_mi_verbose_message("unable to allocate aligned OS memory directly, fall back to over-allocation (size: 0x%zx bytes, address: %p, alignment: 0x%zx, commit: %d)\n", size, p, alignment, commit);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/page-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ static bool mi_page_queue_is_consistent(const mi_page_queue_t* queue);
static void mi_page_queue_push(mi_heap_t* heap, mi_page_queue_t* queue, mi_page_t* page) {
mi_assert_internal(mi_page_heap(page) == heap);
mi_assert_internal(!mi_page_queue_contains(queue, page));
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
mi_assert_internal(_mi_page_segment(page)->kind != MI_SEGMENT_HUGE);
#endif
mi_assert_internal(mi_page_block_size(page) == queue->block_size ||
Expand Down
10 changes: 5 additions & 5 deletions Objects/mimalloc/page.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void _mi_page_reclaim(mi_heap_t* heap, mi_page_t* page) {

mi_assert_internal(mi_page_heap(page) == heap);
mi_assert_internal(mi_page_thread_free_flag(page) != MI_NEVER_DELAYED_FREE);
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
mi_assert_internal(_mi_page_segment(page)->kind != MI_SEGMENT_HUGE);
#endif

Expand All @@ -310,7 +310,7 @@ void _mi_page_reclaim(mi_heap_t* heap, mi_page_t* page) {

// allocate a fresh page from a segment
static mi_page_t* mi_page_fresh_alloc(mi_heap_t* heap, mi_page_queue_t* pq, size_t block_size, size_t page_alignment) {
#if !MI_HUGE_PAGE_ABANDON
#if !defined(MI_HUGE_PAGE_ABANDON)
mi_assert_internal(pq != NULL);
mi_assert_internal(mi_heap_contains_queue(heap, pq));
mi_assert_internal(page_alignment > 0 || block_size > MI_MEDIUM_OBJ_SIZE_MAX || block_size == pq->block_size);
Expand All @@ -320,7 +320,7 @@ static mi_page_t* mi_page_fresh_alloc(mi_heap_t* heap, mi_page_queue_t* pq, size
// this may be out-of-memory, or an abandoned page was reclaimed (and in our queue)
return NULL;
}
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
mi_assert_internal(pq==NULL || _mi_page_segment(page)->page_kind != MI_PAGE_HUGE);
#endif
mi_assert_internal(page_alignment >0 || block_size > MI_MEDIUM_OBJ_SIZE_MAX || _mi_page_segment(page)->kind != MI_SEGMENT_HUGE);
Expand Down Expand Up @@ -994,7 +994,7 @@ static mi_page_t* mi_large_huge_page_alloc(mi_heap_t* heap, size_t size, size_t
size_t block_size = _mi_os_good_alloc_size(size);
mi_assert_internal(mi_bin(block_size) == MI_BIN_HUGE || page_alignment > 0);
bool is_huge = (block_size > MI_LARGE_OBJ_SIZE_MAX || page_alignment > 0);
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
mi_page_queue_t* pq = (is_huge ? NULL : mi_page_queue(heap, block_size));
#else
mi_page_queue_t* pq = mi_page_queue(heap, is_huge ? MI_LARGE_OBJ_SIZE_MAX+1 : block_size);
Expand All @@ -1008,7 +1008,7 @@ static mi_page_t* mi_large_huge_page_alloc(mi_heap_t* heap, size_t size, size_t
mi_assert_internal(mi_page_is_huge(page));
mi_assert_internal(_mi_page_segment(page)->kind == MI_SEGMENT_HUGE);
mi_assert_internal(_mi_page_segment(page)->used==1);
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
mi_assert_internal(_mi_page_segment(page)->thread_id==0); // abandoned, not in the huge queue
mi_page_set_heap(page, NULL);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/segment-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include "mimalloc/atomic.h"

// Reduce total address space to reduce .bss (due to the `mi_segment_map`)
#if (MI_INTPTR_SIZE > 4) && MI_TRACK_ASAN
#if (MI_INTPTR_SIZE > 4) && defined(MI_TRACK_ASAN)
#define MI_SEGMENT_MAP_MAX_ADDRESS (128*1024ULL*MI_GiB) // 128 TiB (see issue #881)
#elif (MI_INTPTR_SIZE > 4)
#define MI_SEGMENT_MAP_MAX_ADDRESS (48*1024ULL*MI_GiB) // 48 TiB
Expand Down
4 changes: 2 additions & 2 deletions Objects/mimalloc/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ static mi_page_t* mi_segment_huge_page_alloc(size_t size, size_t page_alignment,
if (segment == NULL || page==NULL) return NULL;
mi_assert_internal(segment->used==1);
mi_assert_internal(mi_page_block_size(page) >= size);
#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
segment->thread_id = 0; // huge segments are immediately abandoned
#endif

Expand All @@ -1624,7 +1624,7 @@ static mi_page_t* mi_segment_huge_page_alloc(size_t size, size_t page_alignment,
return page;
}

#if MI_HUGE_PAGE_ABANDON
#ifdef MI_HUGE_PAGE_ABANDON
// free huge block from another thread
void _mi_segment_huge_page_free(mi_segment_t* segment, mi_page_t* page, mi_block_t* block) {
// huge page segments are always abandoned and can be freed immediately by any thread
Expand Down
2 changes: 1 addition & 1 deletion Objects/mimalloc/static.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ terms of the MIT license. A copy of the license can be found in the file
#include "segment-map.c"
#include "stats.c"
#include "prim/prim.c"
#if MI_OSX_ZONE
#ifdef MI_OSX_ZONE
#include "prim/osx/alloc-override-zone.c"
#endif
2 changes: 1 addition & 1 deletion Objects/mimalloc/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ static void mi_heap_buf_print_count_bin(mi_heap_buf_t* hbuf, const char* prefix,
const size_t binsize = _mi_bin_size(bin);
const size_t pagesize = (binsize <= MI_SMALL_OBJ_SIZE_MAX ? MI_SMALL_PAGE_SIZE :
(binsize <= MI_MEDIUM_OBJ_SIZE_MAX ? MI_MEDIUM_PAGE_SIZE :
#if MI_LARGE_PAGE_SIZE
#ifdef MI_LARGE_PAGE_SIZE
(binsize <= MI_LARGE_OBJ_SIZE_MAX ? MI_LARGE_PAGE_SIZE : 0)
#else
0
Expand Down
Loading