summaryrefslogtreecommitdiff
path: root/lib/slab.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2010-06-02 22:20:40 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2010-06-02 22:20:40 +0200
commitacb60628f53ba1fc29d1a554683acdb03f961c6f (patch)
treebe767e6d7995dee6708b7530b7dabe74d23b491e /lib/slab.c
parent4461b8979143bd13024663622c419646a1db0c85 (diff)
Implements command that shows memory usage.
Diffstat (limited to 'lib/slab.c')
-rw-r--r--lib/slab.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/slab.c b/lib/slab.c
index 8cce52fe..af6b50b0 100644
--- a/lib/slab.c
+++ b/lib/slab.c
@@ -41,6 +41,7 @@
static void slab_free(resource *r);
static void slab_dump(resource *r);
static resource *slab_lookup(resource *r, unsigned long addr);
+static size_t slab_memsize(resource *r);
#ifdef FAKE_SLAB
@@ -58,7 +59,8 @@ static struct resclass sl_class = {
"FakeSlab",
sizeof(struct slab),
slab_free,
- slab_dump
+ slab_dump,
+ slab_memsize
};
struct sl_obj {
@@ -116,6 +118,20 @@ slab_dump(resource *r)
debug("(%d objects per %d bytes)\n", cnt, s->size);
}
+static size_t
+slab_memsize(resource *r)
+{
+ slab *s = (slab *) r;
+ int cnt = 0;
+ struct sl_obj *o;
+
+ WALK_LIST(o, s->objs)
+ cnt++;
+
+ return ALLOC_OVERHEAD + sizeof(struct slab) + cnt * (ALLOC_OVERHEAD + s->size);
+}
+
+
#else
/*
@@ -136,7 +152,8 @@ static struct resclass sl_class = {
sizeof(struct slab),
slab_free,
slab_dump,
- slab_lookup
+ slab_lookup,
+ slab_memsize
};
struct sl_head {
@@ -324,6 +341,23 @@ slab_dump(resource *r)
debug("(%de+%dp+%df blocks per %d objs per %d bytes)\n", ec, pc, fc, s->objs_per_slab, s->obj_size);
}
+static size_t
+slab_memsize(resource *r)
+{
+ slab *s = (slab *) r;
+ int heads = 0;
+ struct sl_head *h;
+
+ WALK_LIST(h, s->empty_heads)
+ heads++;
+ WALK_LIST(h, s->partial_heads)
+ heads++;
+ WALK_LIST(h, s->full_heads)
+ heads++;
+
+ return ALLOC_OVERHEAD + sizeof(struct slab) + heads * (ALLOC_OVERHEAD + SLAB_SIZE);
+}
+
static resource *
slab_lookup(resource *r, unsigned long a)
{