[RFC PATCH v3 07/13] mm/damon/core: Commit damos->target_nid/migrate_dests

Bijan Tabatabai posted 13 patches 3 months, 1 week ago
There is a newer version of this series
[RFC PATCH v3 07/13] mm/damon/core: Commit damos->target_nid/migrate_dests
Posted by Bijan Tabatabai 3 months, 1 week ago
From: Bijan Tabatabai <bijantabatab@micron.com>

When committing new scheme parameters from the sysfs, copy the
target_nid and migrate_dests of the source schemes into the destination
schemes.

Signed-off-by: Bijan Tabatabai <bijantabatab@micron.com>
---
 mm/damon/core.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index a4c3cfe531df..0565aae8d1fa 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -943,6 +943,41 @@ static void damos_set_filters_default_reject(struct damos *s)
 		damos_filters_default_reject(&s->ops_filters);
 }
 
+static int damos_commit_dests(struct damos *dst, struct damos *src)
+{
+	struct damos_migrate_dests *dst_dests, *src_dests;
+
+	dst_dests = &dst->migrate_dests;
+	src_dests = &src->migrate_dests;
+
+	if (dst_dests->nr_dests != src_dests->nr_dests) {
+		kfree(dst_dests->node_id_arr);
+		kfree(dst_dests->weight_arr);
+
+		dst_dests->node_id_arr = kmalloc_array(src_dests->nr_dests,
+			sizeof(*dst_dests->node_id_arr), GFP_KERNEL);
+		if (!dst_dests->node_id_arr) {
+			dst_dests->weight_arr = NULL;
+			return -ENOMEM;
+		}
+
+		dst_dests->weight_arr = kmalloc_array(src_dests->nr_dests,
+			sizeof(*dst_dests->weight_arr), GFP_KERNEL);
+		if (!dst_dests->weight_arr) {
+			/* ->node_id_arr will be freed by scheme destruction */
+			return -ENOMEM;
+		}
+	}
+
+	dst_dests->nr_dests = src_dests->nr_dests;
+	for (int i = 0; i < src_dests->nr_dests; i++) {
+		dst_dests->node_id_arr[i] = src_dests->node_id_arr[i];
+		dst_dests->weight_arr[i] = src_dests->weight_arr[i];
+	}
+
+	return 0;
+}
+
 static int damos_commit_filters(struct damos *dst, struct damos *src)
 {
 	int err;
@@ -983,6 +1018,11 @@ static int damos_commit(struct damos *dst, struct damos *src)
 
 	dst->wmarks = src->wmarks;
 
+	dst->target_nid = src->target_nid;
+	err = damos_commit_dests(dst, src);
+	if (err)
+		return err;
+
 	err = damos_commit_filters(dst, src);
 	return err;
 }
-- 
2.43.5
Re: [RFC PATCH v3 07/13] mm/damon/core: Commit damos->target_nid/migrate_dests
Posted by SeongJae Park 3 months, 1 week ago
On Wed,  2 Jul 2025 15:13:30 -0500 Bijan Tabatabai <bijan311@gmail.com> wrote:

> From: Bijan Tabatabai <bijantabatab@micron.com>
> 
> When committing new scheme parameters from the sysfs, copy the
> target_nid and migrate_dests of the source schemes into the destination
> schemes.

Fixing the missed update of target_nid deserves Fixes: and Cc: stable@ in my
opinion.  Could you please split and post the part as another patch?  For the
Fixes, I think 83dc7bbaecae ("mm/damon/sysfs: use damon_commit_ctx()") should
be appripriate.

> 
> Signed-off-by: Bijan Tabatabai <bijantabatab@micron.com>

Assuming my above request is accepted,

Reviewed-by: SeongJae Park <sj@kernel.org>

