From 44efe3e49ebee3f1a3c9951d8c1c63c521f06f2d Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 30 Nov 2020 20:27:40 +0100 Subject: [PATCH] Refactor LRU code to use part rather than part_id Signed-off-by: Adam Rutkowski --- src/engine/engine_common.c | 2 +- src/eviction/eviction.c | 13 ++++----- src/eviction/eviction.h | 10 ++++--- src/eviction/lru.c | 35 +++++++++-------------- src/eviction/lru.h | 12 +++++--- src/eviction/ops.h | 11 +++---- src/metadata/metadata_hash.c | 3 +- src/metadata/metadata_partition_structs.h | 4 +-- src/mngt/ocf_mngt_cache.c | 11 +++---- src/ocf_cache_priv.h | 2 -- src/utils/utils_cache_line.c | 6 ++-- src/utils/utils_cleaner.c | 6 ++-- src/utils/utils_part.c | 2 +- 13 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/engine/engine_common.c b/src/engine/engine_common.c index 4f18201..9e8b0ee 100644 --- a/src/engine/engine_common.c +++ b/src/engine/engine_common.c @@ -266,7 +266,7 @@ static void ocf_engine_map_cache_line(struct ocf_request *req, *cache_line); ocf_metadata_end_collision_shared_access(cache, *cache_line); - ocf_eviction_init_cache_line(cache, *cache_line, part_id); + ocf_eviction_init_cache_line(cache, *cache_line); /* Update LRU:: Move this node to head of lru list. */ ocf_eviction_set_hot_cache_line(cache, *cache_line); diff --git a/src/eviction/eviction.c b/src/eviction/eviction.c index 8909e01..5a41935 100644 --- a/src/eviction/eviction.c +++ b/src/eviction/eviction.c @@ -42,11 +42,10 @@ static uint32_t ocf_evict_calculate(struct ocf_user_part *part, static inline uint32_t ocf_evict_do(ocf_cache_t cache, ocf_queue_t io_queue, const uint32_t evict_cline_no, - ocf_part_id_t target_part_id) + struct ocf_user_part *target_part) { 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 */ @@ -68,7 +67,7 @@ static inline uint32_t ocf_evict_do(ocf_cache_t cache, /* It seams that no more partition for eviction */ break; } - if (part_id == target_part_id) { + if (part_id == target_part->id) { /* Omit targeted, evict from different first */ continue; } @@ -84,7 +83,7 @@ static inline uint32_t ocf_evict_do(ocf_cache_t cache, } evicted += ocf_eviction_need_space(cache, io_queue, - part_id, to_evict); + part, to_evict); } if (!ocf_eviction_can_evict(cache)) @@ -95,7 +94,7 @@ static inline uint32_t ocf_evict_do(ocf_cache_t cache, 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); + target_part, to_evict); } } @@ -108,14 +107,14 @@ int space_managment_evict_do(struct ocf_cache *cache, { uint32_t evicted; uint32_t free; + struct ocf_user_part *req_part = &cache->user_parts[req->part_id]; free = ocf_freelist_num_free(cache->freelist); if (evict_cline_no <= free) return LOOKUP_MAPPED; evict_cline_no -= free; - evicted = ocf_evict_do(cache, req->io_queue, evict_cline_no, - req->part_id); + evicted = ocf_evict_do(cache, req->io_queue, evict_cline_no, req_part); if (evict_cline_no <= evicted) return LOOKUP_MAPPED; diff --git a/src/eviction/eviction.h b/src/eviction/eviction.h index 5679271..4843d37 100644 --- a/src/eviction/eviction.h +++ b/src/eviction/eviction.h @@ -16,6 +16,8 @@ #define OCF_NUM_EVICTION_LISTS 32 +struct ocf_user_part; + struct eviction_policy { union { struct lru_eviction_policy lru; @@ -39,16 +41,16 @@ struct eviction_policy_ops { ocf_cache_line_t cline); bool (*can_evict)(ocf_cache_t cache); uint32_t (*req_clines)(ocf_cache_t cache, - ocf_queue_t io_queue, ocf_part_id_t part_id, + ocf_queue_t io_queue, struct ocf_user_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, ocf_part_id_t part_id); + void (*init_evp)(ocf_cache_t cache, struct ocf_user_part *part); void (*dirty_cline)(ocf_cache_t cache, - ocf_part_id_t part_id, + struct ocf_user_part *part, uint32_t cline_no); void (*clean_cline)(ocf_cache_t cache, - ocf_part_id_t part_id, + struct ocf_user_part *part, uint32_t cline_no); const char *name; }; diff --git a/src/eviction/lru.c b/src/eviction/lru.c index 7e8c67a..96ef568 100644 --- a/src/eviction/lru.c +++ b/src/eviction/lru.c @@ -191,9 +191,8 @@ void evp_lru_rm_cline(ocf_cache_t cache, ocf_cache_line_t cline) } static inline void lru_iter_init(struct ocf_lru_iter *iter, ocf_cache_t cache, - ocf_part_id_t part_id, uint32_t start_evp, bool clean) + struct ocf_user_part *part, uint32_t start_evp, bool clean) { - struct ocf_user_part *part = &cache->user_parts[part_id]; uint32_t i; /* entire iterator implementation depends on gcc builtins for @@ -201,7 +200,6 @@ static inline void lru_iter_init(struct ocf_lru_iter *iter, ocf_cache_t cache, ENV_BUILD_BUG_ON(OCF_NUM_EVICTION_LISTS > sizeof(iter->evp) * 8); iter->cache = cache; - iter->part_id = part_id; iter->part = part; /* set iterator value to start_evp - 1 modulo OCF_NUM_EVICTION_LISTS */ iter->evp = (start_evp + OCF_NUM_EVICTION_LISTS - 1) % OCF_NUM_EVICTION_LISTS; @@ -273,7 +271,7 @@ static void evp_lru_clean_end(void *private_data, int error) { struct ocf_lru_iter *iter = private_data; - ocf_refcnt_dec(&iter->cache->refcnt.cleaning[iter->part_id]); + ocf_refcnt_dec(&iter->part->cleaning); } static int evp_lru_clean_getter(ocf_cache_t cache, void *getter_context, @@ -303,10 +301,9 @@ static int evp_lru_clean_getter(ocf_cache_t cache, void *getter_context, } static void evp_lru_clean(ocf_cache_t cache, ocf_queue_t io_queue, - ocf_part_id_t part_id, uint32_t count) + struct ocf_user_part *part, uint32_t count) { - struct ocf_refcnt *counter = &cache->refcnt.cleaning[part_id]; - struct ocf_user_part *part = &cache->user_parts[part_id]; + struct ocf_refcnt *counter = &part->cleaning; struct ocf_cleaner_attribs attribs = { .cache_line_lock = true, .do_sort = true, @@ -337,7 +334,7 @@ static void evp_lru_clean(ocf_cache_t cache, ocf_queue_t io_queue, return; } - lru_iter_init(&part->eviction_clean_iter, cache, part_id, + lru_iter_init(&part->eviction_clean_iter, cache, part, part->eviction_clean_iter.evp, false); ocf_cleaner_fire(cache, &attribs); @@ -387,11 +384,9 @@ bool evp_lru_can_evict(ocf_cache_t cache) return true; } -static bool dirty_pages_present(ocf_cache_t cache, ocf_part_id_t part_id) +static bool dirty_pages_present(ocf_cache_t cache, struct ocf_user_part *part) { uint32_t i; - struct ocf_user_part *part = &cache->user_parts[part_id]; - for (i = 0; i < OCF_NUM_EVICTION_LISTS; i++) { if (evp_lru_get_list(part, i, false)->tail != end_marker) @@ -403,17 +398,16 @@ static bool dirty_pages_present(ocf_cache_t cache, ocf_part_id_t part_id) /* the caller must hold the metadata lock */ uint32_t evp_lru_req_clines(ocf_cache_t cache, ocf_queue_t io_queue, - ocf_part_id_t part_id, uint32_t cline_no) + struct ocf_user_part *part, uint32_t cline_no) { struct ocf_lru_iter iter; uint32_t i; ocf_cache_line_t cline; - struct ocf_user_part *part = &cache->user_parts[part_id]; if (cline_no == 0) return 0; - lru_iter_init(&iter, cache, part_id, part->next_eviction_list, true); + lru_iter_init(&iter, cache, part, part->next_eviction_list, true); i = 0; while (i < cline_no) { @@ -451,8 +445,8 @@ uint32_t evp_lru_req_clines(ocf_cache_t cache, ocf_queue_t io_queue, part->next_eviction_list = iter.evp; - if (i < cline_no && dirty_pages_present(cache, part_id)) - evp_lru_clean(cache, io_queue, part_id, cline_no - i); + if (i < cline_no && dirty_pages_present(cache, part)) + evp_lru_clean(cache, io_queue, part, cline_no - i); /* Return number of clines that were really evicted */ return i; @@ -484,9 +478,8 @@ static inline void _lru_init(struct ocf_lru_list *list) list->tail = end_marker; } -void evp_lru_init_evp(ocf_cache_t cache, ocf_part_id_t part_id) +void evp_lru_init_evp(ocf_cache_t cache, struct ocf_user_part *part) { - struct ocf_user_part *part = &cache->user_parts[part_id]; struct ocf_lru_list *clean_list; struct ocf_lru_list *dirty_list; uint32_t i; @@ -500,10 +493,9 @@ void evp_lru_init_evp(ocf_cache_t cache, ocf_part_id_t part_id) } } -void evp_lru_clean_cline(ocf_cache_t cache, ocf_part_id_t part_id, +void evp_lru_clean_cline(ocf_cache_t cache, struct ocf_user_part *part, uint32_t cline) { - struct ocf_user_part *part = &cache->user_parts[part_id]; uint32_t ev_list = (cline % OCF_NUM_EVICTION_LISTS); struct ocf_lru_list *clean_list; struct ocf_lru_list *dirty_list; @@ -517,10 +509,9 @@ void evp_lru_clean_cline(ocf_cache_t cache, ocf_part_id_t part_id, OCF_METADATA_EVICTION_UNLOCK(cline); } -void evp_lru_dirty_cline(ocf_cache_t cache, ocf_part_id_t part_id, +void evp_lru_dirty_cline(ocf_cache_t cache, struct ocf_user_part *part, uint32_t cline) { - struct ocf_user_part *part = &cache->user_parts[part_id]; uint32_t ev_list = (cline % OCF_NUM_EVICTION_LISTS); struct ocf_lru_list *clean_list; struct ocf_lru_list *dirty_list; diff --git a/src/eviction/lru.h b/src/eviction/lru.h index 601ec89..e8ec81c 100644 --- a/src/eviction/lru.h +++ b/src/eviction/lru.h @@ -8,14 +8,18 @@ #include "eviction.h" #include "lru_structs.h" +struct ocf_user_part; + void evp_lru_init_cline(struct ocf_cache *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_cache *cache, ocf_queue_t io_queue, - ocf_part_id_t part_id, uint32_t cline_no); + struct ocf_user_part *part, uint32_t cline_no); void evp_lru_hot_cline(struct ocf_cache *cache, ocf_cache_line_t cline); -void evp_lru_init_evp(struct ocf_cache *cache, ocf_part_id_t part_id); -void evp_lru_dirty_cline(struct ocf_cache *cache, ocf_part_id_t part_id, uint32_t cline); -void evp_lru_clean_cline(struct ocf_cache *cache, ocf_part_id_t part_id, uint32_t cline); +void evp_lru_init_evp(struct ocf_cache *cache, struct ocf_user_part *part); +void evp_lru_dirty_cline(struct ocf_cache *cache, struct ocf_user_part *part, + uint32_t cline); +void evp_lru_clean_cline(struct ocf_cache *cache, struct ocf_user_part *part, + uint32_t cline); #endif diff --git a/src/eviction/ops.h b/src/eviction/ops.h index 7ef5ea8..2952171 100644 --- a/src/eviction/ops.h +++ b/src/eviction/ops.h @@ -16,7 +16,7 @@ * @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, ocf_part_id_t part_id) + ocf_cache_line_t line) { uint8_t type; @@ -53,7 +53,8 @@ static inline bool ocf_eviction_can_evict(struct ocf_cache *cache) } static inline uint32_t ocf_eviction_need_space(struct ocf_cache *cache, - ocf_queue_t io_queue, ocf_part_id_t part_id, uint32_t clines) + ocf_queue_t io_queue, struct ocf_user_part *part, + uint32_t clines) { uint8_t type; uint32_t result = 0; @@ -68,7 +69,7 @@ static inline uint32_t ocf_eviction_need_space(struct ocf_cache *cache, * eviction lock. */ result = evict_policy_ops[type].req_clines(cache, io_queue, - part_id, clines); + part, clines); } return result; @@ -89,7 +90,7 @@ static inline void ocf_eviction_set_hot_cache_line( } static inline void ocf_eviction_initialize(struct ocf_cache *cache, - ocf_part_id_t part_id) + struct ocf_user_part *part) { uint8_t type = cache->conf_meta->eviction_policy_type; @@ -97,7 +98,7 @@ static inline void ocf_eviction_initialize(struct ocf_cache *cache, if (likely(evict_policy_ops[type].init_evp)) { OCF_METADATA_EVICTION_LOCK_ALL(); - evict_policy_ops[type].init_evp(cache, part_id); + evict_policy_ops[type].init_evp(cache, part); OCF_METADATA_EVICTION_UNLOCK_ALL(); } } diff --git a/src/metadata/metadata_hash.c b/src/metadata/metadata_hash.c index 031e66c..1e72bbf 100644 --- a/src/metadata/metadata_hash.c +++ b/src/metadata/metadata_hash.c @@ -563,6 +563,7 @@ int ocf_metadata_hash_init(struct ocf_cache *cache, for (i = 0; i < OCF_IO_CLASS_MAX + 1; i++) { cache->user_parts[i].config = &part_config[i]; cache->user_parts[i].runtime = &part_runtime[i]; + cache->user_parts[i].id = i; } /* Set core metadata */ @@ -1949,7 +1950,7 @@ 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, part_id); + ocf_eviction_init_cache_line(cache, cache_line); ocf_eviction_set_hot_cache_line(cache, cache_line); diff --git a/src/metadata/metadata_partition_structs.h b/src/metadata/metadata_partition_structs.h index 07cfbc6..baa8c88 100644 --- a/src/metadata/metadata_partition_structs.h +++ b/src/metadata/metadata_partition_structs.h @@ -38,8 +38,6 @@ struct ocf_user_part_runtime { struct ocf_lru_iter { /* cache object */ ocf_cache_t cache; - /* target partition id */ - ocf_part_id_t part_id; /* target partition */ struct ocf_user_part *part; /* per-partition cacheline iterator */ @@ -56,6 +54,8 @@ struct ocf_lru_iter { struct ocf_user_part { struct ocf_user_part_config *config; struct ocf_user_part_runtime *runtime; + struct ocf_refcnt cleaning; + ocf_part_id_t id; struct ocf_lru_iter eviction_clean_iter; uint32_t next_eviction_list; diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 6f57d48..5286ffc 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -177,7 +177,7 @@ static void __init_partitions(ocf_cache_t cache) /* Add other partition to the cache and make it as dummy */ for (i_part = 0; i_part < OCF_IO_CLASS_MAX; i_part++) { - ocf_refcnt_freeze(&cache->refcnt.cleaning[i_part]); + ocf_refcnt_freeze(&cache->user_parts[i_part].cleaning); if (i_part == PARTITION_DEFAULT) continue; @@ -191,14 +191,15 @@ static void __init_partitions(ocf_cache_t cache) static void __init_partitions_attached(ocf_cache_t cache) { + struct ocf_user_part *part; ocf_part_id_t part_id; for (part_id = 0; part_id < OCF_IO_CLASS_MAX; part_id++) { - cache->user_parts[part_id].runtime->head = - cache->device->collision_table_entries; - cache->user_parts[part_id].runtime->curr_size = 0; + part = &cache->user_parts[part_id]; - ocf_eviction_initialize(cache, part_id); + part->runtime->head = cache->device->collision_table_entries; + part->runtime->curr_size = 0; + ocf_eviction_initialize(cache, part); } } diff --git a/src/ocf_cache_priv.h b/src/ocf_cache_priv.h index d0578ca..660ae39 100644 --- a/src/ocf_cache_priv.h +++ b/src/ocf_cache_priv.h @@ -122,8 +122,6 @@ struct ocf_cache { /* # of requests accessing attached metadata, excluding * management reqs */ struct ocf_refcnt metadata; - /* # of forced cleaning requests (eviction path) */ - struct ocf_refcnt cleaning[OCF_IO_CLASS_MAX]; } refcnt; uint32_t fallback_pt_error_threshold; diff --git a/src/utils/utils_cache_line.c b/src/utils/utils_cache_line.c index 3acdb4a..342500a 100644 --- a/src/utils/utils_cache_line.c +++ b/src/utils/utils_cache_line.c @@ -101,6 +101,7 @@ 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_user_part *part = &cache->user_parts[part_id]; uint8_t evp_type = cache->conf_meta->eviction_policy_type; bool line_is_clean; @@ -130,7 +131,7 @@ void set_cache_line_clean(struct ocf_cache *cache, uint8_t start_bit, part_counters[part_id].dirty_clines); if (likely(evict_policy_ops[evp_type].clean_cline)) - evict_policy_ops[evp_type].clean_cline(cache, part_id, line); + evict_policy_ops[evp_type].clean_cline(cache, part, line); ocf_purge_cleaning_policy(cache, line); } @@ -143,6 +144,7 @@ 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_user_part *part = &cache->user_parts[part_id]; uint8_t evp_type = cache->conf_meta->eviction_policy_type; bool line_was_dirty; @@ -170,7 +172,7 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit, part_counters[part_id].dirty_clines); if (likely(evict_policy_ops[evp_type].dirty_cline)) - evict_policy_ops[evp_type].dirty_cline(cache, part_id, line); + evict_policy_ops[evp_type].dirty_cline(cache, part, line); } } diff --git a/src/utils/utils_cleaner.c b/src/utils/utils_cleaner.c index db2620d..d11528b 100644 --- a/src/utils/utils_cleaner.c +++ b/src/utils/utils_cleaner.c @@ -1017,7 +1017,7 @@ void ocf_cleaner_refcnt_freeze(ocf_cache_t cache) ocf_part_id_t part_id; for_each_part(cache, curr_part, part_id) - ocf_refcnt_freeze(&cache->refcnt.cleaning[part_id]); + ocf_refcnt_freeze(&curr_part->cleaning); } void ocf_cleaner_refcnt_unfreeze(ocf_cache_t cache) @@ -1026,7 +1026,7 @@ void ocf_cleaner_refcnt_unfreeze(ocf_cache_t cache) ocf_part_id_t part_id; for_each_part(cache, curr_part, part_id) - ocf_refcnt_unfreeze(&cache->refcnt.cleaning[part_id]); + ocf_refcnt_unfreeze(&curr_part->cleaning); } static void ocf_cleaner_refcnt_register_zero_cb_finish(void *priv) @@ -1050,7 +1050,7 @@ void ocf_cleaner_refcnt_register_zero_cb(ocf_cache_t cache, for_each_part(cache, curr_part, part_id) { env_atomic_inc(&ctx->waiting); - ocf_refcnt_register_zero_cb(&cache->refcnt.cleaning[part_id], + ocf_refcnt_register_zero_cb(&curr_part->cleaning, ocf_cleaner_refcnt_register_zero_cb_finish, ctx); } diff --git a/src/utils/utils_part.c b/src/utils/utils_part.c index 06140f4..3da853b 100644 --- a/src/utils/utils_part.c +++ b/src/utils/utils_part.c @@ -142,7 +142,7 @@ void ocf_part_move(struct ocf_request *req) ocf_metadata_add_to_partition(cache, id_new, line); /* Add to new eviction */ - ocf_eviction_init_cache_line(cache, line, id_new); + ocf_eviction_init_cache_line(cache, line); ocf_eviction_set_hot_cache_line(cache, line); /* Check if cache line is dirty. If yes then need to change