forked from PoliEcho-holding-org/kern
partialy freelist madness
This commit is contained in:
+54
-3
@@ -6,7 +6,8 @@
|
|||||||
// this file contains SLUB inspired HEAP allocator
|
// this file contains SLUB inspired HEAP allocator
|
||||||
|
|
||||||
// TODO this will be an allocated array later when we have APIC MADT
|
// TODO this will be an allocated array later when we have APIC MADT
|
||||||
union per_cpu_freelist_cache freelists_all_cpus[1];
|
union freelists_list freelists_all_cpus[1];
|
||||||
|
union partialy_freelists_list partial_free_lists[1];
|
||||||
|
|
||||||
void* kcalloc(size_t count, size_t size) {
|
void* kcalloc(size_t count, size_t size) {
|
||||||
size_t size_to_alloc;
|
size_t size_to_alloc;
|
||||||
@@ -68,12 +69,62 @@ void* kmalloc(size_t size) {
|
|||||||
}
|
}
|
||||||
alloc_index -= LOWEST_POWER;
|
alloc_index -= LOWEST_POWER;
|
||||||
}
|
}
|
||||||
void** selected_freelist =
|
struct freelist* selected_freelist =
|
||||||
freelists_all_cpus[core_id].freelists[alloc_index];
|
freelists_all_cpus[core_id].freelists[alloc_index];
|
||||||
if (selected_freelist != NULL) {
|
if (selected_freelist != NULL) {
|
||||||
// fast path
|
// fast path
|
||||||
void** second_item_in_list = *selected_freelist;
|
if (selected_freelist->nextnode == NULL) {
|
||||||
|
freelists_all_cpus[core_id].freelists[alloc_index] =
|
||||||
|
NULL;
|
||||||
|
} else {
|
||||||
|
freelists_all_cpus[core_id].freelists[alloc_index] =
|
||||||
|
selected_freelist->nextnode;
|
||||||
|
}
|
||||||
|
return selected_freelist;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// slower path
|
// slower path
|
||||||
|
if (partial_free_lists[core_id]
|
||||||
|
.partialy_freelists[alloc_index] != NULL) {
|
||||||
|
// partialy freelist available
|
||||||
|
struct partialy_freelist* selected_partialy_freelist =
|
||||||
|
partial_free_lists[core_id]
|
||||||
|
.partialy_freelists[alloc_index];
|
||||||
|
|
||||||
|
if (selected_partialy_freelist->freelist_nextnode ==
|
||||||
|
NULL) {
|
||||||
|
// only one free object available
|
||||||
|
if (selected_partialy_freelist
|
||||||
|
->partialy_freelist_nextnode != NULL) {
|
||||||
|
// next partialy free list available
|
||||||
|
partial_free_lists[core_id]
|
||||||
|
.partialy_freelists[alloc_index] =
|
||||||
|
selected_partialy_freelist
|
||||||
|
->partialy_freelist_nextnode;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// no other partialy free list available
|
||||||
|
partial_free_lists[core_id]
|
||||||
|
.partialy_freelists[alloc_index] =
|
||||||
|
NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// multiple free objects available
|
||||||
|
partial_free_lists[core_id]
|
||||||
|
.partialy_freelists[alloc_index] =
|
||||||
|
selected_partialy_freelist
|
||||||
|
->partialy_freelist_nextnode;
|
||||||
|
|
||||||
|
freelists_all_cpus[core_id]
|
||||||
|
.freelists[alloc_index] =
|
||||||
|
selected_partialy_freelist
|
||||||
|
->freelist_nextnode;
|
||||||
|
}
|
||||||
|
return selected_partialy_freelist;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// slowest path
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user