mm/damon: introduce DAMON parameters online commit function
Subsystems (2)
SeongJae Park
maintainercover mm/damon: introduce DAMON parameters online commit function
DAMON context struct (damon_ctx) contains user requests (parameters), internal status, and operation results. For flexible usages, DAMON API users are encouraged to manually manipulate the struct. That works well for simple use cases. However, it has turned out that it is not that simple at least for online parameters udpate. It is easy to forget properly maintaining internal status and operation results. Also, such manual manipulation for online tuning is implemented multiple times on DAMON API users including DAMON sysfs interface, DAMON_RECLAIM and DAMON_LRU_SORT. As a result, we have multiple sources of bugs for same problem. Actually we found and fixed a few bugs from online parameter updating of DAMON API users.
Implement a function for online DAMON parameters update in core layer, and replace DAMON API users' manual manipulation code for the use case. The core layer function could still have bugs, but this change reduces the source of bugs for the problem to one place.
SeongJae Park (12):
mm/damon/core: implement DAMOS quota goals online commit function mm/damon/core: implement DAMON context commit function mm/damon/sysfs: use damon_commit_ctx() mm/damon/sysfs-schemes: use damos_commit_quota_goals() mm/damon/sysfs: remove unnecessary online tuning handling code mm/damon/sysfs: rename damon_sysfs_set_targets() to ...add_targets() mm/damon/sysfs-schemes: remove unnecessary online tuning handling code mm/damon/sysfs-schemes: rename
*_set_{schemes,scheme_filters,quota_score,schemes}()
mm/damon/reclaim: use damon_commit_ctx()
mm/damon/reclaim: remove unnecessary code for online tuning mm/damon/lru_sort: use damon_commit_ctx() mm/damon/lru_sort: remove unnecessary online tuning handling code
include/linux/damon.h | 2 + mm/damon/core.c | 333 +++++++++++++++++++++++++++++++++++++++ mm/damon/lru_sort.c | 53 +++---- mm/damon/reclaim.c | 62 +++----- mm/damon/sysfs-common.h | 2 +- mm/damon/sysfs-schemes.c | 94 +++-------- mm/damon/sysfs-test.h | 10 +- mm/damon/sysfs.c | 81 +++------- 8 files changed, 425 insertions(+), 212 deletions(-)
base-commit: a7b6f23b7fa3f5d1f3ae64034a4aff12fb8c1df0
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 1/12 mm/damon/core: implement DAMOS quota goals online commit function
Implement functions for supporting online DAMOS quota goals parameters update. The function receives two DAMOS quota structs. One is the struct that currently being used by a kdamond and therefore to be updated. The other one contains the parameters to be applied to the first one. The function applies the new parameters to the destination struct while keeping/updating the internal status. The function should be called from parameters-update safe place, like DAMON callbacks.
--- include/linux/damon.h | 1 + mm/damon/core.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
include/linux/damon.h +1 -0
@@ -742,6 +742,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern, int target_nid);void damon_add_scheme (struct damon_ctx *ctx,struct damos *s);void damon_destroy_scheme (struct damos *s); +int damos_commit_quota_goals (struct damos_quota *dst,struct damos_quota *src);struct damon_target *damon_new_target (void );void damon_add_target (struct damon_ctx *ctx,struct damon_target *t);
mm/damon/core.c +59 -0
65 lines not on this page · raw message
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 2/12 mm/damon/core: implement DAMON context commit function
In reply to SeongJae ParkImplement functions for supporting online DAMON context level parameters update. The function receives two DAMON context structs. One is the struct that currently being used by a kdamond and therefore to be updated. The other one contains the parameters to be applied to the first one. The function applies the new parameters to the destination struct while keeping/updating the internal status and operation results. The function should be called from DAMON context-update-safe place, like DAMON callbacks.
--- include/linux/damon.h | 1 + mm/damon/core.c | 274 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 275 insertions(+)
include/linux/damon.h +1 -0
@@ -756,6 +756,7 @@ void damon_destroy_ctx(struct damon_ctx *ctx);int damon_set_attrs (struct damon_ctx *ctx,struct damon_attrs *attrs);void damon_set_schemes (struct damon_ctx *ctx,struct damos **schemes,ssize_t nr_schemes); +int damon_commit_ctx (struct damon_ctx *old_ctx,struct damon_ctx *new_ctx);int damon_nr_running_ctxs (void );bool damon_is_registered_ops (enum damon_ops_id id);int damon_register_ops (struct damon_operations *ops);
mm/damon/core.c +274 -0
280 lines not on this page · raw message
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 3/12 mm/damon/sysfs: use damon_commit_ctx()
In reply to SeongJae ParkDAMON_SYSFS manually manipulates DAMON context structs for online parameters update. Since the struct contains not only input parameters but also internal status and operation results, it is not that simple. Indeed, we found and fixed a few bugs in the code. Now DAMON core layer provides a function for the usage, namely damon_commit_ctx(). Replace the manual manipulation logic with the function. The core layer function could have its own bugs, but this change removes a source of bugs.
--- mm/damon/sysfs.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +13 -2
@@ -1345,6 +1345,9 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,return damon_sysfs_set_schemes (ctx, sys_ctx->schemes); } +static struct damon_ctx *damon_sysfs_build_ctx ( +struct damon_sysfs_context *sys_ctx); +/* * damon_sysfs_commit_input() - Commit user inputs to a running kdamond. * @kdamond: The kobject wrapper for the associated kdamond.
@@ -1353,14 +1356,22 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,*/ static int damon_sysfs_commit_input (struct damon_sysfs_kdamond *kdamond) { +struct damon_ctx *param_ctx; +int err; +if (!damon_sysfs_kdamond_running (kdamond))return -EINVAL ;/* TODO: Support multiple contexts per kdamond */ if (kdamond->contexts->nr !=1 )return -EINVAL ; -return damon_sysfs_apply_inputs (kdamond->damon_ctx, - kdamond->contexts->contexts_arr[0 ]); + param_ctx =damon_sysfs_build_ctx (kdamond->contexts->contexts_arr[0 ]); +if (IS_ERR (param_ctx)) +return PTR_ERR (param_ctx); + err =damon_commit_ctx (kdamond->damon_ctx, param_ctx); +damon_sysfs_destroy_targets (param_ctx); +damon_destroy_ctx (param_ctx); +return err; } static int damon_sysfs_commit_schemes_quota_goals(
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 4/12 mm/damon/sysfs-schemes: use damos_commit_quota_goals()
In reply to SeongJae ParkDAMON_SYSFS manually manipulates the DAMOS quota structs for online quotal goals parameter update. Since the struct contains not only input parameters but also internal status and operation results, it is not that simple. Now DAMON core layer provides a function for the usage, namely damon_commit_quota_goals(). Replace the manual manipulation logic with the function. The core layer function could have its own bugs, but this change removes a source of bugs.
--- mm/damon/sysfs-schemes.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
mm/damon/sysfs-schemes.c +12 -2
@@ -1983,10 +1983,13 @@ int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx) {struct damos *scheme; +struct damos_quota quota = {};int i =0 ; +INIT_LIST_HEAD ("a.goals);damon_for_each_scheme (scheme, ctx) {struct damon_sysfs_scheme *sysfs_scheme; +struct damos_quota_goal *g, *g_next;int err;/* user could have removed the scheme sysfs dir */
@@ -1995,9 +1998,16 @@ int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes, sysfs_scheme = sysfs_schemes->schemes_arr[i]; err =damos_sysfs_set_quota_score (sysfs_scheme->quotas->goals, - &scheme->quota); + "a); +if (err) { +damos_for_each_quota_goal_safe (g, g_next, "a) +damos_destroy_quota_goal (g); +return err; + } + err =damos_commit_quota_goals (&scheme->quota, "a); +damos_for_each_quota_goal_safe (g, g_next, "a) +damos_destroy_quota_goal (g);if (err) -/* kdamond will clean up schemes and terminated */ return err; i++; }
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 5/12 mm/damon/sysfs: remove unnecessary online tuning handling code
In reply to SeongJae Parkdamon/sysfs.c contains code for handling of online DAMON parameters update edge cases. It is no more necessary since damon_commit_ctx() takes care of the cases. Remove the unnecessary code.
--- mm/damon/sysfs-test.h | 2 +- mm/damon/sysfs.c | 60 ++----------------------------------------- 2 files changed, 3 insertions(+), 59 deletions(-)
mm/damon/sysfs-test.h +1 -1
@@ -62,7 +62,7 @@ static void damon_sysfs_test_set_targets(struct kunit *test) sysfs_target->pid =__damon_sysfs_test_get_any_pid ( sysfs_target->pid +1 ,200 );damon_sysfs_set_targets (ctx, sysfs_targets); -KUNIT_EXPECT_EQ (test,1u ,nr_damon_targets (ctx)); +KUNIT_EXPECT_EQ (test,2u ,nr_damon_targets (ctx));damon_destroy_ctx (ctx);kfree (sysfs_targets->targets_arr);
mm/damon/sysfs.c +2 -58
74 lines not on this page · raw message
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 6/12 mm/damon/sysfs: rename damon_sysfs_set_targets() to ...add_targets()
In reply to SeongJae ParkThe function was for updating DAMON structs that may or may not be partially populated. Hence it was not for only adding items, but also removing unnecessary items and updating items in-place. A previous commit has changed the function to assume the structs are not partially populated, and do only adding items. Make the function name better explain the behavior.
--- mm/damon/sysfs-test.h | 8 ++++---- mm/damon/sysfs.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
mm/damon/sysfs-test.h +4 -4
@@ -38,7 +38,7 @@ static int __damon_sysfs_test_get_any_pid(int min, int max)return -1 ; } -static void damon_sysfs_test_set_targets (struct kunit *test) +static void damon_sysfs_test_add_targets (struct kunit *test) {struct damon_sysfs_targets *sysfs_targets;struct damon_sysfs_target *sysfs_target;
@@ -56,12 +56,12 @@ static void damon_sysfs_test_set_targets(struct kunit *test) ctx =damon_new_ctx (); -damon_sysfs_set_targets (ctx, sysfs_targets); +damon_sysfs_add_targets (ctx, sysfs_targets);KUNIT_EXPECT_EQ (test,1u ,nr_damon_targets (ctx)); sysfs_target->pid =__damon_sysfs_test_get_any_pid ( sysfs_target->pid +1 ,200 ); -damon_sysfs_set_targets (ctx, sysfs_targets); +damon_sysfs_add_targets (ctx, sysfs_targets);KUNIT_EXPECT_EQ (test,2u ,nr_damon_targets (ctx));damon_destroy_ctx (ctx);
@@ -71,7 +71,7 @@ static void damon_sysfs_test_set_targets(struct kunit *test) }static struct kunit_case damon_sysfs_test_cases[] = { -KUNIT_CASE (damon_sysfs_test_set_targets), +KUNIT_CASE (damon_sysfs_test_add_targets), {}, };
mm/damon/sysfs.c +2 -2
@@ -1162,7 +1162,7 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,return err; } -static int damon_sysfs_set_targets (struct damon_ctx *ctx, +static int damon_sysfs_add_targets (struct damon_ctx *ctx,struct damon_sysfs_targets *sysfs_targets) {int i, err;
@@ -1283,7 +1283,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx, err =damon_sysfs_set_attrs (ctx, sys_ctx->attrs);if (err)return err; - err =damon_sysfs_set_targets (ctx, sys_ctx->targets); + err =damon_sysfs_add_targets (ctx, sys_ctx->targets);if (err)return err;return damon_sysfs_set_schemes (ctx, sys_ctx->schemes);
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 7/12 mm/damon/sysfs-schemes: remove unnecessary online tuning handling code
In reply to SeongJae Parkdamon/sysfs-schemes.c contains code for handling of online DAMON parameters update edge cases. The logics are no more necessary since damon_commit_ctx() and damon_commit_quota_goals() takes care of the cases. Remove the unnecessary code.
--- mm/damon/sysfs-schemes.c | 68 ++-------------------------------------- 1 file changed, 3 insertions(+), 65 deletions(-)
mm/damon/sysfs-schemes.c +3 -65
@@ -1912,10 +1912,6 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme, struct damon_sysfs_scheme_filters *sysfs_filters) {int i; -struct damos_filter *filter, *next; - -damos_for_each_filter_safe (filter, next, scheme) -damos_destroy_filter (filter);for (i =0 ; i < sysfs_filters->nr; i++) { struct damon_sysfs_scheme_filter *sysfs_filter =
@@ -1955,12 +1951,9 @@ static int damos_sysfs_set_quota_score(struct damos_sysfs_quota_goals *sysfs_goals, struct damos_quota *quota) { - struct damos_quota_goal *goal, *next; + struct damos_quota_goal *goal;int i; -damos_for_each_quota_goal_safe (goal, next, quota) -damos_destroy_quota_goal (goal); -for (i =0 ; i < sysfs_goals->nr; i++) {struct damos_sysfs_quota_goal *sysfs_goal = sysfs_goals->goals_arr[i];
@@ -2091,67 +2084,12 @@ static struct damos *damon_sysfs_mk_scheme(return scheme; } -static void damon_sysfs_update_scheme (struct damos *scheme, -struct damon_sysfs_scheme *sysfs_scheme) -{ -struct damon_sysfs_access_pattern *access_pattern = - sysfs_scheme->access_pattern; -struct damon_sysfs_quotas *sysfs_quotas = sysfs_scheme->quotas; -struct damon_sysfs_weights *sysfs_weights = sysfs_quotas->weights; -struct damon_sysfs_watermarks *sysfs_wmarks = sysfs_scheme->watermarks; -int err; - - scheme->pattern.min_sz_region = access_pattern->sz->min; - scheme->pattern.max_sz_region = access_pattern->sz->max; - scheme->pattern.min_nr_accesses = access_pattern->nr_accesses->min; - scheme->pattern.max_nr_accesses = access_pattern->nr_accesses->max; - scheme->pattern.min_age_region = access_pattern->age->min; - scheme->pattern.max_age_region = access_pattern->age->max; - - scheme->action = sysfs_scheme->action; - scheme->apply_interval_us = sysfs_scheme->apply_interval_us; - scheme->target_nid = sysfs_scheme->target_nid; - - scheme->quota.ms = sysfs_quotas->ms; - scheme->quota.sz = sysfs_quotas->sz; - scheme->quota.reset_interval = sysfs_quotas->reset_interval_ms; - scheme->quota.weight_sz = sysfs_weights->sz; - scheme->quota.weight_nr_accesses = sysfs_weights->nr_accesses; - scheme->quota.weight_age = sysfs_weights->age; - - err =damos_sysfs_set_quota_score (sysfs_quotas->goals, &scheme->quota); -if (err) { -damon_destroy_scheme (scheme); -return ; - } - - scheme->wmarks.metric = sysfs_wmarks->metric; - scheme->wmarks.interval = sysfs_wmarks->interval_us; - scheme->wmarks.high = sysfs_wmarks->high; - scheme->wmarks.mid = sysfs_wmarks->mid; - scheme->wmarks.low = sysfs_wmarks->low; - - err =damon_sysfs_set_scheme_filters (scheme, sysfs_scheme->filters); -if (err) -damon_destroy_scheme (scheme); -} -int damon_sysfs_set_schemes (struct damon_ctx *ctx,struct damon_sysfs_schemes *sysfs_schemes) { -struct damos *scheme, *next; -int i =0 ; - -damon_for_each_scheme_safe (scheme, next, ctx) { -if (i < sysfs_schemes->nr) -damon_sysfs_update_scheme (scheme, - sysfs_schemes->schemes_arr[i]); -else -damon_destroy_scheme (scheme); - i++; - } +int i; -for (; i < sysfs_schemes->nr; i++) { +for (i =0 ; i < sysfs_schemes->nr; i++) {struct damos *scheme, *next; scheme =damon_sysfs_mk_scheme (sysfs_schemes->schemes_arr[i]);
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 8/12 mm/damon/sysfs-schemes: rename *_set_{schemes,scheme_filters,quota_score,schemes}()
In reply to SeongJae ParkThe functions were for updating DAMON structs that may or may not be partially populated. Hence it was not for only adding items, but also removing unnecessary items and updating items in-place. A previous commit has changed the functions to assume the structs are not partially populated, and do only adding items. Make the names better explain the behavior.
--- mm/damon/sysfs-common.h | 2 +- mm/damon/sysfs-schemes.c | 12 ++++++------ mm/damon/sysfs.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-)
mm/damon/sysfs-common.h +1 -1
@@ -38,7 +38,7 @@ void damon_sysfs_schemes_rm_dirs(struct damon_sysfs_schemes *schemes);extern const struct kobj_type damon_sysfs_schemes_ktype; -int damon_sysfs_set_schemes (struct damon_ctx *ctx, +int damon_sysfs_add_schemes (struct damon_ctx *ctx,struct damon_sysfs_schemes *sysfs_schemes); void damon_sysfs_schemes_update_stats(
mm/damon/sysfs-schemes.c +6 -6
@@ -1908,7 +1908,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)return found ?0 : -EINVAL ; } -static int damon_sysfs_set_scheme_filters (struct damos *scheme, +static int damon_sysfs_add_scheme_filters (struct damos *scheme,struct damon_sysfs_scheme_filters *sysfs_filters) {int i;
@@ -1947,7 +1947,7 @@ static int damon_sysfs_set_scheme_filters(struct damos *scheme,return 0 ; } -static int damos_sysfs_set_quota_score ( +static int damos_sysfs_add_quota_score (struct damos_sysfs_quota_goals *sysfs_goals,struct damos_quota *quota) {
@@ -1990,7 +1990,7 @@ int damos_sysfs_set_quota_scores(struct damon_sysfs_schemes *sysfs_schemes,break ; sysfs_scheme = sysfs_schemes->schemes_arr[i]; - err =damos_sysfs_set_quota_score (sysfs_scheme->quotas->goals, + err =damos_sysfs_add_quota_score (sysfs_scheme->quotas->goals, "a);if (err) {damos_for_each_quota_goal_safe (g, g_next, "a)
@@ -2070,13 +2070,13 @@ static struct damos *damon_sysfs_mk_scheme(if (!scheme)return NULL ; - err =damos_sysfs_set_quota_score (sysfs_quotas->goals, &scheme->quota); + err =damos_sysfs_add_quota_score (sysfs_quotas->goals, &scheme->quota);if (err) {damon_destroy_scheme (scheme);return NULL ; } - err =damon_sysfs_set_scheme_filters (scheme, sysfs_filters); + err =damon_sysfs_add_scheme_filters (scheme, sysfs_filters);if (err) {damon_destroy_scheme (scheme);return NULL ;
@@ -2084,7 +2084,7 @@ static struct damos *damon_sysfs_mk_scheme(return scheme; } -int damon_sysfs_set_schemes (struct damon_ctx *ctx, +int damon_sysfs_add_schemes (struct damon_ctx *ctx,struct damon_sysfs_schemes *sysfs_schemes) {int i;
mm/damon/sysfs.c +1 -1
@@ -1286,7 +1286,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx, err =damon_sysfs_add_targets (ctx, sys_ctx->targets);if (err)return err; -return damon_sysfs_set_schemes (ctx, sys_ctx->schemes); +return damon_sysfs_add_schemes (ctx, sys_ctx->schemes); } static struct damon_ctx *damon_sysfs_build_ctx(
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 9/12 mm/damon/reclaim: use damon_commit_ctx()
In reply to SeongJae ParkDAMON_RECLAIM manually manipulates the DAMON context struct for online parameters update. Since the struct contains not only input parameters but also internal status and operation results, it is not that simple. Indeed, we found and fixed a few bugs in the code. Now DAMON core layer provides a function for the usage, namely damon_commit_ctx(). Replace the manual manipulation logic with the function. The core layer function could have its own bugs, but this change removes a source of bugs.
--- mm/damon/reclaim.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)
mm/damon/reclaim.c +24 -19
@@ -195,59 +195,64 @@ static void damon_reclaim_copy_quota_status(struct damos_quota *dst,static int damon_reclaim_apply_parameters (void ) { +struct damon_ctx *param_ctx; +struct damon_target *param_target;struct damos *scheme, *old_scheme;struct damos_quota_goal *goal;struct damos_filter *filter; -int err =0 ; +int err; - err =damon_set_attrs (ctx, &damon_reclaim_mon_attrs); + err =damon_modules_new_paddr_ctx_target (¶m_ctx, ¶m_target);if (err)return err; -/* Will be freed by next 'damon_set_schemes()' below */ + err =damon_set_attrs (ctx, &damon_reclaim_mon_attrs); +if (err) + goto out; + + err = -ENOMEM ; scheme =damon_reclaim_new_scheme ();if (!scheme) -return -ENOMEM ; + goto out;if (!list_empty (&ctx->schemes)) {damon_for_each_scheme (old_scheme, ctx)damon_reclaim_copy_quota_status (&scheme->quota, &old_scheme->quota); } +damon_set_schemes (ctx, &scheme,1 );if (quota_mem_pressure_us) { goal =damos_new_quota_goal (DAMOS_QUOTA_SOME_MEM_PSI_US , quota_mem_pressure_us); -if (!goal) { -damon_destroy_scheme (scheme); -return -ENOMEM ; - } +if (!goal) + goto out;damos_add_quota_goal (&scheme->quota, goal); }if (quota_autotune_feedback) { goal =damos_new_quota_goal (DAMOS_QUOTA_USER_INPUT ,10000 ); -if (!goal) { -damon_destroy_scheme (scheme); -return -ENOMEM ; - } +if (!goal) + goto out; goal->current_value = quota_autotune_feedback;damos_add_quota_goal (&scheme->quota, goal); }if (skip_anon) { filter =damos_new_filter (DAMOS_FILTER_TYPE_ANON , true); -if (!filter) { -/* Will be freed by next 'damon_set_schemes()' below */ -damon_destroy_scheme (scheme); -return -ENOMEM ; - } +if (!filter) + goto out;damos_add_filter (scheme, filter); } -damon_set_schemes (ctx, &scheme,1 ); -return damon_set_region_biggest_system_ram_default (target, + err =damon_set_region_biggest_system_ram_default (param_target, &monitor_region_start, &monitor_region_end); +if (err) + goto out; + err =damon_commit_ctx (ctx, param_ctx); +out: +damon_destroy_ctx (param_ctx); +return err; }static int damon_reclaim_turn (bool on)
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 10/12 mm/damon/reclaim: remove unnecessary code for online tuning
In reply to SeongJae ParkDAMON_RECLAIM contains code for handling of online DAMON parameters update edge cases. It is no more necessary since damon_commit_ctx() takes care of the cases. Remove the unnecessary code.
--- mm/damon/reclaim.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
mm/damon/reclaim.c +1 -18
@@ -181,23 +181,11 @@ static struct damos *damon_reclaim_new_scheme(void) NUMA_NO_NODE); } -static void damon_reclaim_copy_quota_status (struct damos_quota *dst, -struct damos_quota *src) -{ - dst->total_charged_sz = src->total_charged_sz; - dst->total_charged_ns = src->total_charged_ns; - dst->charged_sz = src->charged_sz; - dst->charged_from = src->charged_from; - dst->charge_target_from = src->charge_target_from; - dst->charge_addr_from = src->charge_addr_from; - dst->esz_bp = src->esz_bp; -} -static int damon_reclaim_apply_parameters (void ) {struct damon_ctx *param_ctx;struct damon_target *param_target; -struct damos *scheme, *old_scheme; +struct damos *scheme;struct damos_quota_goal *goal;struct damos_filter *filter;int err;
@@ -214,11 +202,6 @@ static int damon_reclaim_apply_parameters(void) scheme =damon_reclaim_new_scheme ();if (!scheme) goto out; -if (!list_empty (&ctx->schemes)) { -damon_for_each_scheme (old_scheme, ctx) -damon_reclaim_copy_quota_status (&scheme->quota, - &old_scheme->quota); - }damon_set_schemes (ctx, &scheme,1 );if (quota_mem_pressure_us) {
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 11/12 mm/damon/lru_sort: use damon_commit_ctx()
In reply to SeongJae ParkDAMON_LRU_SORT manually manipulates the DAMON context struct for online parameters update. Since the struct contains not only input parameters but also internal status and operation results, it is not that simple. Indeed, we found and fixed a few bugs in the code. Now DAMON core layer provides a function for the usage, namely damon_commit_ctx(). Replace the manual manipulation logic with the function. The core layer function could have its own bugs, but this change removes a source of bugs.
--- mm/damon/lru_sort.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
mm/damon/lru_sort.c +20 -7
@@ -199,15 +199,22 @@ static void damon_lru_sort_copy_quota_status(struct damos_quota *dst,static int damon_lru_sort_apply_parameters (void ) { +struct damon_ctx *param_ctx; +struct damon_target *param_target;struct damos *scheme, *hot_scheme, *cold_scheme;struct damos *old_hot_scheme =NULL , *old_cold_scheme =NULL ;unsigned int hot_thres, cold_thres; -int err =0 ; +int err; - err =damon_set_attrs (ctx, &damon_lru_sort_mon_attrs); + err =damon_modules_new_paddr_ctx_target (¶m_ctx, ¶m_target);if (err)return err; + err =damon_set_attrs (ctx, &damon_lru_sort_mon_attrs); +if (err) + goto out; + + err = -ENOMEM ;damon_for_each_scheme (scheme, ctx) {if (!old_hot_scheme) { old_hot_scheme = scheme;
@@ -220,7 +227,7 @@ static int damon_lru_sort_apply_parameters(void) hot_thres_access_freq /1000 ; hot_scheme =damon_lru_sort_new_hot_scheme (hot_thres);if (!hot_scheme) -return -ENOMEM ; + goto out;if (old_hot_scheme)damon_lru_sort_copy_quota_status (&hot_scheme->quota, &old_hot_scheme->quota);
@@ -229,18 +236,24 @@ static int damon_lru_sort_apply_parameters(void) cold_scheme =damon_lru_sort_new_cold_scheme (cold_thres);if (!cold_scheme) {damon_destroy_scheme (hot_scheme); -return -ENOMEM ; + goto out; }if (old_cold_scheme)damon_lru_sort_copy_quota_status (&cold_scheme->quota, &old_cold_scheme->quota); -damon_set_schemes (ctx, &hot_scheme,1 ); -damon_add_scheme (ctx, cold_scheme); +damon_set_schemes (param_ctx, &hot_scheme,1 ); +damon_add_scheme (param_ctx, cold_scheme); -return damon_set_region_biggest_system_ram_default (target, + err =damon_set_region_biggest_system_ram_default (param_target, &monitor_region_start, &monitor_region_end); +if (err) + goto out; + err =damon_commit_ctx (ctx, param_ctx); +out: +damon_destroy_ctx (param_ctx); +return err; }static int damon_lru_sort_turn (bool on)
Signature · 1 line
2.39.2
SeongJae Park
maintainerPATCH 12/12 mm/damon/lru_sort: remove unnecessary online tuning handling code
In reply to SeongJae ParkDAMON_LRU_SORT contains code for handling of online DAMON parameters update edge cases. It is no more necessary since damon_commit_ctx() takes care of the cases. Remove the unnecessary code.
--- mm/damon/lru_sort.c | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-)
mm/damon/lru_sort.c +1 -27
@@ -186,23 +186,11 @@ static struct damos *damon_lru_sort_new_cold_scheme(unsigned int cold_thres)return damon_lru_sort_new_scheme (&pattern,DAMOS_LRU_DEPRIO ); } -static void damon_lru_sort_copy_quota_status (struct damos_quota *dst, -struct damos_quota *src) -{ - dst->total_charged_sz = src->total_charged_sz; - dst->total_charged_ns = src->total_charged_ns; - dst->charged_sz = src->charged_sz; - dst->charged_from = src->charged_from; - dst->charge_target_from = src->charge_target_from; - dst->charge_addr_from = src->charge_addr_from; -} -static int damon_lru_sort_apply_parameters (void ) {struct damon_ctx *param_ctx;struct damon_target *param_target; -struct damos *scheme, *hot_scheme, *cold_scheme; -struct damos *old_hot_scheme =NULL , *old_cold_scheme =NULL ; +struct damos *hot_scheme, *cold_scheme;unsigned int hot_thres, cold_thres;int err;
@@ -215,22 +203,11 @@ static int damon_lru_sort_apply_parameters(void) goto out; err = -ENOMEM ; -damon_for_each_scheme (scheme, ctx) { -if (!old_hot_scheme) { - old_hot_scheme = scheme; -continue ; - } - old_cold_scheme = scheme; - } - hot_thres =damon_max_nr_accesses (&damon_lru_sort_mon_attrs) * hot_thres_access_freq /1000 ; hot_scheme =damon_lru_sort_new_hot_scheme (hot_thres);if (!hot_scheme) goto out; -if (old_hot_scheme) -damon_lru_sort_copy_quota_status (&hot_scheme->quota, - &old_hot_scheme->quota); cold_thres = cold_min_age / damon_lru_sort_mon_attrs.aggr_interval; cold_scheme =damon_lru_sort_new_cold_scheme (cold_thres);
@@ -238,9 +215,6 @@ static int damon_lru_sort_apply_parameters(void)damon_destroy_scheme (hot_scheme); goto out; } -if (old_cold_scheme) -damon_lru_sort_copy_quota_status (&cold_scheme->quota, - &old_cold_scheme->quota);damon_set_schemes (param_ctx, &hot_scheme,1 );damon_add_scheme (param_ctx, cold_scheme);
Signature · 1 line
2.39.2