Use new non-zeroing allocator APIs
Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
parent
68fccaf9ae
commit
f25d9a8e40
36
env/posix/ocf_env.c
vendored
36
env/posix/ocf_env.c
vendored
@ -17,6 +17,9 @@ struct _env_allocator {
|
||||
|
||||
/*!< Number of currently allocated items in pool */
|
||||
env_atomic count;
|
||||
|
||||
/*!< Should buffer be zeroed while allocating */
|
||||
bool zero;
|
||||
};
|
||||
|
||||
static inline size_t env_allocator_align(size_t size)
|
||||
@ -36,21 +39,26 @@ void *env_allocator_new(env_allocator *allocator)
|
||||
{
|
||||
struct _env_allocator_item *item = NULL;
|
||||
|
||||
item = calloc(1, allocator->item_size);
|
||||
item = malloc(allocator->item_size);
|
||||
|
||||
if (item) {
|
||||
item->cpu = 0;
|
||||
env_atomic_inc(&allocator->count);
|
||||
if (!item) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (allocator->zero) {
|
||||
memset(item, 0, allocator->item_size);
|
||||
}
|
||||
|
||||
item->cpu = 0;
|
||||
item->flags = 0;
|
||||
env_atomic_inc(&allocator->count);
|
||||
|
||||
return &item->data;
|
||||
}
|
||||
|
||||
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...)
|
||||
env_allocator *env_allocator_create(uint32_t size, const char *name, bool zero)
|
||||
{
|
||||
char name[OCF_ALLOCATOR_NAME_MAX] = { '\0' };
|
||||
int result, error = -1;
|
||||
va_list args;
|
||||
int error = -1;
|
||||
|
||||
env_allocator *allocator = calloc(1, sizeof(*allocator));
|
||||
if (!allocator) {
|
||||
@ -59,24 +67,14 @@ env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...)
|
||||
}
|
||||
|
||||
allocator->item_size = size + sizeof(struct _env_allocator_item);
|
||||
allocator->zero = zero;
|
||||
|
||||
/* Format allocator name */
|
||||
va_start(args, fmt_name);
|
||||
result = vsnprintf(name, sizeof(name), fmt_name, args);
|
||||
va_end(args);
|
||||
|
||||
if ((result > 0) && (result < sizeof(name))) {
|
||||
allocator->name = strdup(name);
|
||||
|
||||
if (!allocator->name) {
|
||||
error = __LINE__;
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
/* Formated string name exceed max allowed size of name */
|
||||
error = __LINE__;
|
||||
goto err;
|
||||
}
|
||||
|
||||
return allocator;
|
||||
|
||||
|
6
env/posix/ocf_env.h
vendored
6
env/posix/ocf_env.h
vendored
@ -200,10 +200,10 @@ static inline uint64_t env_get_free_memory(void)
|
||||
/* ALLOCATOR */
|
||||
typedef struct _env_allocator env_allocator;
|
||||
|
||||
env_allocator *env_allocator_create(uint32_t size, const char *fmt_name, ...);
|
||||
env_allocator *env_allocator_create(uint32_t size, const char *name, bool zero);
|
||||
|
||||
#define env_allocator_create_extended(size, fmt_name, limit) \
|
||||
env_allocator_create(size, fmt_name)
|
||||
#define env_allocator_create_extended(size, name, limit, zero) \
|
||||
env_allocator_create(size, name, zero)
|
||||
|
||||
void env_allocator_destroy(env_allocator *allocator);
|
||||
|
||||
|
6
env/posix/utils_mpool.c
vendored
6
env/posix/utils_mpool.c
vendored
@ -29,7 +29,8 @@ struct env_mpool {
|
||||
struct env_mpool *env_mpool_create(uint32_t hdr_size, uint32_t elem_size,
|
||||
int flags, int mpool_max, bool fallback,
|
||||
const uint32_t limits[env_mpool_max],
|
||||
const char *name_perfix)
|
||||
const char *name_perfix,
|
||||
bool zero)
|
||||
{
|
||||
uint32_t i;
|
||||
char name[MPOOL_ALLOCATOR_NAME_MAX] = { '\0' };
|
||||
@ -56,7 +57,8 @@ struct env_mpool *env_mpool_create(uint32_t hdr_size, uint32_t elem_size,
|
||||
size = hdr_size + (elem_size * (1 << i));
|
||||
|
||||
mpool->allocator[i] = env_allocator_create_extended(
|
||||
size, name, limits ? limits[i] : -1);
|
||||
size, name, limits ? limits[i] : -1,
|
||||
zero);
|
||||
|
||||
if (!mpool->allocator[i])
|
||||
goto err;
|
||||
|
2
env/posix/utils_mpool.h
vendored
2
env/posix/utils_mpool.h
vendored
@ -44,7 +44,7 @@ struct env_mpool;
|
||||
struct env_mpool *env_mpool_create(uint32_t hdr_size, uint32_t elem_size,
|
||||
int flags, int mpool_max, bool fallback,
|
||||
const uint32_t limits[env_mpool_max],
|
||||
const char *name_perfix);
|
||||
const char *name_perfix, bool zero);
|
||||
|
||||
/**
|
||||
* @brief Destroy existing memory pool
|
||||
|
@ -108,7 +108,7 @@ int ocf_cache_line_concurrency_init(struct ocf_cache_line_concurrency **self,
|
||||
goto allocation_err;
|
||||
}
|
||||
|
||||
c->allocator = env_allocator_create(sizeof(struct __waiter), name);
|
||||
c->allocator = env_allocator_create(sizeof(struct __waiter), name, false);
|
||||
if (!c->allocator) {
|
||||
error = __LINE__;
|
||||
goto allocation_err;
|
||||
|
@ -492,7 +492,8 @@ int ocf_metadata_io_ctx_init(struct ocf_ctx *ocf_ctx)
|
||||
sizeof(struct metadata_io_request),
|
||||
ENV_MEM_NOIO, ocf_mio_size_max - 1, true,
|
||||
limits,
|
||||
"ocf_mio");
|
||||
"ocf_mio",
|
||||
true);
|
||||
if (ocf_ctx->resources.mio == NULL)
|
||||
return -1;
|
||||
|
||||
|
@ -34,7 +34,8 @@
|
||||
static int ocf_io_allocator_default_init(ocf_io_allocator_t allocator,
|
||||
uint32_t priv_size, const char *name)
|
||||
{
|
||||
allocator->priv = env_allocator_create(OCF_IO_TOTAL(priv_size), name);
|
||||
allocator->priv = env_allocator_create(OCF_IO_TOTAL(priv_size), name,
|
||||
true);
|
||||
if (!allocator->priv)
|
||||
return -OCF_ERR_NO_MEM;
|
||||
|
||||
|
@ -47,7 +47,7 @@ int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx)
|
||||
{
|
||||
ocf_ctx->resources.req = env_mpool_create(sizeof(struct ocf_request),
|
||||
sizeof(struct ocf_map_info), ENV_MEM_NORMAL, ocf_req_size_128,
|
||||
false, NULL, "ocf_req");
|
||||
false, NULL, "ocf_req", true);
|
||||
|
||||
if (ocf_ctx->resources.req == NULL)
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user