alloc: fix new slab allocation
This commit is contained in:
parent
f90b9bd3fd
commit
f2b0edc5a3
11
core/alloc.c
11
core/alloc.c
@ -24,7 +24,7 @@ int allocInit(void)
|
|||||||
pr_devel("Fail to allocBookSlab %d for slabDesc :( \n");
|
pr_devel("Fail to allocBookSlab %d for slabDesc :( \n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
for (uint i = start; i < SLUB_SIZE; i++) {
|
for (uint i = start; i <= SLUB_SIZE; i++) {
|
||||||
if ((ret = allocBookSlab(1U << i, 0))) {
|
if ((ret = allocBookSlab(1U << i, 0))) {
|
||||||
pr_devel("Fail to allocBookSlab %d for %d \n", ret, (1U << i));
|
pr_devel("Fail to allocBookSlab %d for %d \n", ret, (1U << i));
|
||||||
return ret;
|
return ret;
|
||||||
@ -103,7 +103,7 @@ static void *allocFromSlab(struct slabDesc *slab)
|
|||||||
{
|
{
|
||||||
vaddr_t *next = slab->freeEl;
|
vaddr_t *next = slab->freeEl;
|
||||||
if (*next == (vaddr_t)NULL) {
|
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;
|
slab->full = 1;
|
||||||
} else {
|
} else {
|
||||||
slab->freeEl = (void *)(*next);
|
slab->freeEl = (void *)(*next);
|
||||||
@ -128,6 +128,10 @@ void *malloc(size_t size)
|
|||||||
int slabIdx;
|
int slabIdx;
|
||||||
list_foreach(slubEntry, slab, 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) {
|
if (!slab->full) {
|
||||||
pr_devel("found place in slub %d at idx %d for size %d\n", slubIdx,
|
pr_devel("found place in slub %d at idx %d for size %d\n", slubIdx,
|
||||||
slabIdx, size);
|
slabIdx, size);
|
||||||
@ -138,10 +142,11 @@ void *malloc(size_t size)
|
|||||||
// No room found
|
// No room found
|
||||||
struct slabDesc *newSlab;
|
struct slabDesc *newSlab;
|
||||||
int ret;
|
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);
|
pr_devel("Fail to addSlab %d\n", ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pr_devel("Allocate new slab for object of size %d\n", slubEntry->size);
|
||||||
list_add_head(slubEntry, newSlab);
|
list_add_head(slubEntry, newSlab);
|
||||||
return allocFromSlab(newSlab);
|
return allocFromSlab(newSlab);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user