alloc: fix some naming. alloc up to page_size

This commit is contained in:
Mathieu Maret 2019-04-17 23:46:56 +02:00
parent 06c8562a80
commit 340ae6a4d0

View File

@ -9,10 +9,11 @@
#define IS_SELF_CONTAINED(desc) ((vaddr_t)((desc)->page) == (vaddr_t)(desc))
// Slab will contains object from sizeof(void *) to PAGE_SIZE/2 by pow2
#define SLUB_SIZE (PAGE_SHIFT - 1)
#define SLUB_SIZE (PAGE_SHIFT)
struct slabDesc *slub;
int addSlab(struct slabDesc **desc, size_t size, int self_containing);
int allocSlab(struct slabDesc **desc, size_t size, int self_containing);
int allocSlabEntry(struct slabEntry **desc, size_t size, int selfContained);
static int formatPage(struct slabEntry *desc, size_t size, int selfContained);
int allocInit(void)
@ -55,7 +56,7 @@ int allocBookSlab(size_t size, int selfContained)
}
}
struct slabDesc *newSlab;
if ((ret = addSlab(&newSlab, size, selfContained)))
if ((ret = allocSlab(&newSlab, size, selfContained)))
return ret;
if (list_foreach_early_break(slub, slab, slabIdx)) {
list_insert_before(slub, slab, newSlab);
@ -65,7 +66,7 @@ int allocBookSlab(size_t size, int selfContained)
return 0;
}
int addSlab(struct slabDesc **desc, size_t size, int selfContained)
int allocSlab(struct slabDesc **desc, size_t size, int selfContained)
{
// pr_devel("%s for size %d is self %d\n", __func__, size, selfContained);
if (size > PAGE_SIZE)
@ -92,7 +93,7 @@ int addSlab(struct slabDesc **desc, size_t size, int selfContained)
return formatPage(&(*desc)->slab, size, selfContained);
}
int addSlabEntry(struct slabEntry **desc, size_t size, int selfContained)
int allocSlabEntry(struct slabEntry **desc, size_t size, int selfContained)
{
pr_devel("%s for size %d is self %d\n", __func__, size, selfContained);
if (size > PAGE_SIZE)
@ -173,8 +174,8 @@ void *malloc(size_t size)
struct slabEntry *newSlabEntry;
struct slabEntry *slabList = &slab->slab;
int ret;
if ((ret = addSlabEntry(&newSlabEntry, slab->size, IS_SELF_CONTAINED(&slab->slab)))) {
pr_devel("Fail to addSlabEntry %d\n", ret);
if ((ret = allocSlabEntry(&newSlabEntry, slab->size, IS_SELF_CONTAINED(&slab->slab)))) {
pr_devel("Fail to allocSlabEntry %d\n", ret);
return NULL;
}
pr_devel("Allocate new slab for object of size %d\n", slab->size);
@ -182,7 +183,7 @@ void *malloc(size_t size)
return allocFromSlab(newSlabEntry);
}
int slabFree(void *ptr, struct slabEntry *slab)
int freeFromSlab(void *ptr, struct slabEntry *slab)
{
struct slabEntry *slabEntry;
int slabIdx;
@ -212,7 +213,7 @@ void free(void *ptr)
int entryIdx;
list_foreach(&slab->slab, slabEntry, entryIdx)
{
if (slabFree(ptr, slabEntry))
if (freeFromSlab(ptr, slabEntry))
return;
}
}