* [PATCH 1/4] mm/damon: simplify the parameter passing for 'prepare_access_checks'
2022-09-13 9:11 [PATCH 0/4] mm/damon: code simplifications and cleanups xiakaixu1987
@ 2022-09-13 9:11 ` xiakaixu1987
2022-09-13 9:11 ` [PATCH 2/4] mm/damon/sysfs: simplify the variable 'pid' assignment operation xiakaixu1987
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: xiakaixu1987 @ 2022-09-13 9:11 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Kaixu Xia
From: Kaixu Xia <kaixuxia@tencent.com>
The parameter 'struct damon_ctx *ctx' isn't used in the functions
__damon_{p,v}a_prepare_access_check(), so we can remove it and
simplify the parameter passing.
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
mm/damon/paddr.c | 5 ++---
mm/damon/vaddr.c | 6 +++---
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 6b0d9e6aa677..f00cbe74a00e 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -63,8 +63,7 @@ static void damon_pa_mkold(unsigned long paddr)
folio_put(folio);
}
-static void __damon_pa_prepare_access_check(struct damon_ctx *ctx,
- struct damon_region *r)
+static void __damon_pa_prepare_access_check(struct damon_region *r)
{
r->sampling_addr = damon_rand(r->ar.start, r->ar.end);
@@ -78,7 +77,7 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx)
damon_for_each_target(t, ctx) {
damon_for_each_region(r, t)
- __damon_pa_prepare_access_check(ctx, r);
+ __damon_pa_prepare_access_check(r);
}
}
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index c2c08c1b316b..39ea48d9cc15 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -397,8 +397,8 @@ static void damon_va_mkold(struct mm_struct *mm, unsigned long addr)
* Functions for the access checking of the regions
*/
-static void __damon_va_prepare_access_check(struct damon_ctx *ctx,
- struct mm_struct *mm, struct damon_region *r)
+static void __damon_va_prepare_access_check(struct mm_struct *mm,
+ struct damon_region *r)
{
r->sampling_addr = damon_rand(r->ar.start, r->ar.end);
@@ -416,7 +416,7 @@ static void damon_va_prepare_access_checks(struct damon_ctx *ctx)
if (!mm)
continue;
damon_for_each_region(r, t)
- __damon_va_prepare_access_check(ctx, mm, r);
+ __damon_va_prepare_access_check(mm, r);
mmput(mm);
}
}
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/4] mm/damon/sysfs: simplify the variable 'pid' assignment operation
2022-09-13 9:11 [PATCH 0/4] mm/damon: code simplifications and cleanups xiakaixu1987
2022-09-13 9:11 ` [PATCH 1/4] mm/damon: simplify the parameter passing for 'prepare_access_checks' xiakaixu1987
@ 2022-09-13 9:11 ` xiakaixu1987
2022-09-13 9:11 ` [PATCH 3/4] mm/damon/core: simplify the kdamond stop mechanism by removing 'done' xiakaixu1987
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: xiakaixu1987 @ 2022-09-13 9:11 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Kaixu Xia
From: Kaixu Xia <kaixuxia@tencent.com>
We can initialize the variable 'pid' with '-1' in pid_show() to
simplify the variable assignment operation and make the code more
readable.
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
mm/damon/sysfs.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index da01befae8bd..3606eec9b65d 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -2588,19 +2588,16 @@ static ssize_t pid_show(struct kobject *kobj,
struct damon_sysfs_kdamond *kdamond = container_of(kobj,
struct damon_sysfs_kdamond, kobj);
struct damon_ctx *ctx;
- int pid;
+ int pid = -1;
if (!mutex_trylock(&damon_sysfs_lock))
return -EBUSY;
ctx = kdamond->damon_ctx;
- if (!ctx) {
- pid = -1;
+ if (!ctx)
goto out;
- }
+
mutex_lock(&ctx->kdamond_lock);
- if (!ctx->kdamond)
- pid = -1;
- else
+ if (ctx->kdamond)
pid = ctx->kdamond->pid;
mutex_unlock(&ctx->kdamond_lock);
out:
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/4] mm/damon/core: simplify the kdamond stop mechanism by removing 'done'
2022-09-13 9:11 [PATCH 0/4] mm/damon: code simplifications and cleanups xiakaixu1987
2022-09-13 9:11 ` [PATCH 1/4] mm/damon: simplify the parameter passing for 'prepare_access_checks' xiakaixu1987
2022-09-13 9:11 ` [PATCH 2/4] mm/damon/sysfs: simplify the variable 'pid' assignment operation xiakaixu1987
@ 2022-09-13 9:11 ` xiakaixu1987
2022-09-13 9:11 ` [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero xiakaixu1987
2022-09-13 15:12 ` [PATCH 0/4] mm/damon: code simplifications and cleanups SeongJae Park
4 siblings, 0 replies; 10+ messages in thread
From: xiakaixu1987 @ 2022-09-13 9:11 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Kaixu Xia
From: Kaixu Xia <kaixuxia@tencent.com>
When the 'kdamond_wait_activation()' function or 'after_sampling()'
or 'after_aggregation()' DAMON callbacks return an error, it is
unnecessary to use bool 'done' to check if kdamond should be
finished. This commit simplifies the kdamond stop mechanism by
removing 'done' and break the while loop directly in the cases.
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
mm/damon/core.c | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 0b1eb945c68a..4ce860af70ec 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1165,30 +1165,25 @@ static int kdamond_fn(void *data)
struct damon_region *r, *next;
unsigned int max_nr_accesses = 0;
unsigned long sz_limit = 0;
- bool done = false;
pr_debug("kdamond (%d) starts\n", current->pid);
if (ctx->ops.init)
ctx->ops.init(ctx);
if (ctx->callback.before_start && ctx->callback.before_start(ctx))
- done = true;
+ goto done;
sz_limit = damon_region_sz_limit(ctx);
- while (!kdamond_need_stop(ctx) && !done) {
- if (kdamond_wait_activation(ctx)) {
- done = true;
- continue;
- }
+ while (!kdamond_need_stop(ctx)) {
+ if (kdamond_wait_activation(ctx))
+ break;
if (ctx->ops.prepare_access_checks)
ctx->ops.prepare_access_checks(ctx);
if (ctx->callback.after_sampling &&
- ctx->callback.after_sampling(ctx)) {
- done = true;
- continue;
- }
+ ctx->callback.after_sampling(ctx))
+ break;
kdamond_usleep(ctx->sample_interval);
@@ -1200,10 +1195,8 @@ static int kdamond_fn(void *data)
max_nr_accesses / 10,
sz_limit);
if (ctx->callback.after_aggregation &&
- ctx->callback.after_aggregation(ctx)) {
- done = true;
- continue;
- }
+ ctx->callback.after_aggregation(ctx))
+ break;
kdamond_apply_schemes(ctx);
kdamond_reset_aggregated(ctx);
kdamond_split_regions(ctx);
@@ -1217,6 +1210,7 @@ static int kdamond_fn(void *data)
sz_limit = damon_region_sz_limit(ctx);
}
}
+done:
damon_for_each_target(t, ctx) {
damon_for_each_region_safe(r, next, t)
damon_destroy_region(r, t);
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero
2022-09-13 9:11 [PATCH 0/4] mm/damon: code simplifications and cleanups xiakaixu1987
` (2 preceding siblings ...)
2022-09-13 9:11 ` [PATCH 3/4] mm/damon/core: simplify the kdamond stop mechanism by removing 'done' xiakaixu1987
@ 2022-09-13 9:11 ` xiakaixu1987
2022-09-13 15:11 ` SeongJae Park
2022-09-13 15:12 ` [PATCH 0/4] mm/damon: code simplifications and cleanups SeongJae Park
4 siblings, 1 reply; 10+ messages in thread
From: xiakaixu1987 @ 2022-09-13 9:11 UTC (permalink / raw)
To: sj, akpm; +Cc: damon, linux-mm, linux-kernel, Kaixu Xia
From: Kaixu Xia <kaixuxia@tencent.com>
When 'init()' and 'update()' DAMON operations failed and the number
of the damon_target regions is zero, the kdamond would do nothing
to this monitoring target in this case. It makes no sense to run
kdamond when all of monitoring targets have no regions. So add the
judgement in 'target_valid()' operation to indicate the target is
invalid when 'nr_regions' is zero.
Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
mm/damon/vaddr.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
index 39ea48d9cc15..65ff98d49ec0 100644
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@ -598,6 +598,9 @@ static bool damon_va_target_valid(void *target)
struct damon_target *t = target;
struct task_struct *task;
+ if (!damon_nr_regions(t))
+ return false;
+
task = damon_get_task_struct(t);
if (task) {
put_task_struct(task);
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero
2022-09-13 9:11 ` [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero xiakaixu1987
@ 2022-09-13 15:11 ` SeongJae Park
2022-09-14 4:02 ` Kaixu Xia
0 siblings, 1 reply; 10+ messages in thread
From: SeongJae Park @ 2022-09-13 15:11 UTC (permalink / raw)
To: xiakaixu1987; +Cc: sj, akpm, damon, linux-mm, linux-kernel, Kaixu Xia
On Tue, 13 Sep 2022 17:11:27 +0800 xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
>
> When 'init()' and 'update()' DAMON operations failed and the number
> of the damon_target regions is zero,
Well, I think that could be a temporal failure. In the case, later call of
'update()' could success?
Thanks,
SJ
> the kdamond would do nothing
> to this monitoring target in this case. It makes no sense to run
> kdamond when all of monitoring targets have no regions. So add the
> judgement in 'target_valid()' operation to indicate the target is
> invalid when 'nr_regions' is zero.
>
> Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> ---
> mm/damon/vaddr.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> index 39ea48d9cc15..65ff98d49ec0 100644
> --- a/mm/damon/vaddr.c
> +++ b/mm/damon/vaddr.c
> @@ -598,6 +598,9 @@ static bool damon_va_target_valid(void *target)
> struct damon_target *t = target;
> struct task_struct *task;
>
> + if (!damon_nr_regions(t))
> + return false;
> +
> task = damon_get_task_struct(t);
> if (task) {
> put_task_struct(task);
> --
> 2.27.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero
2022-09-13 15:11 ` SeongJae Park
@ 2022-09-14 4:02 ` Kaixu Xia
2022-09-14 8:04 ` SeongJae Park
0 siblings, 1 reply; 10+ messages in thread
From: Kaixu Xia @ 2022-09-14 4:02 UTC (permalink / raw)
To: SeongJae Park; +Cc: akpm, damon, linux-mm, LKML, Kaixu Xia
On Tue, Sep 13, 2022 at 11:11 PM SeongJae Park <sj@kernel.org> wrote:
>
> On Tue, 13 Sep 2022 17:11:27 +0800 xiakaixu1987@gmail.com wrote:
>
> > From: Kaixu Xia <kaixuxia@tencent.com>
> >
> > When 'init()' and 'update()' DAMON operations failed and the number
> > of the damon_target regions is zero,
>
> Well, I think that could be a temporal failure. In the case, later call of
> 'update()' could success?
>
Yeah, the kdamond while() loop calls 'update()' periodically to fix this
temporary failure. But for extreme scenarios that 'update()' continues to fail,
we should have some ways to detect this case.
Thanks,
Kaixu
>
> Thanks,
> SJ
>
> > the kdamond would do nothing
> > to this monitoring target in this case. It makes no sense to run
> > kdamond when all of monitoring targets have no regions. So add the
> > judgement in 'target_valid()' operation to indicate the target is
> > invalid when 'nr_regions' is zero.
>
> >
> > Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> > ---
> > mm/damon/vaddr.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> > index 39ea48d9cc15..65ff98d49ec0 100644
> > --- a/mm/damon/vaddr.c
> > +++ b/mm/damon/vaddr.c
> > @@ -598,6 +598,9 @@ static bool damon_va_target_valid(void *target)
> > struct damon_target *t = target;
> > struct task_struct *task;
> >
> > + if (!damon_nr_regions(t))
> > + return false;
> > +
> > task = damon_get_task_struct(t);
> > if (task) {
> > put_task_struct(task);
> > --
> > 2.27.0
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero
2022-09-14 4:02 ` Kaixu Xia
@ 2022-09-14 8:04 ` SeongJae Park
2022-09-14 8:21 ` Kaixu Xia
0 siblings, 1 reply; 10+ messages in thread
From: SeongJae Park @ 2022-09-14 8:04 UTC (permalink / raw)
To: Kaixu Xia; +Cc: SeongJae Park, akpm, damon, linux-mm, LKML, Kaixu Xia
On Wed, 14 Sep 2022 12:02:05 +0800 Kaixu Xia <xiakaixu1987@gmail.com> wrote:
> On Tue, Sep 13, 2022 at 11:11 PM SeongJae Park <sj@kernel.org> wrote:
> >
> > On Tue, 13 Sep 2022 17:11:27 +0800 xiakaixu1987@gmail.com wrote:
> >
> > > From: Kaixu Xia <kaixuxia@tencent.com>
> > >
> > > When 'init()' and 'update()' DAMON operations failed and the number
> > > of the damon_target regions is zero,
> >
> > Well, I think that could be a temporal failure. In the case, later call of
> > 'update()' could success?
> >
> Yeah, the kdamond while() loop calls 'update()' periodically to fix this
> temporary failure. But for extreme scenarios that 'update()' continues to fail,
> we should have some ways to detect this case.
Even in the case, kdamond will do nothing but continuing the main loop while
sleeping sample_aggr interval (5ms by default) for each iteration, and calling
'update()' for every update interval (100ms by default). Waste is waste, but I
don't think that's a real issue. Further, continuous 'update()' failures mean
the process is in some weird state anyway, so I'd assume the process would be
finished soon. kdamond will also finish as soon as the process finishes.
Users could also find the strange situation (nothing in the monitoring results)
and finish kdamond on their own.
Anything I'm missing?
Andrew, I found you merged this patch in mm-unstable. Could you please hold it
until we finish this discussion?
Thanks,
SJ
>
> Thanks,
> Kaixu
> >
> > Thanks,
> > SJ
> >
> > > the kdamond would do nothing
> > > to this monitoring target in this case. It makes no sense to run
> > > kdamond when all of monitoring targets have no regions. So add the
> > > judgement in 'target_valid()' operation to indicate the target is
> > > invalid when 'nr_regions' is zero.
> >
> > >
> > > Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> > > ---
> > > mm/damon/vaddr.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> > > index 39ea48d9cc15..65ff98d49ec0 100644
> > > --- a/mm/damon/vaddr.c
> > > +++ b/mm/damon/vaddr.c
> > > @@ -598,6 +598,9 @@ static bool damon_va_target_valid(void *target)
> > > struct damon_target *t = target;
> > > struct task_struct *task;
> > >
> > > + if (!damon_nr_regions(t))
> > > + return false;
> > > +
> > > task = damon_get_task_struct(t);
> > > if (task) {
> > > put_task_struct(task);
> > > --
> > > 2.27.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero
2022-09-14 8:04 ` SeongJae Park
@ 2022-09-14 8:21 ` Kaixu Xia
0 siblings, 0 replies; 10+ messages in thread
From: Kaixu Xia @ 2022-09-14 8:21 UTC (permalink / raw)
To: SeongJae Park; +Cc: akpm, damon, linux-mm, LKML, Kaixu Xia
On Wed, Sep 14, 2022 at 4:04 PM SeongJae Park <sj@kernel.org> wrote:
>
> On Wed, 14 Sep 2022 12:02:05 +0800 Kaixu Xia <xiakaixu1987@gmail.com> wrote:
>
> > On Tue, Sep 13, 2022 at 11:11 PM SeongJae Park <sj@kernel.org> wrote:
> > >
> > > On Tue, 13 Sep 2022 17:11:27 +0800 xiakaixu1987@gmail.com wrote:
> > >
> > > > From: Kaixu Xia <kaixuxia@tencent.com>
> > > >
> > > > When 'init()' and 'update()' DAMON operations failed and the number
> > > > of the damon_target regions is zero,
> > >
> > > Well, I think that could be a temporal failure. In the case, later call of
> > > 'update()' could success?
> > >
> > Yeah, the kdamond while() loop calls 'update()' periodically to fix this
> > temporary failure. But for extreme scenarios that 'update()' continues to fail,
> > we should have some ways to detect this case.
>
> Even in the case, kdamond will do nothing but continuing the main loop while
> sleeping sample_aggr interval (5ms by default) for each iteration, and calling
> 'update()' for every update interval (100ms by default). Waste is waste, but I
> don't think that's a real issue. Further, continuous 'update()' failures mean
> the process is in some weird state anyway, so I'd assume the process would be
> finished soon. kdamond will also finish as soon as the process finishes.
> Users could also find the strange situation (nothing in the monitoring results)
> and finish kdamond on their own.
>
> Anything I'm missing?
>
That sounds reasonable. Thanks for your detailed explanation.
Thanks,
Kaixu
>
> Andrew, I found you merged this patch in mm-unstable. Could you please hold it
> until we finish this discussion?
>
>
> Thanks,
> SJ
>
> >
> > Thanks,
> > Kaixu
> > >
> > > Thanks,
> > > SJ
> > >
> > > > the kdamond would do nothing
> > > > to this monitoring target in this case. It makes no sense to run
> > > > kdamond when all of monitoring targets have no regions. So add the
> > > > judgement in 'target_valid()' operation to indicate the target is
> > > > invalid when 'nr_regions' is zero.
> > >
> > > >
> > > > Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
> > > > ---
> > > > mm/damon/vaddr.c | 3 +++
> > > > 1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> > > > index 39ea48d9cc15..65ff98d49ec0 100644
> > > > --- a/mm/damon/vaddr.c
> > > > +++ b/mm/damon/vaddr.c
> > > > @@ -598,6 +598,9 @@ static bool damon_va_target_valid(void *target)
> > > > struct damon_target *t = target;
> > > > struct task_struct *task;
> > > >
> > > > + if (!damon_nr_regions(t))
> > > > + return false;
> > > > +
> > > > task = damon_get_task_struct(t);
> > > > if (task) {
> > > > put_task_struct(task);
> > > > --
> > > > 2.27.0
> >
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] mm/damon: code simplifications and cleanups
2022-09-13 9:11 [PATCH 0/4] mm/damon: code simplifications and cleanups xiakaixu1987
` (3 preceding siblings ...)
2022-09-13 9:11 ` [PATCH 4/4] mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is zero xiakaixu1987
@ 2022-09-13 15:12 ` SeongJae Park
4 siblings, 0 replies; 10+ messages in thread
From: SeongJae Park @ 2022-09-13 15:12 UTC (permalink / raw)
To: xiakaixu1987; +Cc: sj, akpm, damon, linux-mm, linux-kernel, Kaixu Xia
On Tue, 13 Sep 2022 17:11:23 +0800 xiakaixu1987@gmail.com wrote:
> From: Kaixu Xia <kaixuxia@tencent.com>
>
> This patchset contains some code simplifications and cleanups
> for DAMON.
For the first three patches,
Reviewed-by: SeongJae Park <sj@kernel.org>
But, I have a question for the last one. Please answer it.
Thanks,
SJ
>
> Kaixu Xia (4):
> mm/damon: simplify the parameter passing for 'prepare_access_checks'
> mm/damon/sysfs: simplify the variable 'pid' assignment operation
> mm/damon/core: simplify the kdamond stop mechanism by removing 'done'
> mm/damon/vaddr: indicate the target is invalid when 'nr_regions' is
> zero
>
> mm/damon/core.c | 24 +++++++++---------------
> mm/damon/paddr.c | 5 ++---
> mm/damon/sysfs.c | 11 ++++-------
> mm/damon/vaddr.c | 9 ++++++---
> 4 files changed, 21 insertions(+), 28 deletions(-)
>
> --
> 2.27.0
^ permalink raw reply [flat|nested] 10+ messages in thread