0

In Linux kernel, we have a function in mm/slab.c

static void *slab_get_obj(struct kmem_cache *cachep, struct slab
*slabp,
                                int nodeid) {
        void *objp = index_to_obj(cachep, slabp, slabp->free);
        kmem_bufctl_t next;

        slabp->inuse++;
        next = slab_bufctl(slabp)[slabp->free];
#if DEBUG
        slab_bufctl(slabp)[slabp->free] = BUFCTL_FREE;
        WARN_ON(slabp->nodeid != nodeid);
#endif
        slabp->free = next;

        return objp; }

Where,

static inline kmem_bufctl_t *slab_bufctl(struct slab *slabp)
{
        return (kmem_bufctl_t *) (slabp + 1);
}

I don't understand what slab_bufctl() does or how it finds the next free slab with it.

Joe
  • 7,378
  • 4
  • 37
  • 54
dspjm
  • 5,473
  • 6
  • 41
  • 62
  • It seems like `struct slab *slabp` is an array of `struct slab`. Hence, `(slabp + 1)` in `slab_bufctl` just returns the element next to `slabp`. – n3rd4n1 Jun 19 '13 at 08:28

1 Answers1

0

It seems like struct slab *slabp is an array of struct slab. Hence, (slabp + 1) in slab_bufctl() just returns the element next to slabp.

In addition, since slab_bufctl() returns the element as kmem_bufctl_t *, which is later accessed as an array, I think we can have a loose definition of struct slab as follows:

struct slab {
    kmem_bufctl_t *_name;
}
n3rd4n1
  • 371
  • 2
  • 8