From 17404868a6074dc777736b4d0872dc03f93447fc Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Thu, 4 Sep 2014 16:19:37 +0400 Subject: [PATCH] Performance fix for mempool: renames. --- src/lib/small/mempool.c | 22 +++++++++++----------- src/lib/small/mempool.h | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/lib/small/mempool.c b/src/lib/small/mempool.c index 91c990c146..ae32cdf947 100644 --- a/src/lib/small/mempool.c +++ b/src/lib/small/mempool.c @@ -48,8 +48,8 @@ mslab_create(struct mslab *slab, struct mempool *pool) { slab->nfree = pool->objcount; slab->pool = pool; - slab->untouched_offset = 0; - slab->freed_list = 0; + slab->free_idx = 0; + slab->free_list = 0; /* A bit is set if a slot is free. */ memset(slab->map, 0xFF, sizeof(slab->map[0]) * pool->mapsize); } @@ -87,14 +87,14 @@ mslab_alloc(struct mslab *slab) assert(slab->nfree); void *result; uint32_t idx; - if (slab->freed_list) { - /* return pointer from garbage */ - idx = mslab_idx(slab, slab->freed_list); - result = slab->freed_list; - slab->freed_list = *(void **)slab->freed_list; + if (slab->free_list) { + /* Recycle an object from the garbage pool. */ + idx = mslab_idx(slab, slab->free_list); + result = slab->free_list; + slab->free_list = *(void **)slab->free_list; } else { - /* return pointer to new object */ - idx = slab->untouched_offset++; + /* Use an object from the "untouched" area of the slab. */ + idx = slab->free_idx++; result = mslab_obj(slab, idx); } @@ -114,8 +114,8 @@ void mslab_free(struct mempool *pool, struct mslab *slab, void *ptr) { /* put object to garbage list */ - *(void **)ptr = slab->freed_list; - slab->freed_list = ptr; + *(void **)ptr = slab->free_list; + slab->free_list = ptr; uint32_t idx = mslab_idx(slab, ptr); diff --git a/src/lib/small/mempool.h b/src/lib/small/mempool.h index d8bb012501..d465efa43c 100644 --- a/src/lib/small/mempool.h +++ b/src/lib/small/mempool.h @@ -93,10 +93,10 @@ enum { /** mslab - a standard slab formatted to store objects of equal size. */ struct mslab { struct slab slab; - /* Pointer to earlier freed list head */ - void *freed_list; - /** Offset of an object that was never allocated in mslab */ - uint32_t untouched_offset; + /* Head of a list of used but freed objects */ + void *free_list; + /** Index of an object that has never been allocated in mslab */ + uint32_t free_idx; /** Number of available slots in the slab. */ uint32_t nfree; /** Used if this slab is a member of free_slabs tree. */ -- GitLab