linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bijan Tabatabai <bijan311@gmail.com>
To: damon@lists.linux.dev, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net,
	bijantabatab@micron.com, venkataravis@micron.com,
	emirakhur@micron.com, vtavarespetr@micron.com,
	ajayjoshi@micron.com
Subject: [PATCH v4 07/13] mm/damon/core: Commit damos->migrate_dests
Date: Tue,  8 Jul 2025 19:59:37 -0500	[thread overview]
Message-ID: <20250709005952.17776-8-bijan311@gmail.com> (raw)
In-Reply-To: <20250709005952.17776-1-bijan311@gmail.com>

From: Bijan Tabatabai <bijantabatab@micron.com>

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

Signed-off-by: Bijan Tabatabai <bijantabatab@micron.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 62acfd5cf4ea..8d54bfc3ce0e 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;
@@ -984,6 +1019,10 @@ 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.0


  parent reply	other threads:[~2025-07-09  1:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09  0:59 [PATCH v4 00/13] mm/damon/vaddr: Allow interleaving in migrate_{hot,cold} actions Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 01/13] mm/damon: add struct damos_migrate_dests Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 02/13] mm/damon/core: add damos->migrate_dests field Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 03/13] mm/damon/sysfs-schemes: implement DAMOS action destinations directory Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 04/13] mm/damon/sysfs-schemes: set damos->migrate_dests Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 05/13] Docs/ABI/damon: document schemes dests directory Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 06/13] Docs/admin-guide/mm/damon/usage: document " Bijan Tabatabai
2025-07-09  0:59 ` Bijan Tabatabai [this message]
2025-07-09  0:59 ` [PATCH v4 08/13] mm/damon: Move migration helpers from paddr to ops-common Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 09/13] mm/damon/vaddr: Add vaddr versions of migrate_{hot,cold} Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 10/13] Docs/mm/damon/design: Document vaddr support for migrate_{hot,cold} Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 11/13] mm/damon/vaddr: Use damos->migrate_dests in migrate_{hot,cold} Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 12/13] mm/damon: Move folio filtering from paddr to ops-common Bijan Tabatabai
2025-07-09  0:59 ` [PATCH v4 13/13] mm/damon/vaddr: Apply filters in migrate_{hot/cold} Bijan Tabatabai
2025-07-09 11:06 ` [PATCH v4 00/13] mm/damon/vaddr: Allow interleaving in migrate_{hot,cold} actions SeongJae Park
2025-07-09 14:07   ` Bijan Tabatabai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709005952.17776-8-bijan311@gmail.com \
    --to=bijan311@gmail.com \
    --cc=ajayjoshi@micron.com \
    --cc=akpm@linux-foundation.org \
    --cc=bijantabatab@micron.com \
    --cc=corbet@lwn.net \
    --cc=damon@lists.linux.dev \
    --cc=emirakhur@micron.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    --cc=venkataravis@micron.com \
    --cc=vtavarespetr@micron.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).