From a3670076897821660f24815c1e3c655593a4cd5f Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Sat, 5 Mar 2016 09:55:44 -0500 Subject: [PATCH] Add function to track free bytes in the coremap. --- kern/arch/mips/vm/dumbvm.c | 9 +++++++++ kern/include/vm.h | 8 ++++++++ kern/vm/kmalloc.c | 6 +++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/kern/arch/mips/vm/dumbvm.c b/kern/arch/mips/vm/dumbvm.c index 93606d1..5a7d619 100644 --- a/kern/arch/mips/vm/dumbvm.c +++ b/kern/arch/mips/vm/dumbvm.c @@ -126,6 +126,15 @@ free_kpages(vaddr_t addr) (void)addr; } +unsigned +int +coremap_free_bytes() { + + /* dumbvm doesn't track page allocations. Return 0 so that khu works. */ + + return 0; +} + void vm_tlbshootdown_all(void) { diff --git a/kern/include/vm.h b/kern/include/vm.h index fd1b299..96b6ffe 100644 --- a/kern/include/vm.h +++ b/kern/include/vm.h @@ -55,6 +55,14 @@ int vm_fault(int faulttype, vaddr_t faultaddress); vaddr_t alloc_kpages(unsigned npages); void free_kpages(vaddr_t addr); +/* + * Return amount of free memory (in bytes) available in unallocated coremap pages. + * If there are ongoing allocations, this value could change after it is + * returned to the caller. But it should have been correct at some point in + * time. + */ +unsigned int coremap_free_bytes(void); + /* TLB shootdown handling called from interprocessor_interrupt */ void vm_tlbshootdown_all(void); void vm_tlbshootdown(const struct tlbshootdown *); diff --git a/kern/vm/kmalloc.c b/kern/vm/kmalloc.c index 5537c28..bc2771a 100644 --- a/kern/vm/kmalloc.c +++ b/kern/vm/kmalloc.c @@ -827,16 +827,16 @@ kheap_printused(void) { struct pageref *pr; unsigned long total = 0; + char total_string[32]; + /* print the whole thing with interrupts off */ spinlock_acquire(&kmalloc_spinlock); - for (pr = allbase; pr != NULL; pr = pr->next_all) { total += subpage_stats(pr, true); } - + total += coremap_free_bytes(); spinlock_release(&kmalloc_spinlock); - char total_string[32]; snprintf(total_string, sizeof(total_string), "%lu", total); secprintf(SECRET, total_string, "khu"); }