alloc: fix new slab allocation

This commit is contained in:
Mathieu Maret 2019-04-16 21:04:32 +02:00
parent f90b9bd3fd
commit f2b0edc5a3
1 changed files with 8 additions and 3 deletions

View File

@ -24,7 +24,7 @@ int allocInit(void)
pr_devel("Fail to allocBookSlab %d for slabDesc :( \n");
return ret;
}
for (uint i = start; i < SLUB_SIZE; i++) {
for (uint i = start; i <= SLUB_SIZE; i++) {
if ((ret = allocBookSlab(1U << i, 0))) {
pr_devel("Fail to allocBookSlab %d for %d \n", ret, (1U << i));
return ret;
@ -103,7 +103,7 @@ static void *allocFromSlab(struct slabDesc *slab)
{
vaddr_t *next = slab->freeEl;
if (*next == (vaddr_t)NULL) {
pr_devel("Slab @%d for %d full\n", slab, slab->size);
pr_devel("Slab @%d for %d is now full\n", slab, slab->size);
slab->full = 1;
} else {
slab->freeEl = (void *)(*next);
@ -128,6 +128,10 @@ void *malloc(size_t size)
int slabIdx;
list_foreach(slubEntry, slab, slabIdx)
{
if (slab->size > slubEntry->size){
pr_devel("No more room in slub %d\n", slubIdx);
break;
}
if (!slab->full) {
pr_devel("found place in slub %d at idx %d for size %d\n", slubIdx,
slabIdx, size);
@ -138,10 +142,11 @@ void *malloc(size_t size)
// No room found
struct slabDesc *newSlab;
int ret;
if ((ret = addSlab(&newSlab, slab->size, IS_SELF_CONTAINED(slubEntry)))) {
if ((ret = addSlab(&newSlab, slubEntry->size, IS_SELF_CONTAINED(slubEntry)))) {
pr_devel("Fail to addSlab %d\n", ret);
return NULL;
}
pr_devel("Allocate new slab for object of size %d\n", slubEntry->size);
list_add_head(slubEntry, newSlab);
return allocFromSlab(newSlab);
}