diff --git a/src/eviction/eviction.c b/src/eviction/eviction.c index 9c5a948..a61e9df 100644 --- a/src/eviction/eviction.c +++ b/src/eviction/eviction.c @@ -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, - uint32_t to_evict, bool roundup) +static uint32_t ocf_evict_calculate(ocf_cache_t cache, + 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 * 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) to_evict = OCF_TO_EVICTION_MIN; - if (to_evict > (part->runtime->curr_size - part->config->min_size)) - to_evict = part->runtime->curr_size - part->config->min_size; + if (to_evict > (curr_part_size - min_part_size)) + to_evict = curr_part_size - min_part_size; 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)) return 0; - to_evict = ocf_evict_calculate(&cache->user_parts[target_part_id], - evict_cline_no, false); + to_evict = ocf_evict_calculate(cache, target_part, evict_cline_no, + false); return ocf_eviction_need_space(cache, io_queue, target_part, to_evict); @@ -88,7 +92,8 @@ static inline uint32_t ocf_evict_do(ocf_cache_t cache, 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) { /* No cache lines to evict for this partition */ continue; diff --git a/src/metadata/metadata_partition.h b/src/metadata/metadata_partition.h index 0dd024f..272bad4 100644 --- a/src/metadata/metadata_partition.h +++ b/src/metadata/metadata_partition.h @@ -11,7 +11,7 @@ #define PARTITION_DEFAULT 0 #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( struct ocf_cache *cache, ocf_cache_line_t line, diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index 5cf398d..a8ece82 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -43,6 +43,9 @@ int ocf_mngt_add_partition_to_cache(struct ocf_cache *cache, if (cache->user_parts[part_id].config->flags.valid) return -OCF_ERR_INVAL; + if (min_size > max_size) + return -OCF_ERR_INVAL; + if (max_size > PARTITION_SIZE_MAX) return -OCF_ERR_INVAL; @@ -87,8 +90,7 @@ static int _ocf_mngt_set_partition_size(struct ocf_cache *cache, if (min > max) return -OCF_ERR_INVAL; - if (_ocf_mngt_count_parts_min_size(cache) + min - >= cache->device->collision_table_entries) { + if (_ocf_mngt_count_parts_min_size(cache) + min > PARTITION_SIZE_MAX) { /* Illegal configuration in which sum of all min_sizes exceeds * cache size. */ @@ -136,7 +138,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache, /* Try set partition size */ if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { 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); 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, "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); return 0; } @@ -160,7 +162,7 @@ static int _ocf_mngt_io_class_configure(ocf_cache_t cache, /* Try set partition size */ if (_ocf_mngt_set_partition_size(cache, part_id, min, max)) { 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); 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)) { /* Updating existing */ 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); } else { /* Adding new */ ocf_part_set_valid(cache, part_id, true); 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); } diff --git a/src/utils/utils_part.h b/src/utils/utils_part.h index f993061..17c5fb2 100644 --- a/src/utils/utils_part.h +++ b/src/utils/utils_part.h @@ -56,10 +56,31 @@ static inline uint32_t ocf_part_get_occupancy(struct ocf_user_part *part) return part->runtime->curr_size; } -static inline uint32_t ocf_part_get_max_size(ocf_cache_t cache, - ocf_part_id_t part_id) +static inline uint32_t ocf_part_get_min_size(ocf_cache_t cache, + 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);