> ---
>  mm/damon/core.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index a4c3cfe531df..0565aae8d1fa 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -943,6 +943,41 @@ static void damos_set_filters_default_reject(struct damos *s)
>  		damos_filters_default_reject(&s->ops_filters);
>  }
>  
> +static int damos_commit_dests(struct damos *dst, struct damos *src)
> +{
> +	struct damos_migrate_dests *dst_dests, *src_dests;
> +
> +	dst_dests = &dst->migrate_dests;
> +	src_dests = &src->migrate_dests;
> +
> +	if (dst_dests->nr_dests != src_dests->nr_dests) {
> +		kfree(dst_dests->node_id_arr);
> +		kfree(dst_dests->weight_arr);
> +
> +		dst_dests->node_id_arr = kmalloc_array(src_dests->nr_dests,
> +			sizeof(*dst_dests->node_id_arr), GFP_KERNEL);
> +		if (!dst_dests->node_id_arr) {
> +			dst_dests->weight_arr = NULL;
> +			return -ENOMEM;
> +		}
> +
> +		dst_dests->weight_arr = kmalloc_array(src_dests->nr_dests,
> +			sizeof(*dst_dests->weight_arr), GFP_KERNEL);
> +		if (!dst_dests->weight_arr) {
> +			/* ->node_id_arr will be freed by scheme destruction */
> +			return -ENOMEM;
> +		}
> +	}
> +
> +	dst_dests->nr_dests = src_dests->nr_dests;
> +	for (int i = 0; i < src_dests->nr_dests; i++) {
> +		dst_dests->node_id_arr[i] = src_dests->node_id_arr[i];
> +		dst_dests->weight_arr[i] = src_dests->weight_arr[i];
> +	}
> +
> +	return 0;
> +}
> +
>  static int damos_commit_filters(struct damos *dst, struct damos *src)
>  {
>  	int err;
> @@ -983,6 +1018,11 @@ static int damos_commit(struct damos *dst, struct damos *src)
>  
>  	dst->wmarks = src->wmarks;
>  
> +	dst->target_nid = src->target_nid;
> +	err = damos_commit_dests(dst, src);
> +	if (err)
> +		return err;
> +

As mentioned above, let's split and post this part as another individual patch.

>  	err = damos_commit_filters(dst, src);
>  	return err;
>  }
> -- 
> 2.43.5


Thanks,
SJ
Re: [RFC PATCH v3 07/13] mm/damon/core: Commit damos->target_nid/migrate_dests
Posted by Bijan Tabatabai 3 months ago
On Wed, Jul 2, 2025 at 4:03 PM SeongJae Park <sj@kernel.org> wrote:
>
> On Wed,  2 Jul 2025 15:13:30 -0500 Bijan Tabatabai <bijan311@gmail.com> wrote:
>
> > From: Bijan Tabatabai <bijantabatab@micron.com>
> >
> > When committing new scheme parameters from the sysfs, copy the
> > target_nid and migrate_dests of the source schemes into the destination
> > schemes.
>
> Fixing the missed update of target_nid deserves Fixes: and Cc: stable@ in my
> opinion.  Could you please split and post the part as another patch?  For the
> Fixes, I think 83dc7bbaecae ("mm/damon/sysfs: use damon_commit_ctx()") should
> be appripriate.

Hi SJ,

To clarify, would you prefer it to be a seperate patch within the next
version of this patchset? Or would you prefer it to be sent separately
from the next version of the patchset?

Thanks,
Bijan

[...]
Re: [RFC PATCH v3 07/13] mm/damon/core: Commit damos->target_nid/migrate_dests
Posted by SeongJae Park 3 months ago
Hi Bijan,

On Tue, 8 Jul 2025 09:04:02 -0500 Bijan Tabatabai <bijan311@gmail.com> wrote:

> On Wed, Jul 2, 2025 at 4:03 PM SeongJae Park <sj@kernel.org> wrote:
> >
> > On Wed,  2 Jul 2025 15:13:30 -0500 Bijan Tabatabai <bijan311@gmail.com> wrote:
> >
> > > From: Bijan Tabatabai <bijantabatab@micron.com>
> > >
> > > When committing new scheme parameters from the sysfs, copy the
> > > target_nid and migrate_dests of the source schemes into the destination
> > > schemes.
> >
> > Fixing the missed update of target_nid deserves Fixes: and Cc: stable@ in my
> > opinion.  Could you please split and post the part as another patch?  For the
> > Fixes, I think 83dc7bbaecae ("mm/damon/sysfs: use damon_commit_ctx()") should
> > be appripriate.
> 
> Hi SJ,
> 
> To clarify, would you prefer it to be a seperate patch within the next
> version of this patchset? Or would you prefer it to be sent separately
> from the next version of the patchset?

I'd prefer latter (separate one).

Sorry for making the point ambiguous, and giving me this chance to clarify :)


Thanks,
SJ

[...]