Skip to content

Commit 417ab1a

Browse files
Merge pull request #1376 from live4thee/casadm/use-alru-max-dirty-ratio
casadm: use alru dirty ratio trigger
2 parents 47fcc41 + 6cf9dc9 commit 417ab1a

File tree

16 files changed

+359
-29
lines changed

16 files changed

+359
-29
lines changed

casadm/argp.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright(c) 2012-2021 Intel Corporation
3-
* Copyright(c) 2024 Huawei Technologies
3+
* Copyright(c) 2024-2025 Huawei Technologies
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

@@ -13,7 +13,7 @@
1313
#include <sys/stat.h>
1414

1515
#define PADDING " "
16-
#define MAX_OPT_HELP_LEN 30
16+
#define MAX_OPT_HELP_LEN 35
1717

1818
extern cas_printf_t cas_printf;
1919

@@ -154,10 +154,10 @@ void print_list_options(cli_option* options, int flag,
154154
options->long_name, options->arg);
155155
}
156156

157-
cas_printf(LOG_INFO, "%s%-4s%-32s%s\n", PADDING,
157+
cas_printf(LOG_INFO, "%s%-4s%-33s%s\n", PADDING,
158158
short_name, buf, desc);
159159
} else {
160-
cas_printf(LOG_INFO, "%s%-4s--%-30s%s\n", PADDING,
160+
cas_printf(LOG_INFO, "%s%-4s--%-31s%s\n", PADDING,
161161
short_name, options->long_name, desc);
162162
}
163163
}
@@ -207,10 +207,10 @@ static void print_options_help(cli_option *options)
207207
options[i].arg);
208208
}
209209

210-
cas_printf(LOG_INFO, "%s%-4s%-32s%s\n", PADDING,
210+
cas_printf(LOG_INFO, "%s%-4s%-33s%s\n", PADDING,
211211
short_name, buf, desc);
212212
} else {
213-
cas_printf(LOG_INFO, "%s%-4s--%-30s%s\n", PADDING,
213+
cas_printf(LOG_INFO, "%s%-4s--%-31s%s\n", PADDING,
214214
short_name, options[i].long_name,
215215
desc);
216216
}

casadm/cas_main.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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+
713719
static 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")) {

modules/cas_cache/layer_cache_management.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright(c) 2012-2022 Intel Corporation
3+
* Copyright(c) 2022 David Lee <live4thee@gmail.com>
34
* Copyright(c) 2024-2025 Huawei Technologies
45
* SPDX-License-Identifier: BSD-3-Clause
56
*/
@@ -3644,6 +3645,17 @@ int cache_mngt_set_cache_params(struct kcas_set_cache_param *info)
36443645
ocf_cleaning_alru, ocf_alru_activity_threshold,
36453646
info->param_value);
36463647
break;
3648+
case cache_param_cleaning_alru_dirty_ratio_threshold:
3649+
result = cache_mngt_set_cleaning_param(cache,
3650+
ocf_cleaning_alru,
3651+
ocf_alru_dirty_ratio_threshold,
3652+
info->param_value);
3653+
break;
3654+
case cache_param_cleaning_alru_dirty_ratio_inertia:
3655+
result = cache_mngt_set_cleaning_param(cache,
3656+
ocf_cleaning_alru, ocf_alru_dirty_ratio_inertia,
3657+
info->param_value);
3658+
break;
36473659

36483660
case cache_param_cleaning_acp_wake_up_time:
36493661
result = cache_mngt_set_cleaning_param(cache,
@@ -3708,6 +3720,17 @@ int cache_mngt_get_cache_params(struct kcas_get_cache_param *info)
37083720
ocf_cleaning_alru, ocf_alru_activity_threshold,
37093721
&info->param_value);
37103722
break;
3723+
case cache_param_cleaning_alru_dirty_ratio_threshold:
3724+
result = cache_mngt_get_cleaning_param(cache,
3725+
ocf_cleaning_alru,
3726+
ocf_alru_dirty_ratio_threshold,
3727+
&info->param_value);
3728+
break;
3729+
case cache_param_cleaning_alru_dirty_ratio_inertia:
3730+
result = cache_mngt_get_cleaning_param(cache,
3731+
ocf_cleaning_alru, ocf_alru_dirty_ratio_inertia,
3732+
&info->param_value);
3733+
break;
37113734

