mm/damon: A few fixup with lru_sort
Subsystems (2)
v2 cover mm/damon: A few fixup with lru_sort
v1:
https://lore.kernel.org/damon/[email protected]/
Xin Hao (2):
mm/damon/lru_sort: Move target memory region check to head of func mm/damon/lru_sort: Remove struct of damon_lru_sort_ram_walk_arg
mm/damon/lru_sort.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-)
--
2.27.0
PATCH v2 1/2 mm/damon/lru_sort: Move target memory region check to head of func
In damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.
--- mm/damon/lru_sort.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
mm/damon/lru_sort.c +7 -6
@@ -378,6 +378,13 @@ static int damon_lru_sort_apply_parameters(void)unsigned int hot_thres, cold_thres;int err =0 ; +if (monitor_region_start > monitor_region_end) +return -EINVAL ; +if (!monitor_region_start && !monitor_region_end && + !get_monitoring_region (&monitor_region_start, + &monitor_region_end)) +return -EINVAL ; + err =damon_set_attrs (ctx, sample_interval, aggr_interval,0 , min_nr_regions, max_nr_regions);if (err)
@@ -401,12 +408,6 @@ static int damon_lru_sort_apply_parameters(void)return -ENOMEM ;damon_add_scheme (ctx, scheme); -if (monitor_region_start > monitor_region_end) -return -EINVAL ; -if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region (&monitor_region_start, - &monitor_region_end)) -return -EINVAL ; addr_range.start = monitor_region_start; addr_range.end = monitor_region_end;return damon_set_regions (target, &addr_range,1 );
Signature · 1 line
2.27.0
SeongJae Park
maintainerRe: [PATCH V2 1/2] mm/damon/lru_sort: Move target memory region check to head of func
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:31 +0800 Xin Hao <[email protected]> wrote:
In
damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.
The function, 'damon_lru_sort_apply_parameters()', checks validity of parameters and construct the DAMON context one by one. For example, 'damon_set_attrs()' returns an error if the parameters are invalid. So the intended flow is,
1. check DAMON attributes parameters,
2. apply DAMON attributes parameters,
3. check scheme parameters,
4. apply scheme parameters,
5. check target region parameters, and
6. apply target region parameters.
Therefore what this patch does is making the target regions validity check to be done earlier than validity checks of other parameters. There is no special reason to check the region earlier than others. Also, this change makes the flow of the function a little bit weird in my humble opinion, as the flow will be
1. check target region parameters,
2. check DAMON attributes parameters,
3. apply DAMON attributes parameters,
4. check scheme parameters,
5. apply scheme parameters, and
6. apply target region parameters.
So I'd argue this patch seems not really needed, sorry.
Thanks,
SJ
[...]
Re: [PATCH V2 1/2] mm/damon/lru_sort: Move target memory region check to head of func
Quoted 26 lines · SeongJae Park
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:31 +0800 Xin Hao <[email protected]> wrote:
In
damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.The function, '
damon_lru_sort_apply_parameters()', checks validity of parameters and construct the DAMON context one by one. For example, 'damon_set_attrs()' returns an error if the parameters are invalid. So the intended flow is,1. check DAMON attributes parameters,
2. apply DAMON attributes parameters,
3. check scheme parameters,
4. apply scheme parameters,
5. check target region parameters, and
6. apply target region parameters.Therefore what this patch does is making the target regions validity check to be done earlier than validity checks of other parameters. There is no special reason to check the region earlier than others. Also, this change makes the flow of the function a little bit weird in my humble opinion, as the flow will be
Quoted 6 lines
1. check target region parameters,
2. check DAMON attributes parameters,
3. apply DAMON attributes parameters,
4. check scheme parameters,
5. apply scheme parameters, and
6. apply target region parameters.
Ok, understand what you mean, my fix looks ugly, buy any apply above are not not necessary if one of them checks failed, why not check all fisrt and then apply them, like this:
1. check target region parameters,
2. check DAMON attributes parameters,
3. check scheme parameters,
Quoted 8 lines
So I'd argue this patch seems not really needed, sorry.
Thanks,
SJ[...]
SeongJae Park
maintainerRe: [PATCH V2 1/2] mm/damon/lru_sort: Move target memory region check to head of func
Hi Xin,
Quoted 39 lines · SeongJae Park
Quoted 26 lines
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:31 +0800 Xin Hao <[email protected]> wrote:
In
damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.The function, '
damon_lru_sort_apply_parameters()', checks validity of parameters and construct the DAMON context one by one. For example, 'damon_set_attrs()' returns an error if the parameters are invalid. So the intended flow is,1. check DAMON attributes parameters,
2. apply DAMON attributes parameters,
3. check scheme parameters,
4. apply scheme parameters,
5. check target region parameters, and
6. apply target region parameters.Therefore what this patch does is making the target regions validity check to be done earlier than validity checks of other parameters. There is no special reason to check the region earlier than others. Also, this change makes the flow of the function a little bit weird in my humble opinion, as the flow will be
Quoted 6 lines
1. check target region parameters,
2. check DAMON attributes parameters,
3. apply DAMON attributes parameters,
4. check scheme parameters,
5. apply scheme parameters, and
6. apply target region parameters.Ok, understand what you mean, my fix looks ugly, buy any apply above
are not not necessary if one of them checks failed, why not check all fisrt and then apply them, like this:
Quoted 5 lines
1. check target region parameters,
2. check DAMON attributes parameters,
3. check scheme parameters,
The parameter values could be changed by users after the check, so we should cache those somewhere anyway. In other words, we cache those in the DAMON context. Therefore I think the above works were not totally waste of the time. Also, because the parameters applying functions like 'damon_set_attrs()' does the check and applying of the parameters together, I feel like current flow is natural.
If I'm missing something, please let me know.
Thanks,
SJ
Quoted 10 lines
Quoted 9 lines
So I'd argue this patch seems not really needed, sorry.
Thanks,
SJ[...]
Re: [PATCH V2 1/2] mm/damon/lru_sort: Move target memory region check to head of func
Quoted 43 lines · SeongJae Park
Hi Xin,
Quoted 41 lines · SeongJae Park
Quoted 26 lines
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:31 +0800 Xin Hao <[email protected]> wrote:
In
damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.The function, '
damon_lru_sort_apply_parameters()', checks validity of parameters and construct the DAMON context one by one. For example, 'damon_set_attrs()' returns an error if the parameters are invalid. So the intended flow is,1. check DAMON attributes parameters,
2. apply DAMON attributes parameters,
3. check scheme parameters,
4. apply scheme parameters,
5. check target region parameters, and
6. apply target region parameters.Therefore what this patch does is making the target regions validity check to be done earlier than validity checks of other parameters. There is no special reason to check the region earlier than others. Also, this change makes the flow of the function a little bit weird in my humble opinion, as the flow will be
Quoted 6 lines
1. check target region parameters,
2. check DAMON attributes parameters,
3. apply DAMON attributes parameters,
4. check scheme parameters,
5. apply scheme parameters, and
6. apply target region parameters.Ok, understand what you mean, my fix looks ugly, buy any apply above
are not not necessary if one of them checks failed, why not check all fisrt and then apply them, like this:1. check target region parameters,
2. check DAMON attributes parameters,
Quoted 7 lines
Quoted 1 line
3. check scheme parameters,
The parameter values could be changed by users after the check, so we should cache those somewhere anyway. In other words, we cache those in the DAMON context. Therefore I think the above works were not totally waste of the time. Also, because the parameters applying functions like '
damon_set_attrs()' does the check and applying of the parameters together, I feel like current flow is natural.
Ok, Thank you for your detailed explain, just keep it. but there still a problem in damon_lru_sort_apply_parameters
if (!monitor_region_start && !monitor_region_end &&
!get_monitoring_region(&monitor_region_start,
&monitor_region_end))
if (!monitor_region_start || !monitor_region_end ||
!get_monitoring_region(&monitor_region_start,
&monitor_region_end))
the '&&' should fix to '||', anyone checks fail, it should return ?
Quoted 1 line
SeongJae Park
maintainerRe: [PATCH V2 1/2] mm/damon/lru_sort: Move target memory region check to head of func
Quoted 60 lines · On Fri, 19 Aug 2022 10:47:58 +0800 haoxin <[email protected]> wrote:
Quoted 43 lines · SeongJae Park
Hi Xin,
Quoted 41 lines · SeongJae Park
Quoted 26 lines
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:31 +0800 Xin Hao <[email protected]> wrote:
In
damon_lru_sort_apply_parameters(), if "monitor_region_start" and "monitor_region_end" is not a valid physical address range, There no need to run the remainder codes in it.The function, '
damon_lru_sort_apply_parameters()', checks validity of parameters and construct the DAMON context one by one. For example, 'damon_set_attrs()' returns an error if the parameters are invalid. So the intended flow is,1. check DAMON attributes parameters,
2. apply DAMON attributes parameters,
3. check scheme parameters,
4. apply scheme parameters,
5. check target region parameters, and
6. apply target region parameters.Therefore what this patch does is making the target regions validity check to be done earlier than validity checks of other parameters. There is no special reason to check the region earlier than others. Also, this change makes the flow of the function a little bit weird in my humble opinion, as the flow will be
Quoted 6 lines
1. check target region parameters,
2. check DAMON attributes parameters,
3. apply DAMON attributes parameters,
4. check scheme parameters,
5. apply scheme parameters, and
6. apply target region parameters.Ok, understand what you mean, my fix looks ugly, buy any apply above
are not not necessary if one of them checks failed, why not check all fisrt and then apply them, like this:1. check target region parameters,
2. check DAMON attributes parameters,
Quoted 7 lines
Quoted 1 line
3. check scheme parameters,
The parameter values could be changed by users after the check, so we should cache those somewhere anyway. In other words, we cache those in the DAMON context. Therefore I think the above works were not totally waste of the time. Also, because the parameters applying functions like '
damon_set_attrs()' does the check and applying of the parameters together, I feel like current flow is natural.Ok, Thank you for your detailed explain, just keep it. but there still a problem in
damon_lru_sort_apply_parametersif (!monitor_region_start && !monitor_region_end &&
!get_monitoring_region(&monitor_region_start,
&monitor_region_end))
Quoted 5 lines
if (!monitor_region_start || !monitor_region_end ||
!get_monitoring_region(&monitor_region_start,
&monitor_region_end))the '&&' should fix to '||', anyone checks fail, it should return ?
No. The code is for setting the monitoring region as the biggest System RAM resource only if the user didn't set both 'monitor_region_start' and 'monitor_region_end'.
Thanks,
SJ
PATCH v2 2/2 mm/damon/lru_sort: Remove struct of damon_lru_sort_ram_walk_arg
In reply to Xin HaoThe struct of 'damon_lru_sort_ram_walk_arg' is the same with struct of 'damon_addr_range', so, there no need to redefine it, just use struct of 'damon_addr_range' instead.
--- mm/damon/lru_sort.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-)
mm/damon/lru_sort.c +13 -21
@@ -257,18 +257,13 @@ module_param(nr_cold_quota_exceeds, ulong, 0400);static struct damon_ctx *ctx;static struct damon_target *target; -struct damon_lru_sort_ram_walk_arg { -unsigned long start; -unsigned long end; -}; -static int walk_system_ram (struct resource *res,void *arg) { -struct damon_lru_sort_ram_walk_arg *a = arg; +struct damon_addr_range *r = arg; -if (a->end - a->start <resource_size (res)) { - a->start = res->start; - a->end = res->end; +if (r->end - r->start <resource_size (res)) { + r->start = res->start; + r->end = res->end; }return 0 ; }
@@ -277,16 +272,12 @@ static int walk_system_ram(struct resource *res, void *arg)* Find biggest 'System RAM' resource and store its start and end address in * @start and @end, respectively. If no System RAM is found, returns false. */ -static bool get_monitoring_region (unsigned long *start,unsigned long *end) +static bool get_monitoring_region (struct damon_addr_range *range) { -struct damon_lru_sort_ram_walk_arg arg = {}; - -walk_system_ram_res (0 ,ULONG_MAX , &arg, walk_system_ram); -if (arg.end <= arg.start) +walk_system_ram_res (0 ,ULONG_MAX , range, walk_system_ram); +if (range->end <= range->start)return false; - *start = arg.start; - *end = arg.end;return true; }
@@ -380,9 +371,12 @@ static int damon_lru_sort_apply_parameters(void)if (monitor_region_start > monitor_region_end)return -EINVAL ; -if (!monitor_region_start && !monitor_region_end && - !get_monitoring_region (&monitor_region_start, - &monitor_region_end)) +if (!monitor_region_end) +return -EINVAL ; + + addr_range.start = monitor_region_start; + addr_range.end = monitor_region_end; +if (!get_monitoring_region (&addr_range))return -EINVAL ; err = damon_set_attrs(ctx, sample_interval, aggr_interval, 0,
@@ -408,8 +402,6 @@ static int damon_lru_sort_apply_parameters(void)return -ENOMEM ;damon_add_scheme (ctx, scheme); - addr_range.start = monitor_region_start; - addr_range.end = monitor_region_end;return damon_set_regions (target, &addr_range,1 ); }
--
2.27.0
SeongJae Park
maintainerRe: [PATCH V2 2/2] mm/damon/lru_sort: Remove struct of damon_lru_sort_ram_walk_arg
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:32 +0800 Xin Hao <[email protected]> wrote:
The struct of '
damon_lru_sort_ram_walk_arg' is the same with struct of 'damon_addr_range', so, there no need to redefine it, just use struct of 'damon_addr_range' instead.
Reducing code is always good, thanks. However, I think the type of the 'start' and 'end' fields of 'struct damon_addr_range' might be changed in a future. It's very unlikely, though. Also, we might add some more fields to the struct in a future. After all, the purpose of 'struct damon_addr_range' is not saving the 'start' and 'end' fields of 'struct resource'. I'd like to avoid making any possible dependency here, sorry.
Thanks,
SJ
[...]
Re: [PATCH V2 2/2] mm/damon/lru_sort: Remove struct of damon_lru_sort_ram_walk_arg
Quoted 9 lines · SeongJae Park
Hi Xin,
Quoted 3 lines · On Thu, 18 Aug 2022 18:57:32 +0800 Xin Hao <[email protected]> wrote:
The struct of '
damon_lru_sort_ram_walk_arg' is the same with struct of 'damon_addr_range', so, there no need to redefine it, just use struct of 'damon_addr_range' instead.Reducing code is always good, thanks. However, I think the type of the 'start' and 'end' fields of 'struct
damon_addr_range' might be changed in a future.
OK, get it.
Quoted 10 lines
It's very unlikely, though. Also, we might add some more fields to the struct in a future. After all, the purpose of 'struct
damon_addr_range' is not saving the 'start' and 'end' fields of 'struct resource'. I'd like to avoid making any possible dependency here, sorry.Thanks,
SJ[...]