From ed34009b50d733380d6d7deb5c4bb4e89e243802 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 26 Dec 2022 16:17:24 +0100 Subject: [PATCH] Heap: Log more details of blocks --- kernel/src/memory/Heap.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index 3a2f4b67..ace511c4 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -140,7 +140,8 @@ static Result combine_forward(HeapBlock* block) { if (next->status & BLOCK_START_MEM) { - TRY(release_pages(next, get_blocks_from_size(next->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE))); + const usize pages = get_blocks_from_size(next->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE); + TRY(release_pages(next, pages)); return {}; } else @@ -168,7 +169,8 @@ static Result combine_backward(HeapBlock* block) { if (block->status & BLOCK_START_MEM) { - TRY(release_pages(block, get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE))); + const usize pages = get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE); + TRY(release_pages(block, pages)); return last; } else @@ -284,7 +286,8 @@ Result kfree(void* ptr) if ((block->status & BLOCK_START_MEM) && (block->status & BLOCK_END_MEM)) { heap.remove(block); - TRY(release_pages(block, get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE))); + const usize pages = get_blocks_from_size(block->full_size + sizeof(HeapBlock), ARCH_PAGE_SIZE); + TRY(release_pages(block, pages)); } return {}; @@ -363,12 +366,15 @@ void dump_heap_usage() { if (is_block_free(block)) { - kdbgln("- Available block, of size %zu", block->full_size); + kdbgln("- Available block (%p), of size %zu (%s%s)", (void*)block, block->full_size, + block->status & BLOCK_START_MEM ? "b" : "-", block->status & BLOCK_END_MEM ? "e" : "-"); alloc_total += block->full_size + sizeof(HeapBlock); } else { - kdbgln("- Used block, of size %zu, of which %zu bytes are being used", block->full_size, block->req_size); + kdbgln("- Used block (%p), of size %zu, of which %zu bytes are being used (%s%s)", (void*)block, + block->full_size, block->req_size, block->status & BLOCK_START_MEM ? "b" : "-", + block->status & BLOCK_END_MEM ? "e" : "-"); alloc_total += block->full_size + sizeof(HeapBlock); alloc_used += block->req_size; }