37123735
case cache_param_cleaning_acp_wake_up_time:
37133736
result = cache_mngt_get_cleaning_param(cache,

modules/include/cas_ioctl_codes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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

@@ -325,6 +326,8 @@ enum kcas_cache_param_id {
325326
cache_param_cleaning_alru_stale_buffer_time,
326327
cache_param_cleaning_alru_flush_max_buffers,
327328
cache_param_cleaning_alru_activity_threshold,
329+
cache_param_cleaning_alru_dirty_ratio_threshold,
330+
cache_param_cleaning_alru_dirty_ratio_inertia,
328331
cache_param_cleaning_acp_wake_up_time,
329332
cache_param_cleaning_acp_flush_max_buffers,
330333
cache_param_promotion_policy_type,

test/functional/api/cas/cache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ def set_params_alru(self, alru_params: FlushParametersAlru) -> Output:
209209
if alru_params.activity_threshold
210210
else None
211211
),
212+
(alru_params.dirty_ratio_threshold if alru_params.dirty_ratio_threshold else None),
213+
(alru_params.dirty_ratio_inertia if alru_params.dirty_ratio_inertia else None),
212214
)
213215

214216
def set_promotion_policy(self, policy: PromotionPolicy) -> Output:

test/functional/api/cas/cache_config.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,28 @@ def __str__(self):
134134
class FlushParametersAlru:
135135
def __init__(
136136
self,
137-
activity_threshold: Time = None,
138-
flush_max_buffers: int = None,
139-
staleness_time: Time = None,
140-
wake_up_time: Time = None,
137+
activity_threshold: Time | None = None,
138+
flush_max_buffers: int | None = None,
139+
staleness_time: Time | None = None,
140+
wake_up_time: Time | None = None,
141+
dirty_ratio_threshold: int | None = None,
142+
dirty_ratio_inertia: Size | None = None
141143
):
142144
self.activity_threshold = activity_threshold
143145
self.flush_max_buffers = flush_max_buffers
144146
self.staleness_time = staleness_time
145147
self.wake_up_time = wake_up_time
148+
self.dirty_ratio_threshold = dirty_ratio_threshold
149+
self.dirty_ratio_inertia = dirty_ratio_inertia
146150

147151
def __eq__(self, other):
148152
return (
149153
self.activity_threshold == other.activity_threshold
150154
and self.flush_max_buffers == other.flush_max_buffers
151155
and self.staleness_time == other.staleness_time
152156
and self.wake_up_time == other.wake_up_time
157+
and self.dirty_ratio_threshold == other.dirty_ratio_threshold
158+
and self.dirty_ratio_inertia == other.dirty_ratio_inertia
153159
)
154160

155161
def __str__(self):
@@ -162,6 +168,10 @@ def __str__(self):
162168
+ (f"{self.staleness_time}" if self.staleness_time is not None else "default"),
163169
"wake up time: "
164170
+ (f"{self.wake_up_time}" if self.wake_up_time is not None else "default"),
171+
"dirty ratio trigger threshold: "
172+
+ (f"{self.dirty_ratio_threshold}" if self.dirty_ratio_threshold is not None else "default"),
173+
"dirty ratio trigger inertia: "
174+
+ (f"{self.dirty_ratio_inertia.set_unit(Unit.MebiByte)}" if self.dirty_ratio_inertia is not None else "default"),
165175
]
166176
return " | ".join(ret)
167177

