summaryrefslogtreecommitdiffstats
path: root/lib/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/resource.c')
-rw-r--r--lib/resource.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/resource.c b/lib/resource.c
index 5ba23f1..24164ec 100644
--- a/lib/resource.c
+++ b/lib/resource.c
@@ -37,13 +37,15 @@ 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 resclass pool_class = {
"Pool",
sizeof(pool),
pool_free,
pool_dump,
- pool_lookup
+ pool_lookup,
+ pool_memsize
};
pool root_pool;
@@ -95,6 +97,19 @@ pool_dump(resource *P)
indent -= 3;
}
+static size_t
+pool_memsize(resource *P)
+{
+ pool *p = (pool *) P;
+ resource *r;
+ size_t sum = sizeof(pool) + ALLOC_OVERHEAD;
+
+ WALK_LIST(r, p->inside)
+ sum += rmemsize(r);
+
+ return sum;
+}
+
static resource *
pool_lookup(resource *P, unsigned long a)
{
@@ -177,6 +192,17 @@ rdump(void *res)
debug("NULL\n");
}
+size_t
+rmemsize(void *res)
+{
+ resource *r = res;
+ if (!r)
+ return 0;
+ if (!r->class->memsize)
+ return r->class->size + ALLOC_OVERHEAD;
+ return r->class->memsize(r);
+}
+
/**
* ralloc - create a resource
* @p: pool to create the resource in
@@ -277,12 +303,20 @@ mbl_lookup(resource *r, unsigned long a)
return NULL;
}
+static size_t
+mbl_memsize(resource *r)
+{
+ struct mblock *m = (struct mblock *) r;
+ return ALLOC_OVERHEAD + sizeof(struct mblock) + m->size;
+}
+
static struct resclass mb_class = {
"Memory",
0,
mbl_free,
mbl_debug,
- mbl_lookup
+ mbl_lookup,
+ mbl_memsize
};
/**