Use mpool to allocate ocf_requests
Signed-off-by: Jan Musial <jan.musial@intel.com>
This commit is contained in:
parent
8e21aa6441
commit
c243ad3df0
@ -30,7 +30,7 @@ struct ocf_ctx {
|
|||||||
} core_pool;
|
} core_pool;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct ocf_req_allocator *req;
|
struct env_mpool *req;
|
||||||
} resources;
|
} resources;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,11 +32,6 @@ enum ocf_req_size {
|
|||||||
ocf_req_size_32,
|
ocf_req_size_32,
|
||||||
ocf_req_size_64,
|
ocf_req_size_64,
|
||||||
ocf_req_size_128,
|
ocf_req_size_128,
|
||||||
ocf_req_size_max,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ocf_req_allocator {
|
|
||||||
env_allocator *allocator[ocf_req_size_max];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline size_t ocf_req_sizeof_map(struct ocf_request *req)
|
static inline size_t ocf_req_sizeof_map(struct ocf_request *req)
|
||||||
@ -48,113 +43,31 @@ static inline size_t ocf_req_sizeof_map(struct ocf_request *req)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline size_t ocf_req_sizeof(uint32_t lines)
|
|
||||||
{
|
|
||||||
size_t size = sizeof(struct ocf_request) +
|
|
||||||
(lines * sizeof(struct ocf_map_info));
|
|
||||||
|
|
||||||
ENV_BUG_ON(lines == 0);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ALLOCATOR_NAME_FMT "ocf_req_%u"
|
|
||||||
/* Max number of digits in decimal representation of unsigned int is 10 */
|
|
||||||
#define ALLOCATOR_NAME_MAX (sizeof(ALLOCATOR_NAME_FMT) + 10)
|
|
||||||
|
|
||||||
int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx)
|
int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx)
|
||||||
{
|
{
|
||||||
int i;
|
ocf_ctx->resources.req = env_mpool_create(sizeof(struct ocf_request),
|
||||||
struct ocf_req_allocator *req;
|
sizeof(struct ocf_map_info), ENV_MEM_NORMAL, ocf_req_size_128,
|
||||||
char name[ALLOCATOR_NAME_MAX] = { '\0' };
|
false, NULL, "ocf_req");
|
||||||
ssize_t size;
|
|
||||||
|
|
||||||
OCF_DEBUG_TRACE(cache);
|
if (ocf_ctx->resources.req == NULL)
|
||||||
|
return -1;
|
||||||
ocf_ctx->resources.req = env_zalloc(sizeof(*(ocf_ctx->resources.req)),
|
|
||||||
ENV_MEM_NORMAL);
|
|
||||||
req = ocf_ctx->resources.req;
|
|
||||||
|
|
||||||
if (!req)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(req->allocator); i++) {
|
|
||||||
size = ocf_req_sizeof(1 << i);
|
|
||||||
|
|
||||||
if (snprintf(name, sizeof(name), ALLOCATOR_NAME_FMT,
|
|
||||||
(1 << i)) < 0) {
|
|
||||||
goto err;
|
|
||||||
}
|
|
||||||
|
|
||||||
req->allocator[i] = env_allocator_create(size, name);
|
|
||||||
|
|
||||||
if (!req->allocator[i])
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
OCF_DEBUG_PARAM(cache, "New request allocator, lines = %u, "
|
|
||||||
"size = %lu", 1 << i, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
|
||||||
ocf_req_allocator_deinit(ocf_ctx);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ocf_req_allocator_deinit(struct ocf_ctx *ocf_ctx)
|
void ocf_req_allocator_deinit(struct ocf_ctx *ocf_ctx)
|
||||||
{
|
{
|
||||||
int i;
|
env_mpool_destroy(ocf_ctx->resources.req);
|
||||||
struct ocf_req_allocator *req;
|
|
||||||
|
|
||||||
OCF_DEBUG_TRACE(cache);
|
|
||||||
|
|
||||||
|
|
||||||
if (!ocf_ctx->resources.req)
|
|
||||||
return;
|
|
||||||
|
|
||||||
req = ocf_ctx->resources.req;
|
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(req->allocator); i++) {
|
|
||||||
if (req->allocator[i]) {
|
|
||||||
env_allocator_destroy(req->allocator[i]);
|
|
||||||
req->allocator[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
env_free(req);
|
|
||||||
ocf_ctx->resources.req = NULL;
|
ocf_ctx->resources.req = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline env_allocator *_ocf_req_get_allocator_1(
|
|
||||||
struct ocf_cache *cache)
|
|
||||||
{
|
|
||||||
return cache->owner->resources.req->allocator[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
static env_allocator *_ocf_req_get_allocator(
|
|
||||||
struct ocf_cache *cache, uint32_t count)
|
|
||||||
{
|
|
||||||
struct ocf_ctx *ocf_ctx = cache->owner;
|
|
||||||
unsigned int idx = 31 - __builtin_clz(count);
|
|
||||||
|
|
||||||
if (__builtin_ffs(count) <= idx)
|
|
||||||
idx++;
|
|
||||||
|
|
||||||
ENV_BUG_ON(count == 0);
|
|
||||||
|
|
||||||
if (idx >= ocf_req_size_max)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return ocf_ctx->resources.req->allocator[idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
|
struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
|
||||||
uint64_t addr, uint32_t bytes, int rw)
|
uint64_t addr, uint32_t bytes, int rw)
|
||||||
{
|
{
|
||||||
uint64_t core_line_first, core_line_last, core_line_count;
|
uint64_t core_line_first, core_line_last, core_line_count;
|
||||||
ocf_cache_t cache = queue->cache;
|
ocf_cache_t cache = queue->cache;
|
||||||
struct ocf_request *req;
|
struct ocf_request *req;
|
||||||
env_allocator *allocator;
|
bool map_allocated = true;
|
||||||
|
|
||||||
if (likely(bytes)) {
|
if (likely(bytes)) {
|
||||||
core_line_first = ocf_bytes_2_lines(cache, addr);
|
core_line_first = ocf_bytes_2_lines(cache, addr);
|
||||||
@ -166,17 +79,17 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
|
|||||||
core_line_count = 1;
|
core_line_count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
allocator = _ocf_req_get_allocator(cache, core_line_count);
|
req = env_mpool_new(cache->owner->resources.req, core_line_count);
|
||||||
if (allocator) {
|
if (!req) {
|
||||||
req = env_allocator_new(allocator);
|
map_allocated = false;
|
||||||
} else {
|
req = env_mpool_new(cache->owner->resources.req, 1);
|
||||||
req = env_allocator_new(_ocf_req_get_allocator_1(cache));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (unlikely(!req))
|
if (unlikely(!req))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (allocator)
|
if (map_allocated)
|
||||||
req->map = req->__map;
|
req->map = req->__map;
|
||||||
|
|
||||||
OCF_DEBUG_TRACE(cache);
|
OCF_DEBUG_TRACE(cache);
|
||||||
@ -197,7 +110,6 @@ struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core,
|
|||||||
req->core_line_first = core_line_first;
|
req->core_line_first = core_line_first;
|
||||||
req->core_line_last = core_line_last;
|
req->core_line_last = core_line_last;
|
||||||
req->core_line_count = core_line_count;
|
req->core_line_count = core_line_count;
|
||||||
req->alloc_core_line_count = core_line_count;
|
|
||||||
req->rw = rw;
|
req->rw = rw;
|
||||||
req->part_id = PARTITION_DEFAULT;
|
req->part_id = PARTITION_DEFAULT;
|
||||||
|
|
||||||
@ -282,7 +194,6 @@ void ocf_req_get(struct ocf_request *req)
|
|||||||
|
|
||||||
void ocf_req_put(struct ocf_request *req)
|
void ocf_req_put(struct ocf_request *req)
|
||||||
{
|
{
|
||||||
env_allocator *allocator;
|
|
||||||
ocf_queue_t queue = req->io_queue;
|
ocf_queue_t queue = req->io_queue;
|
||||||
|
|
||||||
if (env_atomic_dec_return(&req->ref_count))
|
if (env_atomic_dec_return(&req->ref_count))
|
||||||
@ -293,13 +204,10 @@ void ocf_req_put(struct ocf_request *req)
|
|||||||
if (!req->d2c && req->io_queue != req->cache->mngt_queue)
|
if (!req->d2c && req->io_queue != req->cache->mngt_queue)
|
||||||
ocf_refcnt_dec(&req->cache->refcnt.metadata);
|
ocf_refcnt_dec(&req->cache->refcnt.metadata);
|
||||||
|
|
||||||
allocator = _ocf_req_get_allocator(req->cache,
|
if (!env_mpool_del(req->cache->owner->resources.req, req,
|
||||||
req->alloc_core_line_count);
|
req->core_line_count)) {
|
||||||
if (allocator) {
|
env_mpool_del(req->cache->owner->resources.req, req, 1);
|
||||||
env_allocator_del(allocator, req);
|
|
||||||
} else {
|
|
||||||
env_free(req->map);
|
env_free(req->map);
|
||||||
env_allocator_del(_ocf_req_get_allocator_1(req->cache), req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ocf_queue_put(queue);
|
ocf_queue_put(queue);
|
||||||
|
@ -166,9 +166,6 @@ struct ocf_request {
|
|||||||
uint32_t core_line_count;
|
uint32_t core_line_count;
|
||||||
/*! Core line count */
|
/*! Core line count */
|
||||||
|
|
||||||
uint32_t alloc_core_line_count;
|
|
||||||
/*! Core line count for which request was initially allocated */
|
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
/*!< This filed indicates an error for OCF request */
|
/*!< This filed indicates an error for OCF request */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user