Store min and max ioclass size as percentage val

Min and max values, keept as an explicit number of cachelines, are tightly
coupled with particular cache. This might lead to errors and mismatches after
reattaching cache of different size.

To prevent those errors, min and max should be calculated dynamically.

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
Michal Mielewczyk 2020-11-30 19:21:12 -05:00
parent bcfc821068
commit 0dc8b5811c
4 changed files with 47 additions and 19 deletions

View File

@ -20,10 +20,14 @@ struct eviction_policy_ops evict_policy_ops[ocf_eviction_max] = {
}, },
}; };
static uint32_t ocf_evict_calculate(struct ocf_user_part *part, static uint32_t ocf_evict_calculate(ocf_cache_t cache,
uint32_t to_evict, bool roundup) struct ocf_user_part *part, uint32_t to_evict, bool roundup)
{ {
if (part->runtime->curr_size <= part->config->min_size) {
uint32_t curr_part_size = ocf_part_get_occupancy(part);
uint32_t min_part_size = ocf_part_get_min_size(cache, part);
if (curr_part_size <= min_part_size) {
/* /*
* Cannot evict from this partition because current size * Cannot evict from this partition because current size
* is less than minimum size * is less than minimum size
@ -34,8 +38,8 @@ static uint32_t ocf_evict_calculate(struct ocf_user_part *part,
if (roundup && to_evict < OCF_TO_EVICTION_MIN) if (roundup && to_evict < OCF_TO_EVICTION_MIN)
to_evict = OCF_TO_EVICTION_MIN; to_evict = OCF_TO_EVICTION_MIN;
if (to_evict > (part->runtime->curr_size - part->config->min_size)) if (to_evict > (curr_part_size - min_part_size))
to_evict = part->runtime->curr_size - part->config->min_size; to_evict = curr_part_size - min_part_size;
return to_evict; return to_evict;
} }
@ -49,8 +53,8 @@ static inline uint32_t ocf_evict_part_do(ocf_cache_t cache,
if (!evp_lru_can_evict(cache)) if (!evp_lru_can_evict(cache))
return 0; return 0;
to_evict = ocf_evict_calculate(&cache->user_parts[target_part_id], to_evict = ocf_evict_calculate(cache, target_part, evict_cline_no,
evict_cline_no, false); false);
return ocf_eviction_need_space(cache, io_queue, return ocf_eviction_need_space(cache, io_queue,
target_part, to_evict); target_part, to_evict);
@ -88,7 +92,8 @@ static inline uint32_t ocf_evict_do(ocf_cache_t cache,
goto out; goto out;
} }
to_evict = ocf_evict_calculate(part, evict_cline_no, true); to_evict = ocf_evict_calculate(cache, part, evict_cline_no,
true);
if (to_evict == 0) { if (to_evict == 0) {
/* No cache lines to evict for this partition */ /* No cache lines to evict for this partition */
continue; continue;

View File

@ -11,7 +11,7 @@
#define PARTITION_DEFAULT 0 #define PARTITION_DEFAULT 0
#define PARTITION_INVALID ((ocf_part_id_t)-1) #define PARTITION_INVALID ((ocf_part_id_t)-1)
#define PARTITION_SIZE_MAX ((ocf_cache_line_t)-1) #define PARTITION_SIZE_MAX 100
static inline void ocf_metadata_get_partition_info( static inline void ocf_metadata_get_partition_info(
struct ocf_cache *cache, ocf_cache_line_t line, struct ocf_cache *cache, ocf_cache_line_t line,

View File

@ -43,6 +43,9 @@ int ocf_mngt_add_partition_to_cache(struct ocf_cache *cache,
if (cache->user_parts[part_id].config->flags.valid) if (cache->user_parts[part_id].config->flags.valid)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (min_size > max_size)
return -OCF_ERR_INVAL;
if (max_size > PARTITION_SIZE_MAX) if (max_size > PARTITION_SIZE_MAX)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
@ -87,8 +90,7 @@ static int _ocf_mngt_set_partition_size(struct ocf_cache *cache,
if (min > max) if (min > max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (_ocf_mngt_count_parts_min_size(cache) + min if (_ocf_mngt_count_parts_min_size(cache) + min > PARTITION_SIZE_MAX) {
>= cache->device->collision_table_entries) {
/* Illegal configuration in which sum of all min_sizes exceeds /* Illegal configuration in which sum of all min_sizes exceeds
* cache size. * cache size.
*/ */
@ -136,7 +138,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
/* Try set partition size */ /* Try set partition size */
if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) {
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Setting IO class size, id: %u, name: '%s', max size: %u" "Setting IO class size, id: %u, name: '%s', max size: %u%%"
" [ ERROR ]\n", part_id, dest_part->config->name, max); " [ ERROR ]\n", part_id, dest_part->config->name, max);
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
} }
@ -145,7 +147,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Updating unclassified IO class, id: %u, name :'%s'," "Updating unclassified IO class, id: %u, name :'%s',"
"max size: %u [ OK ]\n", "max size: %u%% [ OK ]\n",
part_id, dest_part->config->name, max); part_id, dest_part->config->name, max);
return 0; return 0;
} }
@ -160,7 +162,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
/* Try set partition size */ /* Try set partition size */
if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) {
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Setting IO class size, id: %u, name: '%s', max size %u" "Setting IO class size, id: %u, name: '%s', max size %u%%"
"[ ERROR ]\n", part_id, dest_part->config->name, max); "[ ERROR ]\n", part_id, dest_part->config->name, max);
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
} }
@ -168,14 +170,14 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache,
if (ocf_part_is_valid(dest_part)) { if (ocf_part_is_valid(dest_part)) {
/* Updating existing */ /* Updating existing */
ocf_cache_log(cache, log_info, "Updating existing IO " ocf_cache_log(cache, log_info, "Updating existing IO "
"class, id: %u, name: '%s', max size %u [ OK ]\n", "class, id: %u, name: '%s', max size %u%% [ OK ]\n",
part_id, dest_part->config->name, max); part_id, dest_part->config->name, max);
} else { } else {
/* Adding new */ /* Adding new */
ocf_part_set_valid(cache, part_id, true); ocf_part_set_valid(cache, part_id, true);
ocf_cache_log(cache, log_info, "Adding new IO class, " ocf_cache_log(cache, log_info, "Adding new IO class, "
"id: %u, name: '%s', max size %u [ OK ]\n", part_id, "id: %u, name: '%s', max size %u%% [ OK ]\n", part_id,
dest_part->config->name, max); dest_part->config->name, max);
} }

View File

@ -56,10 +56,31 @@ static inline uint32_t ocf_part_get_occupancy(struct ocf_user_part *part)
return part->runtime->curr_size; return part->runtime->curr_size;
} }
static inline uint32_t ocf_part_get_max_size(ocf_cache_t cache, static inline uint32_t ocf_part_get_min_size(ocf_cache_t cache,
ocf_part_id_t part_id) struct ocf_user_part *part)
{ {
return cache->user_parts[part_id].config->max_size; uint64_t ioclass_size;
ioclass_size = part->config->min_size * cache->conf_meta->cachelines;
ioclass_size /= 100;
return (uint32_t)ioclass_size;
}
static inline uint32_t ocf_part_get_max_size(ocf_cache_t cache,
struct ocf_user_part *part)
{
uint64_t ioclass_size, max_size, cache_size;
max_size = part->config->max_size;
cache_size = cache->conf_meta->cachelines;
ioclass_size = max_size * cache_size;
ioclass_size = OCF_DIV_ROUND_UP(ioclass_size, 100);
return (uint32_t)ioclass_size;
} }
void ocf_part_move(struct ocf_request *req); void ocf_part_move(struct ocf_request *req);