From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A67722C355; Wed, 2 Jul 2025 05:16:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433367; cv=none; b=gsiofbEP76WKL+HpGaeFqoGanWhLFQr5XFgT9L1ZDslG8Fep9NJLKTJhMpcHs8PpTEDbKIScf8jK6xocVurdI6Mnm8gaoq8jV6xiaa4fs0Lyk9YqPWxdULTMzo0ZTBxpD9NNPTwHk+uk03oo8Vj2XrpN6KOF6qHMFi/2uUcIgOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433367; c=relaxed/simple; bh=pdcyWRPhdb/cEUr29Fl+//1LhV5HJEfdKz0MuDMK0gI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ioEFIhKsAlylQvncZ4oh1eQ0RWAYugIx3f8R4ZwsFSjFvQqH4scKHZFCMnqlPxxXZ3f91dMXRw4h9CfltGKdoSGtKn1Qw3R2FlYp9oZyg85Zv32RCZTopIZ9QrtRpKC6qXuYyXJJcIH7Zh+BEjs+k73eJ2t4pLecwmIQNGXuEfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IKLPHEDs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IKLPHEDs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFA4BC4CEEE; Wed, 2 Jul 2025 05:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433366; bh=pdcyWRPhdb/cEUr29Fl+//1LhV5HJEfdKz0MuDMK0gI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKLPHEDscW0asBaatY8YWMDSRwEYdSjhUjAouUQLJbPr0zQ0Ri12x3EB3Z/IOUcuE Am6Fx5D/vFvsOSwoxt6p6UBJW52c6y90isCKkUXNfMzTQ1qbeQm5Rfm/QFP/K7TzJW u6HMGmZ9/TMMx3zXy39Ibb/4vZvWU9o6mZ29Z+XB78wSaE7hCb2WwppR3SxfF+4KTc 55XGYZVZxsU+ZYt0lH/tsrNt6TiIGwqq4UpHabPrMM5ylzQjJT3beq4HqE7l0Ra/9O ro63YmYEqBozIfJtJLIvHDkbTSIaVRRKa/GTsqDS5MKkUHuSc3/HBVJq3FVjyNMh2e PsYCnxhaLmUbw== From: SeongJae Park To: Cc: SeongJae Park , Bijan Tabatabai , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 1/6] mm/damon: add struct damos_migrate_dest Date: Tue, 1 Jul 2025 22:15:53 -0700 Message-Id: <20250702051558.54138-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce a new struct, namely damos_migrate_dest, for specifying multiple DAMOS' migration destination nodes and their weights. Signed-off-by: SeongJae Park --- include/linux/damon.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index bb58e36f019e..d60addd0b7c8 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -447,6 +447,22 @@ struct damos_access_pattern { unsigned int max_age_region; }; =20 +/** + * struct damos_migrate_dest - Migration destination nodes and their weigh= ts. + * @node_id_arr: Array of migration destination node ids. + * @weight_arr: Array of migration weights for @node_id_arr. + * @nr_dests: Length of the @node_id_arr and @weight_arr arrays. + * + * @node_id_arr is an array of the ids of migration destination nodes. + * @weight_arr is an array of the weights for those. The weights in + * @weight_arr are for nodes in @node_id_arr of same array index. + */ +struct damos_migrate_dest { + unsigned int *node_id_arr; + unsigned int *weight_arr; + size_t nr_dests; +}; + /** * struct damos - Represents a Data Access Monitoring-based Operation Sche= me. * @pattern: Access pattern of target regions. --=20 2.39.5 From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6C2322F74F; Wed, 2 Jul 2025 05:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433368; cv=none; b=j477Um0nEqOTsdw1oQvASIw1gNEjRUwOUiL1LkcTEmdMZQCA4GGj2AcMxUCIMjSA1uMhuTTEtkNKOly2+LUBxM030QvoOJHP9UFc6y99BeD5RZ5uMjbLfgL0E4FW9XrybZKd1dAd9GhiNECLFPJeps7rPxtQSrrq1BF9wxo0h4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433368; c=relaxed/simple; bh=NXC7V5X3FMbwc1GLLQCWiBZv7p+8RjgN4vG6hiuSoDg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fL/mQQZ165pqQtdHh5JdVViwDRRCjejXSNIEqa70r7077LpOc3pQuf6v4t+ZX+lLT5SUvuyIZSsZ3yJu0kwuxYosMYRgspc8848LWUPa7XJvCHUl/t7/EegxciHmB5rtIEOUBuJlRbem7wMs9ZNIgfwUdXJnChVpIKu/QavQ4NA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IpCZFPmZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IpCZFPmZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07E9DC4CEEE; Wed, 2 Jul 2025 05:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433368; bh=NXC7V5X3FMbwc1GLLQCWiBZv7p+8RjgN4vG6hiuSoDg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpCZFPmZwK/QOUz7maPmsOXQbD7D1Wy7ZVA+MtfsllEjCEZPjGKQtaPtbNilbihS3 IZN44M6R7a/CCE9UXc3Bel4ZOUEfYz/Jno/xBS4nNyDbsBjC78bjUJ+r4ftkTpbT7m eftGF13ud+UoXyXfrpOgJU9A6u/0OX7t1BqhObXYjh6lhGKNoQRKeXQac81DT1kGjk cieWk1vku2nd5vMt+NgpAIfBvWx2ncdppAl0RV6CRnGaGHhksLdq4TBfpycOuXuB0l Cka5t6y9Xm60o3psnM8AUVJLVO5fOQQZ5p9NpIjNgJVzwqcZ3hxG8CE5I9S+Vl+nbD H7Hg9deOTtSOA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Bijan Tabatabai , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 2/6] mm/damon/core: add damos->migrate_dest field Date: Tue, 1 Jul 2025 22:15:54 -0700 Message-Id: <20250702051558.54138-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new field to 'struct damos', namely migrate_dest, to allow DAMON API callers specify multiple migration destination nodes and their weights. Also update 'struct damos' creation and destruction functions accordingly to initialize the new field and free up the API caller-allocated buffers on those, respectively. Signed-off-by: SeongJae Park --- include/linux/damon.h | 13 ++++++++++--- mm/damon/core.c | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index d60addd0b7c8..6370cf44486f 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -470,6 +470,7 @@ struct damos_migrate_dest { * @apply_interval_us: The time between applying the @action. * @quota: Control the aggressiveness of this scheme. * @wmarks: Watermarks for automated (in)activation of this scheme. + * @migrate_dest: Destination nodes if @action is "migrate_{hot,cold}". * @target_nid: Destination node if @action is "migrate_{hot,cold}". * @filters: Additional set of &struct damos_filter for &action. * @ops_filters: ops layer handling &struct damos_filter objects list. @@ -488,9 +489,12 @@ struct damos_migrate_dest { * monitoring context are inactive, DAMON stops monitoring either, and just * repeatedly checks the watermarks. * + * @migrate_dest specifies multiple migration target nodes with different + * weights for migrate_hot or migrate_cold actions. @target_nid is ignore= d if + * this is set. + * * @target_nid is used to set the migration target node for migrate_hot or - * migrate_cold actions, which means it's only meaningful when @action is = either - * "migrate_hot" or "migrate_cold". + * migrate_cold actions, and @migrate_dest is unset. * * Before applying the &action to a memory region, &struct damon_operations * implementation could check pages of the region and skip &action to resp= ect @@ -533,7 +537,10 @@ struct damos { struct damos_quota quota; struct damos_watermarks wmarks; union { - int target_nid; + struct { + int target_nid; + struct damos_migrate_dest migrate_dest; + }; }; struct list_head filters; struct list_head ops_filters; diff --git a/mm/damon/core.c b/mm/damon/core.c index 979b29e16ef4..185aafa2e401 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -407,6 +407,7 @@ struct damos *damon_new_scheme(struct damos_access_patt= ern *pattern, scheme->wmarks =3D *wmarks; scheme->wmarks.activated =3D true; =20 + scheme->migrate_dest =3D (struct damos_migrate_dest){}; scheme->target_nid =3D target_nid; =20 return scheme; @@ -449,6 +450,9 @@ void damon_destroy_scheme(struct damos *s) =20 damos_for_each_filter_safe(f, next, s) damos_destroy_filter(f); + + kfree(s->migrate_dest.node_id_arr); + kfree(s->migrate_dest.weight_arr); damon_del_scheme(s); damon_free_scheme(s); } --=20 2.39.5 From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B7FB230BDB; Wed, 2 Jul 2025 05:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433370; cv=none; b=JS+KBCrj6Qppm19ubAhNplYyM9XyADCLma7FJtiTlROVrS9zrKpiurSLCwxbRVDQypUZrRDUnpct5Kzx/rOV7MDQKJ/rqqyo2hpVA20ehixIzntauB79YzBSZyV012hblqKJ6MrLtx4K4hssaGNWZaNUEdhYAtYvBqqCLUVx4bU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433370; c=relaxed/simple; bh=kjOKLngDzUss3QPXY3L0jEKHeiRx/Y/BDT/FqW73VxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pRaSrtfGvuQXnyDjiOkeXHsGOeSID9C3SmlUSo1nqvX+bUBGyDV4umpJrXX2PNpdpDzHfyfmJNZJdYaWGYsLTYZTRYd5NeaDgERRr941f5MM1VeEIQ/dJN1ZPN8PtxpvxAL3snCkEh18s6DXkR7DF7roWb5ZBG2K3DkuRVfJH10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hB/aWu0P; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hB/aWu0P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 619ECC4CEEF; Wed, 2 Jul 2025 05:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433369; bh=kjOKLngDzUss3QPXY3L0jEKHeiRx/Y/BDT/FqW73VxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hB/aWu0PDtilZ2yyBwYjUwd8F6AcCItRGZx79SiTF12/UpeiXhimy2oNRR2TPl3lH qP62xHGhPKmjEN1oIP2COfX3wQ1hi/cS3x9P31iTY67V05+3XDNBSAozEas5tNEdAA eCbeIBe5PvbuWKit7MvY8AqpQdk1e3BPJqeeawAbV08uuTY2YJVMRLETQn1I+yy8Qf qd5SetjmmacHUL1vAqDqkSZJMzp0Ug4k7Gv1F9iXJi2hXaVEYbgCTVDh6dxV07laCB zyQnP85hfLSfGkIGCuRv+WhzKPdjfbc7Xai00r6TZjLQdXMxC3Kr9t8T/vMmB8wtp6 9/BIgu4DWjG3A== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Bijan Tabatabai , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 3/6] mm/damon/sysfs-schemes: implement DAMOS action destinations directory Date: Tue, 1 Jul 2025 22:15:55 -0700 Message-Id: <20250702051558.54138-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DAMOS_MIGRATE_{HOT,COLD} can have multiple action destinations and their weights. Implement sysfs directory named 'dests' under each scheme directory to let DAMON sysfs ABI users utilize the feature. The interface is similar to other multiple parameters directory like kdamonds or filters. The directory contains only nr_dests file initially. Writing a number of desired destinations to nr_dests creates directories of the number. Each of the created directories has two files named id and weight. Users can then write the destination's identifier (node id in case of DAMOS_MIGRATE_*) and weight to the files. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 225 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 224 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 601360e9b521..b9434cdaacdc 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1655,6 +1655,204 @@ static const struct kobj_type damon_sysfs_access_pa= ttern_ktype =3D { .default_groups =3D damon_sysfs_access_pattern_groups, }; =20 +/* + * dest (action destination) directory + */ + +struct damos_sysfs_dest { + struct kobject kobj; + unsigned int id; + unsigned int weight; +}; + +static struct damos_sysfs_dest *damos_sysfs_dest_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_dest), GFP_KERNEL); +} + +static ssize_t id_show( + struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + + return sysfs_emit(buf, "%u\n", dest->id); +} + +static ssize_t id_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + int err =3D kstrtouint(buf, 0, &dest->id); + + return err ? err : count; +} + +static ssize_t weight_show( + struct kobject *kobj, struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + + return sysfs_emit(buf, "%u\n", dest->weight); +} + +static ssize_t weight_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + int err =3D kstrtouint(buf, 0, &dest->weight); + + return err ? err : count; +} + +static void damos_sysfs_dest_release(struct kobject *kobj) +{ + struct damos_sysfs_dest *dest =3D container_of(kobj, + struct damos_sysfs_dest, kobj); + kfree(dest); +} + +static struct kobj_attribute damos_sysfs_dest_id_attr =3D + __ATTR_RW_MODE(id, 0600); + +static struct kobj_attribute damos_sysfs_dest_weight_attr =3D + __ATTR_RW_MODE(weight, 0600); + +static struct attribute *damos_sysfs_dest_attrs[] =3D { + &damos_sysfs_dest_id_attr.attr, + &damos_sysfs_dest_weight_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_dest); + +static const struct kobj_type damos_sysfs_dest_ktype =3D { + .release =3D damos_sysfs_dest_release, + .sysfs_ops =3D &kobj_sysfs_ops, + .default_groups =3D damos_sysfs_dest_groups, +}; + +/* + * dests (action destinations) directory + */ + +struct damos_sysfs_dests { + struct kobject kobj; + struct damos_sysfs_dest **dests_arr; + int nr; +}; + +static struct damos_sysfs_dests * +damos_sysfs_dests_alloc(void) +{ + return kzalloc(sizeof(struct damos_sysfs_dests), GFP_KERNEL); +} + +static void damos_sysfs_dests_rm_dirs( + struct damos_sysfs_dests *dests) +{ + struct damos_sysfs_dest **dests_arr =3D dests->dests_arr; + int i; + + for (i =3D 0; i < dests->nr; i++) + kobject_put(&dests_arr[i]->kobj); + dests->nr =3D 0; + kfree(dests_arr); + dests->dests_arr =3D NULL; +} + +static int damos_sysfs_dests_add_dirs( + struct damos_sysfs_dests *dests, int nr_dests) +{ + struct damos_sysfs_dest **dests_arr, *dest; + int err, i; + + damos_sysfs_dests_rm_dirs(dests); + if (!nr_dests) + return 0; + + dests_arr =3D kmalloc_array(nr_dests, sizeof(*dests_arr), + GFP_KERNEL | __GFP_NOWARN); + if (!dests_arr) + return -ENOMEM; + dests->dests_arr =3D dests_arr; + + for (i =3D 0; i < nr_dests; i++) { + dest =3D damos_sysfs_dest_alloc(); + if (!dest) { + damos_sysfs_dests_rm_dirs(dests); + return -ENOMEM; + } + + err =3D kobject_init_and_add(&dest->kobj, + &damos_sysfs_dest_ktype, + &dests->kobj, "%d", i); + if (err) { + kobject_put(&dest->kobj); + damos_sysfs_dests_rm_dirs(dests); + return err; + } + + dests_arr[i] =3D dest; + dests->nr++; + } + return 0; +} + +static ssize_t nr_dests_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_dests *dests =3D container_of(kobj, + struct damos_sysfs_dests, kobj); + + return sysfs_emit(buf, "%d\n", dests->nr); +} + +static ssize_t nr_dests_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_dests *dests; + int nr, err =3D kstrtoint(buf, 0, &nr); + + if (err) + return err; + if (nr < 0) + return -EINVAL; + + dests =3D container_of(kobj, struct damos_sysfs_dests, kobj); + + if (!mutex_trylock(&damon_sysfs_lock)) + return -EBUSY; + err =3D damos_sysfs_dests_add_dirs(dests, nr); + mutex_unlock(&damon_sysfs_lock); + if (err) + return err; + + return count; +} + +static void damos_sysfs_dests_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damos_sysfs_dests, kobj)); +} + +static struct kobj_attribute damos_sysfs_dests_nr_attr =3D + __ATTR_RW_MODE(nr_dests, 0600); + +static struct attribute *damos_sysfs_dests_attrs[] =3D { + &damos_sysfs_dests_nr_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damos_sysfs_dests); + +static const struct kobj_type damos_sysfs_dests_ktype =3D { + .release =3D damos_sysfs_dests_release, + .sysfs_ops =3D &kobj_sysfs_ops, + .default_groups =3D damos_sysfs_dests_groups, +}; + /* * scheme directory */ @@ -1672,6 +1870,7 @@ struct damon_sysfs_scheme { struct damon_sysfs_stats *stats; struct damon_sysfs_scheme_regions *tried_regions; int target_nid; + struct damos_sysfs_dests *dests; }; =20 struct damos_sysfs_action_name { @@ -1762,6 +1961,22 @@ static int damon_sysfs_scheme_set_access_pattern( return err; } =20 +static int damos_sysfs_set_dests(struct damon_sysfs_scheme *scheme) +{ + struct damos_sysfs_dests *dests =3D damos_sysfs_dests_alloc(); + int err; + + if (!dests) + return -ENOMEM; + err =3D kobject_init_and_add(&dests->kobj, &damos_sysfs_dests_ktype, + &scheme->kobj, "dests"); + if (err) + kobject_put(&dests->kobj); + else + scheme->dests =3D dests; + return err; +} + static int damon_sysfs_scheme_set_quotas(struct damon_sysfs_scheme *scheme) { struct damon_sysfs_quotas *quotas =3D damon_sysfs_quotas_alloc(); @@ -1894,9 +2109,12 @@ static int damon_sysfs_scheme_add_dirs(struct damon_= sysfs_scheme *scheme) err =3D damon_sysfs_scheme_set_access_pattern(scheme); if (err) return err; - err =3D damon_sysfs_scheme_set_quotas(scheme); + err =3D damos_sysfs_set_dests(scheme); if (err) goto put_access_pattern_out; + err =3D damon_sysfs_scheme_set_quotas(scheme); + if (err) + goto put_dests_out; err =3D damon_sysfs_scheme_set_watermarks(scheme); if (err) goto put_quotas_access_pattern_out; @@ -1927,6 +2145,9 @@ static int damon_sysfs_scheme_add_dirs(struct damon_s= ysfs_scheme *scheme) put_quotas_access_pattern_out: kobject_put(&scheme->quotas->kobj); scheme->quotas =3D NULL; +put_dests_out: + kobject_put(&scheme->dests->kobj); + scheme->dests =3D NULL; put_access_pattern_out: kobject_put(&scheme->access_pattern->kobj); scheme->access_pattern =3D NULL; @@ -1937,6 +2158,8 @@ static void damon_sysfs_scheme_rm_dirs(struct damon_s= ysfs_scheme *scheme) { damon_sysfs_access_pattern_rm_dirs(scheme->access_pattern); kobject_put(&scheme->access_pattern->kobj); + kobject_put(&scheme->dests->kobj); + damos_sysfs_dests_rm_dirs(scheme->dests); damon_sysfs_quotas_rm_dirs(scheme->quotas); kobject_put(&scheme->quotas->kobj); kobject_put(&scheme->watermarks->kobj); --=20 2.39.5 From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66626232369; Wed, 2 Jul 2025 05:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433371; cv=none; b=i1T0PbbC9rQMf1r1TD05fL7U/jY/DQgI5s5LvictNXoBGQKQ6jBhvq1XJsNFRi/azACN5U7u9H7GoMseQgtOCLqPQ46JDL+OKBl92uAEsYH/wR/jrs88TJQtVu/23Fl4JgxH04F07qO92B+OK0keHFniNXdWSIm7s/NpfwDkjSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433371; c=relaxed/simple; bh=eAY5XLYA4mfpfPr9vGq4U3HvZbAGIjijytVFdcL31aI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bw6toOiDa8WnEPQOnCwIIJEtnGw94yeqZuqZqsPwSXuGa5aJl9R1IQncrptVZqU90vCMMe0KEHwLBP3TrudnwxFD9vzBwM3txcB2OWQbny+rqkOO/t/k79pDS+FGpnOnFZEIppm3ZTfjZGwajwftSyyE676pDKdNvR5CLirGOEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MjUBoxZk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MjUBoxZk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B860FC4CEEE; Wed, 2 Jul 2025 05:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433370; bh=eAY5XLYA4mfpfPr9vGq4U3HvZbAGIjijytVFdcL31aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MjUBoxZk6Rms4kw/kYxkdd6eKSFU9bLTPMv0wpNzsiwC/Bp14SfV1NKKdPJ8WpLrh 4BioumljZFgdc9qTxz+VREa6wLgZg1hfllVZhSD6s2Dzz0c2F1qS1qmlqffijyHfnZ /ZgaNkP3Xr03ssK20ZdNBo3kkhnyVXRGX+khYYJgCvW9WnHGcHlRJOPvAzvEurJyRN b1bYq7oQqJebeWIjMTyZKWuPvxwBpFGhF5LtbB9JOkNC56fnWVL1486wmfw6R2WWTI Qm1EHmh73ovoF+e5LxiWW2dqmO1zwoWYtScnpscxZi3hcfK3+9fp0MSPcjlCKy8JLo zyXD64JeNAJGg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Bijan Tabatabai , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 4/6] mm/damon/sysfs-schemes: set damos->migrate_dest Date: Tue, 1 Jul 2025 22:15:56 -0700 Message-Id: <20250702051558.54138-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Pass user-specified multiple DAMOS action destinations and their weights to DAMON core API, so that user requests can really work. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b9434cdaacdc..507ca7708078 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2576,6 +2576,29 @@ void damos_sysfs_update_effective_quotas( } } =20 +static int damos_sysfs_add_migrate_dest(struct damos *scheme, + struct damos_sysfs_dests *sysfs_dests) +{ + struct damos_migrate_dest *dest =3D &scheme->migrate_dest; + int i; + + dest->node_id_arr =3D kmalloc_array(sysfs_dests->nr, + sizeof(*dest->node_id_arr), GFP_KERNEL); + if (!dest->node_id_arr) + return -ENOMEM; + dest->weight_arr =3D kmalloc_array(sysfs_dests->nr, + sizeof(*dest->weight_arr), GFP_KERNEL); + if (!dest->weight_arr) + /* ->node_id_arr will be freed by scheme destruction */ + return -ENOMEM; + for (i =3D 0; i < sysfs_dests->nr; i++) { + dest->node_id_arr[i] =3D sysfs_dests->dests_arr[i]->id; + dest->weight_arr[i] =3D sysfs_dests->dests_arr[i]->weight; + } + dest->nr_dests =3D sysfs_dests->nr; + return 0; +} + static struct damos *damon_sysfs_mk_scheme( struct damon_sysfs_scheme *sysfs_scheme) { @@ -2638,6 +2661,11 @@ static struct damos *damon_sysfs_mk_scheme( damon_destroy_scheme(scheme); return NULL; } + err =3D damos_sysfs_add_migrate_dest(scheme, sysfs_scheme->dests); + if (err) { + damon_destroy_scheme(scheme); + return NULL; + } return scheme; } =20 --=20 2.39.5 From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41398234977; Wed, 2 Jul 2025 05:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433372; cv=none; b=URzfnsrlKytOi54MmPH9hbZCAiQCOcOu5ajijcEi8faerTKEj2VZuKrOtphk5wFkH8Tvp6njvqy+ilUHtpCsyvNau8S8yVJSsCTIOkRGWJeOFcFGmJkFHKClmO5IGwBV3BevdZTX6v6aZML4lTkMwPCcQdgsjOEWtS0QNFkMWyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433372; c=relaxed/simple; bh=6b488vZ2iWxqTR7YVUSrEsxdrssHAMUzwsCzJVA6L+8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZSb1KzKm6d21QcvQzgxDpF0I1sQ4g30najvOszR8GZExpLKLOraLCGyBKsy8aA5TmugenQcy3kXnhngwcKYXW5Pj3MtPoZcQyd9louIK5z6mAg9sEtijkQzhp5+quxTO4ixbSAfW7g8f0C/AKa6FQsT4Q0GAVDX+P641mI5V31g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VQEAORAv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VQEAORAv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6799C4CEF1; Wed, 2 Jul 2025 05:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433372; bh=6b488vZ2iWxqTR7YVUSrEsxdrssHAMUzwsCzJVA6L+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VQEAORAvP4AsILpEleQnoxqKrsi6DUC2+7vLAcIYswnyM2L5NdIouXEFNUKb2e6Sq HIZLWYietZawQkVFcLiYcJvWhfuLzCIWmrnkgFCxWUxeflirqu8d//zy13SxGaHL4b 2XIkbvWwG7JywD3vYWhJW5gzcZgrhQaqk8JPra8D1WYWKl1tEkwrpDVQLcCP1U+Nve 6NsKU0dm6rHoSG01IlX0uj4HtxvbMYfZSCGoAntUQsmRMgQdUWp7RkjHusf6k9rtyJ V87Np9ggUsWoswSyWDFxpkLxRu6NjVa9C5hcOA/udGF+NRspB0jeoSFZaaHIKEcByZ Y54lc7kekLprQ== From: SeongJae Park To: Cc: SeongJae Park , Bijan Tabatabai , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 5/6] Docs/ABI/damon: document schemes dests directory Date: Tue, 1 Jul 2025 22:15:57 -0700 Message-Id: <20250702051558.54138-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Document the new DAMOS action destinations sysfs directories on ABI doc. Signed-off-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 5697ab154c1f..e98974dfac7a 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -431,6 +431,28 @@ Description: Directory for DAMON operations set layer-= handled DAMOS filters. /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//filters directory. =20 +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts/nr_dests +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing a number 'N' to this file creates the number of + directories for setting action destinations of the scheme named + '0' to 'N-1' under the dests/ directory. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts//id +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the id of + the DAMOS action destination. For DAMOS_MIGRATE_{HOT,COLD} + actions, the destination node's node id can be written and + read. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//de= sts//weight +Date: Jul 2025 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the weight + of the DAMOS action destination to select as the destination of + each action among the destinations. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//st= ats/nr_tried Date: Mar 2022 Contact: SeongJae Park --=20 2.39.5 From nobody Wed Oct 8 09:05:58 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E1662367D0; Wed, 2 Jul 2025 05:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433373; cv=none; b=quiN9/GkbmrdBLiG5HxfVoZLvKMZ25J6LkCO+DBwthlAEnfzPI4xijQQrtWC0kq1Zdv36lKhjBWt1gR4cBLN1mQa30smRatgcTH21suWYTtfavqk2dbA9At6O1IWYKuGZl8gfzl/Q7XPxj5NrmPga5pSCqzNGAPaHaderPxF4rI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751433373; c=relaxed/simple; bh=4kBKgmAO4np7zdvd9JkbBqwwr9+oQ8UOuTjsr0PkuTc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=U+2yNVbRb9eLM+1XaGQsHMV9cjrTgGazOvaZLR/PgrBfZHeiGqi4SPmRL2y/fxKUvuXpyMcwHh1JDUX0n1T80uPUO1kANFZXD5XCSGyRUDW2Z8jfe7pSHlSy/XPfPhZNCv3fWv4HzuCtGjbnn9bKiseWm4gKCIivYTCeKyEmw34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oVPJBL6H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oVPJBL6H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17ED5C4CEEF; Wed, 2 Jul 2025 05:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1751433373; bh=4kBKgmAO4np7zdvd9JkbBqwwr9+oQ8UOuTjsr0PkuTc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oVPJBL6H2dNgRxmRll33awS9kIJXspDmEAxzkNfDreiYt4TeHAsJVn72hjGbDePNK SV4p3RN231tMEmgmYqZ0HbCTfxn2XmkmwjoqQSv9qpctWq4jIJ7UKgGILJmLFslw5n 2Ysw1kYabYPvMt0UjL3Ps86Tb6WG9yFJo2vrNvhwQ11u3IBA9GVWRaXsmpKddQipSV sz23UEo0yKVAnfNUtTsj0hk1cb/Wxe4z0qrFoQDCR8SVk26tJhmOxNL2p1QAi4N9Fu iEQA2UlFiVTadpVXLNzLt72yKp//XUTtNOt4GWw6Ibm76FsYahQYL3Ad9Wgm2Sidlq bajLNmlx3F7aQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Bijan Tabatabai , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 6/6] Docs/admin-guide/mm/damon/usage: document dests directory Date: Tue, 1 Jul 2025 22:15:58 -0700 Message-Id: <20250702051558.54138-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250702051558.54138-1-sj@kernel.org> References: <20250702051558.54138-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Document the newly added DAMOS action destination directory of the DAMON sysfs interface on the usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index d960aba72b82..fc5c962353ed 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -85,6 +85,8 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`watermarks `/metric,interval_us,high,mid,low =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`{core_,ops_,}filters `/nr_filters =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/type,matching,allow,memcg_path,addr_start,addr_end,target_idx,m= in,max + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`dests `/nr_dests + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/id,weight =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`stats `/nr_tried,sz_tried,nr_applied,sz_applied,= sz_ops_filter_passed,qt_exceeds =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`tried_regions `/total_bytes =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 0/start,end,nr_accesses,age,sz_filter_passed @@ -307,10 +309,10 @@ to ``N-1``. Each directory represents each DAMON-bas= ed operation scheme. schemes// ------------ =20 -In each scheme directory, seven directories (``access_pattern``, ``quotas`= `, -``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``stats``,= and -``tried_regions``) and three files (``action``, ``target_nid`` and -``apply_interval``) exist. +In each scheme directory, eight directories (``access_pattern``, ``quotas`= `, +``watermarks``, ``core_filters``, ``ops_filters``, ``filters``, ``dests``, +``stats``, and ``tried_regions``) and three files (``action``, ``target_ni= d`` +and ``apply_interval``) exist. =20 The ``action`` file is for setting and getting the scheme's :ref:`action `. The keywords that can be written to and read @@ -484,6 +486,29 @@ Refer to the :ref:`DAMOS filters design documentation of different ``allow`` works, when each of the filters are supported, and differences on stats. =20 +.. _damon_sysfs_dests: + +schemes//dests/ +------------------ + +Directory for specifying the destinations of given DAMON-based operation +scheme's action. This directory is ignored if the action of the given sch= eme +is not supporting multiple destinations. Only ``DAMOS_MIGRATE_{HOT,COLD}`` +actions are supporting multiple destinations. + +In the beginning, the directory has only one file, ``nr_dests``. Writing a +number (``N``) to the file creates the number of child directories named `= `0`` +to ``N-1``. Each directory represents each action destination. + +Each destination directory contains two files, namely ``id`` and ``weight`= `. +Users can write and read the identifier of the destination to ``id`` file. +For ``DAMOS_MIGRATE_{HOT,COLD}`` actions, the migrate destination node's n= ode +id should be written to ``id`` file. Users can write and read the weight = of +the destination among the given destinations to the ``weight`` file. The +weight can be an arbitrary integer. When DAMOS apply the action to each e= ntity +of the memory region, it will select the destination of the action based o= n the +relative weights of the destinations. + .. _sysfs_schemes_stats: =20 schemes//stats/ --=20 2.39.5