11/*
22* Copyright(c) 2012-2022 Intel Corporation
3- * Copyright(c) 2024 Huawei Technologies
3+ * Copyright(c) 2022 David Lee <live4thee@gmail.com>
4+ * Copyright(c) 2024-2025 Huawei Technologies
45* SPDX-License-Identifier: BSD-3-Clause
56*/
67
@@ -710,6 +711,11 @@ static char *promotion_policy_type_values[] = {
710711 NULL ,
711712};
712713
714+ uint32_t dirty_ratio_inertia_transform (uint32_t value )
715+ {
716+ return value / MiB ;
717+ }
718+
713719static struct cas_param cas_cache_params [] = {
714720 /* Cleaning policy type */
715721 [cache_param_cleaning_policy_type ] = {
@@ -730,6 +736,13 @@ static struct cas_param cas_cache_params[] = {
730736 [cache_param_cleaning_alru_activity_threshold ] = {
731737 .name = "Activity threshold [ms]" ,
732738 },
739+ [cache_param_cleaning_alru_dirty_ratio_threshold ] = {
740+ .name = "Dirty ratio trigger threshold [%]" ,
741+ },
742+ [cache_param_cleaning_alru_dirty_ratio_inertia ] = {
743+ .name = "Dirty ratio trigger inertia [MiB]" ,
744+ .transform_value = dirty_ratio_inertia_transform ,
745+ },
733746
734747 /* Cleaning policy ACP params */
735748 [cache_param_cleaning_acp_wake_up_time ] = {
@@ -774,6 +787,10 @@ static struct cas_param cas_cache_params[] = {
774787 " <%d-%d> (default: %d)"
775788#define CLEANING_ALRU_ACTIVITY_THRESHOLD_DESC "Cache idle time before flushing thread can start <%d-%d>[ms]" \
776789 " (default: %d ms)"
790+ #define CLEANING_ALRU_DIRTY_RATIO_THRESHOLD_DESC "Dirty ratio of the cache device at which cleaning will be triggered" \
791+ " <%d-%d>[%] (default: %d%)"
792+ #define CLEANING_ALRU_DIRTY_RATIO_INERTIA_DESC "Inertia for dirty ratio triggered cleaning - the trigger will be disabled" \
793+ " after dirty ratio falls below (threshold - inertia) <%d-%d>[MiB] (default: %d MiB)"
777794
778795#define CLEANING_ACP_WAKE_UP_DESC "Time between ACP cleaning thread iterations <%d-%d>[ms] (default: %d ms)"
779796#define CLEANING_ACP_MAX_BUFFERS_DESC "Number of cache lines flushed in single ACP cleaning thread iteration" \
@@ -834,6 +851,14 @@ static cli_namespace set_param_namespace = {
834851 CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT ,
835852 OCF_ALRU_MIN_ACTIVITY_THRESHOLD , OCF_ALRU_MAX_ACTIVITY_THRESHOLD ,
836853 OCF_ALRU_DEFAULT_ACTIVITY_THRESHOLD },
854+ {'d' , "dirty-ratio-threshold" , CLEANING_ALRU_DIRTY_RATIO_THRESHOLD_DESC , 1 , "NUMBER" ,
855+ CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT ,
856+ OCF_ALRU_MIN_DIRTY_RATIO_THRESHOLD , OCF_ALRU_MAX_DIRTY_RATIO_THRESHOLD ,
857+ OCF_ALRU_DEFAULT_DIRTY_RATIO_THRESHOLD },
858+ {0 , "dirty-ratio-inertia" , CLEANING_ALRU_DIRTY_RATIO_INERTIA_DESC , 1 , "NUMBER" ,
859+ CLI_OPTION_RANGE_INT | CLI_OPTION_DEFAULT_INT ,
860+ OCF_ALRU_MIN_DIRTY_RATIO_INERTIA / MiB , OCF_ALRU_MAX_DIRTY_RATIO_INERTIA / MiB ,
861+ OCF_ALRU_DEFAULT_DIRTY_RATIO_INERTIA / MiB },
837862 CACHE_PARAMS_NS_END ()
838863
839864 CACHE_PARAMS_NS_BEGIN ("cleaning-acp" , "Cleaning policy ACP parameters" )
@@ -945,6 +970,22 @@ int set_param_cleaning_alru_handle_option(char *opt, const char **arg)
945970
946971 SET_CACHE_PARAM (cache_param_cleaning_alru_activity_threshold ,
947972 strtoul (arg [0 ], NULL , 10 ));
973+ } else if (!strcmp (opt , "dirty-ratio-threshold" )) {
974+ if (validate_str_num (arg [0 ], "dirty ratio trigger threshold" ,
975+ OCF_ALRU_MIN_DIRTY_RATIO_THRESHOLD , OCF_ALRU_MAX_DIRTY_RATIO_THRESHOLD )) {
976+ return FAILURE ;
977+ }
978+
979+ SET_CACHE_PARAM (cache_param_cleaning_alru_dirty_ratio_threshold ,
980+ strtoul (arg [0 ], NULL , 10 ));
981+ } else if (!strcmp (opt , "dirty-ratio-inertia" )) {
982+ if (validate_str_num (arg [0 ], "dirty ratio trigger inertia" ,
983+ OCF_ALRU_MIN_DIRTY_RATIO_INERTIA / MiB , OCF_ALRU_MAX_DIRTY_RATIO_INERTIA / MiB )) {
984+ return FAILURE ;
985+ }
986+
987+ SET_CACHE_PARAM (cache_param_cleaning_alru_dirty_ratio_inertia ,
988+ strtoul (arg [0 ], NULL , 10 ) * MiB );
948989 } else {
949990 return FAILURE ;
950991 }
@@ -1125,6 +1166,8 @@ int get_param_namespace_handle_option(char *namespace, char *opt, const char **a
11251166 SELECT_CACHE_PARAM (cache_param_cleaning_alru_stale_buffer_time );
11261167 SELECT_CACHE_PARAM (cache_param_cleaning_alru_flush_max_buffers );
11271168 SELECT_CACHE_PARAM (cache_param_cleaning_alru_activity_threshold );
1169+ SELECT_CACHE_PARAM (cache_param_cleaning_alru_dirty_ratio_threshold );
1170+ SELECT_CACHE_PARAM (cache_param_cleaning_alru_dirty_ratio_inertia );
11281171 return cache_param_handle_option_generic (opt , arg ,
11291172 get_param_handle_option );
11301173 } else if (!strcmp (namespace , "cleaning-acp" )) {
0 commit comments