From 88e04a42042103d74a5851aaf84677a9f1168208 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Tue, 15 Jun 2021 20:39:09 +0200 Subject: [PATCH] Remove eviction policy abstraction Signed-off-by: Adam Rutkowski --- inc/ocf_cache.h | 3 - inc/ocf_def.h | 14 --- inc/ocf_io_class.h | 3 - inc/ocf_mngt.h | 6 - src/engine/engine_common.c | 4 +- src/eviction/eviction.c | 34 +----- src/eviction/eviction.h | 34 ------ src/eviction/lru.c | 1 - src/eviction/lru.h | 7 +- src/eviction/ops.h | 108 ------------------ src/metadata/metadata.c | 4 +- src/metadata/metadata_superblock.h | 2 - src/mngt/ocf_mngt_cache.c | 29 +---- src/mngt/ocf_mngt_common.c | 2 +- src/mngt/ocf_mngt_io_class.c | 2 +- src/ocf_cache.c | 1 - src/ocf_cache_priv.h | 2 - src/ocf_io_class.c | 1 - src/utils/utils_cache_line.c | 23 ++-- src/utils/utils_cache_line.h | 3 +- src/utils/utils_user_part.c | 2 +- tests/functional/pyocf/types/cache.py | 10 -- tests/functional/pyocf/types/ioclass.py | 1 - tests/functional/pyocf/types/stats/cache.py | 1 - .../tests/management/test_attach_cache.py | 1 - .../tests/management/test_start_stop.py | 4 +- tests/functional/tests/security/conftest.py | 9 +- .../security/test_management_start_fuzzy.py | 21 +--- .../unit/tests/eviction/eviction.c/eviction.c | 33 +++--- tests/unit/tests/eviction/lru.c/lru_iter.c | 1 - .../_cache_mngt_set_cache_mode_test.c | 2 +- ...gt_cache_set_fallback_pt_error_threshold.c | 2 +- .../ocf_mngt_io_class.c/ocf_mngt_io_class.c | 2 +- 33 files changed, 52 insertions(+), 320 deletions(-) delete mode 100644 src/eviction/ops.h diff --git a/inc/ocf_cache.h b/inc/ocf_cache.h index 4f2b909..5f57db9 100644 --- a/inc/ocf_cache.h +++ b/inc/ocf_cache.h @@ -72,9 +72,6 @@ struct ocf_cache_info { set as a result of reaching IO error threshold */ } fallback_pt; - ocf_eviction_t eviction_policy; - /*!< Eviction policy selected */ - ocf_cleaning_t cleaning_policy; /*!< Cleaning policy selected */ diff --git a/inc/ocf_def.h b/inc/ocf_def.h index 05776bb..89fb2e0 100644 --- a/inc/ocf_def.h +++ b/inc/ocf_def.h @@ -199,20 +199,6 @@ typedef enum { /*!< Default sequential cutoff policy*/ } ocf_seq_cutoff_policy; -/** - * OCF supported eviction policy types - */ -typedef enum { - ocf_eviction_lru = 0, - /*!< Last recently used eviction policy */ - - ocf_eviction_max, - /*!< Stopper of enumerator */ - - ocf_eviction_default = ocf_eviction_lru, - /*!< Default eviction policy */ -} ocf_eviction_t; - /** * OCF supported promotion policy types */ diff --git a/inc/ocf_io_class.h b/inc/ocf_io_class.h index 8409f58..6e923fd 100644 --- a/inc/ocf_io_class.h +++ b/inc/ocf_io_class.h @@ -44,9 +44,6 @@ struct ocf_io_class_info { * of ioclass's cachelines are evicted. */ - uint8_t eviction_policy_type; - /*!< The type of eviction policy for given IO class */ - ocf_cleaning_t cleaning_policy_type; /*!< The type of cleaning policy for given IO class */ }; diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index 4ec286a..aec6892 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -246,11 +246,6 @@ struct ocf_mngt_cache_config { */ ocf_cache_mode_t cache_mode; - /** - * @brief Eviction policy type - */ - ocf_eviction_t eviction_policy; - /** * @brief Promotion policy type */ @@ -307,7 +302,6 @@ static inline void ocf_mngt_cache_config_set_default( struct ocf_mngt_cache_config *cfg) { cfg->cache_mode = ocf_cache_mode_default; - cfg->eviction_policy = ocf_eviction_default; cfg->promotion_policy = ocf_promotion_default; cfg->cache_line_size = ocf_cache_line_size_4; cfg->metadata_layout = ocf_metadata_layout_default; diff --git a/src/engine/engine_common.c b/src/engine/engine_common.c index f47de8a..b2672de 100644 --- a/src/engine/engine_common.c +++ b/src/engine/engine_common.c @@ -202,7 +202,7 @@ static void ocf_engine_set_hot(struct ocf_request *req) if (status == LOOKUP_HIT) { /* Update eviction (LRU) */ - ocf_eviction_set_hot_cache_line(cache, entry->coll_idx); + evp_lru_hot_cline(cache, entry->coll_idx); } } } @@ -518,7 +518,7 @@ int ocf_engine_prepare_clines(struct ocf_request *req) ocf_hb_req_prot_unlock_wr(req); if (ocf_req_is_cleaning_required(req)) { - ocf_lru_flush_dirty(req->cache, user_part, req->io_queue, + evp_lru_clean(req->cache, user_part, req->io_queue, 128); } diff --git a/src/eviction/eviction.c b/src/eviction/eviction.c index 2bf3b00..180b47c 100644 --- a/src/eviction/eviction.c +++ b/src/eviction/eviction.c @@ -4,24 +4,9 @@ */ #include "eviction.h" -#include "ops.h" #include "../utils/utils_user_part.h" #include "../engine/engine_common.h" -struct eviction_policy_ops evict_policy_ops[ocf_eviction_max] = { - [ocf_eviction_lru] = { - .init_cline = evp_lru_init_cline, - .rm_cline = evp_lru_rm_cline, - .req_clines = evp_lru_req_clines, - .hot_cline = evp_lru_hot_cline, - .init_evp = evp_lru_init_evp, - .dirty_cline = evp_lru_dirty_cline, - .clean_cline = evp_lru_clean_cline, - .flush_dirty = evp_lru_clean, - .name = "lru", - }, -}; - static uint32_t ocf_evict_calculate(ocf_cache_t cache, struct ocf_user_part *user_part, uint32_t to_evict) { @@ -49,9 +34,6 @@ static inline uint32_t ocf_evict_part_do(struct ocf_request *req, uint32_t unmapped = ocf_engine_unmapped_count(req); uint32_t to_evict = 0; - if (!evp_lru_can_evict(req->cache)) - return 0; - to_evict = ocf_evict_calculate(req->cache, user_part, unmapped); if (to_evict < unmapped) { @@ -60,8 +42,7 @@ static inline uint32_t ocf_evict_part_do(struct ocf_request *req, return 0; } - return ocf_request_space(req->cache, req, &user_part->part, - to_evict); + return evp_lru_req_clines(req, &user_part->part, to_evict); } static inline uint32_t ocf_evict_user_partitions(ocf_cache_t cache, @@ -75,9 +56,6 @@ static inline uint32_t ocf_evict_user_partitions(ocf_cache_t cache, /* For each partition from the lowest priority to highest one */ for_each_user_part(cache, user_part, part_id) { - if (!ocf_eviction_can_evict(cache)) - goto out; - /* * Check stop and continue conditions */ @@ -111,8 +89,7 @@ static inline uint32_t ocf_evict_user_partitions(ocf_cache_t cache, if (overflown_only) to_evict = OCF_MIN(to_evict, overflow_size); - evicted += ocf_request_space(cache, req, &user_part->part, - to_evict); + evicted += evp_lru_req_clines(req, &user_part->part, to_evict); if (evicted >= evict_cline_no) { /* Evicted requested number of cache line, stop @@ -135,10 +112,9 @@ static inline uint32_t ocf_remap_do(struct ocf_request *req) uint32_t remapped = 0; /* First attempt to map from freelist */ - if (ocf_lru_num_free(cache) > 0) { - remapped = ocf_request_space(cache, req, &cache->free, - remap_cline_no); - } + if (ocf_lru_num_free(cache) > 0) + remapped = evp_lru_req_clines(req, &cache->free, remap_cline_no); + if (remapped >= remap_cline_no) return remapped; diff --git a/src/eviction/eviction.h b/src/eviction/eviction.h index 601ce55..de0eb16 100644 --- a/src/eviction/eviction.h +++ b/src/eviction/eviction.h @@ -31,32 +31,6 @@ union eviction_policy_meta { struct lru_eviction_policy_meta lru; } __attribute__((packed)); -/* the caller must hold the metadata lock for all operations - * - * For range operations the caller can: - * set core_id to -1 to purge the whole cache device - * set core_id to -2 to purge the whole cache partition - */ -struct eviction_policy_ops { - void (*init_cline)(ocf_cache_t cache, ocf_cache_line_t cline); - void (*rm_cline)(ocf_cache_t cache, - ocf_cache_line_t cline); - bool (*can_evict)(ocf_cache_t cache); - uint32_t (*req_clines)(struct ocf_request *req, struct ocf_part *part, - uint32_t cline_no); - void (*hot_cline)(ocf_cache_t cache, ocf_cache_line_t cline); - void (*init_evp)(ocf_cache_t cache, struct ocf_part *part); - void (*dirty_cline)(ocf_cache_t cache, struct ocf_part *part, - ocf_cache_line_t cline); - void (*clean_cline)(ocf_cache_t cache, struct ocf_part *part, - ocf_cache_line_t cline); - void (*flush_dirty)(ocf_cache_t cache, struct ocf_user_part *user_part, - ocf_queue_t io_queue, uint32_t count); - const char *name; -}; - -extern struct eviction_policy_ops evict_policy_ops[ocf_eviction_max]; - /* * Deallocates space according to eviction priorities. * @@ -68,8 +42,6 @@ int ocf_space_managment_remap_do(struct ocf_request *req); int space_management_free(ocf_cache_t cache, uint32_t count); -void ocf_lru_populate(ocf_cache_t cache, ocf_cache_line_t num_free_clines); - typedef void (*ocf_metadata_actor_t)(struct ocf_cache *cache, ocf_cache_line_t cache_line); @@ -77,10 +49,4 @@ int ocf_metadata_actor(struct ocf_cache *cache, ocf_part_id_t part_id, ocf_core_id_t core_id, uint64_t start_byte, uint64_t end_byte, ocf_metadata_actor_t actor); - -void ocf_lru_repart(ocf_cache_t cache, ocf_cache_line_t cline, - struct ocf_part *src_upart, struct ocf_part *dst_upart); - -uint32_t ocf_lru_num_free(ocf_cache_t cache); - #endif diff --git a/src/eviction/lru.c b/src/eviction/lru.c index 965e603..f57fd38 100644 --- a/src/eviction/lru.c +++ b/src/eviction/lru.c @@ -5,7 +5,6 @@ #include "eviction.h" #include "lru.h" -#include "ops.h" #include "../utils/utils_cleaner.h" #include "../utils/utils_cache_line.h" #include "../concurrency/ocf_concurrency.h" diff --git a/src/eviction/lru.h b/src/eviction/lru.h index 9469d75..d6e9fa9 100644 --- a/src/eviction/lru.h +++ b/src/eviction/lru.h @@ -14,7 +14,7 @@ struct ocf_part_runtime; struct ocf_part_cleaning_ctx; struct ocf_request; -void evp_lru_init_cline(struct ocf_cache *cache, ocf_cache_line_t cline); +void evp_lru_init_cline(ocf_cache_t cache, ocf_cache_line_t cline); void evp_lru_rm_cline(struct ocf_cache *cache, ocf_cache_line_t cline); bool evp_lru_can_evict(struct ocf_cache *cache); uint32_t evp_lru_req_clines(struct ocf_request *req, @@ -27,4 +27,9 @@ void evp_lru_clean_cline(struct ocf_cache *cache, struct ocf_part *part, ocf_cache_line_t cline); void evp_lru_clean(ocf_cache_t cache, struct ocf_user_part *user_part, ocf_queue_t io_queue, uint32_t count); +void ocf_lru_repart(ocf_cache_t cache, ocf_cache_line_t cline, + struct ocf_part *src_upart, struct ocf_part *dst_upart); +uint32_t ocf_lru_num_free(ocf_cache_t cache); +void ocf_lru_populate(ocf_cache_t cache, ocf_cache_line_t num_free_clines); + #endif diff --git a/src/eviction/ops.h b/src/eviction/ops.h deleted file mode 100644 index ca6622d..0000000 --- a/src/eviction/ops.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright(c) 2012-2021 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef LAYER_EVICTION_POLICY_OPS_H_ -#define LAYER_EVICTION_POLICY_OPS_H_ - -#include "eviction.h" -#include "../metadata/metadata.h" -#include "../concurrency/ocf_metadata_concurrency.h" - -/** - * @brief Initialize cache line before adding it into eviction - * - * @note This operation is called under WR metadata lock - */ -static inline void ocf_eviction_init_cache_line(struct ocf_cache *cache, - ocf_cache_line_t line) -{ - uint8_t type; - - type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].init_cline)) - evict_policy_ops[type].init_cline(cache, line); -} - -static inline void ocf_eviction_purge_cache_line( - struct ocf_cache *cache, ocf_cache_line_t line) -{ - uint8_t type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].rm_cline)) { - evict_policy_ops[type].rm_cline(cache, line); - } -} - -static inline bool ocf_eviction_can_evict(struct ocf_cache *cache) -{ - uint8_t type = cache->conf_meta->eviction_policy_type; - - if (likely(evict_policy_ops[type].can_evict)) - return evict_policy_ops[type].can_evict(cache); - - return true; -} - -static inline uint32_t ocf_request_space(ocf_cache_t cache, - struct ocf_request *req, struct ocf_part *part, - uint32_t clines) -{ - uint8_t type; - uint32_t result = 0; - - type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].req_clines)) - result = evict_policy_ops[type].req_clines(req, part, clines); - - return result; -} - -static inline void ocf_eviction_set_hot_cache_line( - struct ocf_cache *cache, ocf_cache_line_t line) -{ - uint8_t type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].hot_cline)) { - evict_policy_ops[type].hot_cline(cache, line); - } -} - -static inline void ocf_eviction_initialize(struct ocf_cache *cache, - struct ocf_part *part) -{ - uint8_t type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].init_evp)) { - evict_policy_ops[type].init_evp(cache, part); - } -} - -static inline void ocf_lru_flush_dirty(ocf_cache_t cache, - struct ocf_user_part *user_part, ocf_queue_t io_queue, - uint32_t count) -{ - uint8_t type = cache->conf_meta->eviction_policy_type; - - ENV_BUG_ON(type >= ocf_eviction_max); - - if (likely(evict_policy_ops[type].flush_dirty)) { - evict_policy_ops[type].flush_dirty(cache, user_part, io_queue, - count); - } -} - -#endif /* LAYER_EVICTION_POLICY_OPS_H_ */ diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index 238c03c..9a997b6 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -1167,9 +1167,9 @@ static void _recovery_rebuild_cline_metadata(ocf_cache_t cache, ocf_metadata_add_to_collision(cache, core_id, core_line, hash_index, cache_line); - ocf_eviction_init_cache_line(cache, cache_line); + evp_lru_init_cline(cache, cache_line); - ocf_eviction_set_hot_cache_line(cache, cache_line); + evp_lru_hot_cline(cache, cache_line); env_atomic_inc(&core->runtime_meta->cached_clines); env_atomic_inc(&core->runtime_meta-> diff --git a/src/metadata/metadata_superblock.h b/src/metadata/metadata_superblock.h index cbc866f..032dab3 100644 --- a/src/metadata/metadata_superblock.h +++ b/src/metadata/metadata_superblock.h @@ -49,8 +49,6 @@ struct ocf_superblock_config { ocf_promotion_t promotion_policy_type; struct promotion_policy_config promotion[PROMOTION_POLICY_TYPE_MAX]; - ocf_eviction_t eviction_policy_type; - /* * Checksum for each metadata region. * This field has to be the last one! diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 92cf963..de86f8f 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -21,7 +21,7 @@ #include "../utils/utils_refcnt.h" #include "../utils/utils_async_lock.h" #include "../concurrency/ocf_concurrency.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "../ocf_ctx_priv.h" #include "../cleaning/cleaning.h" #include "../promotion/ops.h" @@ -185,9 +185,9 @@ static void __init_parts_attached(ocf_cache_t cache) ocf_part_id_t part_id; for (part_id = 0; part_id < OCF_USER_IO_CLASS_MAX; part_id++) - ocf_eviction_initialize(cache, &cache->user_parts[part_id].part); + evp_lru_init_evp(cache, &cache->user_parts[part_id].part); - ocf_eviction_initialize(cache, &cache->free); + evp_lru_init_evp(cache, &cache->free); } static void __init_free(ocf_cache_t cache) @@ -227,14 +227,6 @@ static void __deinit_cleaning_policy(ocf_cache_t cache) cleaning_policy_ops[cleaning_policy].deinitialize(cache); } -static void __init_eviction_policy(ocf_cache_t cache, - ocf_eviction_t eviction) -{ - ENV_BUG_ON(eviction < 0 || eviction >= ocf_eviction_max); - - cache->conf_meta->eviction_policy_type = eviction; -} - static void __setup_promotion_policy(ocf_cache_t cache) { int i; @@ -286,8 +278,7 @@ static void __reset_stats(ocf_cache_t cache) } } -static ocf_error_t init_attached_data_structures(ocf_cache_t cache, - ocf_eviction_t eviction_policy) +static ocf_error_t init_attached_data_structures(ocf_cache_t cache) { ocf_error_t result; @@ -305,7 +296,6 @@ static ocf_error_t init_attached_data_structures(ocf_cache_t cache, return result; } - __init_eviction_policy(cache, eviction_policy); __setup_promotion_policy(cache); return 0; @@ -680,7 +670,6 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param cache->pt_unaligned_io = cfg->pt_unaligned_io; cache->use_submit_io_fast = cfg->use_submit_io_fast; - cache->eviction_policy_init = cfg->eviction_policy; cache->metadata.is_volatile = cfg->metadata_volatile; out: @@ -1010,7 +999,7 @@ static void _ocf_mngt_attach_init_instance(ocf_pipeline_t pipeline, ocf_cache_t cache = context->cache; ocf_error_t result; - result = init_attached_data_structures(cache, cache->eviction_policy_init); + result = init_attached_data_structures(cache); if (result) OCF_PL_FINISH_RET(pipeline, result); @@ -1872,11 +1861,6 @@ static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg) if (!ocf_cache_mode_is_valid(cfg->cache_mode)) return -OCF_ERR_INVALID_CACHE_MODE; - if (cfg->eviction_policy >= ocf_eviction_max || - cfg->eviction_policy < 0) { - return -OCF_ERR_INVAL; - } - if (cfg->promotion_policy >= ocf_promotion_max || cfg->promotion_policy < 0 ) { return -OCF_ERR_INVAL; @@ -2077,15 +2061,12 @@ static int _ocf_mngt_cache_load_core_log(ocf_core_t core, void *cntx) static void _ocf_mngt_cache_load_log(ocf_cache_t cache) { ocf_cache_mode_t cache_mode = ocf_cache_get_mode(cache); - ocf_eviction_t eviction_type = cache->conf_meta->eviction_policy_type; ocf_cleaning_t cleaning_type = cache->conf_meta->cleaning_policy_type; ocf_promotion_t promotion_type = cache->conf_meta->promotion_policy_type; ocf_cache_log(cache, log_info, "Successfully loaded\n"); ocf_cache_log(cache, log_info, "Cache mode : %s\n", _ocf_cache_mode_get_name(cache_mode)); - ocf_cache_log(cache, log_info, "Eviction policy : %s\n", - evict_policy_ops[eviction_type].name); ocf_cache_log(cache, log_info, "Cleaning policy : %s\n", cleaning_policy_ops[cleaning_type].name); ocf_cache_log(cache, log_info, "Promotion policy : %s\n", diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index a40eb42..592b3d0 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -11,7 +11,7 @@ #include "../metadata/metadata.h" #include "../engine/cache_engine.h" #include "../ocf_request.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "../ocf_logger_priv.h" #include "../ocf_queue_priv.h" #include "../engine/engine_common.h" diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index 54c5f5a..295d830 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -9,7 +9,7 @@ #include "../metadata/metadata.h" #include "../engine/cache_engine.h" #include "../utils/utils_user_part.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "ocf_env.h" static uint64_t _ocf_mngt_count_user_parts_min_size(struct ocf_cache *cache) diff --git a/src/ocf_cache.c b/src/ocf_cache.c index 8226465..cc29a49 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -170,7 +170,6 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info) info->fallback_pt.error_counter = env_atomic_read(&cache->fallback_pt_error_counter); - info->eviction_policy = cache->conf_meta->eviction_policy_type; info->cleaning_policy = cache->conf_meta->cleaning_policy_type; info->promotion_policy = cache->conf_meta->promotion_policy_type; info->metadata_footprint = ocf_cache_is_device_attached(cache) ? diff --git a/src/ocf_cache_priv.h b/src/ocf_cache_priv.h index a824101..858ba8c 100644 --- a/src/ocf_cache_priv.h +++ b/src/ocf_cache_priv.h @@ -81,8 +81,6 @@ struct ocf_cache { struct ocf_part free; - ocf_eviction_t eviction_policy_init; - uint32_t fallback_pt_error_threshold; ocf_queue_t mngt_queue; diff --git a/src/ocf_io_class.c b/src/ocf_io_class.c index 21a4d7d..008cba8 100644 --- a/src/ocf_io_class.c +++ b/src/ocf_io_class.c @@ -42,7 +42,6 @@ int ocf_cache_io_class_get_info(ocf_cache_t cache, uint32_t io_class, info->min_size = cache->user_parts[part_id].config->min_size; info->max_size = cache->user_parts[part_id].config->max_size; - info->eviction_policy_type = cache->conf_meta->eviction_policy_type; info->cleaning_policy_type = cache->conf_meta->cleaning_policy_type; info->cache_mode = cache->user_parts[part_id].config->cache_mode; diff --git a/src/utils/utils_cache_line.c b/src/utils/utils_cache_line.c index 3cda6c5..96a2323 100644 --- a/src/utils/utils_cache_line.c +++ b/src/utils/utils_cache_line.c @@ -103,9 +103,11 @@ void set_cache_line_clean(struct ocf_cache *cache, uint8_t start_bit, ocf_cache_line_t line = req->map[map_idx].coll_idx; ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache, line); struct ocf_part *part = &cache->user_parts[part_id].part; - uint8_t evp_type = cache->conf_meta->eviction_policy_type; bool line_is_clean; + ENV_BUG_ON(part_id > OCF_USER_IO_CLASS_MAX); + part = &cache->user_parts[part_id].part; + if (metadata_clear_dirty_sec_changed(cache, line, start_bit, end_bit, &line_is_clean)) { ocf_metadata_flush_mark(cache, req, map_idx, CLEAN, start_bit, @@ -130,12 +132,7 @@ void set_cache_line_clean(struct ocf_cache *cache, uint8_t start_bit, */ env_atomic_dec(&req->core->runtime_meta-> part_counters[part_id].dirty_clines); - - if (likely(evict_policy_ops[evp_type].clean_cline)) { - evict_policy_ops[evp_type].clean_cline(cache, - part, line); - } - + evp_lru_clean_cline(cache, part, line); ocf_purge_cleaning_policy(cache, line); } } @@ -147,10 +144,12 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit, { ocf_cache_line_t line = req->map[map_idx].coll_idx; ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache, line); - struct ocf_part *part = &cache->user_parts[part_id].part; - uint8_t evp_type = cache->conf_meta->eviction_policy_type; + struct ocf_part *part; bool line_was_dirty; + ENV_BUG_ON(part_id > OCF_USER_IO_CLASS_MAX); + part = &cache->user_parts[part_id].part; + if (metadata_set_dirty_sec_changed(cache, line, start_bit, end_bit, &line_was_dirty)) { ocf_metadata_flush_mark(cache, req, map_idx, DIRTY, start_bit, @@ -175,11 +174,7 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit, */ env_atomic_inc(&req->core->runtime_meta-> part_counters[part_id].dirty_clines); - - if (likely(evict_policy_ops[evp_type].dirty_cline)) { - evict_policy_ops[evp_type].dirty_cline(cache, - part, line); - } + evp_lru_dirty_cline(cache, part, line); } } diff --git a/src/utils/utils_cache_line.h b/src/utils/utils_cache_line.h index 5c44f21..72c6d3e 100644 --- a/src/utils/utils_cache_line.h +++ b/src/utils/utils_cache_line.h @@ -9,7 +9,6 @@ #include "../metadata/metadata.h" #include "../concurrency/ocf_cache_line_concurrency.h" #include "../eviction/eviction.h" -#include "../eviction/ops.h" #include "../engine/cache_engine.h" #include "../ocf_request.h" #include "../ocf_def_priv.h" @@ -180,7 +179,7 @@ static inline void ocf_purge_cleaning_policy(struct ocf_cache *cache, static inline void ocf_purge_eviction_policy(struct ocf_cache *cache, ocf_cache_line_t line) { - ocf_eviction_purge_cache_line(cache, line); + evp_lru_rm_cline(cache, line); } /** diff --git a/src/utils/utils_user_part.c b/src/utils/utils_user_part.c index e873ff6..88ac96f 100644 --- a/src/utils/utils_user_part.c +++ b/src/utils/utils_user_part.c @@ -8,7 +8,7 @@ #include "../ocf_request.h" #include "../metadata/metadata.h" #include "../engine/cache_engine.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "utils_user_part.h" static struct ocf_lst_entry *ocf_user_part_lst_getter_valid( diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index a1bef30..f4c88ca 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -48,7 +48,6 @@ class CacheConfig(Structure): _fields_ = [ ("_name", c_char * MAX_CACHE_NAME_SIZE), ("_cache_mode", c_uint32), - ("_eviction_policy", c_uint32), ("_promotion_policy", c_uint32), ("_cache_line_size", c_uint64), ("_metadata_layout", c_uint32), @@ -115,11 +114,6 @@ class CacheMode(IntEnum): return self.value not in [CacheMode.PT, CacheMode.WO] -class EvictionPolicy(IntEnum): - LRU = 0 - DEFAULT = LRU - - class PromotionPolicy(IntEnum): ALWAYS = 0 NHIT = 1 @@ -167,7 +161,6 @@ class Cache: owner, name: str = "cache", cache_mode: CacheMode = CacheMode.DEFAULT, - eviction_policy: EvictionPolicy = EvictionPolicy.DEFAULT, promotion_policy: PromotionPolicy = PromotionPolicy.DEFAULT, cache_line_size: CacheLineSize = CacheLineSize.DEFAULT, metadata_layout: MetadataLayout = MetadataLayout.DEFAULT, @@ -186,7 +179,6 @@ class Cache: self.cfg = CacheConfig( _name=name.encode("ascii"), _cache_mode=cache_mode, - _eviction_policy=eviction_policy, _promotion_policy=promotion_policy, _cache_line_size=cache_line_size, _metadata_layout=metadata_layout, @@ -351,7 +343,6 @@ class Cache: "_curr_size": (ioclass_info._curr_size), "_min_size": int(ioclass_info._min_size), "_max_size": int(ioclass_info._max_size), - "_eviction_policy_type": int(ioclass_info._eviction_policy_type), "_cleaning_policy_type": int(ioclass_info._cleaning_policy_type), } @@ -625,7 +616,6 @@ class Cache: "status": cache_info.fallback_pt.status, }, "state": cache_info.state, - "eviction_policy": EvictionPolicy(cache_info.eviction_policy), "cleaning_policy": CleaningPolicy(cache_info.cleaning_policy), "promotion_policy": PromotionPolicy(cache_info.promotion_policy), "cache_line_size": line_size, diff --git a/tests/functional/pyocf/types/ioclass.py b/tests/functional/pyocf/types/ioclass.py index 908f281..2d03c08 100644 --- a/tests/functional/pyocf/types/ioclass.py +++ b/tests/functional/pyocf/types/ioclass.py @@ -15,7 +15,6 @@ class IoClassInfo(Structure): ("_curr_size", c_uint32), ("_min_size", c_uint32), ("_max_size", c_uint32), - ("_eviction_policy_type", c_uint8), ("_cleaning_policy_type", c_int), ] diff --git a/tests/functional/pyocf/types/stats/cache.py b/tests/functional/pyocf/types/stats/cache.py index 521416d..a624cc6 100644 --- a/tests/functional/pyocf/types/stats/cache.py +++ b/tests/functional/pyocf/types/stats/cache.py @@ -28,7 +28,6 @@ class CacheInfo(Structure): ("dirty_for", c_uint64), ("cache_mode", c_uint32), ("fallback_pt", _FallbackPt), - ("eviction_policy", c_uint32), ("cleaning_policy", c_uint32), ("promotion_policy", c_uint32), ("cache_line_size", c_uint64), diff --git a/tests/functional/tests/management/test_attach_cache.py b/tests/functional/tests/management/test_attach_cache.py index 56557a3..1cd9d17 100644 --- a/tests/functional/tests/management/test_attach_cache.py +++ b/tests/functional/tests/management/test_attach_cache.py @@ -15,7 +15,6 @@ from pyocf.types.cache import ( Cache, CacheMode, MetadataLayout, - EvictionPolicy, CleaningPolicy, ) from pyocf.types.core import Core diff --git a/tests/functional/tests/management/test_start_stop.py b/tests/functional/tests/management/test_start_stop.py index 42149a8..7edef73 100644 --- a/tests/functional/tests/management/test_start_stop.py +++ b/tests/functional/tests/management/test_start_stop.py @@ -11,7 +11,7 @@ from itertools import count import pytest from pyocf.ocf import OcfLib -from pyocf.types.cache import Cache, CacheMode, MetadataLayout, EvictionPolicy, CleaningPolicy +from pyocf.types.cache import Cache, CacheMode, MetadataLayout, CleaningPolicy from pyocf.types.core import Core from pyocf.types.data import Data from pyocf.types.io import IoDir @@ -38,7 +38,6 @@ def test_start_check_default(pyocf_ctx): assert stats["conf"]["cleaning_policy"] == CleaningPolicy.DEFAULT assert stats["conf"]["cache_mode"] == CacheMode.DEFAULT assert stats["conf"]["cache_line_size"] == CacheLineSize.DEFAULT - assert stats["conf"]["eviction_policy"] == EvictionPolicy.DEFAULT core_stats = core.get_stats() assert core_stats["seq_cutoff_policy"] == SeqCutOffPolicy.DEFAULT @@ -156,7 +155,6 @@ def test_start_params(pyocf_ctx, mode: CacheMode, cls: CacheLineSize, layout: Me stats = cache.get_stats() assert stats["conf"]["cache_mode"] == mode, "Cache mode" assert stats["conf"]["cache_line_size"] == cls, "Cache line size" - assert stats["conf"]["eviction_policy"] == EvictionPolicy.DEFAULT, "Eviction policy" assert cache.get_name() == name, "Cache name" # TODO: metadata_layout, metadata_volatile, max_queue_size, # queue_unblock_size, pt_unaligned_io, use_submit_fast diff --git a/tests/functional/tests/security/conftest.py b/tests/functional/tests/security/conftest.py index 44eb9cf..a38ec40 100644 --- a/tests/functional/tests/security/conftest.py +++ b/tests/functional/tests/security/conftest.py @@ -13,7 +13,7 @@ from ctypes import ( ) from tests.utils.random import RandomStringGenerator, RandomGenerator, DefaultRanges, Range -from pyocf.types.cache import CacheMode, EvictionPolicy, MetadataLayout, PromotionPolicy +from pyocf.types.cache import CacheMode, MetadataLayout, PromotionPolicy from pyocf.types.shared import CacheLineSize import pytest @@ -77,13 +77,6 @@ def not_cache_line_size_randomize(request): return request.param -@pytest.fixture( - params=RandomGenerator(DefaultRanges.UINT32).exclude_range(enum_range(EvictionPolicy)) -) -def not_eviction_policy_randomize(request): - return request.param - - @pytest.fixture( params=RandomGenerator(DefaultRanges.UINT32).exclude_range(enum_range(PromotionPolicy)) ) diff --git a/tests/functional/tests/security/test_management_start_fuzzy.py b/tests/functional/tests/security/test_management_start_fuzzy.py index c152b78..49b78dc 100644 --- a/tests/functional/tests/security/test_management_start_fuzzy.py +++ b/tests/functional/tests/security/test_management_start_fuzzy.py @@ -7,7 +7,7 @@ import logging import pytest -from pyocf.types.cache import Cache, CacheMode, EvictionPolicy, MetadataLayout, PromotionPolicy +from pyocf.types.cache import Cache, CacheMode, MetadataLayout, PromotionPolicy from pyocf.types.shared import OcfError, CacheLineSize from pyocf.types.volume import Volume from pyocf.utils import Size @@ -73,25 +73,6 @@ def test_fuzzy_start_name(pyocf_ctx, string_randomize, cm, cls): cache.stop() -@pytest.mark.security -@pytest.mark.parametrize("cm", CacheMode) -@pytest.mark.parametrize("cls", CacheLineSize) -def test_fuzzy_start_eviction_policy(pyocf_ctx, not_eviction_policy_randomize, cm, cls): - """ - Test whether it is impossible to start cache with invalid eviction policy value. - :param pyocf_ctx: basic pyocf context fixture - :param c_uint32_randomize: eviction policy enum value to start cache with - :param cm: cache mode value to start cache with - :param cls: cache line size value to start cache with - """ - with pytest.raises(OcfError, match="OCF_ERR_INVAL"): - try_start_cache( - eviction_policy=not_eviction_policy_randomize, - cache_mode=cm, - cache_line_size=cls - ) - - @pytest.mark.security @pytest.mark.parametrize("cm", CacheMode) @pytest.mark.parametrize("cls", CacheLineSize) diff --git a/tests/unit/tests/eviction/eviction.c/eviction.c b/tests/unit/tests/eviction/eviction.c/eviction.c index d9b0798..9891a87 100644 --- a/tests/unit/tests/eviction/eviction.c/eviction.c +++ b/tests/unit/tests/eviction/eviction.c/eviction.c @@ -18,7 +18,6 @@ #include "print_desc.h" #include "eviction.h" -#include "ops.h" #include "../utils/utils_user_part.h" #include "eviction/eviction.c/eviction_generated_wraps.c" @@ -38,11 +37,6 @@ uint32_t __wrap_ocf_lru_num_free(ocf_cache_t cache) return 0; } -bool __wrap_ocf_eviction_can_evict(ocf_cache_t cache) -{ - return true; -} - uint32_t __wrap_ocf_user_part_overflow_size(struct ocf_cache *cache, struct ocf_user_part *user_part) { @@ -59,21 +53,20 @@ uint32_t __wrap_ocf_evict_calculate(ocf_cache_t cache, return min(tcache->evictable[user_part->part.id], to_evict); } -uint32_t __wrap_ocf_request_space(struct ocf_cache *cache, - ocf_queue_t io_queue, struct ocf_part *part, - uint32_t clines) +uint32_t __wrap_evp_lru_req_clines(struct ocf_request *req, + struct ocf_part *src_part, uint32_t cline_no) { - struct test_cache *tcache = (struct test_cache *)cache; + struct test_cache *tcache = (struct test_cache *)req->cache; unsigned overflown_consumed; - overflown_consumed = min(clines, tcache->overflow[part->id]); + overflown_consumed = min(cline_no, tcache->overflow[src_part->id]); - tcache->overflow[part->id] -= overflown_consumed; - tcache->evictable[part->id] -= clines; - tcache->req_unmapped -= clines; + tcache->overflow[src_part->id] -= overflown_consumed; + tcache->evictable[src_part->id] -= cline_no; + tcache->req_unmapped -= cline_no; - check_expected(part); - check_expected(clines); + check_expected(src_part); + check_expected(cline_no); function_called(); return mock(); @@ -200,10 +193,10 @@ uint32_t __wrap_ocf_engine_unmapped_count(struct ocf_request *req) #define _expect_evict_call(tcache, part_id, req_count, ret_count) \ do { \ - expect_value(__wrap_ocf_request_space, part, &tcache.cache.user_parts[part_id].part); \ - expect_value(__wrap_ocf_request_space, clines, req_count); \ - expect_function_call(__wrap_ocf_request_space); \ - will_return(__wrap_ocf_request_space, ret_count); \ + expect_value(__wrap_evp_lru_req_clines, src_part, &tcache.cache.user_parts[part_id].part); \ + expect_value(__wrap_evp_lru_req_clines, cline_no, req_count); \ + expect_function_call(__wrap_evp_lru_req_clines); \ + will_return(__wrap_evp_lru_req_clines, ret_count); \ } while (false); static void ocf_remap_do_test01(void **state) diff --git a/tests/unit/tests/eviction/lru.c/lru_iter.c b/tests/unit/tests/eviction/lru.c/lru_iter.c index 6a78957..883d6fa 100644 --- a/tests/unit/tests/eviction/lru.c/lru_iter.c +++ b/tests/unit/tests/eviction/lru.c/lru_iter.c @@ -28,7 +28,6 @@ #include "eviction.h" #include "lru.h" -#include "ops.h" #include "../utils/utils_cleaner.h" #include "../utils/utils_cache_line.h" #include "../concurrency/ocf_concurrency.h" diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c index ae85336..48420b0 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mngt_set_cache_mode_test.c @@ -36,7 +36,7 @@ ocf_mngt_cache_mode_has_lazy_write #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" #include "../concurrency/ocf_concurrency.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "../ocf_ctx_priv.h" #include "../cleaning/cleaning.h" diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c index 1c5479d..3dc53f5 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c @@ -30,7 +30,7 @@ #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" #include "../concurrency/ocf_concurrency.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "../ocf_ctx_priv.h" #include "../cleaning/cleaning.h" diff --git a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c index f3ce86b..7676535 100644 --- a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c +++ b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c @@ -32,7 +32,7 @@ #include "../metadata/metadata.h" #include "../engine/cache_engine.h" #include "../utils/utils_user_part.h" -#include "../eviction/ops.h" +#include "../eviction/lru.h" #include "ocf_env.h" #include "mngt/ocf_mngt_io_class.c/ocf_mngt_io_class_generated_wraps.c"