Shuffle entries within freelists
#include "ocf_lru.h"
#include "utils/utils_cleaner.h"
#include "utils/utils_cache_line.h"
+#include "utils/utils_generator.h"
#include "utils/utils_parallelize.h"
#include "concurrency/ocf_concurrency.h"
#include "mngt/ocf_mngt_common.h"
@@ -883,17 +884,29 @@ static int ocf_lru_populate_handle(ocf_parallelize_t parallelize,
ocf_cache_t cache = context->cache;
ocf_cache_line_t cnt, cline;
ocf_cache_line_t entries = ocf_metadata_collision_table_entries(cache);
+ struct ocf_generator_bisect_state generator;
struct ocf_lru_list *list;
unsigned lru_list = shard_id;
unsigned step = 0;
+ uint32_t portion, offset;
+ uint32_t i, idx;
+
+ portion = DIV_ROUND_UP((uint64_t)entries, shards_cnt);
+ offset = shard_id * portion / shards_cnt;
+ ocf_generator_bisect_init(&generator, portion, offset);
+
+ list = ocf_lru_get_list(&cache->free, lru_list, true);
cnt = 0;
- for (cline = shard_id; cline < entries; cline += shards_cnt) {
+ for (i = 0; i < portion; i++) {
OCF_COND_RESCHED_DEFAULT(step);
- ocf_metadata_set_partition_id(cache, cline, PARTITION_FREELIST);
+ idx = ocf_generator_bisect_next(&generator);
+ cline = idx * shards_cnt + shard_id;
+ if (cline >= entries)
+ continue;
- list = ocf_lru_get_list(&cache->free, lru_list, true);
+ ocf_metadata_set_partition_id(cache, cline, PARTITION_FREELIST);
add_lru_head_nobalance(cache, list, cline);
