Heap: Log more details of blocks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2022-12-26 16:17:24 +01:00
parent 2af3997456
commit ed34009b50
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -140,7 +140,8 @@ static Result<void> combine_forward(HeapBlock* block)
{ {
if (next->status & BLOCK_START_MEM) 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 {}; return {};
} }
else else
@ -168,7 +169,8 @@ static Result<HeapBlock*> combine_backward(HeapBlock* block)
{ {
if (block->status & BLOCK_START_MEM) 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; return last;
} }
else else
@ -284,7 +286,8 @@ Result<void> kfree(void* ptr)
if ((block->status & BLOCK_START_MEM) && (block->status & BLOCK_END_MEM)) if ((block->status & BLOCK_START_MEM) && (block->status & BLOCK_END_MEM))
{ {
heap.remove(block); 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 {}; return {};
@ -363,12 +366,15 @@ void dump_heap_usage()
{ {
if (is_block_free(block)) 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); alloc_total += block->full_size + sizeof(HeapBlock);
} }
else 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_total += block->full_size + sizeof(HeapBlock);
alloc_used += block->req_size; alloc_used += block->req_size;
} }