Fix a bug in the slab allocator and improve the debugging output.
This commit is contained in:
parent
b052cc6740
commit
b84ee76c20
@ -53,8 +53,10 @@ SlabExtend(Slab *slab)
|
||||
inc = 4 * PGSIZE;
|
||||
}
|
||||
|
||||
if (!XMem_Allocate(slab->xmem, len + inc))
|
||||
if (!XMem_Allocate(slab->xmem, len + inc)) {
|
||||
kprintf("Slab: Cannot grow XMem region!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Add empty objects to linked list
|
||||
uintptr_t i;
|
||||
@ -82,8 +84,11 @@ Slab_Alloc(Slab *slab)
|
||||
SlabExtend(slab);
|
||||
|
||||
elem = LIST_FIRST(&slab->freeList);
|
||||
LIST_REMOVE(elem, free);
|
||||
slab->allocs++;
|
||||
if (elem != NULL) {
|
||||
LIST_REMOVE(elem, free);
|
||||
slab->allocs++;
|
||||
slab->freeObjs--;
|
||||
}
|
||||
|
||||
Spinlock_Unlock(&slab->lock);
|
||||
|
||||
@ -98,6 +103,7 @@ Slab_Free(Slab *slab, void *region)
|
||||
SlabElement *elem = (SlabElement *)region;
|
||||
LIST_INSERT_HEAD(&slab->freeList, elem, free);
|
||||
slab->frees++;
|
||||
slab->freeObjs++;
|
||||
|
||||
Spinlock_Unlock(&slab->lock);
|
||||
}
|
||||
@ -107,9 +113,9 @@ Debug_Slabs(int argc, const char *argv[])
|
||||
{
|
||||
Slab *slab;
|
||||
|
||||
kprintf("%-36s\n", "Slab Name");
|
||||
kprintf("%-36s %-10s %-10s\n", "Slab Name", "Free", "Total");
|
||||
LIST_FOREACH(slab, &slabList, slabList) {
|
||||
kprintf("%-36s\n", slab->name);
|
||||
kprintf("%-36s %-10lld %-10lld\n", slab->name, slab->freeObjs, slab->objs);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user