summaryrefslogtreecommitdiff
path: root/lib/resource.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-12-01 13:02:44 +0100
committerMaria Matejka <mq@ucw.cz>2021-12-01 13:04:52 +0100
commitb50224a00351904f25a5105a98d56a62ed2c33a4 (patch)
tree8478675603fd2a91fb4f36f8ac2e4ffd0ac20cd3 /lib/resource.c
parent55ee9961e0d130bb16b22b7b5acffd815f266d63 (diff)
parentf772afc525156498900770ffe5a98349df89a45c (diff)
Merge branch 'master' into HEAD
Diffstat (limited to 'lib/resource.c')
-rw-r--r--lib/resource.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/lib/resource.c b/lib/resource.c
index d98cd4ff..9a4c7717 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.
*/
@@ -33,7 +34,7 @@
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",
@@ -155,19 +156,26 @@ rp_dump(pool *p)
birdloop_leave(p->loop);
}
-static size_t
+static struct resmem
pool_memsize_locked(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;
}
-static size_t
+static struct resmem
pool_memsize(resource *P)
{
pool *p = (pool *) P;
@@ -178,7 +186,7 @@ pool_memsize(resource *P)
if (p->loop != parent->loop)
birdloop_enter(p->loop);
- size_t sum = pool_memsize_locked(p);
+ struct resmem sum = pool_memsize_locked(p);
if (p->loop != parent->loop)
birdloop_leave(p->loop);
@@ -188,7 +196,7 @@ pool_memsize(resource *P)
return sum;
}
-size_t
+struct resmem
rp_memsize(pool *p)
{
int inside = birdloop_inside(p->loop);
@@ -197,7 +205,7 @@ rp_memsize(pool *p)
ASSERT_DIE(pool_parent == NULL);
pool_parent = p;
- size_t sum = pool_memsize_locked(p);
+ struct resmem sum = pool_memsize_locked(p);
ASSERT_DIE(pool_parent == p);
pool_parent = NULL;
@@ -290,14 +298,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);
}
@@ -407,11 +418,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 = {