From 7b105c4810e5f029043bc5441839cf15426687f9 Mon Sep 17 00:00:00 2001 From: daan Date: Sun, 11 Aug 2019 10:31:00 -0700 Subject: [PATCH] improve layout of page for x64 --- CMakeLists.txt | 2 +- include/mimalloc-types.h | 4 ++-- src/alloc.c | 16 ++++++++-------- src/init.c | 12 ++++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b37e579..3ea4e607 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,7 +91,7 @@ if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") if(CMAKE_C_COMPILER_ID MATCHES "GNU") list(APPEND mi_cflags -Wno-invalid-memory-model) list(APPEND mi_cflags -fvisibility=hidden) - list(APPEND mi_cflags -fbranch-target-load-optimize ) + list(APPEND mi_cflags -fbranch-target-load-optimize) endif() endif() diff --git a/include/mimalloc-types.h b/include/mimalloc-types.h index db5b52cc..eca5c2eb 100644 --- a/include/mimalloc-types.h +++ b/include/mimalloc-types.h @@ -182,7 +182,7 @@ typedef struct mi_page_s { // improve page index calculation #if (MI_INTPTR_SIZE==8 && MI_SECURE==0) - void* padding[1]; // 12 words on 64-bit + // void* padding[1]; // 12 words on 64-bit #elif MI_INTPTR_SIZE==4 // void* padding[1]; // 12 words on 32-bit #endif @@ -383,7 +383,7 @@ typedef struct mi_segments_tld_s { } mi_segments_tld_t; // OS thread local data -typedef struct mi_os_tld_s { +typedef struct mi_os_tld_s { mi_stats_t* stats; // points to tld stats } mi_os_tld_t; diff --git a/src/alloc.c b/src/alloc.c index d0fd28cb..7ad7c552 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -72,7 +72,7 @@ extern inline void* mi_heap_malloc(mi_heap_t* heap, size_t size) mi_attr_noexcep void* p; if (mi_likely(size <= MI_SMALL_SIZE_MAX)) { p = mi_heap_malloc_small(heap, size); - } + } else { p = _mi_malloc_generic(heap, size); } @@ -200,16 +200,16 @@ static void mi_decl_noinline mi_free_generic(const mi_segment_t* segment, mi_pag // Free a block void mi_free(void* p) mi_attr_noexcept -{ +{ #if (MI_DEBUG>0) if (mi_unlikely(((uintptr_t)p & (MI_INTPTR_SIZE - 1)) != 0)) { _mi_error_message("trying to free an invalid (unaligned) pointer: %p\n", p); return; } #endif - + const mi_segment_t* const segment = _mi_ptr_segment(p); - if (segment == NULL) return; // checks for (p==NULL) + if (segment == NULL) return; // checks for (p==NULL) #if (MI_DEBUG>0) if (mi_unlikely(!mi_is_in_heap_region(p))) { @@ -224,8 +224,8 @@ void mi_free(void* p) mi_attr_noexcept return; } #endif - - mi_page_t* page = _mi_segment_page_of(segment, p); + + mi_page_t* const page = _mi_segment_page_of(segment, p); #if (MI_STAT>1) mi_heap_t* heap = mi_heap_get_default(); @@ -236,11 +236,11 @@ void mi_free(void* p) mi_attr_noexcept // huge page stat is accounted for in `_mi_page_retire` #endif - uintptr_t tid = _mi_thread_id(); + const uintptr_t tid = _mi_thread_id(); if (mi_likely(tid == page->flags)) { // if equal, the thread id matches and it is not a full page, nor has aligned blocks // local, and not full or aligned mi_block_t* block = (mi_block_t*)p; - mi_block_set_next(page, block, page->local_free); + mi_block_set_next(page, block, page->local_free); page->local_free = block; page->used--; if (mi_unlikely(mi_page_all_free(page))) { _mi_page_retire(page); } diff --git a/src/init.c b/src/init.c index f73ca6cf..ad82853e 100644 --- a/src/init.c +++ b/src/init.c @@ -12,7 +12,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, 0, 0, + 0, false, false, false, 0, 0, NULL, // free #if MI_SECURE 0, @@ -21,7 +21,7 @@ const mi_page_t _mi_page_empty = { NULL, 0, 0, 0, NULL, NULL, NULL #if (MI_INTPTR_SIZE==8 && MI_SECURE==0) - , { NULL } + // , { NULL } #endif }; @@ -421,7 +421,7 @@ static void mi_process_load(void) { // show message from the redirector (if present) const char* msg = NULL; mi_allocator_init(&msg); - if (msg != NULL) _mi_verbose_message(msg); + if (msg != NULL) _mi_verbose_message(msg); } // Initialize the process; called by thread_init or the process loader @@ -433,7 +433,7 @@ void mi_process_init(void) mi_attr_noexcept { // when using dynamic linking with interpose. mi_heap_t* h = _mi_heap_default; _mi_process_is_initialized = true; - + _mi_heap_main.thread_id = _mi_thread_id(); _mi_verbose_message("process init: 0x%zx\n", _mi_heap_main.thread_id); uintptr_t random = _mi_random_init(_mi_heap_main.thread_id) ^ (uintptr_t)h; @@ -442,7 +442,7 @@ void mi_process_init(void) mi_attr_noexcept { #endif _mi_heap_main.random = _mi_random_shuffle(random); mi_process_setup_auto_thread_done(); - _mi_os_init(); + _mi_os_init(); #if (MI_DEBUG) _mi_verbose_message("debug level : %d\n", MI_DEBUG); #endif @@ -480,7 +480,7 @@ static void mi_process_done(void) { __declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) { UNUSED(reserved); UNUSED(inst); - if (reason==DLL_PROCESS_ATTACH) { + if (reason==DLL_PROCESS_ATTACH) { mi_process_load(); } else if (reason==DLL_THREAD_DETACH) {