Lines Matching refs:slab

23  *	Create's a slab for a single type of object in the kernel.
25 * @param [in] slab Slab that the object belongs to.
31 Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
35 slab->objsz = objsz;
36 slab->align = align;
37 slab->xmem = XMem_New();
38 slab->objs = 0;
39 slab->freeObjs = 0;
40 slab->allocs = 0;
41 slab->frees = 0;
42 LIST_INIT(&slab->freeList);
44 ASSERT(slab->xmem != NULL);
46 strncpy(&slab->name[0], name, SLAB_NAMELEN);
48 Spinlock_Init(&slab->lock, name, SPINLOCK_TYPE_NORMAL);
50 LIST_INSERT_HEAD(&slabList, slab, slabList);
56 * Grow the slab to allocate new objects.
58 * @param [in] slab Slab that we want to expand.
59 * @retval -1 Failed to expand the slab.
63 SlabExtend(Slab *slab)
65 uintptr_t base = XMem_GetBase(slab->xmem);
66 uintptr_t len = XMem_GetLength(slab->xmem);
68 uintptr_t realObjSz = ROUNDUP(slab->objsz, slab->align);
75 if (!XMem_Allocate(slab->xmem, len + inc)) {
86 LIST_INSERT_HEAD(&slab->freeList, elem, free);
89 slab->objs += objs;
90 slab->freeObjs += objs;
98 * Free a slab object.
100 * @param [in] slab Slab that the object belongs to.
105 Slab_Alloc(Slab *slab)
109 Spinlock_Lock(&slab->lock);
111 if (slab->freeObjs == 0)
112 SlabExtend(slab);
114 elem = LIST_FIRST(&slab->freeList);
117 slab->allocs++;
118 slab->freeObjs--;
121 Spinlock_Unlock(&slab->lock);
129 * Free a slab object.
131 * @param [in] slab Slab that the object belongs to.
135 Slab_Free(Slab *slab, void *region)
137 Spinlock_Lock(&slab->lock);
140 LIST_INSERT_HEAD(&slab->freeList, elem, free);
141 slab->frees++;
142 slab->freeObjs++;
144 Spinlock_Unlock(&slab->lock);
150 Slab *slab;
153 LIST_FOREACH(slab, &slabList, slabList) {
154 kprintf("%-36s %-10lld %-10lld %-10lld\n", slab->name,
155 slab->objs - slab->freeObjs, slab->freeObjs, slab->objs);