[Skiboot] [PATCH 03/11] Dump out free space in each memory region on boot.

Stewart Smith stewart at linux.vnet.ibm.com
Thu May 7 17:11:42 AEST 2015


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 <stewart at linux.vnet.ibm.com>
---
 core/init.c       |    4 ++++
 core/mem_region.c |   38 +++++++++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/core/init.c b/core/init.c
index 445272a..e35c885 100644
--- a/core/init.c
+++ b/core/init.c
@@ -361,6 +361,8 @@ static void load_initramfs(void)
 			(uint64_t)INITRAMFS_LOAD_BASE + size);
 }
 
+int64_t mem_dump_free(void);
+
 void __noreturn load_and_boot_kernel(bool is_reboot)
 {
 	const struct dt_property *memprop;
@@ -431,6 +433,8 @@ void __noreturn load_and_boot_kernel(bool is_reboot)
 
 	cpu_give_self_os();
 
+	mem_dump_free();
+
 	printf("INIT: Starting kernel at 0x%llx, fdt at %p (size 0x%x)\n",
 	       kernel_entry, fdt, fdt_totalsize(fdt));
 
diff --git a/core/mem_region.c b/core/mem_region.c
index d7c677d..4fb6d34 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -25,6 +25,9 @@
 #include <mem_region.h>
 #include <mem_region-malloc.h>
 
+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
@@ -243,7 +246,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;
@@ -270,6 +273,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(&regions, 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)
 {
-- 
1.7.10.4



More information about the Skiboot mailing list