fix page count of heap when absorbing

This commit is contained in:
daan 2019-06-27 13:29:55 -07:00
parent 36826a96c9
commit 12d756e7b2
3 changed files with 13 additions and 6 deletions

View File

@ -59,7 +59,7 @@ void _mi_page_abandon(mi_page_t* page, mi_page_queue_t* pq); //
void _mi_heap_delayed_free(mi_heap_t* heap); void _mi_heap_delayed_free(mi_heap_t* heap);
void _mi_page_use_delayed_free(mi_page_t* page, bool enable); void _mi_page_use_delayed_free(mi_page_t* page, bool enable);
void _mi_page_queue_append(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_queue_t* append); size_t _mi_page_queue_append(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_queue_t* append);
void _mi_deferred_free(mi_heap_t* heap, bool force); void _mi_deferred_free(mi_heap_t* heap, bool force);
void _mi_page_free_collect(mi_page_t* page); void _mi_page_free_collect(mi_page_t* page);
@ -136,6 +136,7 @@ static inline bool mi_mul_overflow(size_t size, size_t count, size_t* total) {
// Align a byte size to a size in _machine words_, // Align a byte size to a size in _machine words_,
// i.e. byte size == `wsize*sizeof(void*)`. // i.e. byte size == `wsize*sizeof(void*)`.
static inline size_t _mi_wsize_from_size(size_t size) { static inline size_t _mi_wsize_from_size(size_t size) {
mi_assert_internal(size <= SIZE_MAX - sizeof(uintptr_t));
return (size + sizeof(uintptr_t) - 1) / sizeof(uintptr_t); return (size + sizeof(uintptr_t) - 1) / sizeof(uintptr_t);
} }
@ -190,7 +191,7 @@ static inline mi_segment_t* _mi_ptr_segment(const void* p) {
// Segment belonging to a page // Segment belonging to a page
static inline mi_segment_t* _mi_page_segment(const mi_page_t* page) { static inline mi_segment_t* _mi_page_segment(const mi_page_t* page) {
mi_segment_t* segment = _mi_ptr_segment(page); mi_segment_t* segment = _mi_ptr_segment(page);
mi_assert_internal(page == &segment->pages[page->segment_idx]); mi_assert_internal(segment == NULL || page == &segment->pages[page->segment_idx]);
return segment; return segment;
} }

View File

@ -302,9 +302,12 @@ static void mi_heap_absorb(mi_heap_t* heap, mi_heap_t* from) {
for (size_t i = 0; i < MI_BIN_FULL; i++) { for (size_t i = 0; i < MI_BIN_FULL; i++) {
mi_page_queue_t* pq = &heap->pages[i]; mi_page_queue_t* pq = &heap->pages[i];
mi_page_queue_t* append = &from->pages[i]; mi_page_queue_t* append = &from->pages[i];
_mi_page_queue_append(heap, pq, append); size_t pcount = _mi_page_queue_append(heap, pq, append);
heap->page_count += pcount;
from->page_count -= pcount;
} }
mi_assert_internal(from->thread_delayed_free == NULL); mi_assert_internal(from->thread_delayed_free == NULL);
mi_assert_internal(from->page_count == 0);
// and reset the `from` heap // and reset the `from` heap
mi_heap_reset_pages(from); mi_heap_reset_pages(from);

View File

@ -323,15 +323,17 @@ static void mi_page_queue_enqueue_from(mi_page_queue_t* to, mi_page_queue_t* fro
page->flags.in_full = mi_page_queue_is_full(to); page->flags.in_full = mi_page_queue_is_full(to);
} }
void _mi_page_queue_append(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_queue_t* append) { size_t _mi_page_queue_append(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_queue_t* append) {
mi_assert_internal(mi_heap_contains_queue(heap,pq)); mi_assert_internal(mi_heap_contains_queue(heap,pq));
mi_assert_internal(pq->block_size == append->block_size); mi_assert_internal(pq->block_size == append->block_size);
if (append->first==NULL) return; if (append->first==NULL) return 0;
// set append pages to new heap // set append pages to new heap and count
size_t count = 0;
for (mi_page_t* page = append->first; page != NULL; page = page->next) { for (mi_page_t* page = append->first; page != NULL; page = page->next) {
page->heap = heap; page->heap = heap;
count++;
} }
if (pq->last==NULL) { if (pq->last==NULL) {
@ -349,4 +351,5 @@ void _mi_page_queue_append(mi_heap_t* heap, mi_page_queue_t* pq, mi_page_queue_t
append->first->prev = pq->last; append->first->prev = pq->last;
pq->last = append->last; pq->last = append->last;
} }
return count;
} }