From: Heng Li Date: Fri, 19 Jan 2018 22:36:02 +0000 (-0500) Subject: find the largest chunk of free memory X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=5319e469b1c71f30c74cdd4f2554e9a10559db07;p=klib.git find the largest chunk of free memory --- diff --git a/kalloc.c b/kalloc.c index fe55681..b36c333 100644 --- 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; + } } diff --git a/kalloc.h b/kalloc.h index 85b54a7..e891892 100644 --- 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);