]> git.kaiwu.me - klib.git/commitdiff
find the largest chunk of free memory
authorHeng Li <lh3@me.com>
Fri, 19 Jan 2018 22:36:02 +0000 (17:36 -0500)
committerHeng Li <lh3@me.com>
Fri, 19 Jan 2018 22:36:02 +0000 (17:36 -0500)
kalloc.c
kalloc.h

index fe556815d7a4a376b36423f0d28022ecaf01c421..b36c333e4c1cd7ce7cedba3da6c61da45f93a4bd 100644 (file)
--- a/kalloc.c
+++ b/kalloc.c
@@ -189,6 +189,10 @@ void km_stat(const void *_km, km_stat_t *s)
                        panic("[km_stat] The end of a free block enters another free block.");
                if (p->ptr == km->loop_head) break;
        }
-       for (p = km->core_head; p != NULL; p = p->ptr)
-               ++s->n_cores, s->capacity += p->size * sizeof(header_t);
+       for (p = km->core_head; p != NULL; p = p->ptr) {
+               size_t size = p->size * sizeof(header_t);
+               ++s->n_cores;
+               s->capacity += size;
+               s->largest = s->largest > size? s->largest : size;
+       }
 }
index 85b54a7bb4939a27104823b2c74d2be25d687cf0..e891892994df3f124376071dbe809dfcda0ab337 100644 (file)
--- a/kalloc.h
+++ b/kalloc.h
@@ -8,7 +8,7 @@ extern "C" {
 #endif
 
 typedef struct {
-       size_t capacity, available, n_blocks, n_cores;
+       size_t capacity, available, n_blocks, n_cores, largest;
 } km_stat_t;
 
 void *kmalloc(void *km, size_t size);