Buddy alloc now returns block size on liberation

This commit is contained in:
2023-09-08 03:54:05 -05:00
parent 217a73f2e9
commit e087e699c5
2 changed files with 6 additions and 4 deletions

View File

@@ -45,9 +45,9 @@ unsigned long buddy_map_size(const memory_map_t *map, unsigned long block_size);
unsigned long buddy_reserve(buddy_descriptor_t *heap, unsigned long size); unsigned long buddy_reserve(buddy_descriptor_t *heap, unsigned long size);
void buddy_free(buddy_descriptor_t *heap, unsigned long location); unsigned long buddy_free(buddy_descriptor_t *heap, unsigned long location);
void buddy_free_size(buddy_descriptor_t *heap, unsigned long size, unsigned long buddy_free_size(buddy_descriptor_t *heap, unsigned long size,
unsigned long location); unsigned long location);
int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map); int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map);

View File

@@ -83,19 +83,21 @@ unsigned long buddy_reserve(buddy_descriptor_t *heap, unsigned long size)
return NOMEM; return NOMEM;
} }
void buddy_free(buddy_descriptor_t *heap, unsigned long location) unsigned long buddy_free(buddy_descriptor_t *heap, unsigned long location)
{ {
unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size; unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size;
unsigned long k = llog2((heap->block_size * (1UL << heap->block_map[index].kval)) / heap->block_size); unsigned long k = llog2((heap->block_size * (1UL << heap->block_map[index].kval)) / heap->block_size);
insert_block(heap, index, k); insert_block(heap, index, k);
return (1UL << k) * heap->block_size;
} }
void buddy_free_size(buddy_descriptor_t *heap, unsigned long location, unsigned long buddy_free_size(buddy_descriptor_t *heap, unsigned long location,
unsigned long size) unsigned long size)
{ {
unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size; unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size;
unsigned long k = llog2(size / heap->block_size); unsigned long k = llog2(size / heap->block_size);
insert_block(heap, index, k); insert_block(heap, index, k);
return (1UL << k) * heap->block_size;
} }
int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map) int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map)