From 7c17c3d33ed03a5cc19144cb99e3a8030b1c7cdf Mon Sep 17 00:00:00 2001 From: Daan Leijen Date: Sun, 24 Mar 2024 22:41:33 -0700 Subject: [PATCH] optimize page struct layout --- include/mimalloc/types.h | 7 ++++--- src/init.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/mimalloc/types.h b/include/mimalloc/types.h index b8e7f97d..a08555ee 100644 --- a/include/mimalloc/types.h +++ b/include/mimalloc/types.h @@ -292,14 +292,15 @@ typedef struct mi_page_s { // layout like this to optimize access in `mi_malloc` and `mi_free` uint16_t capacity; // number of blocks committed, must be the first field, see `segment.c:page_clear` uint16_t reserved; // number of blocks reserved in memory - uint16_t used; // number of blocks in use (including blocks in `thread_free`) mi_page_flags_t flags; // `in_full` and `has_aligned` flags (8 bits) - uint8_t block_size_shift; // if not zero, then `(1 << block_size_shift) == block_size` (only used for fast path in `free.c:_mi_page_ptr_unalign`) uint8_t free_is_zero:1; // `true` if the blocks in the free list are zero initialized uint8_t retire_expire:7; // expiration count for retired blocks - // padding + mi_block_t* free; // list of available free blocks (`malloc` allocates from this list) mi_block_t* local_free; // list of deferred free blocks by this thread (migrates to `free`) + uint16_t used; // number of blocks in use (including blocks in `thread_free`) + uint8_t block_size_shift; // if not zero, then `(1 << block_size_shift) == block_size` (only used for fast path in `free.c:_mi_page_ptr_unalign`) + // padding size_t block_size; // size available in each block (always `>0`) uint8_t* page_start; // start of the page area containing the blocks diff --git a/src/init.c b/src/init.c index 1a6a30e5..33161062 100644 --- a/src/init.c +++ b/src/init.c @@ -14,17 +14,17 @@ 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, + 0, false, false, false, false, 0, // capacity 0, // reserved capacity - 0, // used { 0 }, // flags - 0, // block size shift false, // is_zero 0, // retire_expire NULL, // free NULL, // local_free + 0, // used + 0, // block size shift 0, // block_size NULL, // page_start #if (MI_PADDING || MI_ENCODE_FREELIST)