Re: [RFC v2 PATCH] mm, sl[au]b: Introduce lockless cache

From: Hyeonggon Yoo
Date: Wed Sep 22 2021 - 05:12:05 EST


> @@ -491,13 +492,13 @@ void kmem_cache_free_cached(struct kmem_cache *s, void *p)
> cache = get_cpu_ptr(s->cache);
> if (cache->size < KMEM_LOCKLESS_CACHE_QUEUE_SIZE) {
> cache->queue[cache->size++] = p;
> - put_cpu_ptr(s->cache);
> - return ;
> + } else {
> + kmem_cache_free_bulk(s,
> + KMEM_LOCKLESS_CACHE_BATCHCOUNT,
> + cache->queue - KMEM_LOCKLESS_CACHE_BATCHCOUNT);
> + cache->size -= KMEM_LOCKLESS_CACHE_BATCHCOUNT;
> }
> put_cpu_ptr(s->cache);
> -
> - /* Is there better way to do this? */
> - kmem_cache_free(s, p);
> }
> EXPORT_SYMBOL(kmem_cache_free_cached);

Sent you a wrong code.

Above was buggy code from some hours ago
because of cache->queue - KMEM_LOCKLESS_CACHE_BATCHCOUNT.

So that is now:

cache = get_cpu_ptr(s->cache);
if (cache->size < KMEM_LOCKLESS_CACHE_QUEUE_SIZE) {
cache->queue[cache->size++] = p;
} else {
kmem_cache_free_bulk(s,
KMEM_LOCKLESS_CACHE_BATCHCOUNT,
cache->queue + KMEM_LOCKLESS_CACHE_QUEUE_SIZE
- KMEM_LOCKLESS_CACHE_BATCHCOUNT);
cache->size -= KMEM_LOCKLESS_CACHE_BATCHCOUNT;
}
put_cpu_ptr(s->cache);