From nobody Thu Oct 9 01:09:55 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 CFF55267732; Sat, 21 Jun 2025 17:31:35 +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=1750527098; cv=none; b=qx3xO7GRv7OnxNxUzlOTyBN8QAejTf3K6cAIWtFLJepEv51/fxGi94kam+eyD5uGsGdElHxZMTmc/qW2CBab/B56fJhmcG2gCgaOkHhBBQKoAsrus1t7n5TKV3wLmMHOrp6l6EioquSkZanVNtSoc8a2fGS8Quy9OmormWAPDAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750527098; c=relaxed/simple; bh=pdcyWRPhdb/cEUr29Fl+//1LhV5HJEfdKz0MuDMK0gI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lH8B5FKsKZBD6GuqBI2QOyblDwPU0V1JW1gWfckY9mQsA3VRoOHrx8kbgAWbiIDRwNlT1t5ci9TBkegPcbhJL1jl/kEIFDVciT8mHlL2XIaX3SxUhEap4QjP34prYlTmnVutuP5xk/S5Tzt6/9fvTHF0+3xrLWMQKiXNREDXN9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Dr1XIiLZ; 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="Dr1XIiLZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B926C4CEEE; Sat, 21 Jun 2025 17:31:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750527095; bh=pdcyWRPhdb/cEUr29Fl+//1LhV5HJEfdKz0MuDMK0gI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dr1XIiLZ+ix4RZ5xxjvkWQBPfGqPsMo/4roF6u2SlzD4CGnSW/RUgOMiBatMc/2KI PVyWMUBk7/VYWJXgY4vVLsHc3hRIyiWTK3ZLGxTDBmrJPthVzqwQnNWFWWMTh1fTXu tPcbyzIv12jLvEzhl3b5RvevikWwvOsf352T2wEulKcYETmqANDQiVmQ2IBQDLZVe2 EVnE/FuUrqXe357rWuSRTtB2GG+n4A1PN76nR0qDk/FgFA/B9RZ5sN6MboArR+Lne4 Gd/HS9rfPObP4x5ngx3pqhl9D3VMebgS399V5mHaHGpxLPfBCpVvfLLBzA4oIGtQAz q9pClqSAOS7ow== 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 1/4] mm/damon: add struct damos_migrate_dest Date: Sat, 21 Jun 2025 10:31:28 -0700 Message-Id: <20250621173131.23917-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250621173131.23917-1-sj@kernel.org> References: <20250621173131.23917-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 Thu Oct 9 01:09:55 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 CFFC1267B07; Sat, 21 Jun 2025 17:31:36 +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=1750527098; cv=none; b=jkwuVjZGNEE+G3AmDHxCyQEa8GM2Yr4dtLglrLNHl2G9myiAdRKLGcShsOaagtdeDjqEyCxzKBHdC3ITWbFxIhJftUKKyeLX5sVIfC/+R7CXor7oAapqhvNQtn0ZrinZV519stVCAW04+zavZE/75Q0qmeYrWpA7ve9XUBsQPhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750527098; c=relaxed/simple; bh=XwUe6eyej2+X6VVhw6Bc1wVY5GDm97pjooComOJUL4k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nfg2CgFf1J33RVhR9C51URJF3eTZcnnnlxvKb0g/u6lnf3HmAYTV/F49M8Zz8MoVF97rc9alOhn8FuTXnNCsDgJv2cuW3TS0W9hfbpQLRPBJ4Wbx/sIQcP1VypVi4Bak/nT0UElZjnlhYlc7d7brm5Edvw9WD8lOG5TGaZ3TbnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kqlH/ax+; 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="kqlH/ax+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D20EC4CEF3; Sat, 21 Jun 2025 17:31:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750527096; bh=XwUe6eyej2+X6VVhw6Bc1wVY5GDm97pjooComOJUL4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kqlH/ax+l7Hdk7k4TXe6XwMHpEvU9xY2JmbGFidhk6efSzgCgu+HESiUXyFHodoEd uw9H1+y2J5vm/qIuE8jUXm/RXr1BqG1pQ8lccaBqU/exfZOGlm7OB0IenzCcUMKjhK CDuNStCShNel4RS4XJpgbCvM9me6VQoXyDKCLBNESAT7YPR6YKZ0MTowNxvyRMlKUi 9yl3l/kCD6z9kw0Oqyo3QnzhSNxthi7Pz7eXiPZJZt9+JVi823rqANZpLArRd6/aWX f/IhcfJAFJiRPuAazufHnKp0XdBL5Dbp8X3geyQm6wRZhhVHebZPCsUyVKB1TXlbL6 2aKYH1TuUb3EA== 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 2/4] mm/damon/core: add damos->migrate_dest field Date: Sat, 21 Jun 2025 10:31:29 -0700 Message-Id: <20250621173131.23917-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250621173131.23917-1-sj@kernel.org> References: <20250621173131.23917-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 b217e0120e09..ea2a17b2dee7 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 Thu Oct 9 01:09:55 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 24C6C267F57; Sat, 21 Jun 2025 17:31:37 +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=1750527099; cv=none; b=iMULrSoYW5uWt/bU3WfL9CtpzWh9nytVlF+1nNBlJwL1n4yayYSzwOOSh+EBJ30//NeIrSjBQK9gOU3eY8OtL9aeIIop0QowNJS7+gDhhxG9YOotPnZDYXRvV0sDkOE9tra2CNBIF8dsbVzxJH1QPloq8jEZX15n3EYNqiugOWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750527099; c=relaxed/simple; bh=jZXRGMPd1LoZQ4l+0QnmyjiGPlISD4Tjf+yuD/8T/qM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o/s9Mx/VOJxc5pvYQm2VkUpole9gozxK7z84UIXM6+T6wxOTkrM8LJ4VzT1YF9BgW6geclzeuXL9g6w1aisacvCygX4ZoRnvNtEzZA7iZ+TEKfqwOvLqQUu7IbYRNXk4Ov8zacsZ+e0a5UP+G9lOOfGyaC4SCRH+xn5QUm8vTRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yqxl+nl3; 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="Yqxl+nl3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46863C4CEE7; Sat, 21 Jun 2025 17:31:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750527097; bh=jZXRGMPd1LoZQ4l+0QnmyjiGPlISD4Tjf+yuD/8T/qM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yqxl+nl3Cl38VIiZHQjeIwQLmHgOUy34ICddF+996FMBQR/2vkac5w6y5KHs/kJi4 AsFR4dEsvoxW+Yc9zP10w1xx+QYxBGy+vbQmqX3O20y+BiVssToh1KnZe3SdRKbDqu qwzijkPt9lhz5yYlxaYJiY/5WdqAwX3TXBk+vrrnETmgJNYoGPg5dNzp5yG9Ea5YI8 NbSQm8tlvblYDULrrCwF8SnJXwetwWmZrd4EehvQttiVaco4VtnvsUL2yLk+meIrLh 1s4H5Q9RwkEiGjkUzliYo86q6fAJrlecc7LKqB4JD9FiHfI36GsUyaLhm+gUjVVg3f dKwrQZBVWSFug== 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 3/4] mm/damon/sysfs-schemes: implement DAMOS action destinations directory Date: Sat, 21 Jun 2025 10:31:30 -0700 Message-Id: <20250621173131.23917-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250621173131.23917-1-sj@kernel.org> References: <20250621173131.23917-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 that has files named id and weight. Users can then write the destination id (node id in case of DAMOS_MIGRATE_*) and their 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 30ae7518ffbf..e04cd8d592b8 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1568,6 +1568,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 */ @@ -1585,6 +1783,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 /* This should match with enum damos_action */ @@ -1641,6 +1840,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(); @@ -1773,9 +1988,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; @@ -1806,6 +2024,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; @@ -1816,6 +2037,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 Thu Oct 9 01:09:55 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 24CE7267F58; Sat, 21 Jun 2025 17:31:38 +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=1750527099; cv=none; b=J4GCBuOcifXrr2n1ahF/VwccQzZRYNCBi0fl0/MxQpfTnoQldcLRM0lOPTBVofOMARg8KuwVn/Y19NpLIk9a+Iv0T6Hp4DUUxP6QbgrKtPgFsgkk0+TQBSLhb0xuleQjHXH2HQlSXyf6KASgXyGOI4RqXCRScv4j+pT2AXqPkU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750527099; c=relaxed/simple; bh=Yysf3LajEIuwtoLoQcbL1zEZegxsuk3/GotP4vddbz4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H+3837xsGIC8q9QzXzDlBzuHHQBRWhrzFwxe4uXY+NB6exBDXytGNKb1De69SU1dN3S56DeJTA/J3t+m2rsctsyNCw3ypMH44XZrMe93BFNlqI4O9aPjU1FcvTE2JkDQofiE0ZkiT6ymcm8dQ8QHsIHl16qGBz7OFyrByHg4U14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EP52vihA; 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="EP52vihA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7794BC4CEEF; Sat, 21 Jun 2025 17:31:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1750527098; bh=Yysf3LajEIuwtoLoQcbL1zEZegxsuk3/GotP4vddbz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EP52vihAGOvoB7EdJ3ZYt5Celh2McBShfE+llp9YSQdwmeUWFrcCxPF6DOSvCKaEp t1kS/NLjjHzjZjMnR/Dbf1PBwXe0VJskyhjpuOCFKb+nWpPl4X0R1mdV33O2GVCJ18 o2B/ECLOWLQpzlfvwFEswh7W0HBeKeuBynvQ79uRdJU2lZg6G500FAfncdtWSY3Wge D1vtDrY+VjjaPjfLM64jPc9Chc5ik6jyQ7fD5Kto6nUbMQ8cU61NRxKnC+/LGNFVjz O8JHNK/6MDtavuJrSG3V1B34Y7568FUDxpuWKPOMT3HqkOklx6eQnB04qREJGtLM7g ESnMkHIOTf+bw== 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 4/4] mm/damon/sysfs-schemes: set damos->migrate_dest Date: Sat, 21 Jun 2025 10:31:31 -0700 Message-Id: <20250621173131.23917-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250621173131.23917-1-sj@kernel.org> References: <20250621173131.23917-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 e04cd8d592b8..158a2be3fd45 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2445,6 +2445,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) { @@ -2507,6 +2530,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