Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
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
7 changes: 4 additions & 3 deletions include/mimalloc/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,10 @@ struct mi_heap_s {
uintptr_t cookie; // random cookie to verify pointers (see `_mi_ptr_cookie`)
uintptr_t keys[2]; // two random keys used to encode the `thread_delayed_free` list
mi_random_ctx_t random; // random number context used for secure allocation
size_t page_count; // total number of pages in the `pages` queues.
size_t page_retired_min; // smallest retired index (retired pages are fully free, but still in the page queues)
size_t page_retired_max; // largest retired index into the `pages` array.
uint32_t page_count; // total number of pages in the `pages` queues.
uint16_t page_retired_min; // smallest retired index (retired pages are fully free, but still in the page queues)
uint16_t page_retired_max; // largest retired index into the `pages` array.
size_t full_page_size; // total size of pages residing in MI_BIN_FULL bin.
long generic_count; // how often is `_mi_malloc_generic` called?
long generic_collect_count; // how often is `_mi_malloc_generic` called without collecting?
mi_heap_t* next; // list of heaps per thread
Expand Down
2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ mi_decl_cache_align const mi_heap_t _mi_heap_empty = {
{ {0}, {0}, 0, true }, // random
0, // page count
MI_BIN_FULL, 0, // page retired min/max
0, // full page size
0, 0, // generic count
NULL, // next
false, // can reclaim
Expand Down Expand Up @@ -167,6 +168,7 @@ mi_decl_cache_align mi_heap_t _mi_heap_main = {
{ {0x846ca68b}, {0}, 0, true }, // random
0, // page count
MI_BIN_FULL, 0, // page retired min/max
0, // full page size
0, 0, // generic count
NULL, // next heap
false, // can reclaim
Expand Down
13 changes: 13 additions & 0 deletions src/page-queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ static void mi_page_queue_remove(mi_page_queue_t* queue, mi_page_t* page) {
page->next = NULL;
page->prev = NULL;
// mi_atomic_store_ptr_release(mi_atomic_cast(void*, &page->heap), NULL);
if (mi_page_queue_is_full(queue)) {
mi_assert_internal(heap->full_page_size >= mi_page_block_size(page) * page->capacity);
heap->full_page_size -= mi_page_block_size(page) * page->capacity;
}
mi_page_set_in_full(page,false);
}

Expand All @@ -246,6 +250,9 @@ static void mi_page_queue_push(mi_heap_t* heap, mi_page_queue_t* queue, mi_page_
(mi_page_is_large_or_huge(page) && mi_page_queue_is_huge(queue)) ||
(mi_page_is_in_full(page) && mi_page_queue_is_full(queue)));

if (mi_page_queue_is_full(queue)) {
heap->full_page_size += mi_page_block_size(page) * page->capacity;
}
mi_page_set_in_full(page, mi_page_queue_is_full(queue));
// mi_atomic_store_ptr_release(mi_atomic_cast(void*, &page->heap), heap);
page->next = queue->first;
Expand Down Expand Up @@ -339,6 +346,12 @@ static void mi_page_queue_enqueue_from_ex(mi_page_queue_t* to, mi_page_queue_t*
}
}

if (mi_page_queue_is_full(to)) {
heap->full_page_size += mi_page_block_size(page) * page->capacity;
} else if (mi_page_queue_is_full(from)) {
mi_assert_internal(heap->full_page_size >= mi_page_block_size(page) * page->capacity);
heap->full_page_size -= mi_page_block_size(page) * page->capacity;
}
mi_page_set_in_full(page, mi_page_queue_is_full(to));
}

Expand Down