Replace eviction with lru in metadata structs

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski 2021-06-15 22:36:27 +02:00
parent 88e04a4204
commit 7c0f940876
10 changed files with 58 additions and 83 deletions

View File

@ -20,17 +20,6 @@ struct ocf_part_runtime;
struct ocf_part_cleaning_ctx; struct ocf_part_cleaning_ctx;
struct ocf_request; struct ocf_request;
struct eviction_policy {
union {
struct lru_eviction_policy lru;
} policy;
};
/* Eviction policy metadata per cache line */
union eviction_policy_meta {
struct lru_eviction_policy_meta lru;
} __attribute__((packed));
/* /*
* Deallocates space according to eviction priorities. * Deallocates space according to eviction priorities.
* *

View File

@ -24,12 +24,12 @@ static void add_lru_head(ocf_cache_t cache,
unsigned int collision_index) unsigned int collision_index)
{ {
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
unsigned int curr_head_index; unsigned int curr_head_index;
ENV_BUG_ON(collision_index == end_marker); ENV_BUG_ON(collision_index == end_marker);
node = &ocf_metadata_get_eviction_policy(cache, collision_index)->lru; node = ocf_metadata_get_lru(cache, collision_index);
node->hot = false; node->hot = false;
/* First node to be added/ */ /* First node to be added/ */
@ -42,15 +42,14 @@ static void add_lru_head(ocf_cache_t cache,
list->num_nodes = 1; list->num_nodes = 1;
} else { } else {
struct lru_eviction_policy_meta *curr_head; struct ocf_lru_meta *curr_head;
/* Not the first node to be added. */ /* Not the first node to be added. */
curr_head_index = list->head; curr_head_index = list->head;
ENV_BUG_ON(curr_head_index == end_marker); ENV_BUG_ON(curr_head_index == end_marker);
curr_head = &ocf_metadata_get_eviction_policy(cache, curr_head = ocf_metadata_get_lru(cache, curr_head_index);
curr_head_index)->lru;
node->next = curr_head_index; node->next = curr_head_index;
node->prev = end_marker; node->prev = end_marker;
@ -75,11 +74,11 @@ static void remove_lru_list(ocf_cache_t cache,
{ {
int is_head = 0, is_tail = 0; int is_head = 0, is_tail = 0;
uint32_t prev_lru_node, next_lru_node; uint32_t prev_lru_node, next_lru_node;
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
ENV_BUG_ON(collision_index == end_marker); ENV_BUG_ON(collision_index == end_marker);
node = &ocf_metadata_get_eviction_policy(cache, collision_index)->lru; node = ocf_metadata_get_lru(cache, collision_index);
is_head = (list->head == collision_index); is_head = (list->head == collision_index);
is_tail = (list->tail == collision_index); is_tail = (list->tail == collision_index);
@ -108,12 +107,11 @@ static void remove_lru_list(ocf_cache_t cache,
* update head and return * update head and return
*/ */
else if (is_head) { else if (is_head) {
struct lru_eviction_policy_meta *next_node; struct ocf_lru_meta *next_node;
ENV_BUG_ON(next_lru_node == end_marker); ENV_BUG_ON(next_lru_node == end_marker);
next_node = &ocf_metadata_get_eviction_policy(cache, next_node = ocf_metadata_get_lru(cache, next_lru_node);
next_lru_node)->lru;
if (list->last_hot == collision_index) { if (list->last_hot == collision_index) {
ENV_BUG_ON(list->num_hot != 0); ENV_BUG_ON(list->num_hot != 0);
@ -130,14 +128,13 @@ static void remove_lru_list(ocf_cache_t cache,
* update tail and return * update tail and return
*/ */
else if (is_tail) { else if (is_tail) {
struct lru_eviction_policy_meta *prev_node; struct ocf_lru_meta *prev_node;
ENV_BUG_ON(prev_lru_node == end_marker); ENV_BUG_ON(prev_lru_node == end_marker);
list->tail = prev_lru_node; list->tail = prev_lru_node;
prev_node = &ocf_metadata_get_eviction_policy(cache, prev_node = ocf_metadata_get_lru(cache, prev_lru_node);
prev_lru_node)->lru;
node->prev = end_marker; node->prev = end_marker;
prev_node->next = end_marker; prev_node->next = end_marker;
@ -147,16 +144,14 @@ static void remove_lru_list(ocf_cache_t cache,
* change to the head and the tail pointers. * change to the head and the tail pointers.
*/ */
else { else {
struct lru_eviction_policy_meta *prev_node; struct ocf_lru_meta *prev_node;
struct lru_eviction_policy_meta *next_node; struct ocf_lru_meta *next_node;
ENV_BUG_ON(next_lru_node == end_marker); ENV_BUG_ON(next_lru_node == end_marker);
ENV_BUG_ON(prev_lru_node == end_marker); ENV_BUG_ON(prev_lru_node == end_marker);
next_node = &ocf_metadata_get_eviction_policy(cache, next_node = ocf_metadata_get_lru(cache, next_lru_node);
next_lru_node)->lru; prev_node = ocf_metadata_get_lru(cache, prev_lru_node);
prev_node = &ocf_metadata_get_eviction_policy(cache,
prev_lru_node)->lru;
if (list->last_hot == collision_index) { if (list->last_hot == collision_index) {
ENV_BUG_ON(list->num_hot == 0); ENV_BUG_ON(list->num_hot == 0);
@ -184,7 +179,7 @@ static void balance_lru_list(ocf_cache_t cache,
struct ocf_lru_list *list) struct ocf_lru_list *list)
{ {
unsigned target_hot_count = list->num_nodes / OCF_LRU_HOT_RATIO; unsigned target_hot_count = list->num_nodes / OCF_LRU_HOT_RATIO;
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
if (!list->track_hot) if (!list->track_hot)
return; return;
@ -193,8 +188,7 @@ static void balance_lru_list(ocf_cache_t cache,
return; return;
if (list->num_hot == 0) { if (list->num_hot == 0) {
node = &ocf_metadata_get_eviction_policy(cache, node = ocf_metadata_get_lru(cache, list->head);
list->head)->lru;
list->last_hot = list->head; list->last_hot = list->head;
list->num_hot = 1; list->num_hot = 1;
node->hot = 1; node->hot = 1;
@ -202,14 +196,12 @@ static void balance_lru_list(ocf_cache_t cache,
} }
ENV_BUG_ON(list->last_hot == end_marker); ENV_BUG_ON(list->last_hot == end_marker);
node = &ocf_metadata_get_eviction_policy(cache, node = ocf_metadata_get_lru(cache, list->last_hot);
list->last_hot)->lru;
if (target_hot_count > list->num_hot) { if (target_hot_count > list->num_hot) {
++list->num_hot; ++list->num_hot;
list->last_hot = node->next; list->last_hot = node->next;
node = &ocf_metadata_get_eviction_policy(cache, node = ocf_metadata_get_lru(cache, node->next);
node->next)->lru;
node->hot = true; node->hot = true;
} else { } else {
if (list->last_hot == list->head) { if (list->last_hot == list->head) {
@ -230,9 +222,9 @@ static void balance_lru_list(ocf_cache_t cache,
void evp_lru_init_cline(ocf_cache_t cache, ocf_cache_line_t cline) void evp_lru_init_cline(ocf_cache_t cache, ocf_cache_line_t cline)
{ {
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
node = &ocf_metadata_get_eviction_policy(cache, cline)->lru; node = ocf_metadata_get_lru(cache, cline);
node->hot = false; node->hot = false;
node->prev = end_marker; node->prev = end_marker;
@ -242,8 +234,8 @@ void evp_lru_init_cline(ocf_cache_t cache, ocf_cache_line_t cline)
static struct ocf_lru_list *evp_lru_get_list(struct ocf_part *part, static struct ocf_lru_list *evp_lru_get_list(struct ocf_part *part,
uint32_t evp, bool clean) uint32_t evp, bool clean)
{ {
return clean ? &part->runtime->eviction[evp].policy.lru.clean : return clean ? &part->runtime->lru[evp].clean :
&part->runtime->eviction[evp].policy.lru.dirty; &part->runtime->lru[evp].dirty;
} }
static inline struct ocf_lru_list *evp_get_cline_list(ocf_cache_t cache, static inline struct ocf_lru_list *evp_get_cline_list(ocf_cache_t cache,
@ -486,8 +478,7 @@ static inline ocf_cache_line_t lru_iter_eviction_next(struct ocf_lru_iter *iter,
cline = list->tail; cline = list->tail;
while (cline != end_marker && !_lru_iter_evition_lock(iter, while (cline != end_marker && !_lru_iter_evition_lock(iter,
cline, core_id, core_line)) { cline, core_id, core_line)) {
cline = ocf_metadata_get_eviction_policy( cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
iter->cache, cline)->lru.prev;
} }
if (cline != end_marker) { if (cline != end_marker) {
@ -540,8 +531,7 @@ static inline ocf_cache_line_t lru_iter_free_next(struct ocf_lru_iter *iter,
cline = list->tail; cline = list->tail;
while (cline != end_marker && !ocf_cache_line_try_lock_wr( while (cline != end_marker && !ocf_cache_line_try_lock_wr(
iter->c, cline)) { iter->c, cline)) {
cline = ocf_metadata_get_eviction_policy( cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
iter->cache, cline)->lru.prev;
} }
if (cline != end_marker) { if (cline != end_marker) {
@ -574,13 +564,11 @@ static inline ocf_cache_line_t lru_iter_cleaning_next(struct ocf_lru_iter *iter)
while (cline != end_marker && ! ocf_cache_line_try_lock_rd( while (cline != end_marker && ! ocf_cache_line_try_lock_rd(
iter->c, cline)) { iter->c, cline)) {
cline = ocf_metadata_get_eviction_policy( cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
iter->cache, cline)->lru.prev;
} }
if (cline != end_marker) { if (cline != end_marker) {
iter->curr_cline[curr_evp] = iter->curr_cline[curr_evp] =
ocf_metadata_get_eviction_policy( ocf_metadata_get_lru(iter->cache , cline)->prev;
iter->cache , cline)->lru.prev;
} }
if (cline == end_marker && !_lru_evp_is_empty(iter)) { if (cline == end_marker && !_lru_evp_is_empty(iter)) {
@ -811,11 +799,11 @@ uint32_t evp_lru_req_clines(struct ocf_request *req,
/* the caller must hold the metadata lock */ /* the caller must hold the metadata lock */
void evp_lru_hot_cline(ocf_cache_t cache, ocf_cache_line_t cline) void evp_lru_hot_cline(ocf_cache_t cache, ocf_cache_line_t cline)
{ {
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
struct ocf_lru_list *list; struct ocf_lru_list *list;
bool hot; bool hot;
node = &ocf_metadata_get_eviction_policy(cache, cline)->lru; node = ocf_metadata_get_lru(cache, cline);
OCF_METADATA_EVICTION_RD_LOCK(cline); OCF_METADATA_EVICTION_RD_LOCK(cline);
hot = node->hot; hot = node->hot;
@ -1013,7 +1001,7 @@ int ocf_metadata_actor(struct ocf_cache *cache,
struct ocf_lru_list *list; struct ocf_lru_list *list;
struct ocf_part *part; struct ocf_part *part;
unsigned i, cline; unsigned i, cline;
struct lru_eviction_policy_meta *node; struct ocf_lru_meta *node;
start_line = ocf_bytes_2_lines(cache, start_byte); start_line = ocf_bytes_2_lines(cache, start_byte);
end_line = ocf_bytes_2_lines(cache, end_byte); end_line = ocf_bytes_2_lines(cache, end_byte);
@ -1042,8 +1030,7 @@ int ocf_metadata_actor(struct ocf_cache *cache,
cline = list->tail; cline = list->tail;
while (cline != end_marker) { while (cline != end_marker) {
node = &ocf_metadata_get_eviction_policy(cache, node = ocf_metadata_get_lru(cache, cline);
cline)->lru;
if (!_is_cache_line_acting(cache, cline, if (!_is_cache_line_acting(cache, cline,
core_id, start_line, core_id, start_line,
end_line)) { end_line)) {

View File

@ -6,7 +6,7 @@
#define __EVICTION_LRU_STRUCTS_H__ #define __EVICTION_LRU_STRUCTS_H__
struct lru_eviction_policy_meta { struct ocf_lru_meta {
uint32_t prev; uint32_t prev;
uint32_t next; uint32_t next;
uint8_t hot; uint8_t hot;
@ -21,7 +21,7 @@ struct ocf_lru_list {
bool track_hot; bool track_hot;
}; };
struct lru_eviction_policy { struct ocf_lru_part_meta {
struct ocf_lru_list clean; struct ocf_lru_list clean;
struct ocf_lru_list dirty; struct ocf_lru_list dirty;
}; };

View File

@ -71,7 +71,7 @@ static ocf_cache_line_t ocf_metadata_get_entries(
switch (type) { switch (type) {
case metadata_segment_collision: case metadata_segment_collision:
case metadata_segment_cleaning: case metadata_segment_cleaning:
case metadata_segment_eviction: case metadata_segment_lru:
case metadata_segment_list_info: case metadata_segment_list_info:
return cache_lines; return cache_lines;
@ -124,8 +124,8 @@ static int64_t ocf_metadata_get_element_size(
ENV_BUG_ON(type >= metadata_segment_variable_size_start && !settings); ENV_BUG_ON(type >= metadata_segment_variable_size_start && !settings);
switch (type) { switch (type) {
case metadata_segment_eviction: case metadata_segment_lru:
size = sizeof(union eviction_policy_meta); size = sizeof(struct ocf_lru_meta);
break; break;
case metadata_segment_cleaning: case metadata_segment_cleaning:
@ -328,7 +328,7 @@ const char * const ocf_metadata_segment_names[] = {
[metadata_segment_part_config] = "Part config", [metadata_segment_part_config] = "Part config",
[metadata_segment_part_runtime] = "Part runtime", [metadata_segment_part_runtime] = "Part runtime",
[metadata_segment_cleaning] = "Cleaning", [metadata_segment_cleaning] = "Cleaning",
[metadata_segment_eviction] = "Eviction", [metadata_segment_lru] = "LRU list",
[metadata_segment_collision] = "Collision", [metadata_segment_collision] = "Collision",
[metadata_segment_list_info] = "List info", [metadata_segment_list_info] = "List info",
[metadata_segment_hash] = "Hash", [metadata_segment_hash] = "Hash",
@ -957,7 +957,7 @@ struct ocf_pipeline_arg ocf_metadata_flush_all_args[] = {
OCF_PL_ARG_INT(metadata_segment_part_runtime), OCF_PL_ARG_INT(metadata_segment_part_runtime),
OCF_PL_ARG_INT(metadata_segment_core_runtime), OCF_PL_ARG_INT(metadata_segment_core_runtime),
OCF_PL_ARG_INT(metadata_segment_cleaning), OCF_PL_ARG_INT(metadata_segment_cleaning),
OCF_PL_ARG_INT(metadata_segment_eviction), OCF_PL_ARG_INT(metadata_segment_lru),
OCF_PL_ARG_INT(metadata_segment_collision), OCF_PL_ARG_INT(metadata_segment_collision),
OCF_PL_ARG_INT(metadata_segment_list_info), OCF_PL_ARG_INT(metadata_segment_list_info),
OCF_PL_ARG_INT(metadata_segment_hash), OCF_PL_ARG_INT(metadata_segment_hash),
@ -1101,7 +1101,7 @@ out:
struct ocf_pipeline_arg ocf_metadata_load_all_args[] = { struct ocf_pipeline_arg ocf_metadata_load_all_args[] = {
OCF_PL_ARG_INT(metadata_segment_core_runtime), OCF_PL_ARG_INT(metadata_segment_core_runtime),
OCF_PL_ARG_INT(metadata_segment_cleaning), OCF_PL_ARG_INT(metadata_segment_cleaning),
OCF_PL_ARG_INT(metadata_segment_eviction), OCF_PL_ARG_INT(metadata_segment_lru),
OCF_PL_ARG_INT(metadata_segment_collision), OCF_PL_ARG_INT(metadata_segment_collision),
OCF_PL_ARG_INT(metadata_segment_list_info), OCF_PL_ARG_INT(metadata_segment_list_info),
OCF_PL_ARG_INT(metadata_segment_hash), OCF_PL_ARG_INT(metadata_segment_hash),

View File

@ -11,15 +11,14 @@
/* /*
* Eviction policy - Get * Eviction policy - Get
*/ */
union eviction_policy_meta * struct ocf_lru_meta * ocf_metadata_get_lru(struct ocf_cache *cache,
ocf_metadata_get_eviction_policy(struct ocf_cache *cache,
ocf_cache_line_t line) ocf_cache_line_t line)
{ {
struct ocf_metadata_ctrl *ctrl struct ocf_metadata_ctrl *ctrl
= (struct ocf_metadata_ctrl *) cache->metadata.priv; = (struct ocf_metadata_ctrl *) cache->metadata.priv;
return ocf_metadata_raw_wr_access(cache, return ocf_metadata_raw_wr_access(cache,
&(ctrl->raw_desc[metadata_segment_eviction]), line); &(ctrl->raw_desc[metadata_segment_lru]), line);
} }

View File

@ -6,8 +6,8 @@
#ifndef __METADATA_EVICTION_H__ #ifndef __METADATA_EVICTION_H__
#define __METADATA_EVICTION_H__ #define __METADATA_EVICTION_H__
union eviction_policy_meta * struct ocf_lru_meta *
ocf_metadata_get_eviction_policy( ocf_metadata_get_lru(
struct ocf_cache *cache, ocf_cache_line_t line); struct ocf_cache *cache, ocf_cache_line_t line);
#endif /* METADATA_EVICTION_H_ */ #endif /* METADATA_EVICTION_H_ */

View File

@ -30,7 +30,7 @@ struct ocf_user_part_config {
struct ocf_part_runtime { struct ocf_part_runtime {
env_atomic curr_size; env_atomic curr_size;
struct eviction_policy eviction[OCF_NUM_EVICTION_LISTS]; struct ocf_lru_part_meta lru[OCF_NUM_EVICTION_LISTS];
}; };
typedef bool ( *_lru_hash_locked_pfn)(struct ocf_request *req, typedef bool ( *_lru_hash_locked_pfn)(struct ocf_request *req,

View File

@ -32,7 +32,7 @@ enum ocf_metadata_segment_id {
/* sections with size dependent on cache device size go here: */ /* sections with size dependent on cache device size go here: */
metadata_segment_cleaning = /*!< Cleaning policy */ metadata_segment_cleaning = /*!< Cleaning policy */
metadata_segment_variable_size_start, metadata_segment_variable_size_start,
metadata_segment_eviction, /*!< Eviction policy */ metadata_segment_lru, /*!< Eviction policy */
metadata_segment_collision, /*!< Collision */ metadata_segment_collision, /*!< Collision */
metadata_segment_list_info, /*!< Collision */ metadata_segment_list_info, /*!< Collision */
metadata_segment_hash, /*!< Hash */ metadata_segment_hash, /*!< Hash */

View File

@ -37,15 +37,15 @@
#define META_COUNT 128 #define META_COUNT 128
static union eviction_policy_meta meta[META_COUNT]; static struct ocf_lru_meta meta[META_COUNT];
struct ocf_cache_line_concurrency *__wrap_ocf_cache_line_concurrency(ocf_cache_t cache) struct ocf_cache_line_concurrency *__wrap_ocf_cache_line_concurrency(ocf_cache_t cache)
{ {
return NULL; return NULL;
} }
union eviction_policy_meta* struct ocf_lru_meta*
__wrap_ocf_metadata_get_eviction_policy(ocf_cache_t cache, ocf_cache_line_t line) __wrap_ocf_metadata_get_lru(ocf_cache_t cache, ocf_cache_line_t line)
{ {
assert (line < META_COUNT); assert (line < META_COUNT);
return &meta[line]; return &meta[line];
@ -76,12 +76,12 @@ static void check_hot_elems(struct ocf_lru_list *l)
unsigned curr = l->head; unsigned curr = l->head;
for (i = 0; i < l->num_hot; i++) { for (i = 0; i < l->num_hot; i++) {
assert_int_equal(meta[curr].lru.hot, 1); assert_int_equal(meta[curr].hot, 1);
curr = meta[curr].lru.next; curr = meta[curr].next;
} }
for (i = l->num_hot; i < l->num_nodes; i++) { for (i = l->num_hot; i < l->num_nodes; i++) {
assert_int_equal(meta[curr].lru.hot, 0); assert_int_equal(meta[curr].hot, 0);
curr = meta[curr].lru.next; curr = meta[curr].next;
} }
} }

View File

@ -236,9 +236,9 @@ inline struct ocf_lru_list *__wrap_evp_get_cline_list(ocf_cache_t cache,
} }
union eviction_policy_meta policy; struct ocf_lru_meta policy;
union eviction_policy_meta *__wrap_ocf_metadata_get_eviction_policy( struct ocf_lru_meta *__wrap_ocf_metadata_get_lru(
struct ocf_cache *cache, ocf_cache_line_t line) struct ocf_cache *cache, ocf_cache_line_t line)
{ {
unsigned i, j; unsigned i, j;
@ -250,17 +250,17 @@ union eviction_policy_meta *__wrap_ocf_metadata_get_eviction_policy(
while (test_cases[j][i][current_case] != -1) { while (test_cases[j][i][current_case] != -1) {
if (test_cases[j][i][current_case] == line) { if (test_cases[j][i][current_case] == line) {
if (j == 0) { if (j == 0) {
policy.lru.prev = -1; policy.prev = -1;
} else { } else {
policy.lru.prev = policy.prev =
test_cases[j - 1][i][current_case]; test_cases[j - 1][i][current_case];
} }
policy.lru.next = test_cases[j + 1][i][current_case]; policy.next = test_cases[j + 1][i][current_case];
#ifdef DEBUG #ifdef DEBUG
print_message("[%u] next %u prev %u\n", print_message("[%u] next %u prev %u\n",
line, policy.lru.next, line, policy.next,
policy.lru.prev); policy.prev);
#endif #endif
return &policy; return &policy;
} }