@@ -172,6 +182,8 @@ def alru_params_range():
172182
alru_params.flush_max_buffers = (1, 10000)
173183
alru_params.staleness_time = (1, 3600)
174184
alru_params.wake_up_time = (0, 3600)
185+
alru_params.dirty_ratio_threshold = (0, 100)
186+
alru_params.dirty_ratio_inertia = (0, (2**32 - 1) // Unit.MebiByte.get_value())
175187
return alru_params
176188

177189
@staticmethod
@@ -181,6 +193,8 @@ def default_alru_params():
181193
alru_params.flush_max_buffers = 100
182194
alru_params.staleness_time = Time(seconds=120)
183195
alru_params.wake_up_time = Time(seconds=20)
196+
alru_params.dirty_ratio_threshold = 100
197+
alru_params.dirty_ratio_inertia = Size(128, Unit.MebiByte)
184198
return alru_params
185199

186200

test/functional/api/cas/casadm.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,29 @@ def set_param_cleaning(cache_id: int, policy: CleaningPolicy, shortcut: bool = F
182182

183183
def set_param_cleaning_alru(
184184
cache_id: int,
185-
wake_up: int = None,
186-
staleness_time: int = None,
187-
flush_max_buffers: int = None,
188-
activity_threshold: int = None,
185+
wake_up: int | None = None,
186+
staleness_time: int | None = None,
187+
flush_max_buffers: int | None = None,
188+
activity_threshold: int | None = None,
189+
dirty_ratio_threshold: int | None = None,
190+
dirty_ratio_inertia: Size | None = None,
189191
shortcut: bool = False,
190192
) -> Output:
191193
_wake_up = str(wake_up) if wake_up is not None else None
192194
_staleness_time = str(staleness_time) if staleness_time is not None else None
193195
_flush_max_buffers = str(flush_max_buffers) if flush_max_buffers is not None else None
194196
_activity_threshold = str(activity_threshold) if activity_threshold is not None else None
197+
_dirty_ratio_threshold = str(dirty_ratio_threshold) if dirty_ratio_threshold is not None else None
198+
_dirty_ratio_inertia = str(dirty_ratio_inertia.get_value(Unit.MebiByte)) if dirty_ratio_inertia is not None else None
195199
output = TestRun.executor.run(
196200
set_param_cleaning_alru_cmd(
197201
cache_id=str(cache_id),
198202
wake_up=_wake_up,
199203
staleness_time=_staleness_time,
200204
flush_max_buffers=_flush_max_buffers,
201205
activity_threshold=_activity_threshold,
206+
dirty_ratio_threshold=_dirty_ratio_threshold,
207+
dirty_ratio_inertia=_dirty_ratio_inertia,
202208
shortcut=shortcut,
203209
)
204210
)

test/functional/api/cas/casadm_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def get_flush_parameters_alru(cache_id: int):
188188
flush_parameters.staleness_time = Time(seconds=int(line.split(",")[1]))
189189
if "Wake up time" in line:
190190
flush_parameters.wake_up_time = Time(seconds=int(line.split(",")[1]))
191+
if "trigger threshold" in line:
192+
flush_parameters.dirty_ratio_threshold = int(line.split(",")[1])
193+
if "trigger inertia" in line:
194+
flush_parameters.dirty_ratio_inertia = Size(int(line.split(",")[1]), Unit.MebiByte)
191195
return flush_parameters
192196

193197

test/functional/api/cas/cli.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright(c) 2019-2022 Intel Corporation
3-
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
3+
# Copyright(c) 2024-2025 Huawei Technologies Co., Ltd.
44
# SPDX-License-Identifier: BSD-3-Clause
55
#
66

@@ -120,10 +120,12 @@ def set_param_cleaning_cmd(cache_id: str, policy: str, shortcut: bool = False) -
120120

121121
def set_param_cleaning_alru_cmd(
122122
cache_id: str,
123-
wake_up: str = None,
124-
staleness_time: str = None,
125-
flush_max_buffers: str = None,
126-
activity_threshold: str = None,
123+
wake_up: str | None = None,
124+
staleness_time: str | None = None,
125+
flush_max_buffers: str | None = None,
126+
activity_threshold: str | None = None,
127+
dirty_ratio_threshold: str | None = None,
128+
dirty_ratio_inertia: str | None = None,
127129
shortcut: bool = False,
128130
) -> str:
129131
name = "cleaning-alru"
@@ -136,6 +138,10 @@ def set_param_cleaning_alru_cmd(
136138
command += (" -b " if shortcut else " --flush-max-buffers ") + flush_max_buffers
137139
if activity_threshold:
138140
command += (" -t " if shortcut else " --activity-threshold ") + activity_threshold
141+
if dirty_ratio_threshold:
142+
command += (" -d " if shortcut else " --dirty-ratio-threshold ") + dirty_ratio_threshold
143+
if dirty_ratio_inertia:
144+
command += " --dirty-ratio-inertia " + dirty_ratio_inertia
139145
return casadm_bin + command
140146

141147

0 commit comments

Comments
 (0)