Replace eviction with lru in metadata structs
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
parent
88e04a4204
commit
7c0f940876
@ -20,17 +20,6 @@ struct ocf_part_runtime;
|
||||
struct ocf_part_cleaning_ctx;
|
||||
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.
|
||||
*
|
||||
|
@ -24,12 +24,12 @@ static void add_lru_head(ocf_cache_t cache,
|
||||
unsigned int collision_index)
|
||||
|
||||
{
|
||||
struct lru_eviction_policy_meta *node;
|
||||
struct ocf_lru_meta *node;
|
||||
unsigned int curr_head_index;
|
||||
|
||||
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;
|
||||
|
||||
/* First node to be added/ */
|
||||
@ -42,15 +42,14 @@ static void add_lru_head(ocf_cache_t cache,
|
||||
|
||||
list->num_nodes = 1;
|
||||
} else {
|
||||
struct lru_eviction_policy_meta *curr_head;
|
||||
struct ocf_lru_meta *curr_head;
|
||||
|
||||
/* Not the first node to be added. */
|
||||
curr_head_index = list->head;
|
||||
|
||||
ENV_BUG_ON(curr_head_index == end_marker);
|
||||
|
||||
curr_head = &ocf_metadata_get_eviction_policy(cache,
|
||||
curr_head_index)->lru;
|
||||
curr_head = ocf_metadata_get_lru(cache, curr_head_index);
|
||||
|
||||
node->next = curr_head_index;
|
||||
node->prev = end_marker;
|
||||
@ -75,11 +74,11 @@ static void remove_lru_list(ocf_cache_t cache,
|
||||
{
|
||||
int is_head = 0, is_tail = 0;
|
||||
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);
|
||||
|
||||
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_tail = (list->tail == collision_index);
|
||||
@ -108,12 +107,11 @@ static void remove_lru_list(ocf_cache_t cache,
|
||||
* update head and return
|
||||
*/
|
||||
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);
|
||||
|
||||
next_node = &ocf_metadata_get_eviction_policy(cache,
|
||||
next_lru_node)->lru;
|
||||
next_node = ocf_metadata_get_lru(cache, next_lru_node);
|
||||
|
||||
if (list->last_hot == collision_index) {
|
||||
ENV_BUG_ON(list->num_hot != 0);
|
||||
@ -130,14 +128,13 @@ static void remove_lru_list(ocf_cache_t cache,
|
||||
* update tail and return
|
||||
*/
|
||||
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);
|
||||
|
||||
list->tail = prev_lru_node;
|
||||
|
||||
prev_node = &ocf_metadata_get_eviction_policy(cache,
|
||||
prev_lru_node)->lru;
|
||||
prev_node = ocf_metadata_get_lru(cache, prev_lru_node);
|
||||
|
||||
node->prev = 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.
|
||||
*/
|
||||
else {
|
||||
struct lru_eviction_policy_meta *prev_node;
|
||||
struct lru_eviction_policy_meta *next_node;
|
||||
struct ocf_lru_meta *prev_node;
|
||||
struct ocf_lru_meta *next_node;
|
||||
|
||||
ENV_BUG_ON(next_lru_node == end_marker);
|
||||
ENV_BUG_ON(prev_lru_node == end_marker);
|
||||
|
||||
next_node = &ocf_metadata_get_eviction_policy(cache,
|
||||
next_lru_node)->lru;
|
||||
prev_node = &ocf_metadata_get_eviction_policy(cache,
|
||||
prev_lru_node)->lru;
|
||||
next_node = ocf_metadata_get_lru(cache, next_lru_node);
|
||||
prev_node = ocf_metadata_get_lru(cache, prev_lru_node);
|
||||
|
||||
if (list->last_hot == collision_index) {
|
||||
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)
|
||||
{
|
||||
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)
|
||||
return;
|
||||
@ -193,8 +188,7 @@ static void balance_lru_list(ocf_cache_t cache,
|
||||
return;
|
||||
|
||||
if (list->num_hot == 0) {
|
||||
node = &ocf_metadata_get_eviction_policy(cache,
|
||||
list->head)->lru;
|
||||
node = ocf_metadata_get_lru(cache, list->head);
|
||||
list->last_hot = list->head;
|
||||
list->num_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);
|
||||
node = &ocf_metadata_get_eviction_policy(cache,
|
||||
list->last_hot)->lru;
|
||||
node = ocf_metadata_get_lru(cache, list->last_hot);
|
||||
|
||||
if (target_hot_count > list->num_hot) {
|
||||
++list->num_hot;
|
||||
list->last_hot = node->next;
|
||||
node = &ocf_metadata_get_eviction_policy(cache,
|
||||
node->next)->lru;
|
||||
node = ocf_metadata_get_lru(cache, node->next);
|
||||
node->hot = true;
|
||||
} else {
|
||||
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)
|
||||
{
|
||||
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->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,
|
||||
uint32_t evp, bool clean)
|
||||
{
|
||||
return clean ? &part->runtime->eviction[evp].policy.lru.clean :
|
||||
&part->runtime->eviction[evp].policy.lru.dirty;
|
||||
return clean ? &part->runtime->lru[evp].clean :
|
||||
&part->runtime->lru[evp].dirty;
|
||||
}
|
||||
|
||||
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;
|
||||
while (cline != end_marker && !_lru_iter_evition_lock(iter,
|
||||
cline, core_id, core_line)) {
|
||||
cline = ocf_metadata_get_eviction_policy(
|
||||
iter->cache, cline)->lru.prev;
|
||||
cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
|
||||
}
|
||||
|
||||
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;
|
||||
while (cline != end_marker && !ocf_cache_line_try_lock_wr(
|
||||
iter->c, cline)) {
|
||||
cline = ocf_metadata_get_eviction_policy(
|
||||
iter->cache, cline)->lru.prev;
|
||||
cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
|
||||
}
|
||||
|
||||
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(
|
||||
iter->c, cline)) {
|
||||
cline = ocf_metadata_get_eviction_policy(
|
||||
iter->cache, cline)->lru.prev;
|
||||
cline = ocf_metadata_get_lru(iter->cache, cline)->prev;
|
||||
}
|
||||
if (cline != end_marker) {
|
||||
iter->curr_cline[curr_evp] =
|
||||
ocf_metadata_get_eviction_policy(
|
||||
iter->cache , cline)->lru.prev;
|
||||
ocf_metadata_get_lru(iter->cache , cline)->prev;
|
||||
}
|
||||
|
||||
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 */
|
||||
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;
|
||||
bool hot;
|
||||
|
||||
node = &ocf_metadata_get_eviction_policy(cache, cline)->lru;
|
||||
node = ocf_metadata_get_lru(cache, cline);
|
||||
|
||||
OCF_METADATA_EVICTION_RD_LOCK(cline);
|
||||
hot = node->hot;
|
||||
@ -1013,7 +1001,7 @@ int ocf_metadata_actor(struct ocf_cache *cache,
|
||||
struct ocf_lru_list *list;
|
||||
struct ocf_part *part;
|
||||
unsigned i, cline;
|
||||
struct lru_eviction_policy_meta *node;
|
||||
struct ocf_lru_meta *node;
|
||||
|
||||
start_line = ocf_bytes_2_lines(cache, start_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;
|
||||
while (cline != end_marker) {
|
||||
node = &ocf_metadata_get_eviction_policy(cache,
|
||||
cline)->lru;
|
||||
node = ocf_metadata_get_lru(cache, cline);
|
||||
if (!_is_cache_line_acting(cache, cline,
|
||||
core_id, start_line,
|
||||
end_line)) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#define __EVICTION_LRU_STRUCTS_H__
|
||||
|
||||
struct lru_eviction_policy_meta {
|
||||
struct ocf_lru_meta {
|
||||
uint32_t prev;
|
||||
uint32_t next;
|
||||
uint8_t hot;
|
||||
@ -21,7 +21,7 @@ struct ocf_lru_list {
|
||||
bool track_hot;
|
||||
};
|
||||
|
||||
struct lru_eviction_policy {
|
||||
struct ocf_lru_part_meta {
|
||||
struct ocf_lru_list clean;
|
||||
struct ocf_lru_list dirty;
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ static ocf_cache_line_t ocf_metadata_get_entries(
|
||||
switch (type) {
|
||||
case metadata_segment_collision:
|
||||
case metadata_segment_cleaning:
|
||||
case metadata_segment_eviction:
|
||||
case metadata_segment_lru:
|
||||
case metadata_segment_list_info:
|
||||
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);
|
||||
|
||||
switch (type) {
|
||||
case metadata_segment_eviction:
|
||||
size = sizeof(union eviction_policy_meta);
|
||||
case metadata_segment_lru:
|
||||
size = sizeof(struct ocf_lru_meta);
|
||||
break;
|
||||
|
||||
case metadata_segment_cleaning:
|
||||
@ -328,7 +328,7 @@ const char * const ocf_metadata_segment_names[] = {
|
||||
[metadata_segment_part_config] = "Part config",
|
||||
[metadata_segment_part_runtime] = "Part runtime",
|
||||
[metadata_segment_cleaning] = "Cleaning",
|
||||
[metadata_segment_eviction] = "Eviction",
|
||||
[metadata_segment_lru] = "LRU list",
|
||||
[metadata_segment_collision] = "Collision",
|
||||
[metadata_segment_list_info] = "List info",
|
||||
[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_core_runtime),
|
||||
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_list_info),
|
||||
OCF_PL_ARG_INT(metadata_segment_hash),
|
||||
@ -1101,7 +1101,7 @@ out:
|
||||
struct ocf_pipeline_arg ocf_metadata_load_all_args[] = {
|
||||
OCF_PL_ARG_INT(metadata_segment_core_runtime),
|
||||
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_list_info),
|
||||
OCF_PL_ARG_INT(metadata_segment_hash),
|
||||
|
@ -11,15 +11,14 @@
|
||||
/*
|
||||
* Eviction policy - Get
|
||||
*/
|
||||
union eviction_policy_meta *
|
||||
ocf_metadata_get_eviction_policy(struct ocf_cache *cache,
|
||||
struct ocf_lru_meta * ocf_metadata_get_lru(struct ocf_cache *cache,
|
||||
ocf_cache_line_t line)
|
||||
{
|
||||
struct ocf_metadata_ctrl *ctrl
|
||||
= (struct ocf_metadata_ctrl *) cache->metadata.priv;
|
||||
|
||||
return ocf_metadata_raw_wr_access(cache,
|
||||
&(ctrl->raw_desc[metadata_segment_eviction]), line);
|
||||
&(ctrl->raw_desc[metadata_segment_lru]), line);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
#ifndef __METADATA_EVICTION_H__
|
||||
#define __METADATA_EVICTION_H__
|
||||
|
||||
union eviction_policy_meta *
|
||||
ocf_metadata_get_eviction_policy(
|
||||
struct ocf_lru_meta *
|
||||
ocf_metadata_get_lru(
|
||||
struct ocf_cache *cache, ocf_cache_line_t line);
|
||||
|
||||
#endif /* METADATA_EVICTION_H_ */
|
||||
|
@ -30,7 +30,7 @@ struct ocf_user_part_config {
|
||||
|
||||
struct ocf_part_runtime {
|
||||
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,
|
||||
|
@ -32,7 +32,7 @@ enum ocf_metadata_segment_id {
|
||||
/* sections with size dependent on cache device size go here: */
|
||||
metadata_segment_cleaning = /*!< Cleaning policy */
|
||||
metadata_segment_variable_size_start,
|
||||
metadata_segment_eviction, /*!< Eviction policy */
|
||||
metadata_segment_lru, /*!< Eviction policy */
|
||||
metadata_segment_collision, /*!< Collision */
|
||||
metadata_segment_list_info, /*!< Collision */
|
||||
metadata_segment_hash, /*!< Hash */
|
||||
|
@ -37,15 +37,15 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
union eviction_policy_meta*
|
||||
__wrap_ocf_metadata_get_eviction_policy(ocf_cache_t cache, ocf_cache_line_t line)
|
||||
struct ocf_lru_meta*
|
||||
__wrap_ocf_metadata_get_lru(ocf_cache_t cache, ocf_cache_line_t line)
|
||||
{
|
||||
assert (line < META_COUNT);
|
||||
return &meta[line];
|
||||
@ -76,12 +76,12 @@ static void check_hot_elems(struct ocf_lru_list *l)
|
||||
unsigned curr = l->head;
|
||||
|
||||
for (i = 0; i < l->num_hot; i++) {
|
||||
assert_int_equal(meta[curr].lru.hot, 1);
|
||||
curr = meta[curr].lru.next;
|
||||
assert_int_equal(meta[curr].hot, 1);
|
||||
curr = meta[curr].next;
|
||||
}
|
||||
for (i = l->num_hot; i < l->num_nodes; i++) {
|
||||
assert_int_equal(meta[curr].lru.hot, 0);
|
||||
curr = meta[curr].lru.next;
|
||||
assert_int_equal(meta[curr].hot, 0);
|
||||
curr = meta[curr].next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
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) {
|
||||
if (test_cases[j][i][current_case] == line) {
|
||||
if (j == 0) {
|
||||
policy.lru.prev = -1;
|
||||
policy.prev = -1;
|
||||
} else {
|
||||
policy.lru.prev =
|
||||
policy.prev =
|
||||
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
|
||||
print_message("[%u] next %u prev %u\n",
|
||||
line, policy.lru.next,
|
||||
policy.lru.prev);
|
||||
line, policy.next,
|
||||
policy.prev);
|
||||
#endif
|
||||
return &policy;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user