Merge pull request #216 from robertbaldyga/io-and-req-in-single-allocation
Allocate io and req in single allocation
This commit is contained in:
@@ -270,16 +270,14 @@ static int _ocf_cleaner_fire_flush_cache(struct ocf_request *req)
|
||||
|
||||
OCF_DEBUG_TRACE(req->cache);
|
||||
|
||||
io = ocf_volume_new_io(&req->cache->device->volume);
|
||||
io = ocf_new_cache_io(req->cache, req->io_queue, 0, 0, OCF_WRITE, 0, 0);
|
||||
if (!io) {
|
||||
ocf_metadata_error(req->cache);
|
||||
req->error = -OCF_ERR_NO_MEM;
|
||||
return -OCF_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
|
||||
ocf_io_set_cmpl(io, req, NULL, _ocf_cleaner_flush_cache_io_end);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
|
||||
ocf_volume_submit_flush(io);
|
||||
|
||||
@@ -395,6 +393,7 @@ static int _ocf_cleaner_fire_flush_cores(struct ocf_request *req)
|
||||
ocf_core_id_t core_id = OCF_CORE_MAX;
|
||||
struct ocf_cache *cache = req->cache;
|
||||
struct ocf_map_info *iter = req->map;
|
||||
ocf_core_t core;
|
||||
struct ocf_io *io;
|
||||
|
||||
OCF_DEBUG_TRACE(req->cache);
|
||||
@@ -419,15 +418,15 @@ static int _ocf_cleaner_fire_flush_cores(struct ocf_request *req)
|
||||
|
||||
env_atomic_inc(&req->req_remaining);
|
||||
|
||||
io = ocf_new_core_io(cache, core_id);
|
||||
core = ocf_cache_get_core(cache, core_id);
|
||||
io = ocf_new_core_io(core, req->io_queue, 0, 0,
|
||||
OCF_WRITE, 0, 0);
|
||||
if (!io) {
|
||||
_ocf_cleaner_flush_cores_io_end(iter, req, -OCF_ERR_NO_MEM);
|
||||
continue;
|
||||
}
|
||||
|
||||
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
|
||||
ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_flush_cores_io_cmpl);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
|
||||
ocf_volume_submit_flush(io);
|
||||
}
|
||||
@@ -480,25 +479,24 @@ static void _ocf_cleaner_core_io_for_dirty_range(struct ocf_request *req,
|
||||
{
|
||||
uint64_t addr, offset;
|
||||
int err;
|
||||
struct ocf_cache *cache = req->cache;
|
||||
ocf_cache_t cache = req->cache;
|
||||
ocf_core_t core = ocf_cache_get_core(cache, iter->core_id);
|
||||
struct ocf_io *io;
|
||||
struct ocf_counters_block *core_stats =
|
||||
&cache->core[iter->core_id].counters->core_blocks;
|
||||
ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache,
|
||||
iter->coll_idx);
|
||||
|
||||
io = ocf_new_core_io(cache, iter->core_id);
|
||||
if (!io)
|
||||
goto error;
|
||||
|
||||
addr = (ocf_line_size(cache) * iter->core_line)
|
||||
+ SECTORS_TO_BYTES(begin);
|
||||
offset = (ocf_line_size(cache) * iter->hash_key)
|
||||
+ SECTORS_TO_BYTES(begin);
|
||||
|
||||
ocf_io_configure(io, addr, SECTORS_TO_BYTES(end - begin), OCF_WRITE,
|
||||
part_id, 0);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
io = ocf_new_core_io(core, req->io_queue, addr,
|
||||
SECTORS_TO_BYTES(end - begin), OCF_WRITE, part_id, 0);
|
||||
if (!io)
|
||||
goto error;
|
||||
|
||||
err = ocf_io_set_data(io, req->data, offset);
|
||||
if (err) {
|
||||
ocf_io_put(io);
|
||||
@@ -660,14 +658,6 @@ static int _ocf_cleaner_fire_cache(struct ocf_request *req)
|
||||
cache_stats = &cache->core[iter->core_id].
|
||||
counters->cache_blocks;
|
||||
|
||||
io = ocf_new_cache_io(cache);
|
||||
if (!io) {
|
||||
/* Allocation error */
|
||||
iter->invalid = true;
|
||||
_ocf_cleaner_set_error(req);
|
||||
continue;
|
||||
}
|
||||
|
||||
OCF_DEBUG_PARAM(req->cache, "Cache read, line = %u",
|
||||
iter->coll_idx);
|
||||
|
||||
@@ -680,10 +670,17 @@ static int _ocf_cleaner_fire_cache(struct ocf_request *req)
|
||||
|
||||
part_id = ocf_metadata_get_partition_id(cache, iter->coll_idx);
|
||||
|
||||
io = ocf_new_cache_io(cache, req->io_queue,
|
||||
addr, ocf_line_size(cache),
|
||||
OCF_READ, part_id, 0);
|
||||
if (!io) {
|
||||
/* Allocation error */
|
||||
iter->invalid = true;
|
||||
_ocf_cleaner_set_error(req);
|
||||
continue;
|
||||
}
|
||||
|
||||
ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_cache_io_cmpl);
|
||||
ocf_io_configure(io, addr, ocf_line_size(cache), OCF_READ,
|
||||
part_id, 0);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
err = ocf_io_set_data(io, req->data, offset);
|
||||
if (err) {
|
||||
ocf_io_put(io);
|
||||
|
@@ -31,11 +31,10 @@ void ocf_submit_volume_flush(ocf_volume_t volume,
|
||||
{
|
||||
struct ocf_io *io;
|
||||
|
||||
io = ocf_volume_new_io(volume);
|
||||
io = ocf_volume_new_io(volume, NULL, 0, 0, OCF_WRITE, 0, 0);
|
||||
if (!io)
|
||||
OCF_CMPL_RET(priv, -OCF_ERR_NO_MEM);
|
||||
|
||||
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
|
||||
ocf_io_set_cmpl(io, cmpl, priv, _ocf_volume_flush_end);
|
||||
|
||||
ocf_volume_submit_flush(io);
|
||||
@@ -74,7 +73,10 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr,
|
||||
context->priv = priv;
|
||||
|
||||
while (length) {
|
||||
io = ocf_volume_new_io(volume);
|
||||
bytes = OCF_MIN(length, max_length);
|
||||
|
||||
io = ocf_volume_new_io(volume, NULL, addr, bytes,
|
||||
OCF_WRITE, 0, 0);
|
||||
if (!io) {
|
||||
context->error = -OCF_ERR_NO_MEM;
|
||||
break;
|
||||
@@ -82,9 +84,6 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr,
|
||||
|
||||
env_atomic_inc(&context->req_remaining);
|
||||
|
||||
bytes = OCF_MIN(length, max_length);
|
||||
|
||||
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
|
||||
ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end);
|
||||
ocf_volume_submit_discard(io);
|
||||
|
||||
@@ -116,7 +115,10 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr,
|
||||
context->priv = priv;
|
||||
|
||||
while (length) {
|
||||
io = ocf_volume_new_io(volume);
|
||||
bytes = OCF_MIN(length, max_length);
|
||||
|
||||
io = ocf_volume_new_io(volume, NULL, addr, bytes,
|
||||
OCF_WRITE, 0, 0);
|
||||
if (!io) {
|
||||
context->error = -OCF_ERR_NO_MEM;
|
||||
break;
|
||||
@@ -124,9 +126,6 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr,
|
||||
|
||||
env_atomic_inc(&context->req_remaining);
|
||||
|
||||
bytes = OCF_MIN(length, max_length);
|
||||
|
||||
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
|
||||
ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end);
|
||||
ocf_volume_submit_write_zeroes(io);
|
||||
|
||||
@@ -181,7 +180,7 @@ void ocf_submit_cache_page(ocf_cache_t cache, uint64_t addr, int dir,
|
||||
context->cmpl = cmpl;
|
||||
context->priv = priv;
|
||||
|
||||
io = ocf_volume_new_io(&cache->device->volume);
|
||||
io = ocf_new_cache_io(cache, NULL, addr, PAGE_SIZE, dir, 0, 0);
|
||||
if (!io) {
|
||||
result = -OCF_ERR_NO_MEM;
|
||||
goto err_io;
|
||||
@@ -200,7 +199,6 @@ void ocf_submit_cache_page(ocf_cache_t cache, uint64_t addr, int dir,
|
||||
if (result)
|
||||
goto err_set_data;
|
||||
|
||||
ocf_io_configure(io, addr, PAGE_SIZE, dir, 0, 0);
|
||||
ocf_io_set_cmpl(io, context, NULL, ocf_submit_cache_page_end);
|
||||
|
||||
ocf_volume_submit_io(io);
|
||||
@@ -230,8 +228,8 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
uint64_t size, unsigned int reqs, ocf_req_end_t callback)
|
||||
{
|
||||
struct ocf_counters_block *cache_stats;
|
||||
uint64_t flags = req->io ? req->io->flags : 0;
|
||||
uint32_t class = req->io ? req->io->io_class : 0;
|
||||
uint64_t flags = req->ioi.io.flags;
|
||||
uint32_t class = req->ioi.io.io_class;
|
||||
uint64_t addr, bytes, total_bytes = 0;
|
||||
struct ocf_io *io;
|
||||
int err;
|
||||
@@ -245,12 +243,6 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
cache_stats = &req->core->counters->cache_blocks;
|
||||
|
||||
if (reqs == 1) {
|
||||
io = ocf_new_cache_io(cache);
|
||||
if (!io) {
|
||||
callback(req, -OCF_ERR_NO_MEM);
|
||||
goto update_stats;
|
||||
}
|
||||
|
||||
addr = ocf_metadata_map_lg2phy(cache,
|
||||
req->map[first_cl].coll_idx);
|
||||
addr *= ocf_line_size(cache);
|
||||
@@ -258,8 +250,13 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
addr += ((req->byte_position + offset) % ocf_line_size(cache));
|
||||
bytes = size;
|
||||
|
||||
ocf_io_configure(io, addr, bytes, dir, class, flags);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
io = ocf_new_cache_io(cache, req->io_queue,
|
||||
addr, bytes, dir, class, flags);
|
||||
if (!io) {
|
||||
callback(req, -OCF_ERR_NO_MEM);
|
||||
goto update_stats;
|
||||
}
|
||||
|
||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||
|
||||
err = ocf_io_set_data(io, req->data, offset);
|
||||
@@ -277,15 +274,6 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
|
||||
/* Issue requests to cache. */
|
||||
for (i = 0; i < reqs; i++) {
|
||||
io = ocf_new_cache_io(cache);
|
||||
|
||||
if (!io) {
|
||||
/* Finish all IOs which left with ERROR */
|
||||
for (; i < reqs; i++)
|
||||
callback(req, -OCF_ERR_NO_MEM);
|
||||
goto update_stats;
|
||||
}
|
||||
|
||||
addr = ocf_metadata_map_lg2phy(cache,
|
||||
req->map[first_cl + i].coll_idx);
|
||||
addr *= ocf_line_size(cache);
|
||||
@@ -309,8 +297,15 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
bytes = OCF_MIN(bytes, size - total_bytes);
|
||||
ENV_BUG_ON(bytes == 0);
|
||||
|
||||
ocf_io_configure(io, addr, bytes, dir, class, flags);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
io = ocf_new_cache_io(cache, req->io_queue,
|
||||
addr, bytes, dir, class, flags);
|
||||
if (!io) {
|
||||
/* Finish all IOs which left with ERROR */
|
||||
for (; i < reqs; i++)
|
||||
callback(req, -OCF_ERR_NO_MEM);
|
||||
goto update_stats;
|
||||
}
|
||||
|
||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||
|
||||
err = ocf_io_set_data(io, req->data, offset + total_bytes);
|
||||
@@ -338,8 +333,8 @@ void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
|
||||
ocf_req_end_t callback)
|
||||
{
|
||||
struct ocf_counters_block *core_stats;
|
||||
uint64_t flags = req->io ? req->io->flags : 0;
|
||||
uint32_t class = req->io ? req->io->io_class : 0;
|
||||
uint64_t flags = req->ioi.io.flags;
|
||||
uint32_t class = req->ioi.io.io_class;
|
||||
int dir = req->rw;
|
||||
struct ocf_io *io;
|
||||
int err;
|
||||
@@ -350,15 +345,13 @@ void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
|
||||
else if (dir == OCF_READ)
|
||||
env_atomic64_add(req->byte_length, &core_stats->read_bytes);
|
||||
|
||||
io = ocf_volume_new_io(volume);
|
||||
io = ocf_volume_new_io(volume, req->io_queue, req->byte_position,
|
||||
req->byte_length, dir, class, flags);
|
||||
if (!io) {
|
||||
callback(req, -OCF_ERR_NO_MEM);
|
||||
return;
|
||||
}
|
||||
|
||||
ocf_io_configure(io, req->byte_position, req->byte_length, dir,
|
||||
class, flags);
|
||||
ocf_io_set_queue(io, req->io_queue);
|
||||
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
|
||||
err = ocf_io_set_data(io, req->data, 0);
|
||||
if (err) {
|
||||
|
@@ -64,17 +64,21 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
|
||||
struct ocf_request *req, int dir, uint64_t offset,
|
||||
uint64_t size, unsigned int reqs, ocf_req_end_t callback);
|
||||
|
||||
static inline struct ocf_io *ocf_new_cache_io(struct ocf_cache *cache)
|
||||
static inline struct ocf_io *ocf_new_cache_io(ocf_cache_t cache,
|
||||
ocf_queue_t queue, uint64_t addr, uint32_t bytes,
|
||||
uint32_t dir, uint32_t io_class, uint64_t flags)
|
||||
|
||||
{
|
||||
return ocf_volume_new_io(&cache->device->volume);
|
||||
return ocf_volume_new_io(ocf_cache_get_volume(cache), queue,
|
||||
addr, bytes, dir, io_class, flags);
|
||||
}
|
||||
|
||||
static inline struct ocf_io *ocf_new_core_io(struct ocf_cache *cache,
|
||||
ocf_core_id_t core_id)
|
||||
static inline struct ocf_io *ocf_new_core_io(ocf_core_t core,
|
||||
ocf_queue_t queue, uint64_t addr, uint32_t bytes,
|
||||
uint32_t dir, uint32_t io_class, uint64_t flags)
|
||||
{
|
||||
ENV_BUG_ON(core_id >= OCF_CORE_MAX);
|
||||
|
||||
return ocf_volume_new_io(&cache->core[core_id].volume);
|
||||
return ocf_volume_new_io(ocf_core_get_volume(core), queue,
|
||||
addr, bytes, dir, io_class, flags);
|
||||
}
|
||||
|
||||
#endif /* UTILS_IO_H_ */
|
||||
|
62
src/utils/utils_io_allocator.h
Normal file
62
src/utils/utils_io_allocator.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright(c) 2019 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef __UTILS_IO_ALLOCATOR_H__
|
||||
#define __UTILS_IO_ALLOCATOR_H__
|
||||
|
||||
#include "ocf/ocf_types.h"
|
||||
|
||||
typedef struct ocf_io_allocator *ocf_io_allocator_t;
|
||||
|
||||
struct ocf_io_allocator_ops {
|
||||
int (*allocator_init)(ocf_io_allocator_t allocator,
|
||||
uint32_t priv_size, const char *name);
|
||||
void (*allocator_deinit)(ocf_io_allocator_t allocator);
|
||||
void *(*allocator_new)(ocf_io_allocator_t allocator,
|
||||
ocf_volume_t volume, ocf_queue_t queue,
|
||||
uint64_t addr, uint32_t bytes, uint32_t dir);
|
||||
void (*allocator_del)(ocf_io_allocator_t allocator, void *obj);
|
||||
};
|
||||
|
||||
struct ocf_io_allocator_type {
|
||||
struct ocf_io_allocator_ops ops;
|
||||
};
|
||||
|
||||
typedef const struct ocf_io_allocator_type *ocf_io_allocator_type_t;
|
||||
|
||||
struct ocf_io_allocator {
|
||||
const struct ocf_io_allocator_type *type;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
static inline void *ocf_io_allocator_new(ocf_io_allocator_t allocator,
|
||||
ocf_volume_t volume, ocf_queue_t queue,
|
||||
uint64_t addr, uint32_t bytes, uint32_t dir)
|
||||
{
|
||||
return allocator->type->ops.allocator_new(allocator, volume, queue,
|
||||
addr, bytes, dir);
|
||||
}
|
||||
|
||||
static inline void ocf_io_allocator_del(ocf_io_allocator_t allocator, void *obj)
|
||||
{
|
||||
allocator->type->ops.allocator_del(allocator, obj);
|
||||
}
|
||||
|
||||
static inline int ocf_io_allocator_init(ocf_io_allocator_t allocator,
|
||||
ocf_io_allocator_type_t type, uint32_t size, const char *name)
|
||||
|
||||
{
|
||||
allocator->type = type;
|
||||
return allocator->type->ops.allocator_init(allocator, size, name);
|
||||
}
|
||||
|
||||
static inline void ocf_io_allocator_deinit(ocf_io_allocator_t allocator)
|
||||
{
|
||||
allocator->type->ops.allocator_deinit(allocator);
|
||||
}
|
||||
|
||||
ocf_io_allocator_type_t ocf_io_allocator_get_type_default(void);
|
||||
|
||||
#endif /* __UTILS_IO_ALLOCATOR__ */
|
Reference in New Issue
Block a user