kmalloc cache: embed cache pointer into kmalloc_header

Conflicts:
	kernel/mem.c
This commit is contained in:
Balazs Gerofi
2017-08-24 17:35:51 +09:00
parent 4dea1842e0
commit a65faeaed4

View File

@ -2613,67 +2613,3 @@ int ihk_mc_get_mem_user_page(void *arg0, page_table_t pt, pte_t *ptep, void *pga
return 0;
}
/*
* Generic lockless kmalloc cache.
*/
void kmalloc_cache_prealloc(struct kmalloc_cache_header *cache,
size_t size)
{
struct kmalloc_cache_header *first;
int i;
kprintf("%s: pre-allocating for 0x%lx...\n",
__FUNCTION__, cache);
for (i = 0; i < 128; ++i) {
first = (struct kmalloc_cache_header *)
kmalloc(size, IHK_MC_AP_NOWAIT);
if (!first) {
kprintf("%s: ERROR: allocating cache element\n", __FUNCTION__);
continue;
}
kmalloc_cache_free(cache, first);
}
}
void *kmalloc_cache_alloc(struct kmalloc_cache_header *cache,
size_t size)
{
struct kmalloc_cache_header *first, *next;
retry:
next = NULL;
first = cache->next;
if (first) {
next = first->next;
if (!__sync_bool_compare_and_swap(&cache->next,
first, next)) {
goto retry;
}
}
else {
kmalloc_cache_prealloc(cache, size);
goto retry;
}
return (void *)first;
}
void kmalloc_cache_free(struct kmalloc_cache_header *cache, void *elem)
{
struct kmalloc_cache_header *current = NULL;
struct kmalloc_cache_header *new =
(struct kmalloc_cache_header *)elem;
retry:
current = cache->next;
new->next = current;
if (!__sync_bool_compare_and_swap(&cache->next, current, new)) {
goto retry;
}
}