From 0810df2a0e3f557f278957b147e4b61feda63e4e Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 10 Sep 2019 16:26:07 +0200 Subject: [PATCH 1/7] Add OCL wrappers for promotion policy management --- modules/cas_cache/layer_cache_management.c | 81 ++++++++++++++++++++++ modules/cas_cache/layer_cache_management.h | 10 +++ ocf | 2 +- 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 8495617..e37741f 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -348,6 +348,73 @@ int cache_mngt_get_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type, return result; } +int cache_mngt_set_promotion_policy(ocf_cache_t cache, uint32_t type) +{ + int result; + + result = _cache_mngt_lock_sync(cache); + if (result) { + return result; + } + + result = ocf_mngt_cache_promotion_set_policy(cache, type); + if (result) + goto out; + + result = _cache_mngt_save_sync(cache); + +out: + ocf_mngt_cache_unlock(cache); + return result; +} + +int cache_mngt_get_promotion_policy(ocf_cache_t cache, uint32_t *type) +{ + int result; + + result = _cache_mngt_read_lock_sync(cache); + if (result) { + return result; + } + + *type = ocf_mngt_cache_promotion_get_policy(cache); + + ocf_mngt_cache_read_unlock(cache); + return result; +} + +int cache_mngt_set_promotion_param(ocf_cache_t cache, uint32_t param_id, + uint32_t param_value) +{ + int result; + + result = _cache_mngt_lock_sync(cache); + if (result) { + return result; + } + + result = ocf_mngt_cache_promotion_set_param(cache, param_id, param_value); + + ocf_mngt_cache_unlock(cache); + return result; +} + +int cache_mngt_get_promotion_param(ocf_cache_t cache, uint32_t param_id, + uint32_t *param_value) +{ + int result; + + result = _cache_mngt_read_lock_sync(cache); + if (result) { + return result; + } + + result = ocf_mngt_cache_promotion_get_param(cache, param_id, param_value); + + ocf_mngt_cache_read_unlock(cache); + return result; +} + struct get_paths_ctx { char *core_path_name_tab; int max_count; @@ -1064,6 +1131,7 @@ int cache_mngt_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg, cfg->cache_mode = cmd->caching_mode; cfg->cache_line_size = cmd->line_size; cfg->eviction_policy = cmd->eviction_policy; + cfg->promotion_policy = ocf_promotion_default; cfg->cache_line_size = cmd->line_size; cfg->pt_unaligned_io = !unaligned_io; cfg->use_submit_io_fast = !use_io_scheduler; @@ -2109,6 +2177,19 @@ int cache_mngt_get_cache_params(struct kcas_get_cache_param *info) ocf_cleaning_acp, ocf_acp_flush_max_buffers, &info->param_value); break; + case cache_param_promotion_policy_type: + result = cache_mngt_get_promotion_policy(cache, &info->param_value); + break; + case cache_param_promotion_nhit_insertion_threshold: + result = cache_mngt_get_promotion_param(cache, + ocf_nhit_insertion_threshold, + &info->param_value); + break; + case cache_param_promotion_nhit_trigger_threshold: + result = cache_mngt_get_promotion_param(cache, + ocf_nhit_trigger_threshold, + &info->param_value); + break; default: result = -EINVAL; } diff --git a/modules/cas_cache/layer_cache_management.h b/modules/cas_cache/layer_cache_management.h index bd1babd..f646423 100644 --- a/modules/cas_cache/layer_cache_management.h +++ b/modules/cas_cache/layer_cache_management.h @@ -20,6 +20,16 @@ int cache_mngt_set_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type, int cache_mngt_get_cleaning_param(ocf_cache_t cache, ocf_cleaning_t type, uint32_t param_id, uint32_t *param_value); +int cache_mngt_set_promotion_policy(ocf_cache_t cache, uint32_t type); + +int cache_mngt_get_promotion_policy(ocf_cache_t cache, uint32_t *type); + +int cache_mngt_set_promotion_param(ocf_cache_t cache, uint32_t param_id, + uint32_t param_value); + +int cache_mngt_get_promotion_param(ocf_cache_t cache, uint32_t param_id, + uint32_t *param_value); + int cache_mngt_add_core_to_cache(const char *cache_name, struct ocf_mngt_core_config *cfg, struct kcas_insert_core *cmd_info); diff --git a/ocf b/ocf index f86287e..af48ee5 160000 --- a/ocf +++ b/ocf @@ -1 +1 @@ -Subproject commit f86287ef06190b080f9529c9f2514e56da8b726b +Subproject commit af48ee56e3d86c5de4a0ce7def35a1fedf35edf4 From bb1e554dacd857e8265c0b0c6d2e79c7e37d7c26 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 10 Sep 2019 16:26:50 +0200 Subject: [PATCH 2/7] Dump and restore PP config in upgrade path Signed-off-by: Jan Musial --- modules/cas_cache/layer_upgrade.c | 148 +++++++++++++++++++++++++++++- 1 file changed, 147 insertions(+), 1 deletion(-) diff --git a/modules/cas_cache/layer_upgrade.c b/modules/cas_cache/layer_upgrade.c index f612f0a..971f734 100644 --- a/modules/cas_cache/layer_upgrade.c +++ b/modules/cas_cache/layer_upgrade.c @@ -66,6 +66,10 @@ bool cas_upgrade_is_in_upgrade(void) * |core | core_X_path | string | * |core | core_X_type | uint | * |------------|-------------------------------|---------------| + * |promotion | promotion_policy | uint | + * |promotion | nhit_insertion_threshold| uint | + * |promotion | nhit_insertion_trigger | uint | + * |------------|-------------------------------|---------------| * |flush | flush_cleaning_policy | uint | * |flush | flush_wake_up_time | uint | * |flush | flush_staleness_time | uint | @@ -99,6 +103,10 @@ bool cas_upgrade_is_in_upgrade(void) #define CORE_SEQ_CUTOFF_THRESHOLD_STR "core_%lu_seq_cutoff_thresh" #define CORE_SEQ_CUTOFF_POLICY_STR "core_%lu_seq_cutoff_policy" +#define PROMOTION_POLICY_STR "promotion_policy" +#define PROMOTION_NHIT_INSERTION_STR "nhit_insertion_threshold" +#define PROMOTION_NHIT_TRIGGER_STR "nhit_trigger_threshold" + #define CLEANING_POLICY_STR "flush_cleaning_policy" #define CLEANING_ALRU_WAKEUP_TIME_STR "flush_wakeup_time" #define CLEANING_ALRU_STALENESS_TIME_STR "flush_staleness_time" @@ -116,7 +124,8 @@ bool cas_upgrade_is_in_upgrade(void) #define IO_CLASS_CACHE_MODE_STR "io_class_%lu_cache_mode" #define CAS_UPGRADE_IFACE_VERSION_19_03_00 190300 -#define CAS_UPGRADE_IFACE_CURRENT_VERSION CAS_UPGRADE_IFACE_VERSION_19_03_00 +#define CAS_UPGRADE_IFACE_VERSION_19_09_00 190900 +#define CAS_UPGRADE_IFACE_CURRENT_VERSION CAS_UPGRADE_IFACE_VERSION_19_09_00 static int _cas_upgrade_dump_cache_conf_main(ocf_cache_t cache, struct cas_properties *cache_props) @@ -305,6 +314,72 @@ err: return result; } +static int _cas_upgrade_dump_cache_conf_promotion(ocf_cache_t cache, + struct cas_properties *cache_props) +{ + uint32_t promotion_type = ocf_promotion_default; + uint32_t nhit_insertion_threshold; + uint32_t nhit_trigger_threshold; + + int result = 0; + + result = cache_mngt_get_promotion_policy(cache, &promotion_type); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT + "Unable to get promotion policy type\n"); + return result; + } + + if (promotion_type == ocf_promotion_nhit) { + result |= cache_mngt_get_promotion_param(cache, + ocf_nhit_insertion_threshold, + &nhit_insertion_threshold); + result |= cache_mngt_get_promotion_param(cache, + ocf_nhit_trigger_threshold, + &nhit_trigger_threshold); + } + + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT + "Unable to get promotion policy params\n"); + return result; + } + + result = cas_properties_add_uint(cache_props, PROMOTION_POLICY_STR, + promotion_type, CAS_PROPERTIES_CONST); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT + "Error during adding promotion policy type\n"); + return result; + } + + if (promotion_type == ocf_promotion_nhit) { + result = cas_properties_add_uint(cache_props, + PROMOTION_NHIT_INSERTION_STR, + nhit_insertion_threshold, + CAS_PROPERTIES_CONST); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT + "Error during adding nhit insertion " + "threshold\n"); + return result; + } + + result = cas_properties_add_uint(cache_props, + PROMOTION_NHIT_TRIGGER_STR, + nhit_trigger_threshold, + CAS_PROPERTIES_CONST); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT + "Error during adding nhit trigger " + "threshold\n"); + return result; + } + } + + return result; +} + static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache, struct cas_properties *cache_props) { @@ -315,6 +390,7 @@ static int _cas_upgrade_dump_cache_conf_flush(ocf_cache_t cache, uint32_t alru_activity_threshold; uint32_t acp_thread_wakeup_time; uint32_t acp_flush_max_buffers; + int result = 0; CAS_DEBUG_TRACE(); @@ -586,6 +662,10 @@ static int _cas_upgrade_dump_cache_conf(ocf_cache_t device, if (result) return result; + result = _cas_upgrade_dump_cache_conf_promotion(device, cache_props); + if (result) + return result; + result = _cas_upgrade_dump_cache_conf_io_class(device, cache_props); if (result) return result; @@ -1078,6 +1158,68 @@ static int _cas_upgrade_restore_conf_flush(struct cas_properties *cache_props, return result; } +static int _cas_upgrade_restore_conf_promotion(struct cas_properties *cache_props, + ocf_cache_t cache) +{ + uint64_t promotion_type; + uint64_t nhit_insertion_threshold; + uint64_t nhit_trigger_threshold; + + int result = 0; + + result = cas_properties_get_uint(cache_props, PROMOTION_POLICY_STR, + &promotion_type); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve promotion " + "policy type \n"); + goto out; + } + + result = cache_mngt_set_promotion_policy(cache, promotion_type); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set promotion policy\n"); + goto out; + } + + if (promotion_type != ocf_promotion_nhit) + goto out; + + result = cas_properties_get_uint(cache_props, + PROMOTION_NHIT_INSERTION_STR, &nhit_insertion_threshold); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve NHIT insertion " + "threshold parameter \n"); + goto out; + } + + result = cas_properties_get_uint(cache_props, + PROMOTION_NHIT_TRIGGER_STR, &nhit_trigger_threshold); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't retrieve NHIT insertion " + "trigger parameter \n"); + goto out; + } + + result = cache_mngt_set_promotion_param(cache, ocf_nhit_insertion_threshold, + nhit_insertion_threshold); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set NHIT insertion " + "threshold parameter \n"); + goto out; + } + + result = cache_mngt_set_promotion_param(cache, ocf_nhit_trigger_threshold, + nhit_trigger_threshold); + if (result) { + printk(KERN_ERR OCF_PREFIX_SHORT "Couldn't set NHIT trigger " + "threshold parameter \n"); + goto out; + } + +out: + return result; +} + static int _cas_upgrade_restore_conf_io_class( struct cas_properties *cache_props, ocf_cache_t cache) { @@ -1210,6 +1352,10 @@ static int _cas_upgrade_restore_cache(struct cas_properties *cache_props) if (result) goto error; + result = _cas_upgrade_restore_conf_promotion(cache_props, cache); + if (result) + goto error; + result = _cas_upgrade_restore_conf_io_class(cache_props, cache); if (result) goto error; From 9598fa76f12511225f41cdbdcefc8ca5636d29d3 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Wed, 11 Sep 2019 10:12:03 +0200 Subject: [PATCH 3/7] Expose PP settings in IOCTL iface Signed-off-by: Jan Musial --- modules/cas_cache/layer_cache_management.c | 11 +++++++++++ modules/include/cas_ioctl_codes.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index e37741f..6fd1399 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -2123,6 +2123,17 @@ int cache_mngt_set_cache_params(struct kcas_set_cache_param *info) ocf_cleaning_acp, ocf_acp_flush_max_buffers, info->param_value); break; + case cache_param_promotion_policy_type: + result = cache_mngt_set_promotion_policy(cache, info->param_value); + break; + case cache_param_promotion_nhit_insertion_threshold: + result = cache_mngt_set_promotion_param(cache, + ocf_nhit_insertion_threshold, info->param_value); + break; + case cache_param_promotion_nhit_trigger_threshold: + result = cache_mngt_set_promotion_param(cache, + ocf_nhit_trigger_threshold, info->param_value); + break; default: result = -EINVAL; } diff --git a/modules/include/cas_ioctl_codes.h b/modules/include/cas_ioctl_codes.h index fa3332e..8f51ac4 100644 --- a/modules/include/cas_ioctl_codes.h +++ b/modules/include/cas_ioctl_codes.h @@ -353,6 +353,9 @@ enum kcas_cache_param_id { cache_param_cleaning_alru_activity_threshold, cache_param_cleaning_acp_wake_up_time, cache_param_cleaning_acp_flush_max_buffers, + cache_param_promotion_policy_type, + cache_param_promotion_nhit_insertion_threshold, + cache_param_promotion_nhit_trigger_threshold, cache_param_id_max, }; From fd24803b743994f6a9e61b5fb26449ee3dcedd9d Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Mon, 16 Sep 2019 09:47:00 +0200 Subject: [PATCH 4/7] Handle promotion policy selection in casadm Signed-off-by: Jan Musial --- casadm/cas_lib.c | 17 ++++++ casadm/cas_lib.h | 3 ++ casadm/cas_main.c | 106 ++++++++++++++++++++++++++++++++++++++ casadm/statistics_model.c | 2 + 4 files changed, 128 insertions(+) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index ef0a33b..fb4a42f 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -265,6 +265,12 @@ static struct name_to_val_mapping cleaning_policy_names[] = { { NULL } }; +static struct name_to_val_mapping promotion_policy_names[] = { + { .short_name = "always", .value = ocf_promotion_always }, + { .short_name = "nhit", .value = ocf_promotion_nhit }, + { NULL} +}; + static struct name_to_val_mapping metadata_mode_names[] = { { .short_name = "normal", .value = CAS_METADATA_MODE_NORMAL }, { .short_name = "atomic", .value = CAS_METADATA_MODE_ATOMIC }, @@ -434,6 +440,16 @@ inline const char *cleaning_policy_to_name(uint8_t policy) return val_to_short_name(policy, cleaning_policy_names, "Unknown"); } +inline int validate_str_promotion_policy(const char *s) +{ + return validate_str_val_mapping(s, promotion_policy_names, -1); +} + +inline const char *promotion_policy_to_name(uint8_t policy) +{ + return val_to_short_name(policy, promotion_policy_names, "Unknown"); +} + const char *metadata_mode_to_name(uint8_t metadata_mode) { return val_to_short_name(metadata_mode, metadata_mode_names, "Invalid"); @@ -707,6 +723,7 @@ struct cache_device *get_cache_device(const struct kcas_cache_info *info) cache->flushed = info->info.flushed; cache->eviction_policy = info->info.eviction_policy; cache->cleaning_policy = info->info.cleaning_policy; + cache->promotion_policy = info->info.promotion_policy; cache->size = info->info.cache_line_size; if ((info->info.state & (1 << ocf_cache_state_running)) == 0) { diff --git a/casadm/cas_lib.h b/casadm/cas_lib.h index a4bc266..cc545ac 100644 --- a/casadm/cas_lib.h +++ b/casadm/cas_lib.h @@ -44,6 +44,7 @@ struct cache_device { int mode; int eviction_policy; int cleaning_policy; + int promotion_policy; int dirty; int flushed; unsigned size; @@ -92,6 +93,7 @@ enum metadata_mode_t { const char *eviction_policy_to_name(uint8_t policy); const char *cleaning_policy_to_name(uint8_t policy); +const char *promotion_policy_to_name(uint8_t policy); const char *cache_mode_to_name(uint8_t cache_mode); const char *get_cache_state_name(int cache_state); const char *get_core_state_name(int core_state); @@ -256,6 +258,7 @@ int validate_path(const char *path, int exist); int validate_str_cache_mode(const char *s); int validate_str_ev_policy(const char *s); int validate_str_cln_policy(const char *s); +int validate_str_promotion_policy(const char *s); int validate_str_meta_variant(const char *s); int validate_str_stats_filters(const char* s); int validate_str_output_format(const char* s); diff --git a/casadm/cas_main.c b/casadm/cas_main.c index 8fb8393..8258069 100644 --- a/casadm/cas_main.c +++ b/casadm/cas_main.c @@ -50,6 +50,7 @@ struct command_args{ int cache_state_flush; int flush_data; int cleaning_policy_type; + int promotion_policy_type; int script_subcmd; int try_add; int update_path; @@ -75,6 +76,7 @@ static struct command_args command_args_values = { .cache_state_flush = UNDEFINED, /* three state logic: YES NO UNDEFINED */ .flush_data = 1, .cleaning_policy_type = 0, + .promotion_policy_type = 0, .script_subcmd = -1, .try_add = false, .update_path = false, @@ -560,6 +562,12 @@ static char *cleaning_policy_type_values[] = { NULL, }; +static char *promotion_policy_type_values[] = { + [ocf_promotion_always] = "always", + [ocf_promotion_nhit] = "nhit", + NULL, +}; + static struct cas_param cas_cache_params[] = { /* Cleaning policy type */ [cache_param_cleaning_policy_type] = { @@ -588,6 +596,20 @@ static struct cas_param cas_cache_params[] = { [cache_param_cleaning_acp_flush_max_buffers] = { .name = "Flush max buffers" , }, + + /* Promotion policy type */ + [cache_param_promotion_policy_type] = { + .name = "Promotion policy type", + .value_names = promotion_policy_type_values, + }, + + /*Promotion policy NHIT params */ + [cache_param_promotion_nhit_insertion_threshold] = { + .name = "Insertion threshold", + }, + [cache_param_promotion_nhit_trigger_threshold] = { + .name = "Policy trigger [%]", + }, {0}, }; @@ -614,6 +636,15 @@ static struct cas_param cas_cache_params[] = { #define CLEANING_ACP_MAX_BUFFERS_DESC "Number of cache lines flushed in single ACP cleaning thread iteration" \ " <%d-%d> (default: %d)" +#define PROMOTION_POLICY_TYPE_DESC "Promotion policy type. "\ + "Available policy types: {always|nhit}" + +#define PROMOTION_NHIT_TRIGGER_DESC "Cache occupancy value over which NHIT promotion is active " \ + "<%d-%d>[%] (default: %d%)" + +#define PROMOTION_NHIT_THRESHOLD_DESC "Number of requests for given core line " \ + "after which NHIT policy allows insertion into cache <%d-%d> (default: %d)" + static cli_namespace set_param_namespace = { .short_name = 'n', .long_name = "name", @@ -627,6 +658,21 @@ static cli_namespace set_param_namespace = { {'p', "policy", CLEANING_POLICY_TYPE_DESC, 1, "POLICY", 0}, CACHE_PARAMS_NS_END() + CACHE_PARAMS_NS_BEGIN("promotion", "Promotion policy parameters") + {'p', "policy", PROMOTION_POLICY_TYPE_DESC, 1, "POLICY", 0}, + CACHE_PARAMS_NS_END() + + CACHE_PARAMS_NS_BEGIN("promotion-nhit", "Promotion policy NHIT parameters") + {'t', "threshold", PROMOTION_NHIT_THRESHOLD_DESC, 1, "NUMBER", + CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT, + OCF_NHIT_MIN_THRESHOLD, OCF_NHIT_MAX_THRESHOLD, + OCF_NHIT_THRESHOLD_DEFAULT}, + {'o', "trigger", PROMOTION_NHIT_TRIGGER_DESC, 1, "NUMBER", + CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT, + OCF_NHIT_MIN_TRIGGER, OCF_NHIT_MAX_TRIGGER, + OCF_NHIT_TRIGGER_DEFAULT}, + CACHE_PARAMS_NS_END() + CACHE_PARAMS_NS_BEGIN("cleaning-alru", "Cleaning policy ALRU parameters") {'w', "wake-up", CLEANING_ALRU_WAKE_UP_DESC, 1, "NUMBER", CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT, @@ -772,6 +818,49 @@ int set_param_cleaning_acp_handle_option(char *opt, const char **arg) SET_CACHE_PARAM(cache_param_cleaning_acp_flush_max_buffers, strtoul(arg[0], NULL, 10)); + } + + return FAILURE; +} + +int set_param_promotion_handle_option(char *opt, const char **arg) +{ + if (!strcmp(opt, "policy")) { + if (!strcmp("always", arg[0])) { + SET_CACHE_PARAM(cache_param_promotion_policy_type, + ocf_promotion_always); + } else if (!strcmp("nhit", arg[0])) { + SET_CACHE_PARAM(cache_param_promotion_policy_type, + ocf_promotion_nhit); + } else { + cas_printf(LOG_ERR, "Error: Invalid policy name.\n"); + return FAILURE; + } + } else { + return FAILURE; + } + + return SUCCESS; +} + +int set_param_promotion_nhit_handle_option(char *opt, const char **arg) +{ + if (!strcmp(opt, "threshold")) { + if (validate_str_num(arg[0], "threshold", + OCF_NHIT_MIN_THRESHOLD, OCF_NHIT_MAX_THRESHOLD)) { + return FAILURE; + } + + SET_CACHE_PARAM(cache_param_promotion_nhit_insertion_threshold, + strtoul(arg[0], NULL, 10)); + } else if (!strcmp(opt, "trigger")) { + if (validate_str_num(arg[0], "trigger", + OCF_NHIT_MIN_TRIGGER, OCF_NHIT_MAX_THRESHOLD)) { + return FAILURE; + } + + SET_CACHE_PARAM(cache_param_promotion_nhit_trigger_threshold, + strtoul(arg[0], NULL, 10)); } else { return FAILURE; } @@ -793,6 +882,12 @@ int set_param_namespace_handle_option(char *namespace, char *opt, const char **a } else if (!strcmp(namespace, "cleaning-acp")) { return cache_param_handle_option_generic(opt, arg, set_param_cleaning_acp_handle_option); + } else if (!strcmp(namespace, "promotion")) { + return cache_param_handle_option_generic(opt, arg, + set_param_promotion_handle_option); + } else if (!strcmp(namespace, "promotion-nhit")) { + return cache_param_handle_option_generic(opt, arg, + set_param_promotion_nhit_handle_option); } else { return FAILURE; } @@ -831,6 +926,8 @@ static cli_namespace get_param_namespace = { GET_CACHE_PARAMS_NS("cleaning", "Cleaning policy parameters") GET_CACHE_PARAMS_NS("cleaning-alru", "Cleaning policy ALRU parameters") GET_CACHE_PARAMS_NS("cleaning-acp", "Cleaning policy ACP parameters") + GET_CACHE_PARAMS_NS("promotion", "Promotion policy parameters") + GET_CACHE_PARAMS_NS("promotion-nhit", "Promotion policy NHIT parameters") {0}, }, @@ -872,6 +969,15 @@ int get_param_namespace_handle_option(char *namespace, char *opt, const char **a SELECT_CACHE_PARAM(cache_param_cleaning_acp_flush_max_buffers); return cache_param_handle_option_generic(opt, arg, get_param_handle_option); + } else if (!strcmp(namespace, "promotion")) { + SELECT_CACHE_PARAM(cache_param_promotion_policy_type); + return cache_param_handle_option_generic(opt, arg, + get_param_handle_option); + } else if (!strcmp(namespace, "promotion-nhit")) { + SELECT_CACHE_PARAM(cache_param_promotion_nhit_insertion_threshold); + SELECT_CACHE_PARAM(cache_param_promotion_nhit_trigger_threshold); + return cache_param_handle_option_generic(opt, arg, + get_param_handle_option); } else { return FAILURE; } diff --git a/casadm/statistics_model.c b/casadm/statistics_model.c index 72c0a77..cba80f9 100644 --- a/casadm/statistics_model.c +++ b/casadm/statistics_model.c @@ -548,6 +548,8 @@ int cache_stats_conf(int ctrl_fd, const struct kcas_cache_info *cache_info, eviction_policy_to_name(cache_info->info.eviction_policy)); print_kv_pair(outfile, "Cleaning Policy", "%s", cleaning_policy_to_name(cache_info->info.cleaning_policy)); + print_kv_pair(outfile, "Promotion Policy", "%s", + promotion_policy_to_name(cache_info->info.promotion_policy)); print_kv_pair(outfile, "Cache line size", "%llu, [KiB]", cache_info->info.cache_line_size / KiB); From 9408c685cd44bb95043fdc4dad35a7950c3a6ee8 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Tue, 17 Sep 2019 15:29:28 +0200 Subject: [PATCH 5/7] Update casadm man page Signed-off-by: Jan Musial --- utils/casadm.8 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/utils/casadm.8 b/utils/casadm.8 index 5cc65b3..d7a6f54 100644 --- a/utils/casadm.8 +++ b/utils/casadm.8 @@ -236,6 +236,8 @@ Available namespaces are: \fBcleaning\fR - Cleaning policy parameters. \fBcleaning-alru\fR - Cleaning policy ALRU parameters. \fBcleaning-acp\fR - Cleaning policy ACP parameters. +\fBpromotion\fR - Promotion policy parameters. +\fBpromotion-nhit\fR - Promotion policy NHIT parameters. .SH Options that are valid with --set-param (-X) --name (-n) seq-cutoff are: @@ -310,6 +312,36 @@ Period of time between awakenings of flushing thread [ms] (default: 10 ms). .B -b, --flush-max-buffers Number of dirty cache blocks to be flushed in one cleaning cycle (default: 128). +.SH Options that are valid with --set-param (-X) --name (-n) promotion are: + +.TP +.B -i, --cache-id +Identifier of cache instance <1-16384>. + +.TP +.B -p, --policy {always|nhit} +Promotion policy type to be used with a given cache instance. + +Available policies: +.br +1. \fBalways\fR. Core lines are attempted to be promoted each time they're accessed. +.br +2. \fBnhit\fR. Core lines are attempted to be promoted after n accesses. + +.SH Options that are valid with --set-param (-X) --name (-n) promotion-nhit are: + +.TP +.B -i, --cache-id +Identifier of cache instance <1-16384>. + +.TP +.B -o, --trigger +Percent of cache to be occupied before cache inserts will be filtered by the policy. + +.TP +.B -t, --threshold +Number of core line accesses required for it to be inserted into cache. + .SH Options that are valid with --get-param (-G) are: .TP @@ -322,6 +354,8 @@ Available namespaces are: \fBcleaning\fR - Cleaning policy parameters. \fBcleaning-alru\fR - Cleaning policy ALRU parameters. \fBcleaning-acp\fR - Cleaning policy ACP parameters. +\fBpromotion\fR - Promotion policy parameters. +\fBpromotion-nhit\fR - Promotion policy NHIT parameters. .SH Options that are valid with --get-param (-G) --name (-n) seq-cutoff are: @@ -367,6 +401,26 @@ Identifier of cache instance <1-16384>. .B -o, --output-format {table|csv} Defines output format for parameter list. It can be either \fBtable\fR (default) or \fBcsv\fR. +.SH Options that are valid with --get-param (-G) --name (-n) promotion are: + +.TP +.B -i, --cache-id +Identifier of cache instance <1-16384>. + +.TP +.B -o, --output-format {table|csv} +Defines output format for parameter list. It can be either \fBtable\fR (default) or \fBcsv\fR. + +.SH Options that are valid with --get-param (-G) --name (-n) promotion-nhit are: + +.TP +.B -i, --cache-id +Identifier of cache instance <1-16384>. + +.TP +.B -o, --output-format {table|csv} +Defines output format for parameter list. It can be either \fBtable\fR (default) or \fBcsv\fR. + .SH Options that are valid with --set-cache-mode (-Q) are: .TP .B -c, --cache-mode {wt|wb|wa|pt} From 735c1e5008f88544cb836d27c2d61e4f709a96e0 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Wed, 18 Sep 2019 09:04:12 +0200 Subject: [PATCH 6/7] Handle promotion_policy as conf param Signed-off-by: Jan Musial --- utils/opencas.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/utils/opencas.py b/utils/opencas.py index 1d4b640..f2fbdf7 100644 --- a/utils/opencas.py +++ b/utils/opencas.py @@ -236,6 +236,8 @@ class cas_config(object): raise ValueError('Incorrect path to io_class file') elif param_name == 'cleaning_policy': self.check_cleaning_policy_valid(param_value) + elif param_name == 'promotion_policy': + self.check_promotion_policy_valid(param_value) elif param_name == 'cache_line_size': self.check_cache_line_size_valid(param_value) else: @@ -269,6 +271,11 @@ class cas_config(object): raise ValueError('{0} is invalid cleaning policy name'.format( cleaning_policy)) + def check_promotion_policy_valid(self, promotion_policy): + if promotion_policy.lower() not in ['always', 'nhit']: + raise ValueError('{0} is invalid promotion policy name'.format( + promotion_policy)) + def check_cache_line_size_valid(self, cache_line_size): if cache_line_size not in ['4', '8', '16', '32', '64']: raise ValueError('{0} is invalid cache line size'.format( @@ -500,12 +507,19 @@ def start_cache(cache, load, force=False): force=force) def configure_cache(cache): - if 'cleaning_policy' in cache.params: - casadm.set_param('cleaning', cache_id=cache.cache_id, - policy=cache.params['cleaning_policy']) - if 'ioclass_file' in cache.params: - casadm.io_class_load_config(cache_id=cache.cache_id, - ioclass_file=cache.params['ioclass_file']) + if "cleaning_policy" in cache.params: + casadm.set_param( + "cleaning", cache_id=cache.cache_id, policy=cache.params["cleaning_policy"] + ) + if "promotion_policy" in cache.params: + casadm.set_param( + "promotion", cache_id=cache.cache_id, policy=cache.params["promotion"] + ) + if "ioclass_file" in cache.params: + casadm.io_class_load_config( + cache_id=cache.cache_id, ioclass_file=cache.params["ioclass_file"] + ) + def add_core(core, attach): casadm.add_core( From a8c3c651dee9f3ea2d072c53dca0128779a58769 Mon Sep 17 00:00:00 2001 From: Jan Musial Date: Wed, 18 Sep 2019 09:04:45 +0200 Subject: [PATCH 7/7] Update opencas.conf man page Signed-off-by: Jan Musial --- utils/opencas.conf.5 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/opencas.conf.5 b/utils/opencas.conf.5 index 4b4ab64..776e3ff 100644 --- a/utils/opencas.conf.5 +++ b/utils/opencas.conf.5 @@ -24,7 +24,7 @@ Cache device .br Cache mode {wt|wb|wa|pt} .br -Extra fields (optional) ioclass_file=,cleaning_policy= +Extra fields (optional) ioclass_file=,cleaning_policy=,promotion_policy= .RE .TP \fB[cores]\fR Cores configuration. Following columns are required: