diff --git a/src/heap.c b/src/heap.c index 412c6465..a1b06c6b 100644 --- a/src/heap.c +++ b/src/heap.c @@ -340,6 +340,7 @@ static bool _mi_heap_page_destroy(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_ // mi_page_free(page,false); page->next = NULL; page->prev = NULL; + mi_page_set_heap(page, NULL); _mi_arena_page_free(page); return true; // keep going @@ -507,7 +508,7 @@ bool mi_heap_reload(mi_heap_t* heap, mi_arena_id_t arena_id) { // reinit direct pages (as we may be in a different process) mi_assert_internal(heap->page_count == 0); - for (int i = 0; i < MI_PAGES_DIRECT; i++) { + for (size_t i = 0; i < MI_PAGES_DIRECT; i++) { heap->pages_free_direct[i] = (mi_page_t*)&_mi_page_empty; } diff --git a/src/page-map.c b/src/page-map.c index 7b74c711..d6517f72 100644 --- a/src/page-map.c +++ b/src/page-map.c @@ -9,6 +9,14 @@ terms of the MIT license. A copy of the license can be found in the file #include "mimalloc/internal.h" #include "bitmap.h" +// The page-map contains a byte for each 64kb slice in the address space. +// For an address `a` where `n = _mi_page_map[a >> 16]`: +// 0 = unused +// 1 = the slice at `a & ~0xFFFF` is a mimalloc page. +// 1 < n << 127 = the slice is part of a page, starting at `(((a>>16) - n - 1) << 16)`. +// +// 1 byte per slice => 1 GiB page map = 2^30 slices of 2^16 = 2^46 = 64 TiB address space. +// 4 GiB virtual for 256 TiB address space (48 bit) (and 64 KiB for 4 GiB address space (on 32-bit)). mi_decl_cache_align uint8_t* _mi_page_map = NULL; static bool mi_page_map_all_committed = false; static size_t mi_page_map_entries_per_commit_bit = MI_ARENA_SLICE_SIZE; @@ -24,10 +32,11 @@ bool _mi_page_map_init(void) { size_t vbits = (size_t)mi_option_get_clamp(mi_option_max_vabits, 0, MI_SIZE_BITS); if (vbits == 0) { vbits = _mi_os_virtual_address_bits(); + #if MI_ARCH_X64 if (vbits >= 48) { vbits = 47; } + #endif } - // 1 byte per block = 2 GiB for 128 TiB address space (48 bit = 256 TiB address space) - // 64 KiB for 4 GiB address space (on 32-bit) + mi_page_map_max_address = (void*)(MI_PU(1) << vbits); const size_t page_map_size = (MI_ZU(1) << (vbits - MI_ARENA_SLICE_SHIFT));