lru refactor

rearanging lru implementation for easier journaling

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2021-05-09 13:46:39 +02:00
parent c8268245ba
commit 1e1955b833
5 changed files with 214 additions and 215 deletions

View File

@@ -6,9 +6,13 @@
* update_lru_tail
* update_lru_head_tail
* _lru_init
* add_lru_head
* remove_lru_list
* add_lru_head_nobalance
* remove_lru_list_nobalance
* remove_update_list
* remove_update_ptrs
* balance_lru_list
* balance_update_last_hot
* ocf_get_lru
* </functions_to_leave>
*/
@@ -98,8 +102,8 @@ static void _lru_init_test02(void **state)
for (i = 1; i <= 8; i++)
{
add_lru_head(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
add_lru_head_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
assert_int_equal(l.num_hot, i / 2);
assert_int_equal(l.num_nodes, i);
assert_int_equal(l.head, i);
@@ -122,8 +126,8 @@ static void _lru_init_test03(void **state)
_lru_init(&l, true);
for (i = 1; i <= 8; i++) {
add_lru_head(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
add_lru_head_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
}
for (i = 8; i >= 1; i--) {
@@ -135,8 +139,8 @@ static void _lru_init_test03(void **state)
i - i / 2 + 1);
check_hot_elems(&l);
remove_lru_list(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
}
assert_int_equal(l.num_hot, 0);
@@ -158,8 +162,8 @@ static void _lru_init_test04(void **state)
_lru_init(&l, true);
for (i = 1; i <= 8; i++) {
add_lru_head(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
add_lru_head_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
}
for (i = 8; i >= 1; i--) {
@@ -171,8 +175,8 @@ static void _lru_init_test04(void **state)
8 - i / 2 + 1);
check_hot_elems(&l);
remove_lru_list(NULL, &l, 9 - i, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 9 - i, NULL);
balance_lru_list(NULL, &l, NULL);
}
assert_int_equal(l.num_hot, 0);
@@ -196,8 +200,8 @@ static void _lru_init_test05(void **state)
_lru_init(&l, true);
for (i = 1; i <= 8; i++) {
add_lru_head(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
add_lru_head_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
present[i] = true;
}
@@ -219,8 +223,8 @@ static void _lru_init_test05(void **state)
check_hot_elems(&l);
present[l.last_hot] = false;
remove_lru_list(NULL, &l, l.last_hot, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, l.last_hot, NULL);
balance_lru_list(NULL, &l, NULL);
}
assert_int_equal(l.num_hot, 1);
@@ -243,14 +247,14 @@ static void _lru_init_test06(void **state)
_lru_init(&l, true);
for (i = 1; i <= 8; i++) {
add_lru_head(NULL, &l, i, end_marker);
balance_lru_list(NULL, &l, end_marker);
add_lru_head_nobalance(NULL, &l, i, NULL);
balance_lru_list(NULL, &l, NULL);
}
count = 8;
remove_lru_list(NULL, &l, 7, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 7, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -258,8 +262,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 5);
remove_lru_list(NULL, &l, 6, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 6, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -267,8 +271,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 4);
remove_lru_list(NULL, &l, 5, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 5, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -276,8 +280,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 4);
remove_lru_list(NULL, &l, 4, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 4, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -285,8 +289,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 3);
remove_lru_list(NULL, &l, 3, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 3, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -294,8 +298,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 8);
remove_lru_list(NULL, &l, 8, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 8, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);
@@ -303,8 +307,8 @@ static void _lru_init_test06(void **state)
assert_int_equal(l.tail, 1);
assert_int_equal(l.last_hot, 2);
remove_lru_list(NULL, &l, 2, end_marker);
balance_lru_list(NULL, &l, end_marker);
remove_lru_list_nobalance(NULL, &l, 2, NULL);
balance_lru_list(NULL, &l, NULL);
--count;
assert_int_equal(l.num_hot, count / 2);
assert_int_equal(l.num_nodes, count);

View File

@@ -5,11 +5,13 @@
* INSERT HERE LIST OF FUNCTIONS YOU WANT TO LEAVE
* ONE FUNCTION PER LINE
* lru_iter_init
* lru_iter_cleaning_init
* _lru_next_lru
* _lru_lru_is_empty
* _lru_lru_set_empty
* _lru_lru_all_empty
* ocf_rotate_right
* ocf_get_lru
* lru_iter_eviction_next
* lru_iter_cleaning_next
* </functions_to_leave>
@@ -37,7 +39,7 @@
#include "ocf_lru.c/lru_iter_generated_wraps.c"
//#define DEBUG
// #define DEBUG
struct ocf_cache_line_concurrency *__wrap_ocf_cache_line_concurrency(ocf_cache_t cache)
{
@@ -222,7 +224,7 @@ struct ocf_lru_list *__wrap_ocf_lru_get_list(struct ocf_user_part *user_part,
}
#ifdef DEBUG
print_message("list for case %u lru %u: head: %u tail %u elems %u\n",
print_message("list for case %u lru %u: head: 0x%x tail 0x%x elems 0x%x\n",
current_case, lru, list.head, list.tail, list.num_nodes);
#endif
@@ -258,7 +260,7 @@ struct ocf_lru_meta *__wrap_ocf_metadata_get_lru(
g_lru_meta.next = test_cases[j + 1][i][current_case];
#ifdef DEBUG
print_message("[%u] next %u prev %u\n",
print_message("[%u] next 0x%x prev 0x%x\n",
line, g_lru_meta.next,
g_lru_meta.prev);
#endif
@@ -372,8 +374,7 @@ static void _lru_run_test(unsigned test_case)
pos[i]++;
}
lru_iter_init(&iter, NULL, NULL, start_pos, false, false, false,
NULL, NULL);
lru_iter_cleaning_init(&iter, NULL, NULL, start_pos);
do {
/* check what is expected to be returned from iterator */
@@ -402,6 +403,15 @@ static void _lru_run_test(unsigned test_case)
/* get cacheline from iterator */
cache_line = lru_iter_cleaning_next(&iter);
#ifdef DEBUG
if (cache_line == expected_cache_line) {
print_message("case %u cline 0x%x ok\n",
test_case, cache_line);
} else {
print_message("case %u cline 0x%x NOK expected 0x%x\n",
test_case, cache_line, expected_cache_line);
}
#endif
assert_int_equal(cache_line, expected_cache_line);
curr_lru = (curr_lru + 1) % OCF_NUM_LRU_LISTS;