From acb60628f53ba1fc29d1a554683acdb03f961c6f Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Wed, 2 Jun 2010 22:20:40 +0200 Subject: Implements command that shows memory usage. --- lib/slab.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'lib/slab.c') diff --git a/lib/slab.c b/lib/slab.c index 8cce52f..af6b50b 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) { -- cgit v1.2.3