slab: Properly account for allocs from slabs
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 1 Aug 2017 20:03:20 +0000 (16:03 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 14 Aug 2017 21:02:19 +0000 (17:02 -0400)
Previously, we only counted the magazine allocations.  However, all of the
magazines are built from direct slab allocations, which we weren't
counting.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/mem.c
kern/include/slab.h
kern/src/slab.c

index a93b45b..7de9556 100644 (file)
@@ -302,6 +302,7 @@ static size_t fetch_slab_line(struct kmem_cache *kc, struct sized_alloc *sza,
                nr_unalloc_objs += s_i->num_total_obj;
        TAILQ_FOREACH(s_i, &kc->partial_slab_list, link)
                nr_unalloc_objs += s_i->num_total_obj - s_i->num_busy_obj;
                nr_unalloc_objs += s_i->num_total_obj;
        TAILQ_FOREACH(s_i, &kc->partial_slab_list, link)
                nr_unalloc_objs += s_i->num_total_obj - s_i->num_busy_obj;
+       nr_allocs_ever = kc->nr_direct_allocs_ever;
        spin_unlock_irqsave(&kc->cache_lock);
        /* Lockless peak at the pcpu state */
        for (int i = 0; i < kmc_nr_pcpu_caches(); i++) {
        spin_unlock_irqsave(&kc->cache_lock);
        /* Lockless peak at the pcpu state */
        for (int i = 0; i < kmc_nr_pcpu_caches(); i++) {
index 4d90556..28e89a7 100644 (file)
@@ -116,6 +116,7 @@ struct kmem_cache {
        void (*dtor)(void *obj, void *priv);
        void *priv;
        unsigned long nr_cur_alloc;
        void (*dtor)(void *obj, void *priv);
        void *priv;
        unsigned long nr_cur_alloc;
+       unsigned long nr_direct_allocs_ever;
        struct hash_helper hh;
        struct kmem_bufctl_list *alloc_hash;
        struct kmem_bufctl_list static_hash[HASH_INIT_SZ];
        struct hash_helper hh;
        struct kmem_bufctl_list *alloc_hash;
        struct kmem_bufctl_list static_hash[HASH_INIT_SZ];
index a9eab4a..4581bcb 100644 (file)
@@ -284,6 +284,7 @@ void __kmem_cache_create(struct kmem_cache *kc, const char *name,
        kc->dtor = dtor;
        kc->priv = priv;
        kc->nr_cur_alloc = 0;
        kc->dtor = dtor;
        kc->priv = priv;
        kc->nr_cur_alloc = 0;
+       kc->nr_direct_allocs_ever = 0;
        kc->alloc_hash = kc->static_hash;
        hash_init_hh(&kc->hh);
        for (int i = 0; i < kc->hh.nr_hash_lists; i++)
        kc->alloc_hash = kc->static_hash;
        hash_init_hh(&kc->hh);
        for (int i = 0; i < kc->hh.nr_hash_lists; i++)
@@ -542,6 +543,7 @@ static void *__kmem_alloc_from_slab(struct kmem_cache *cp, int flags)
                TAILQ_INSERT_HEAD(&cp->full_slab_list, a_slab, link);
        }
        cp->nr_cur_alloc++;
                TAILQ_INSERT_HEAD(&cp->full_slab_list, a_slab, link);
        }
        cp->nr_cur_alloc++;
+       cp->nr_direct_allocs_ever++;
        spin_unlock_irqsave(&cp->cache_lock);
        if (cp->ctor) {
                if (cp->ctor(retval, cp->priv, flags)) {
        spin_unlock_irqsave(&cp->cache_lock);
        if (cp->ctor) {
                if (cp->ctor(retval, cp->priv, flags)) {