cleaner: Rework request allocation
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
This commit is contained in:
parent
3248c85828
commit
3300dbd4e7
@ -73,56 +73,81 @@ enum {
|
|||||||
ocf_cleaner_req_type_slave = 2
|
ocf_cleaner_req_type_slave = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct ocf_request *_ocf_cleaner_alloc_master_req(
|
static inline uint32_t _ocf_cleaner_get_req_max_count(uint32_t count,
|
||||||
struct ocf_cache *cache, uint32_t count,
|
bool low_mem)
|
||||||
const struct ocf_cleaner_attribs *attribs)
|
|
||||||
{
|
{
|
||||||
struct ocf_request *req = _ocf_cleaner_alloc_req(cache, count, attribs);
|
if (low_mem || count <= 4096)
|
||||||
|
return count < 128 ? count : 128;
|
||||||
|
|
||||||
if (req) {
|
return 1024;
|
||||||
/* Set type of cleaning request */
|
}
|
||||||
req->master_io_req_type = ocf_cleaner_req_type_master;
|
|
||||||
|
|
||||||
/* In master, save completion context and function */
|
static struct ocf_request *_ocf_cleaner_alloc_master_req(
|
||||||
req->priv = attribs->cmpl_context;
|
struct ocf_cache *cache, uint32_t count,
|
||||||
req->master_io_req = attribs->cmpl_fn;
|
const struct ocf_cleaner_attribs *attribs)
|
||||||
req->complete_queue = attribs->cmpl_queue;
|
{
|
||||||
|
struct ocf_request *req;
|
||||||
|
|
||||||
/* The count of all requests */
|
req =_ocf_cleaner_alloc_req(cache, count, attribs);
|
||||||
env_atomic_set(&req->master_remaining, 1);
|
if (unlikely(!req)) {
|
||||||
|
/* Some memory allocation error, try re-allocate request */
|
||||||
OCF_DEBUG_PARAM(cache, "New master request, count = %u",
|
count = _ocf_cleaner_get_req_max_count(count, true);
|
||||||
count);
|
req = _ocf_cleaner_alloc_req(cache, count, attribs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unlikely(!req))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* Set type of cleaning request */
|
||||||
|
req->master_io_req_type = ocf_cleaner_req_type_master;
|
||||||
|
|
||||||
|
/* In master, save completion context and function */
|
||||||
|
req->priv = attribs->cmpl_context;
|
||||||
|
req->master_io_req = attribs->cmpl_fn;
|
||||||
|
req->complete_queue = attribs->cmpl_queue;
|
||||||
|
|
||||||
|
/* The count of all requests */
|
||||||
|
env_atomic_set(&req->master_remaining, 1);
|
||||||
|
|
||||||
|
OCF_DEBUG_PARAM(cache, "New master request, count = %u", count);
|
||||||
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ocf_request *_ocf_cleaner_alloc_slave_req(
|
static struct ocf_request *_ocf_cleaner_alloc_slave_req(
|
||||||
struct ocf_request *master,
|
struct ocf_request *master, uint32_t count,
|
||||||
uint32_t count, const struct ocf_cleaner_attribs *attribs)
|
const struct ocf_cleaner_attribs *attribs)
|
||||||
{
|
{
|
||||||
struct ocf_request *req = _ocf_cleaner_alloc_req(
|
struct ocf_request *req;
|
||||||
master->cache, count, attribs);
|
|
||||||
|
|
||||||
if (req) {
|
req = _ocf_cleaner_alloc_req(master->cache, count, attribs);
|
||||||
/* Set type of cleaning request */
|
if (unlikely(!req)) {
|
||||||
req->master_io_req_type = ocf_cleaner_req_type_slave;
|
/* Some memory allocation error, try re-allocate request */
|
||||||
|
count = _ocf_cleaner_get_req_max_count(count, true);
|
||||||
|
req = _ocf_cleaner_alloc_req(master->cache, count, attribs);
|
||||||
|
}
|
||||||
|
|
||||||
/* Slave refers to master request, get its reference counter */
|
if (unlikely(!req))
|
||||||
ocf_req_get(master);
|
return NULL;
|
||||||
|
|
||||||
/* Slave request contains reference to master */
|
/* Set type of cleaning request */
|
||||||
req->master_io_req = master;
|
req->master_io_req_type = ocf_cleaner_req_type_slave;
|
||||||
|
|
||||||
/* One more additional slave request, increase global counter
|
/* Slave refers to master request, get its reference counter */
|
||||||
* of requests count
|
ocf_req_get(master);
|
||||||
*/
|
|
||||||
env_atomic_inc(&master->master_remaining);
|
|
||||||
|
|
||||||
OCF_DEBUG_PARAM(req->cache,
|
/* Slave request contains reference to master */
|
||||||
|
req->master_io_req = master;
|
||||||
|
|
||||||
|
/* One more additional slave request, increase global counter
|
||||||
|
* of requests count
|
||||||
|
*/
|
||||||
|
env_atomic_inc(&master->master_remaining);
|
||||||
|
|
||||||
|
OCF_DEBUG_PARAM(req->cache,
|
||||||
"New slave request, count = %u,all requests count = %d",
|
"New slave request, count = %u,all requests count = %d",
|
||||||
count, env_atomic_read(&master->master_remaining));
|
count, env_atomic_read(&master->master_remaining));
|
||||||
}
|
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,15 +802,6 @@ static int _ocf_cleaner_do_fire(struct ocf_request *req, uint32_t count)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t _ocf_cleaner_get_req_max_count(uint32_t count,
|
|
||||||
bool low_mem)
|
|
||||||
{
|
|
||||||
if (low_mem || count <= 4096)
|
|
||||||
return count < 128 ? count : 128;
|
|
||||||
|
|
||||||
return 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _ocf_cleaner_fire_error(struct ocf_request *master,
|
static void _ocf_cleaner_fire_error(struct ocf_request *master,
|
||||||
struct ocf_request *req, int err)
|
struct ocf_request *req, int err)
|
||||||
{
|
{
|
||||||
@ -823,14 +839,7 @@ void ocf_cleaner_fire(struct ocf_cache *cache,
|
|||||||
|
|
||||||
/* Allocate master request */
|
/* Allocate master request */
|
||||||
master = _ocf_cleaner_alloc_master_req(cache, max, attribs);
|
master = _ocf_cleaner_alloc_master_req(cache, max, attribs);
|
||||||
|
if (unlikely(!master)) {
|
||||||
if (!master) {
|
|
||||||
/* Some memory allocation error, try re-allocate request */
|
|
||||||
max = _ocf_cleaner_get_req_max_count(count, true);
|
|
||||||
master = _ocf_cleaner_alloc_master_req(cache, max, attribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!master) {
|
|
||||||
attribs->cmpl_fn(attribs->cmpl_context, -OCF_ERR_NO_MEM);
|
attribs->cmpl_fn(attribs->cmpl_context, -OCF_ERR_NO_MEM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -843,27 +852,17 @@ void ocf_cleaner_fire(struct ocf_cache *cache,
|
|||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
/* when request hasn't yet been allocated or is just issued */
|
/* when request hasn't yet been allocated or is just issued */
|
||||||
if (!req) {
|
if (unlikely(!req)) {
|
||||||
if (max > count - i) {
|
if (max > count - i) {
|
||||||
/* less than max left */
|
/* less than max left */
|
||||||
max = count - i;
|
max = count - i;
|
||||||
}
|
}
|
||||||
|
|
||||||
req = _ocf_cleaner_alloc_slave_req(master, max, attribs);
|
req = _ocf_cleaner_alloc_slave_req(master, max, attribs);
|
||||||
}
|
if (unlikely(!req)) {
|
||||||
|
master->error = -OCF_ERR_NO_MEM;
|
||||||
if (!req) {
|
break;
|
||||||
/* Some memory allocation error,
|
}
|
||||||
* try re-allocate request
|
|
||||||
*/
|
|
||||||
max = _ocf_cleaner_get_req_max_count(max, true);
|
|
||||||
req = _ocf_cleaner_alloc_slave_req(master, max, attribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* when request allocation failed stop processing */
|
|
||||||
if (!req) {
|
|
||||||
master->error = -OCF_ERR_NO_MEM;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attribs->getter(cache, attribs->getter_context,
|
if (attribs->getter(cache, attribs->getter_context,
|
||||||
|
Loading…
Reference in New Issue
Block a user