Debugging: print_free_mem()
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 5 Feb 2014 02:46:39 +0000 (18:46 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sun, 9 Feb 2014 07:22:59 +0000 (23:22 -0800)
Used this to track down some memory leaks.  Called via kfunc.

kern/src/pmap.c

index 3d5b540..2cd8286 100644 (file)
@@ -333,3 +333,25 @@ bool regions_collide_unsafe(uintptr_t start1, uintptr_t end1,
                return TRUE;
        }
 }
+
+void print_free_mem(void)
+{
+       static uint8_t *bm = 0;
+       /* racy, but this is debugging code */
+       if (!bm)
+               bm = kzmalloc((max_nr_pages + 1) / 8, 0);
+
+       long x = 0;
+       for (int i = 0; i < max_nr_pages; i++) {
+               if (page_is_free(i)) {
+                       x++;
+                       SET_BITMASK_BIT(bm, i);
+               } else {
+                       if (GET_BITMASK_BIT(bm, i)) {
+                               print_pageinfo(ppn2page(i));
+                               CLR_BITMASK_BIT(bm, i);
+                       }
+               }
+       }
+       printk("Nr Free pages: %lld\n", x);
+}