From 4fed073fd02ae24c1e3f099e20bed623ac00df2e Mon Sep 17 00:00:00 2001 From: Stewart Smith Date: Thu, 7 May 2015 17:11:42 +1000 Subject: Dump out free space in each memory region on boot. This way we can track free HEAP when we're done with all the skiboot boot magic and see what we have to play with at runtime. Signed-off-by: Stewart Smith --- core/mem_region.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'core/mem_region.c') diff --git a/core/mem_region.c b/core/mem_region.c index 79c9842..f387f37 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -25,6 +25,9 @@ #include #include +int64_t mem_dump_free(void); +void mem_dump_allocs(void); + /* Memory poisoning on free (if POISON_MEM_REGION set to 1) */ #define POISON_MEM_REGION 0 #define POISON_MEM_REGION_WITH 0x99 @@ -258,7 +261,7 @@ static bool region_is_reserved(struct mem_region *region) return region->type != REGION_OS; } -static void mem_dump_allocs(void) +void mem_dump_allocs(void) { struct mem_region *region; struct alloc_hdr *hdr; @@ -285,6 +288,39 @@ static void mem_dump_allocs(void) } } +int64_t mem_dump_free(void) +{ + struct mem_region *region; + struct alloc_hdr *hdr; + int64_t total_free; + int64_t region_free; + + total_free = 0; + + printf("Free space in HEAP memory regions:\n"); + list_for_each(®ions, region, list) { + if (region->type != REGION_SKIBOOT_HEAP) + continue; + region_free = 0; + + if (region->free_list.n.next == NULL) { + continue; + } + for (hdr = region_start(region); hdr; hdr = next_hdr(region, hdr)) { + if (!hdr->free) + continue; + + region_free+= hdr->num_longs * sizeof(long); + } + printf("Region %s free: %llu\n", region->name, region_free); + total_free += region_free; + } + + printf("Total free: %llu\n", total_free); + + return total_free; +} + static void *__mem_alloc(struct mem_region *region, size_t size, size_t align, const char *location) { -- cgit v1.1