From 8d127e6351f88590df5392602da9ca7a673e8cc5 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 31 Dec 2018 14:51:51 +0100 Subject: [PATCH] Move eviction stuff to eviction/ directory Signed-off-by: Robert Baldyga --- src/engine/cache_engine.c | 2 +- src/engine/engine_common.c | 2 +- src/eviction/eviction.c | 104 ++++++++++++++++++++++++++++++++ src/eviction/eviction.h | 20 +++++- src/layer_space_management.c | 114 ----------------------------------- src/layer_space_management.h | 25 -------- 6 files changed, 123 insertions(+), 144 deletions(-) delete mode 100644 src/layer_space_management.c delete mode 100644 src/layer_space_management.h diff --git a/src/engine/cache_engine.c b/src/engine/cache_engine.c index f96451f..0ff8dc6 100644 --- a/src/engine/cache_engine.c +++ b/src/engine/cache_engine.c @@ -22,7 +22,7 @@ #include "../utils/utils_part.h" #include "../utils/utils_req.h" #include "../metadata/metadata.h" -#include "../layer_space_management.h" +#include "../eviction/eviction.h" enum ocf_io_if_type { /* Public OCF IO interfaces to be set by user */ diff --git a/src/engine/engine_common.c b/src/engine/engine_common.c index 9b816d4..84b7b91 100644 --- a/src/engine/engine_common.c +++ b/src/engine/engine_common.c @@ -14,7 +14,7 @@ #include "../utils/utils_req.h" #include "../utils/utils_cleaner.h" #include "../metadata/metadata.h" -#include "../layer_space_management.h" +#include "../eviction/eviction.h" void ocf_engine_error(struct ocf_request *req, bool stop_cache, const char *msg) diff --git a/src/eviction/eviction.c b/src/eviction/eviction.c index 4196dea..01f463a 100644 --- a/src/eviction/eviction.c +++ b/src/eviction/eviction.c @@ -4,6 +4,8 @@ */ #include "eviction.h" +#include "ops.h" +#include "../utils/utils_part.h" struct eviction_policy_ops evict_policy_ops[ocf_eviction_max] = { [ocf_eviction_lru] = { @@ -17,3 +19,105 @@ struct eviction_policy_ops evict_policy_ops[ocf_eviction_max] = { .name = "lru", }, }; + +static uint32_t ocf_evict_calculate(struct ocf_user_part *part, + uint32_t to_evict) +{ + if (part->runtime->curr_size <= part->config->min_size) { + /* + * Cannot evict from this partition because current size + * is less than minimum size + */ + return 0; + } + + if (to_evict < OCF_TO_EVICTION_MIN) + to_evict = OCF_TO_EVICTION_MIN; + + if (to_evict > (part->runtime->curr_size - part->config->min_size)) + to_evict = part->runtime->curr_size - part->config->min_size; + + return to_evict; +} + +static inline uint32_t ocf_evict_do(struct ocf_cache *cache, + uint32_t io_queue, const uint32_t evict_cline_no, + ocf_core_id_t core_id, ocf_part_id_t target_part_id) +{ + uint32_t to_evict = 0, evicted = 0; + struct ocf_user_part *part; + struct ocf_user_part *target_part = &cache->user_parts[target_part_id]; + ocf_part_id_t part_id; + + /* For each partition from the lowest priority to highest one */ + for_each_part(cache, part, part_id) { + + if (!ocf_eviction_can_evict(cache)) + goto out; + + /* + * Check stop and continue conditions + */ + if (target_part->config->priority > part->config->priority) { + /* + * iterate partition have higher priority, do not evict + */ + break; + } + if (!part->config->flags.eviction) { + /* It seams that no more partition for eviction */ + break; + } + if (part_id == target_part_id) { + /* Omit targeted, evict from different first */ + continue; + } + if (evicted >= evict_cline_no) { + /* Evicted requested number of cache line, stop */ + goto out; + } + + to_evict = ocf_evict_calculate(part, evict_cline_no); + if (to_evict == 0) { + /* No cache lines to evict for this partition */ + continue; + } + + evicted += ocf_eviction_need_space(cache, io_queue, + part_id, to_evict, core_id); + } + + if (!ocf_eviction_can_evict(cache)) + goto out; + + if (evicted < evict_cline_no) { + /* Now we can evict form targeted partition */ + to_evict = ocf_evict_calculate(target_part, evict_cline_no); + if (to_evict) { + evicted += ocf_eviction_need_space(cache, io_queue, + target_part_id, to_evict, core_id); + } + } + +out: + return evicted; +} + +int space_managment_evict_do(struct ocf_cache *cache, + struct ocf_request *req, uint32_t evict_cline_no) +{ + uint32_t evicted; + + if (evict_cline_no <= cache->device->freelist_part->curr_size) + return LOOKUP_MAPPED; + + evict_cline_no = evict_cline_no - cache->device->freelist_part->curr_size; + evicted = ocf_evict_do(cache, req->io_queue, evict_cline_no, + req->core_id, req->part_id); + + if (evict_cline_no <= evicted) + return LOOKUP_MAPPED; + + req->info.eviction_error |= true; + return LOOKUP_MISS; +} diff --git a/src/eviction/eviction.h b/src/eviction/eviction.h index f3a8a9b..d213063 100644 --- a/src/eviction/eviction.h +++ b/src/eviction/eviction.h @@ -2,15 +2,17 @@ * Copyright(c) 2012-2018 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause-Clear */ + #ifndef __LAYER_EVICTION_POLICY_H__ - #define __LAYER_EVICTION_POLICY_H__ -#define OCF_PENDING_EVICTION_LIMIT 512UL - #include "ocf/ocf.h" #include "lru.h" #include "lru_structs.h" +#include "../ocf_request.h" + +#define OCF_TO_EVICTION_MIN 128UL +#define OCF_PENDING_EVICTION_LIMIT 512UL struct eviction_policy { union { @@ -53,4 +55,16 @@ struct eviction_policy_ops { extern struct eviction_policy_ops evict_policy_ops[ocf_eviction_max]; +/* + * Deallocates space from low priority partitions. + * + * Returns -1 on error + * or the destination partition ID for the free buffers + * (it matches label and is part of the object (#core_id) IO group) + */ +int space_managment_evict_do(struct ocf_cache *cache, + struct ocf_request *req, uint32_t evict_cline_no); + +int space_management_free(struct ocf_cache *cache, uint32_t count); + #endif diff --git a/src/layer_space_management.c b/src/layer_space_management.c deleted file mode 100644 index 9408a19..0000000 --- a/src/layer_space_management.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#include "ocf/ocf.h" -#include "layer_space_management.h" -#include "utils/utils_allocator.h" -#include "utils/utils_part.h" -#include "concurrency/ocf_concurrency.h" -#include "engine/engine_common.h" -#include "eviction/ops.h" - -static uint32_t ocf_evict_calculate(struct ocf_user_part *part, - uint32_t to_evict) -{ - if (part->runtime->curr_size <= part->config->min_size) { - /* - * Cannot evict from this partition because current size - * is less than minimum size - */ - return 0; - } - - if (to_evict < OCF_TO_EVICTION_MIN) - to_evict = OCF_TO_EVICTION_MIN; - - if (to_evict > (part->runtime->curr_size - part->config->min_size)) - to_evict = part->runtime->curr_size - part->config->min_size; - - return to_evict; -} - -static inline uint32_t ocf_evict_do(struct ocf_cache *cache, - uint32_t io_queue, const uint32_t evict_cline_no, - ocf_core_id_t core_id, ocf_part_id_t target_part_id) -{ - uint32_t to_evict = 0, evicted = 0; - struct ocf_user_part *part; - struct ocf_user_part *target_part = &cache->user_parts[target_part_id]; - ocf_part_id_t part_id; - - /* For each partition from the lowest priority to highest one */ - for_each_part(cache, part, part_id) { - - if (!ocf_eviction_can_evict(cache)) - goto out; - - /* - * Check stop and continue conditions - */ - if (target_part->config->priority > part->config->priority) { - /* - * iterate partition have higher priority, do not evict - */ - break; - } - if (!part->config->flags.eviction) { - /* It seams that no more partition for eviction */ - break; - } - if (part_id == target_part_id) { - /* Omit targeted, evict from different first */ - continue; - } - if (evicted >= evict_cline_no) { - /* Evicted requested number of cache line, stop */ - goto out; - } - - to_evict = ocf_evict_calculate(part, evict_cline_no); - if (to_evict == 0) { - /* No cache lines to evict for this partition */ - continue; - } - - evicted += ocf_eviction_need_space(cache, io_queue, - part_id, to_evict, core_id); - } - - if (!ocf_eviction_can_evict(cache)) - goto out; - - if (evicted < evict_cline_no) { - /* Now we can evict form targeted partition */ - to_evict = ocf_evict_calculate(target_part, evict_cline_no); - if (to_evict) { - evicted += ocf_eviction_need_space(cache, io_queue, - target_part_id, to_evict, core_id); - } - } - -out: - return evicted; -} - -int space_managment_evict_do(struct ocf_cache *cache, - struct ocf_request *req, uint32_t evict_cline_no) -{ - uint32_t evicted; - - if (evict_cline_no <= cache->device->freelist_part->curr_size) - return LOOKUP_MAPPED; - - evict_cline_no = evict_cline_no - cache->device->freelist_part->curr_size; - evicted = ocf_evict_do(cache, req->io_queue, evict_cline_no, - req->core_id, req->part_id); - - if (evict_cline_no <= evicted) - return LOOKUP_MAPPED; - - req->info.eviction_error |= true; - return LOOKUP_MISS; -} diff --git a/src/layer_space_management.h b/src/layer_space_management.h deleted file mode 100644 index e7b325e..0000000 --- a/src/layer_space_management.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ -#ifndef __LAYER_SPACE_MANAGEMENT_H__ - -#define __LAYER_SPACE_MANAGEMENT_H__ - -#include "ocf_request.h" - -#define OCF_TO_EVICTION_MIN 128UL - -/* - * Deallocates space from low priority partitions. - * - * Returns -1 on error - * or the destination partition ID for the free buffers - * (it matches label and is part of the object (#core_id) IO group) - */ -int space_managment_evict_do(struct ocf_cache *cache, - struct ocf_request *req, uint32_t evict_cline_no); - -int space_management_free(struct ocf_cache *cache, uint32_t count); - -#endif