Remove mpool from OCF utils
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
parent
b1321edf69
commit
cda536a14a
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "ocf_def.h"
|
#include "ocf_def.h"
|
||||||
#include "ocf_types.h"
|
#include "ocf_types.h"
|
||||||
#include "ocf_utilities.h"
|
|
||||||
#include "ocf_io.h"
|
#include "ocf_io.h"
|
||||||
#include "ocf_volume.h"
|
#include "ocf_volume.h"
|
||||||
#include "ocf_cache.h"
|
#include "ocf_cache.h"
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright(c) 2012-2018 Intel Corporation
|
|
||||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __OCF_UTILITIES_H__
|
|
||||||
#define __OCF_UTILITIES_H__
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief OCF memory pool reference
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct ocf_mpool;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Create OCF memory pool
|
|
||||||
*
|
|
||||||
* @param cache OCF cache instance
|
|
||||||
* @param size Size of particular item
|
|
||||||
* @param hdr_size Header size before array of items
|
|
||||||
* @param flags Allocation flags
|
|
||||||
* @param mpool_max Maximal allocator size (power of two)
|
|
||||||
* @param fmt_name Format name of allocator
|
|
||||||
* @param ... Format parameters
|
|
||||||
*
|
|
||||||
* @return OCF memory pool reference
|
|
||||||
*/
|
|
||||||
struct ocf_mpool *ocf_mpool_create(struct ocf_cache *cache,
|
|
||||||
uint32_t hdr_size, uint32_t size, int flags, int mpool_max,
|
|
||||||
const char *name_perfix);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Destroy existing memory pool
|
|
||||||
*
|
|
||||||
* @param mpool memory pool
|
|
||||||
*/
|
|
||||||
void ocf_mpool_destroy(struct ocf_mpool *mpool);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Allocate new items of memory pool
|
|
||||||
*
|
|
||||||
* @note Allocation based on ATOMIC memory pool and this function can be called
|
|
||||||
* when IRQ disable
|
|
||||||
*
|
|
||||||
* @param mpool OCF memory pool reference
|
|
||||||
* @param count Count of elements to be allocated
|
|
||||||
*
|
|
||||||
* @return Pointer to the new items
|
|
||||||
*/
|
|
||||||
void *ocf_mpool_new(struct ocf_mpool *mpool, uint32_t count);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Allocate new items of memory pool with specified allocation flag
|
|
||||||
*
|
|
||||||
* @param mpool OCF memory pool reference
|
|
||||||
* @param count Count of elements to be allocated
|
|
||||||
* @param flags Kernel allocation falgs
|
|
||||||
*
|
|
||||||
* @return Pointer to the new items
|
|
||||||
*/
|
|
||||||
void *ocf_mpool_new_f(struct ocf_mpool *mpool, uint32_t count, int flags);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Free existing items of memory pool
|
|
||||||
*
|
|
||||||
* @param mpool OCF memory pool reference
|
|
||||||
* @param items Items to be freed
|
|
||||||
* @param count - Count of elements to be free
|
|
||||||
*/
|
|
||||||
void ocf_mpool_del(struct ocf_mpool *mpool, void *items, uint32_t count);
|
|
||||||
|
|
||||||
#endif /* __OCF_UTILITIES_H__ */
|
|
@ -4,8 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "ocf/ocf.h"
|
#include "ocf/ocf.h"
|
||||||
#include "utils_allocator.h"
|
#include "utils_allocator.h"
|
||||||
#include "../ocf_priv.h"
|
|
||||||
#include "../ocf_cache_priv.h"
|
|
||||||
#include "ocf_env.h"
|
#include "ocf_env.h"
|
||||||
|
|
||||||
#define OCF_ALLOCATOR_K_MAX (128 * KiB)
|
#define OCF_ALLOCATOR_K_MAX (128 * KiB)
|
||||||
@ -117,151 +115,3 @@ void ocf_realloc_init(void **mem, size_t *limit)
|
|||||||
*mem = NULL;
|
*mem = NULL;
|
||||||
*((size_t *)limit) = 0;
|
*((size_t *)limit) = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
|
||||||
ocf_mpool_1,
|
|
||||||
ocf_mpool_2,
|
|
||||||
ocf_mpool_4,
|
|
||||||
ocf_mpool_8,
|
|
||||||
ocf_mpool_16,
|
|
||||||
ocf_mpool_32,
|
|
||||||
ocf_mpool_64,
|
|
||||||
ocf_mpool_128,
|
|
||||||
|
|
||||||
ocf_mpool_max
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ocf_mpool {
|
|
||||||
struct ocf_cache *cache;
|
|
||||||
/*!< Cache instance */
|
|
||||||
|
|
||||||
uint32_t item_size;
|
|
||||||
/*!< Size of specific item of memory pool */
|
|
||||||
|
|
||||||
uint32_t hdr_size;
|
|
||||||
/*!< Header size before items */
|
|
||||||
|
|
||||||
env_allocator *allocator[ocf_mpool_max];
|
|
||||||
/*!< OS handle to memory pool */
|
|
||||||
|
|
||||||
int flags;
|
|
||||||
/*!< Allocation flags */
|
|
||||||
};
|
|
||||||
|
|
||||||
#define ALLOCATOR_NAME_MAX 128
|
|
||||||
|
|
||||||
struct ocf_mpool *ocf_mpool_create(struct ocf_cache *cache,
|
|
||||||
uint32_t hdr_size, uint32_t size, int flags, int mpool_max,
|
|
||||||
const char *name_perfix)
|
|
||||||
{
|
|
||||||
uint32_t i;
|
|
||||||
char name[ALLOCATOR_NAME_MAX] = { '\0' };
|
|
||||||
int result;
|
|
||||||
struct ocf_mpool *mpool;
|
|
||||||
|
|
||||||
OCF_CHECK_NULL(name_perfix);
|
|
||||||
|
|
||||||
mpool = env_zalloc(sizeof(*mpool), ENV_MEM_NORMAL);
|
|
||||||
if (!mpool)
|
|
||||||
goto ocf_multi_allocator_create_ERROR;
|
|
||||||
|
|
||||||
mpool->item_size = size;
|
|
||||||
mpool->hdr_size = hdr_size;
|
|
||||||
mpool->cache = cache;
|
|
||||||
mpool->flags = flags;
|
|
||||||
|
|
||||||
for (i = 0; i < OCF_MIN(ocf_mpool_max, mpool_max + 1); i++) {
|
|
||||||
result = snprintf(name, sizeof(name), "%s_%u", name_perfix,
|
|
||||||
(1 << i));
|
|
||||||
if (result < 0 || result >= sizeof(name))
|
|
||||||
goto ocf_multi_allocator_create_ERROR;
|
|
||||||
|
|
||||||
mpool->allocator[i] = env_allocator_create(
|
|
||||||
hdr_size + (size * (1 << i)), name);
|
|
||||||
|
|
||||||
if (!mpool->allocator[i])
|
|
||||||
goto ocf_multi_allocator_create_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mpool;
|
|
||||||
|
|
||||||
ocf_multi_allocator_create_ERROR:
|
|
||||||
|
|
||||||
ocf_mpool_destroy(mpool);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ocf_mpool_destroy(struct ocf_mpool *mallocator)
|
|
||||||
{
|
|
||||||
if (mallocator) {
|
|
||||||
uint32_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < ocf_mpool_max; i++)
|
|
||||||
if (mallocator->allocator[i])
|
|
||||||
env_allocator_destroy(mallocator->allocator[i]);
|
|
||||||
|
|
||||||
env_free(mallocator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static env_allocator *ocf_mpool_get_allocator(
|
|
||||||
struct ocf_mpool *mallocator, uint32_t count)
|
|
||||||
{
|
|
||||||
unsigned int idx;
|
|
||||||
|
|
||||||
if (unlikely(count == 0))
|
|
||||||
return ocf_mpool_1;
|
|
||||||
|
|
||||||
idx = 31 - __builtin_clz(count);
|
|
||||||
|
|
||||||
if (__builtin_ffs(count) <= idx)
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
if (idx >= ocf_mpool_max)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return mallocator->allocator[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
void *ocf_mpool_new_f(struct ocf_mpool *mpool, uint32_t count, int flags)
|
|
||||||
{
|
|
||||||
void *items = NULL;
|
|
||||||
env_allocator *allocator;
|
|
||||||
|
|
||||||
OCF_CHECK_NULL(mpool);
|
|
||||||
|
|
||||||
allocator = ocf_mpool_get_allocator(mpool, count);
|
|
||||||
|
|
||||||
if (allocator)
|
|
||||||
items = env_allocator_new(allocator);
|
|
||||||
else
|
|
||||||
items = env_zalloc(mpool->hdr_size + (mpool->item_size * count), flags);
|
|
||||||
|
|
||||||
#ifdef ZERO_OR_NULL_PTR
|
|
||||||
if (ZERO_OR_NULL_PTR(items))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *ocf_mpool_new(struct ocf_mpool *mpool, uint32_t count)
|
|
||||||
{
|
|
||||||
return ocf_mpool_new_f(mpool, count, mpool->flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ocf_mpool_del(struct ocf_mpool *mpool,
|
|
||||||
void *items, uint32_t count)
|
|
||||||
{
|
|
||||||
env_allocator *allocator;
|
|
||||||
|
|
||||||
OCF_CHECK_NULL(mpool);
|
|
||||||
|
|
||||||
allocator = ocf_mpool_get_allocator(mpool, count);
|
|
||||||
|
|
||||||
if (allocator)
|
|
||||||
env_allocator_del(allocator, items);
|
|
||||||
else
|
|
||||||
env_free(items);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user