1
0
mirror of https://gitlab.labs.nic.cz/labs/bird.git synced 2024-05-11 16:54:54 +00:00

Memory statistics split into Effective and Overhead

This feature is intended mostly for checking that BIRD's allocation
strategies don't consume much memory space. There are some cases where
withdrawing routes in a specific order lead to memory fragmentation and
this output should give the user at least a notion of how much memory is
actually used for data storage and how much memory is "just allocated"
or used for overhead.

Also raising the "system allocator overhead estimation" from 8 to 16
bytes; it is probably even more. I've found 16 as a local minimum in
best scenarios among reachable machines. I couldn't find any reasonable
method to estimate this value when BIRD starts up.

This commit also fixes the inaccurate computation of memory overhead for
slabs where the "system allocater overhead estimation" was improperly
added to the size of mmap-ed memory.
This commit is contained in:
Maria Matejka
2021-11-27 00:21:12 +01:00
parent 644e9ca94e
commit f772afc525
5 changed files with 98 additions and 35 deletions

View File

@@ -2,6 +2,7 @@
* BIRD Resource Manager
*
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
* (c) 2021 Maria Matejka <mq@jmq.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
@@ -37,7 +38,7 @@ struct pool {
static void pool_dump(resource *);
static void pool_free(resource *);
static resource *pool_lookup(resource *, unsigned long);
static size_t pool_memsize(resource *P);
static struct resmem pool_memsize(resource *P);
static struct resclass pool_class = {
"Pool",
@@ -97,15 +98,22 @@ pool_dump(resource *P)
indent -= 3;
}
static size_t
static struct resmem
pool_memsize(resource *P)
{
pool *p = (pool *) P;
resource *r;
size_t sum = sizeof(pool) + ALLOC_OVERHEAD;
struct resmem sum = {
.effective = 0,
.overhead = sizeof(pool) + ALLOC_OVERHEAD,
};
WALK_LIST(r, p->inside)
sum += rmemsize(r);
{
struct resmem add = rmemsize(r);
sum.effective += add.effective;
sum.overhead += add.overhead;
}
return sum;
}
@@ -193,14 +201,17 @@ rdump(void *res)
debug("NULL\n");
}
size_t
struct resmem
rmemsize(void *res)
{
resource *r = res;
if (!r)
return 0;
return (struct resmem) {};
if (!r->class->memsize)
return r->class->size + ALLOC_OVERHEAD;
return (struct resmem) {
.effective = r->class->size - sizeof(resource),
.overhead = ALLOC_OVERHEAD + sizeof(resource),
};
return r->class->memsize(r);
}
@@ -305,11 +316,14 @@ mbl_lookup(resource *r, unsigned long a)
return NULL;
}
static size_t
static struct resmem
mbl_memsize(resource *r)
{
struct mblock *m = (struct mblock *) r;
return ALLOC_OVERHEAD + sizeof(struct mblock) + m->size;
return (struct resmem) {
.effective = m->size,
.overhead = ALLOC_OVERHEAD + sizeof(struct mblock),
};
}
static struct resclass mb_class = {