Refactor LRU code to use part rather than part_id

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2020-11-30 20:27:40 +01:00
parent 41a767de97
commit 44efe3e49e
13 changed files with 58 additions and 59 deletions

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -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;

View File

@@ -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

View File

@@ -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();
}
}