alloc: fix some naming. alloc up to page_size
This commit is contained in:
parent
06c8562a80
commit
340ae6a4d0
19
core/alloc.c
19
core/alloc.c
@ -9,10 +9,11 @@
|
|||||||
|
|
||||||
#define IS_SELF_CONTAINED(desc) ((vaddr_t)((desc)->page) == (vaddr_t)(desc))
|
#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
|
// 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;
|
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);
|
static int formatPage(struct slabEntry *desc, size_t size, int selfContained);
|
||||||
|
|
||||||
int allocInit(void)
|
int allocInit(void)
|
||||||
@ -55,7 +56,7 @@ int allocBookSlab(size_t size, int selfContained)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct slabDesc *newSlab;
|
struct slabDesc *newSlab;
|
||||||
if ((ret = addSlab(&newSlab, size, selfContained)))
|
if ((ret = allocSlab(&newSlab, size, selfContained)))
|
||||||
return ret;
|
return ret;
|
||||||
if (list_foreach_early_break(slub, slab, slabIdx)) {
|
if (list_foreach_early_break(slub, slab, slabIdx)) {
|
||||||
list_insert_before(slub, slab, newSlab);
|
list_insert_before(slub, slab, newSlab);
|
||||||
@ -65,7 +66,7 @@ int allocBookSlab(size_t size, int selfContained)
|
|||||||
return 0;
|
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);
|
// pr_devel("%s for size %d is self %d\n", __func__, size, selfContained);
|
||||||
if (size > PAGE_SIZE)
|
if (size > PAGE_SIZE)
|
||||||
@ -92,7 +93,7 @@ int addSlab(struct slabDesc **desc, size_t size, int selfContained)
|
|||||||
return formatPage(&(*desc)->slab, size, 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);
|
pr_devel("%s for size %d is self %d\n", __func__, size, selfContained);
|
||||||
if (size > PAGE_SIZE)
|
if (size > PAGE_SIZE)
|
||||||
@ -173,8 +174,8 @@ void *malloc(size_t size)
|
|||||||
struct slabEntry *newSlabEntry;
|
struct slabEntry *newSlabEntry;
|
||||||
struct slabEntry *slabList = &slab->slab;
|
struct slabEntry *slabList = &slab->slab;
|
||||||
int ret;
|
int ret;
|
||||||
if ((ret = addSlabEntry(&newSlabEntry, slab->size, IS_SELF_CONTAINED(&slab->slab)))) {
|
if ((ret = allocSlabEntry(&newSlabEntry, slab->size, IS_SELF_CONTAINED(&slab->slab)))) {
|
||||||
pr_devel("Fail to addSlabEntry %d\n", ret);
|
pr_devel("Fail to allocSlabEntry %d\n", ret);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pr_devel("Allocate new slab for object of size %d\n", slab->size);
|
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);
|
return allocFromSlab(newSlabEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int slabFree(void *ptr, struct slabEntry *slab)
|
int freeFromSlab(void *ptr, struct slabEntry *slab)
|
||||||
{
|
{
|
||||||
struct slabEntry *slabEntry;
|
struct slabEntry *slabEntry;
|
||||||
int slabIdx;
|
int slabIdx;
|
||||||
@ -212,7 +213,7 @@ void free(void *ptr)
|
|||||||
int entryIdx;
|
int entryIdx;
|
||||||
list_foreach(&slab->slab, slabEntry, entryIdx)
|
list_foreach(&slab->slab, slabEntry, entryIdx)
|
||||||
{
|
{
|
||||||
if (slabFree(ptr, slabEntry))
|
if (freeFromSlab(ptr, slabEntry))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user