From 60023ff70ba34bc8c8d31d483b2a1e6db51af1a4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 2 May 2019 16:35:57 +0200 Subject: [PATCH] LibC: free() should move kept empty ChunkedBlocks to the end of the list. This ensures that we continue allocating from partially-used blocks until they are full. --- LibC/malloc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/LibC/malloc.cpp b/LibC/malloc.cpp index b7204d0d8f..38feddd216 100644 --- a/LibC/malloc.cpp +++ b/LibC/malloc.cpp @@ -204,6 +204,13 @@ void free(void* ptr) #ifdef MALLOC_DEBUG dbgprintf("Keeping block %p around for size class %u\n", block, good_size); #endif + if (allocator->blocks.tail() != block) { +#ifdef MALLOC_DEBUG + dbgprintf("Moving block %p to tail of list for size class %u\n", block, good_size); +#endif + allocator->blocks.remove(block); + allocator->blocks.append(block); + } return; } #ifdef MALLOC_DEBUG