From 08e4ced116451c6476371db12525cbdb64495b38 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Wed, 30 Jan 2019 17:15:54 +0000 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/442695 Tested-by: SPDK CI Jenkins Reviewed-by: Darek Stojaczyk Reviewed-by: Ben Walker Reviewed-by: Jim Harris --- lib/bdev/ocf/env/ocf_env.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/bdev/ocf/env/ocf_env.c b/lib/bdev/ocf/env/ocf_env.c index 6fa9589d0..acbcecdbd 100644 --- a/lib/bdev/ocf/env/ocf_env.c +++ b/lib/bdev/ocf/env/ocf_env.c @@ -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,