bdev/ocf: synchronize env_allocator creation

Make modyfication of global allocator index tread safe
  by using atomic operation

This patch also changes mempool size to be 2^n - 1
  which makes it more efficient

Change-Id: I5b7426f2feef31471d3a4e6c6d2c7f7474200d68
Signed-off-by: Vitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/442695
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Vitaliy Mysak 2019-01-30 17:15:54 +00:00 committed by Jim Harris
parent 885bc99596
commit 08e4ced116

View File

@ -38,16 +38,16 @@
#include "spdk_internal/log.h"
/* Number of buffers for mempool
* Need to be power of two
* Need to be power of two - 1 for better memory utilization
* It depends on memory usage of OCF which
* in itself depends on the workload
* It is a big number because OCF uses allocators
* for every request it sends and recieves
*/
#define ENV_ALLOCATOR_NBUFS 32768
#define ENV_ALLOCATOR_NBUFS 32767
/* Use unique index for env allocators */
static int g_env_allocator_index = 0;
static env_atomic g_env_allocator_index = 0;
void *
env_allocator_new(env_allocator *allocator)
@ -61,7 +61,7 @@ env_allocator_create(uint32_t size, const char *name)
env_allocator *allocator;
char qualified_name[128] = {0};
snprintf(qualified_name, 128, "ocf_env_%d", g_env_allocator_index++);
snprintf(qualified_name, 128, "ocf_env_%d", env_atomic_inc_return(&g_env_allocator_index));
allocator = spdk_mempool_create(qualified_name,
ENV_ALLOCATOR_NBUFS, size,