summaryrefslogtreecommitdiff
path: root/lib/resource.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-11-27 00:21:12 +0100
committerMaria Matejka <mq@ucw.cz>2021-11-27 22:54:15 +0100
commitf772afc525156498900770ffe5a98349df89a45c (patch)
treefef3e68e487fb35335bdb14eb60821165b7dc066 /lib/resource.c
parent644e9ca94e2d10ba0c2de45f94523da2414328e3 (diff)
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.
Diffstat (limited to 'lib/resource.c')
-rw-r--r--lib/resource.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/resource.c b/lib/resource.c
index 4c4b92ec..5d4c7780 100644
--- a/lib/resource.c
+++ b/lib/resource.c
@@ -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 = {