Commit b949f131 authored by Michal Mielewczyk's avatar Michal Mielewczyk Committed by Jim Harris
Browse files

ocf: Added zeroing memory returned from mempool



OCF requires memory retrived from mempool to be filled with zeros.

When mempool is created, information about element size is stored to be used
when new memory is retrived.

This is fix for issue #671

Signed-off-by: default avatarMichal Mielewczyk <michal.mielewczyk@intel.com>
Change-Id: Ieb533e3bdae0665dae18e7b3a379da0ed843c35a
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/449155


Reviewed-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent b6abc16b
Loading
Loading
Loading
Loading
+27 −8
Original line number Diff line number Diff line
@@ -52,7 +52,13 @@ static env_atomic g_env_allocator_index = 0;
void *
env_allocator_new(env_allocator *allocator)
{
	return spdk_mempool_get(allocator);
	void *mem = spdk_mempool_get(allocator->mempool);

	if (spdk_likely(mem)) {
		memset(mem, 0, allocator->element_size);
	}

	return mem;
}

env_allocator *
@@ -63,30 +69,43 @@ env_allocator_create(uint32_t size, const char *name)

	snprintf(qualified_name, 128, "ocf_env_%d", env_atomic_inc_return(&g_env_allocator_index));

	allocator = spdk_mempool_create(qualified_name,
	allocator = calloc(1, sizeof(*allocator));
	if (!allocator) {
		return NULL;
	}

	allocator->mempool = spdk_mempool_create(qualified_name,
			     ENV_ALLOCATOR_NBUFS, size,
			     SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
			     SPDK_ENV_SOCKET_ID_ANY);

	if (!allocator->mempool) {
		free(allocator);
		return NULL;
	}

	allocator->element_size = size;

	return allocator;
}

void
env_allocator_del(env_allocator *allocator, void *item)
{
	spdk_mempool_put(allocator, item);
	spdk_mempool_put(allocator->mempool, item);
}

void
env_allocator_destroy(env_allocator *allocator)
{
	if (allocator) {
		if (ENV_ALLOCATOR_NBUFS - spdk_mempool_count(allocator)) {
		if (ENV_ALLOCATOR_NBUFS - spdk_mempool_count(allocator->mempool)) {
			SPDK_ERRLOG("Not all objects deallocated\n");
			assert(false);
		}

		spdk_mempool_free(allocator);
		spdk_mempool_free(allocator->mempool);
		free(allocator);
	}
}

+4 −1
Original line number Diff line number Diff line
@@ -155,7 +155,10 @@ static inline uint64_t env_get_free_memory(void)

#define OCF_ALLOCATOR_NAME_MAX 128

typedef struct spdk_mempool env_allocator;
typedef struct {
	struct spdk_mempool *mempool;
	size_t element_size;
} env_allocator;

env_allocator *env_allocator_create(uint32_t size, const char *name);