From nobody Mon Feb 9 05:38:37 2026 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 3580B1C5F2C; Sun, 20 Apr 2025 19:40: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=1745178038; cv=none; b=aVw6C2tifI9zjKPWuqhOZZ8VeYTb15ttNA0PdCI2cOLaDlDsESzis8tNbYuaUi6DhkzGYkMPy5Jwmr4T1fxFyGFsgLlh3ZOnVLuezLizERjBnGW+VIeGw5vRFNRmzaajYq8l4jNBgEMR6A4RS0XHnb4ecJyq7cyCMB066sdQThw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178038; c=relaxed/simple; bh=TOtCGrkDZVAaA1HvRz3yyFtveCVko96aYWnah99Y0Hk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A2pPmRK6XK8KMo4Vebt9+mL+ckSD+fCS0PTY+CtwQ1lNeRPjYkX8zs0lDfB/z2xqaz3jh+ZhGoYW9WxyFh/qMWvqU+TO+XGLjUh0M4tayT0svO0PMOKcXuJlZi79EjgZq/QpytXWtt0DyeYBc/SL4bdako77rwkUUGS0g4OG8pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ie2sg2Qu; 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="Ie2sg2Qu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C559C4CEE2; Sun, 20 Apr 2025 19:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178037; bh=TOtCGrkDZVAaA1HvRz3yyFtveCVko96aYWnah99Y0Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ie2sg2Qu7jppqBnu2UeOfQIH9KynSFtWEMiz3BdekMK/ampgBmK5k/e8jyQZJbPBp BZYAumO5SAPYm9b4MT9jUG4cO30+GAJALnRYVRE6ihy8VK/tAdRvcwqcxS3dZi+b+n /f6SfVVSPATV3YKyTtAbCU75FSSZXYK6f6UZLtD8cov2OL42qef344nDm0Tzl/1Jav dfGsT2Cu0qMIhFB409ft1P/IZsn9Z3MnBqVvi2+fHOOiiAZinhjLVZ0vhLU2GfisJT cyy+PAublkveW3rr1LV7BZsxF2C1O+kNc4u2dXyly9qGDail84tbtMrvR+2CrKKrL/ mr4aWpm9Q27CA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/7] mm/damon/core: introduce damos quota goal metrics for memory node utilization Date: Sun, 20 Apr 2025 12:40:24 -0700 Message-Id: <20250420194030.75838-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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" Used and free space ratios for specific NUMA nodes can be useful inputs for NUMA-specific DAMOS schemes' aggressiveness self-tuning feedback loop. Implement DAMOS quota goal metrics for such self-tuned schemes. Signed-off-by: SeongJae Park --- include/linux/damon.h | 6 ++++++ mm/damon/core.c | 27 +++++++++++++++++++++++++++ mm/damon/sysfs-schemes.c | 2 ++ 3 files changed, 35 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 47e36e6ea203..a4011726cb3b 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -145,6 +145,8 @@ enum damos_action { * * @DAMOS_QUOTA_USER_INPUT: User-input value. * @DAMOS_QUOTA_SOME_MEM_PSI_US: System level some memory PSI in us. + * @DAMOS_QUOTA_NODE_MEM_USED_BP: MemUsed ratio of a node. + * @DAMOS_QUOTA_NODE_MEM_FREE_BP: MemFree ratio of a node. * @NR_DAMOS_QUOTA_GOAL_METRICS: Number of DAMOS quota goal metrics. * * Metrics equal to larger than @NR_DAMOS_QUOTA_GOAL_METRICS are unsupport= ed. @@ -152,6 +154,8 @@ enum damos_action { enum damos_quota_goal_metric { DAMOS_QUOTA_USER_INPUT, DAMOS_QUOTA_SOME_MEM_PSI_US, + DAMOS_QUOTA_NODE_MEM_USED_BP, + DAMOS_QUOTA_NODE_MEM_FREE_BP, NR_DAMOS_QUOTA_GOAL_METRICS, }; =20 @@ -161,6 +165,7 @@ enum damos_quota_goal_metric { * @target_value: Target value of @metric to achieve with the tuning. * @current_value: Current value of @metric. * @last_psi_total: Last measured total PSI + * @nid: Node id. * @list: List head for siblings. * * Data structure for getting the current score of the quota tuning goal. = The @@ -179,6 +184,7 @@ struct damos_quota_goal { /* metric-dependent fields */ union { u64 last_psi_total; + int nid; }; struct list_head list; }; diff --git a/mm/damon/core.c b/mm/damon/core.c index f0c1676f0599..587fb9a4fef8 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1889,6 +1889,29 @@ static inline u64 damos_get_some_mem_psi_total(void) =20 #endif /* CONFIG_PSI */ =20 +#ifdef CONFIG_NUMA +static __kernel_ulong_t damos_get_node_mem_bp( + struct damos_quota_goal *goal) +{ + struct sysinfo i; + __kernel_ulong_t numerator; + + si_meminfo_node(&i, goal->nid); + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEM_USED_BP) + numerator =3D i.totalram - i.freeram; + else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */ + numerator =3D i.freeram; + return numerator * 10000 / i.totalram; +} +#else +static __kernel_ulong_t damos_get_node_mem_bp( + struct damos_quota_goal *goal) +{ + return 0; +} +#endif + + static void damos_set_quota_goal_current_value(struct damos_quota_goal *go= al) { u64 now_psi_total; @@ -1902,6 +1925,10 @@ static void damos_set_quota_goal_current_value(struc= t damos_quota_goal *goal) goal->current_value =3D now_psi_total - goal->last_psi_total; goal->last_psi_total =3D now_psi_total; break; + case DAMOS_QUOTA_NODE_MEM_USED_BP: + case DAMOS_QUOTA_NODE_MEM_FREE_BP: + goal->current_value =3D damos_get_node_mem_bp(goal); + break; default: break; } diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 23b562df0839..98108f082178 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -942,6 +942,8 @@ struct damos_sysfs_quota_goal { static const char * const damos_sysfs_quota_goal_metric_strs[] =3D { "user_input", "some_mem_psi_us", + "node_mem_used_bp", + "node_mem_free_bp", }; =20 static struct damos_sysfs_quota_goal *damos_sysfs_quota_goal_alloc(void) --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 6170F1C84BC; Sun, 20 Apr 2025 19:40: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=1745178039; cv=none; b=tmuncb9StfYYKKxZQC2zfMbvsxoeQkoSH9lY8DDEcXSE5C+EHgSYBdCRtNoHbKrI1ReVAcc5q7yJFOVbQfHP2jHOnXK7pasyqOy0FCuOvqMlQs1SWKc0BPfZyDq6LwuIM7Rc7S27/NGJZAVXqs/584uVgaZgaziFKuZarDJHh8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178039; c=relaxed/simple; bh=YrnSVlsWWaNU8yWNre3Ssi6/DIgFSJQgBiB+f6Xdzok=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=udkkX56NpAbDfczJOO1H4g8DBk+yX2gqIb1SlPPhsYF6awaBk2zYWwx16s/awLGsgA/sF/Nwn2OGy9lMxfFUfmS9grjLfCbChOpjJzEZuAZ80fs7AzwFuKF8OuOUfoY1k/5JMZnZ7mXeoemQNJTNxpBfB823jfnonIy1tLXPasE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UXMItcxk; 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="UXMItcxk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C0EBC4CEE2; Sun, 20 Apr 2025 19:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178038; bh=YrnSVlsWWaNU8yWNre3Ssi6/DIgFSJQgBiB+f6Xdzok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UXMItcxkOIFjk5OK458tYbEGtY1gX/42/4ZGXGr/wA5pulJ+2NH3vzZ8fdB7AM6Yp MAHbz3qV6kUE2tUn6ArpWR5aWvRmINKHWe6pVRa3GIutCrLlVdH4Prymjqq7+zK4Pl R/bk/60BHJ1AWa51BCXtw/CTSAQeKE4YXR3jGCbYIK+omzf2OVUs5a0s8zqwhnT5YX ApVrrplK1q9jHQi5xP/MYdNK/zq5XNDf9BjzBJkhd2alTGghoWJCylsbn7WJI/GH0O d6D8UBT6rrd1005l+BquSXGxpwq5/OHN0dS+HJmmetRPvM6YnsP34Ym4NnNr2uHPXQ teATEL+h9kItA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/7] mm/damon/sysfs-schemes: implement file for quota goal nid parameter Date: Sun, 20 Apr 2025 12:40:25 -0700 Message-Id: <20250420194030.75838-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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_QUOTA_NODE_MEM_{USED,FREE}_BP DAMOS quota goal metrics require the node id parameter. However, there is no DAMON user ABI for setting it. Implement a DAMON sysfs file for that with name 'nid', under the quota goal directory. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 98108f082178..7681ed293b62 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -936,6 +936,7 @@ struct damos_sysfs_quota_goal { enum damos_quota_goal_metric metric; unsigned long target_value; unsigned long current_value; + int nid; }; =20 /* This should match with enum damos_action */ @@ -1016,6 +1017,28 @@ static ssize_t current_value_store(struct kobject *k= obj, return err ? err : count; } =20 +static ssize_t nid_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damos_sysfs_quota_goal *goal =3D container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + + /* todo: return error if the goal is not using nid */ + + return sysfs_emit(buf, "%d\n", goal->nid); +} + +static ssize_t nid_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damos_sysfs_quota_goal *goal =3D container_of(kobj, struct + damos_sysfs_quota_goal, kobj); + int err =3D kstrtoint(buf, 0, &goal->nid); + + /* feed callback should check existence of this file and read value */ + return err ? err : count; +} + static void damos_sysfs_quota_goal_release(struct kobject *kobj) { /* or, notify this release to the feed callback */ @@ -1031,10 +1054,14 @@ static struct kobj_attribute damos_sysfs_quota_goal= _target_value_attr =3D static struct kobj_attribute damos_sysfs_quota_goal_current_value_attr =3D __ATTR_RW_MODE(current_value, 0600); =20 +static struct kobj_attribute damos_sysfs_quota_goal_nid_attr =3D + __ATTR_RW_MODE(nid, 0600); + static struct attribute *damos_sysfs_quota_goal_attrs[] =3D { &damos_sysfs_quota_goal_target_metric_attr.attr, &damos_sysfs_quota_goal_target_value_attr.attr, &damos_sysfs_quota_goal_current_value_attr.attr, + &damos_sysfs_quota_goal_nid_attr.attr, NULL, }; ATTRIBUTE_GROUPS(damos_sysfs_quota_goal); --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 67AA91D5ABF; Sun, 20 Apr 2025 19:40:40 +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=1745178041; cv=none; b=pXAIZN4oD3HG8BcaByLLgbW+oT2k603XYvlMrQ2fOt9XCCN0ZFaK0SRG82I7XKvt4Wdqf89tMALWDPsKdSa7e4nL8ebkR5bAn4Ig7Ohf++x2npBVgSsFfCJ5CCdMoTi0zBKTPkUzPPb+NWqlMv9yszvUSEty2uYQ3Yh7ncV863E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178041; c=relaxed/simple; bh=3TYJVSgc9rMx2w0Ytz6/FAhhzHJ5CZhkTze93ru2E9w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aXHG9CfwYMgIiAEeoYJ1Mos3GWU7eGDjA3GUk2wVVjJe3Vh/PJV1tZBnrCiLlV742Q3qK7TOlG09wDd12r0kn1bdCJOxyzxk9kBIZSd17gdMgnLRvbe1+S8vuuZxWAWiUsO7pGC8dXaHwF6Cr7TrvHXNKzDMYUUblu9WvNwz3i0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dB/+9hkd; 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="dB/+9hkd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69E1C4CEE2; Sun, 20 Apr 2025 19:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178039; bh=3TYJVSgc9rMx2w0Ytz6/FAhhzHJ5CZhkTze93ru2E9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dB/+9hkdeS/+vtFexHDFckLptSB20GvfwhNr1k6nuTTS1RPNyQA4Y6KkmNEGRZPrA YAV+H9DxanIbrPOiYBlR9UqNMONiI+l2494Ut7MMJ9Hpdy/ILtDAncUIdyENvV5Z0w Jz5bKfYKGfm9TLH2SG7oUDyedGxBTP7zILupwXU5yk0CQADf/oq8xLltjoCx0t//Mm bj82gWSmKoUuapR2lp8vlkr3K/10mABvRZ3V7L2+8MM5OQm4ALCdyepMOH1X0ABpcc +OiXELPZIYgR+y8NFlmWOIVagM4WO3QX5R+IHTvm/VdOQ9S01gR711CQj7Pj76Fduf jFmAWfDGrloxg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/7] mm/damon/sysfs-schemes: connect damos_quota_goal nid with core layer Date: Sun, 20 Apr 2025 12:40:26 -0700 Message-Id: <20250420194030.75838-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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" DAMON sysfs interface file for DAMOS quota goal's node id argument is not passed to core layer. Implement the link. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index 7681ed293b62..729fe5f1ef30 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2149,8 +2149,17 @@ static int damos_sysfs_add_quota_score( sysfs_goal->target_value); if (!goal) return -ENOMEM; - if (sysfs_goal->metric =3D=3D DAMOS_QUOTA_USER_INPUT) + switch (sysfs_goal->metric) { + case DAMOS_QUOTA_USER_INPUT: goal->current_value =3D sysfs_goal->current_value; + break; + case DAMOS_QUOTA_NODE_MEM_USED_BP: + case DAMOS_QUOTA_NODE_MEM_FREE_BP: + goal->nid =3D sysfs_goal->nid; + break; + default: + break; + } damos_add_quota_goal(quota, goal); } return 0; --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 67B331D5ADC; Sun, 20 Apr 2025 19:40:41 +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=1745178041; cv=none; b=aBrwRVcIsHY95uxPZ9UR39mH9Vnj4Rta/IKcU/VYg5ShurcgNI19Ojn0QsTO7EGht0dTzt6NTVughc8nM9B1F2rrP8j57TvMCQLpNMQuWxeEWeT4WSX7POpztwxhXkxbElFL/3G88LKZqogBhs7f/kdq5uHlWJP2L2B3seuULFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178041; c=relaxed/simple; bh=O2QyPpvrJel3yg5xTV6SbG3aWvJ/8ntEB2kQvqlcRMA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q+tpN41jdswfKxAJYcYM9y9lC4VlEL4tzQWANEbVWG8dPA4qD2zSAhLd7fudsqzLmlcHzDe6bfcwKeOQjRt1TZ1IT8e9tItdwpPTW5Q8+WaB5CnMbYZNql8Hos01O7vQryV0SIUIMeRQfncUBpkqehNy1NxQedWiezAndIU/pB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m+66FnMg; 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="m+66FnMg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC032C4CEE9; Sun, 20 Apr 2025 19:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178041; bh=O2QyPpvrJel3yg5xTV6SbG3aWvJ/8ntEB2kQvqlcRMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m+66FnMgcD+CJtwBxR5WWy1A5UzEWfX0UVpz9MTQlFUQtBjjb0kE0LMjLqhXjDAwY xCk831yNZdJ44WsB3Tor6plm2LGP2tQc4X4QOX4DLNGsm7zpMOxT7aw7YC41MD8Kk+ aoe4pE7NV+bfUUBsNb/mY8jt9KGUR9Am923cYTBe4ksldXmntuCPlNu3xJSOo2teZB FpI0W5IG1dkcILs0AdPkuoYHs4xfecxIekA5k16TbejzF8K2G0puvqrp6+/AEDQ65P OtoEF8hXDk1qbsP0hSf9L2V/AgEPLNRmvbOM0h0qxhjoZY84WfJrhPtA3CDnrR5wAV tcMuU96DYhH2w== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , 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: [PATCH 4/7] Docs/mm/damon/design: document node_mem_{used,free}_bp Date: Sun, 20 Apr 2025 12:40:27 -0700 Message-Id: <20250420194030.75838-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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 description of DAMOS quota goal metrics for NUMA node utilization on the DAMON deesign document. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index f12d33749329..728bf5754343 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -550,10 +550,10 @@ aggressiveness (the quota) of the corresponding schem= e. For example, if DAMOS is under achieving the goal, DAMOS automatically increases the quota. If = DAMOS is over achieving the goal, it decreases the quota. =20 -The goal can be specified with three parameters, namely ``target_metric``, -``target_value``, and ``current_value``. The auto-tuning mechanism tries = to -make ``current_value`` of ``target_metric`` be same to ``target_value``. -Currently, two ``target_metric`` are provided. +The goal can be specified with four parameters, namely ``target_metric``, +``target_value``, ``current_value`` and ``nid``. The auto-tuning mechanism +tries to make ``current_value`` of ``target_metric`` be same to +``target_value``. =20 - ``user_input``: User-provided value. Users could use any metric that th= ey has interest in for the value. Use space main workload's latency or @@ -565,6 +565,11 @@ Currently, two ``target_metric`` are provided. in microseconds that measured from last quota reset to next quota reset. DAMOS does the measurement on its own, so only ``target_value`` need to = be set by users at the initial time. In other words, DAMOS does self-feedb= ack. +- ``node_mem_used_bp``: Specific NUMA node's used memory ratio in bp (1/10= ,000). +- ``node_mem_free_bp``: Specific NUMA node's free memory ratio in bp (1/10= ,000). + +``nid`` is optionally required for only ``node_mem_used_bp`` and +``node_mem_free_bp`` to point the specific NUMA node. =20 To know how user-space can set the tuning goal metric, the target value, a= nd/or the current value via :ref:`DAMON sysfs interface `, refe= r to --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 3DE7F1D7E35; Sun, 20 Apr 2025 19:40:42 +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=1745178042; cv=none; b=ewtqTkh7bL50loaXR1BcLMwsNkwD+YYpbJjWoptJRekFS+XUAXbbrURmRfyT7xZcCEuUGGz4dlK5DwbS+OOkzlC5Q5tPIIhcYyOXjQ7UetXWQhn3Sl5Nua8mz+UiutdZcKldyMcMmD9wqx0R62friOZnnMvUFlNlQIpNRPfv/IU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178042; c=relaxed/simple; bh=twOnYczGHwHXpz8e7UmyZwF+rnltKS4AmY2MSDBAKIA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=MRV8MpAFHNgqs4InVEnsWHUJsSTCqnEBP0Mk2pcwz3xfugo4cv67VYm/dOF4DdodJejtFiHbvt1tyPdtJavBBlwtv//gKOJBIi5v4k7CowhAls6SZPm/fy4PYIhcdfuFBaM2OLpwXkeml+SLXiJL8BTtxVMbTke/wyBYVROoQZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JbG9g6fy; 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="JbG9g6fy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7163C4CEE2; Sun, 20 Apr 2025 19:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178042; bh=twOnYczGHwHXpz8e7UmyZwF+rnltKS4AmY2MSDBAKIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JbG9g6fyfGlOu1n0zH18CPGPRRJxOc98hqCc2XeHvk/rMF49pRonYRVhwOntauLjD cTQSL/GH3WrXOe5iMvd88dd4L5E/4/h55njdLfDSYyy42XdzY57Y8qNE+WOtht6Owa Gjht85rtsueCy4P1z6Mw3cU2BMGdr0pUI2Lq7TmlWdcBkTtpcWXbpz9ktB6qwXXZg2 XMBHV2yM4SA1qhG4bba+7RmH1dKLcomVaOrphYv2gvgh/TPgSZdzrpvzmmCxljvhfb Z5fhIcYqSTmGQZVsBmN/rWy9M7Xf8dSo6Ie8YXT4KsM1H8n0JyReDxlawwjJWBpVT7 5gGzM+O7/7EKA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , 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: [PATCH 5/7] Docs/admin-guide/mm/damon/usage: document 'nid' file Date: Sun, 20 Apr 2025 12:40:28 -0700 Message-Id: <20250420194030.75838-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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 Add description of 'nid' file, which is optionally used for specific DAMOS quota goal metrics such as node_mem_{used,free}_bp on DAMON usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index ced2013db3df..d960aba72b82 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -81,7 +81,7 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = :ref:`quotas `/ms,bytes,reset_interval_ms,effective_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 weights/sz_permil,nr_accesses_permil,age_permil =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = =E2=94=82 :ref:`goals `/nr_goals - =E2=94=82 =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/target_metric,target_value,current_value + =E2=94=82 =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/target_metric,target_value,current_value,nid =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 @@ -390,11 +390,11 @@ number (``N``) to the file creates the number of chil= d directories named ``0`` to ``N-1``. Each directory represents each goal and current achievement. Among the multiple feedback, the best one is used. =20 -Each goal directory contains three files, namely ``target_metric``, -``target_value`` and ``current_value``. Users can set and get the three -parameters for the quota auto-tuning goals that specified on the :ref:`des= ign -doc ` by writing to and reading fro= m each -of the files. Note that users should further write +Each goal directory contains four files, namely ``target_metric``, +``target_value``, ``current_value`` and ``nid``. Users can set and get the +four parameters for the quota auto-tuning goals that specified on the +:ref:`design doc ` by writing to and +reading from each of the files. Note that users should further write ``commit_schemes_quota_goals`` to the ``state`` file of the :ref:`kdamond directory ` to pass the feedback to DAMON. =20 --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 2131C1DD9AC; Sun, 20 Apr 2025 19:40:44 +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=1745178044; cv=none; b=SzrQkWYSSxVr3ogsyRdDJQ7tgwINsSUoAS7AWJ1kIrjlaY1dbqqmZVr7jFZ30nQM5msTSB71tXKhu6y0axwyglzDU0G471LNSVJV27mpCg38ntLZDc5zhmBzPk7FNx0TKMU4NJt3RILcx/GWU7Qf2nGwhj/rgBWz2ELJJ+PpGrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178044; c=relaxed/simple; bh=4toUflKBJ0stxy41rSp4MADpFGvyQOLZX1iQYpsRRqw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MJby1A0kEeXddgi28NTKYJp6ZhhBd+SeOU7B7m/pDAYGEbxCfkxWrjAxjozz4SkBqvi05IR9D8dRfcft+oCrNKrWRPmAeu+0m2RSpEsiEy0dSpcgHtNKrl7QdqKwMr3veamAXHjEUoQpZ3cjX7M4yuqYEsDWGYPn0Yfxd07MgfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3V6vmE7; 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="l3V6vmE7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7414C4CEF2; Sun, 20 Apr 2025 19:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178043; bh=4toUflKBJ0stxy41rSp4MADpFGvyQOLZX1iQYpsRRqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3V6vmE7Fl4j3+dGHjCNr6Tzv41/jZU73BjEebno2mhQfo4bqtRUQfxDxy3OvFusJ V2SLhBsAvlm62aju1TUyeZ2k8l/KWK2ALf4Qao6juLmZE1nnyZWG6dRvp4Xg3KCnDy y6sUV+vdmVeN40jGjWo3Je2m/4mFpqM4lrW0T/cfwVSy3EQY7JFbcGidXuNGhTm61N cve6rNy+HCY1qio0OtESKvrupAcVVmg/btMUaCI3dfmWz4G7H/vyN2++SjV01xIyza +6I6WtSGHUvy5aIty3VAPGtEk7vCtLtao5n6cpSeMQug7tQ6xQDT0Vq8wcwPq+KUYt g7yKj2c32LEWA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/7] Docs/ABI/damon: document nid file Date: Sun, 20 Apr 2025 12:40:29 -0700 Message-Id: <20250420194030.75838-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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 description of 'nid' file, which is optionally used for specific DAMOS quota goal metrics such as node_mem_{used,free}_bp on the DAMON sysfs ABI document. Signed-off-by: SeongJae Park --- Documentation/ABI/testing/sysfs-kernel-mm-damon | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 293197f180ad..5697ab154c1f 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -283,6 +283,12 @@ Contact: SeongJae Park Description: Writing to and reading from this file sets and gets the curre= nt value of the goal metric. =20 +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//qu= otas/goals//nid +Date: Apr 2025 +Contact: SeongJae Park +Description: Writing to and reading from this file sets and gets the nid + parameter of the goal. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//schemes//qu= otas/weights/sz_permil Date: Mar 2022 Contact: SeongJae Park --=20 2.39.5 From nobody Mon Feb 9 05:38:37 2026 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 800411DED5C; Sun, 20 Apr 2025 19:40:45 +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=1745178046; cv=none; b=F0cj87PgMA7zlK+H/bogKrGbv5iaJy08AxORGl04r6WdQ+1PvJijUviukG+D2t7jvjQmWdJluvji5VXXrLkmwj8JvEyerZ1Iyi3Q6Jk42S8783j6qoMyb7r73/dp51SwkQoh19Cak7UoPKgV1wgEcBpetYnpInOMZA6/A9k+6Vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745178046; c=relaxed/simple; bh=edQP+KhuArJze7tr3pDlMhuWrs27WlBNlib9Ik5OOrE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gW/1W8JU892FoDc0fKTj4pylOqgktkY4fVUYZYEQCQ8zZzEiGKsDIEdPd/n0wDQbdBJA4C3hLDVooyEQwiYLq8tYIuVvgcdd7c6IvXHQpYy2QTVw2kUn/oFeqh9MckqX6tIKmHFGAXviE2J/Qvg04e79cS5fGvyt89q/bnX8mKA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YhGGabv2; 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="YhGGabv2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2FE0C4CEE9; Sun, 20 Apr 2025 19:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1745178045; bh=edQP+KhuArJze7tr3pDlMhuWrs27WlBNlib9Ik5OOrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YhGGabv2M2JUAiqhb4gaJbHZgrumRy5ZbjCF1j5VoSRJm2Y0zt5bvDcDCYMd1IPef J5/pZeuxMtxo3EZ4YuLqOyARZC0jQKfUlk1Msh5b10JDMw1MS///7VbAX+bYE/fUdC wvSfjyJQUMOgz/ODgJ1YUPHubIVktA6ig5cSySmvqp4SPW4y6/VpXtzH3waeBrLGbV uJu6DsEu1MlsEx5TIang2rIGG8AMtFbjbve62ci8QcA8wJOnWzJTJXebizCsK9rRxo PacxSgFv0P6jAEJdvaU8txIcwEFmFzlrtN7wJ4rmxCqo1JKDe8MdwEnws4S8f1G8t/ ubUD6m20BXi3Q== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/7] samples/damon: implement a DAMON module for memory tiering Date: Sun, 20 Apr 2025 12:40:30 -0700 Message-Id: <20250420194030.75838-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250420194030.75838-1-sj@kernel.org> References: <20250420194030.75838-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" Implement a sample DAMON module that shows how self-tuned DAMON-based memory tiering can be written. It is a sample since the purpose is to give an idea about how it can be implemented and perform, rather than be used on general production setups. Especially, it supports only two tiers memory setup having only one CPU-attached NUMA node. Signed-off-by: SeongJae Park --- samples/damon/Kconfig | 13 ++++ samples/damon/Makefile | 1 + samples/damon/mtier.c | 167 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 samples/damon/mtier.c diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig index 564c49ed69a2..cbf96fd8a8bf 100644 --- a/samples/damon/Kconfig +++ b/samples/damon/Kconfig @@ -27,4 +27,17 @@ config SAMPLE_DAMON_PRCL =20 If unsure, say N. =20 +config SAMPLE_DAMON_MTIER + bool "DAMON sample module for memory tiering" + depends on DAMON && DAMON_PADDR + help + Thps builds DAMON sample module for memory tierign. + + The module assumes the system is constructed with two NUMA nodes, + which seems as local and remote nodes to all CPUs. For example, + node0 is for DDR5 DRAMs connected via DIMM, while node1 is for DDR4 + DRAMs connected via CXL. + + If unsure, say N. + endmenu diff --git a/samples/damon/Makefile b/samples/damon/Makefile index 7f155143f237..72f68cbf422a 100644 --- a/samples/damon/Makefile +++ b/samples/damon/Makefile @@ -2,3 +2,4 @@ =20 obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D wsse.o obj-$(CONFIG_SAMPLE_DAMON_PRCL) +=3D prcl.o +obj-$(CONFIG_SAMPLE_DAMON_MTIER) +=3D mtier.o diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c new file mode 100644 index 000000000000..3390b7d30c26 --- /dev/null +++ b/samples/damon/mtier.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * memory tiering: migrate cold pages in node 0 and hot pages in node 1 to= node + * 1 and node 0, respectively. Adjust the hotness/coldness threshold aimi= ng + * resulting 99.6 % node 0 utilization ratio. + */ + +#define pr_fmt(fmt) "damon_sample_mtier: " fmt + +#include +#include +#include +#include + +static unsigned long node0_start_addr __read_mostly; +module_param(node0_start_addr, ulong, 0600); + +static unsigned long node0_end_addr __read_mostly; +module_param(node0_end_addr, ulong, 0600); + +static unsigned long node1_start_addr __read_mostly; +module_param(node1_start_addr, ulong, 0600); + +static unsigned long node1_end_addr __read_mostly; +module_param(node1_end_addr, ulong, 0600); + +static int damon_sample_mtier_enable_store( + const char *val, const struct kernel_param *kp); + +static const struct kernel_param_ops enable_param_ops =3D { + .set =3D damon_sample_mtier_enable_store, + .get =3D param_get_bool, +}; + +static bool enable __read_mostly; +module_param_cb(enable, &enable_param_ops, &enable, 0600); +MODULE_PARM_DESC(enable, "Enable of disable DAMON_SAMPLE_MTIER"); + +static struct damon_ctx *ctxs[2]; + +static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote) +{ + struct damon_ctx *ctx; + struct damon_target *target; + struct damon_region *region; + struct damos *scheme; + struct damos_quota_goal *quota_goal; + struct damos_filter *filter; + + ctx =3D damon_new_ctx(); + if (!ctx) + return NULL; + /* + * auto-tune sampling and aggregation interval aiming 4% DAMON-observed + * accesses ratio, keeping sampling interval in [5ms, 10s] range. + */ + ctx->attrs.intervals_goal =3D (struct damon_intervals_goal) { + .access_bp =3D 400, .aggrs =3D 3, + .min_sample_us =3D 5000, .max_sample_us =3D 10000000, + }; + if (damon_select_ops(ctx, DAMON_OPS_PADDR)) + goto free_out; + + target =3D damon_new_target(); + if (!target) + goto free_out; + damon_add_target(ctx, target); + region =3D damon_new_region( + promote ? node1_start_addr : node0_start_addr, + promote ? node1_end_addr : node0_end_addr); + if (!region) + goto free_out; + damon_add_region(region, target); + + scheme =3D damon_new_scheme( + /* access pattern */ + &(struct damos_access_pattern) { + .min_sz_region =3D PAGE_SIZE, + .max_sz_region =3D ULONG_MAX, + .min_nr_accesses =3D promote ? 1 : 0, + .max_nr_accesses =3D promote ? UINT_MAX : 0, + .min_age_region =3D 0, + .max_age_region =3D UINT_MAX}, + /* action */ + promote ? DAMOS_MIGRATE_HOT : DAMOS_MIGRATE_COLD, + 1000000, /* apply interval (1s) */ + &(struct damos_quota){ + /* 200 MiB per sec by most */ + .reset_interval =3D 1000, + .sz =3D 200 * 1024 * 1024, + /* ignore size of region when prioritizing */ + .weight_sz =3D 0, + .weight_nr_accesses =3D 100, + .weight_age =3D 100, + }, + &(struct damos_watermarks){}, + promote ? 0 : 1); /* migrate target node id */ + if (!scheme) + goto free_out; + damon_set_schemes(ctx, &scheme, 1); + quota_goal =3D damos_new_quota_goal( + promote ? DAMOS_QUOTA_NODE_MEM_USED_BP : + DAMOS_QUOTA_NODE_MEM_FREE_BP, + promote ? 9970 : 50); + if (!quota_goal) + goto free_out; + quota_goal->nid =3D 0; + damos_add_quota_goal(&scheme->quota, quota_goal); + filter =3D damos_new_filter(DAMOS_FILTER_TYPE_YOUNG, true, promote); + if (!filter) + goto free_out; + damos_add_filter(scheme, filter); + return ctx; +free_out: + damon_destroy_ctx(ctx); + return NULL; +} + +static int damon_sample_mtier_start(void) +{ + struct damon_ctx *ctx; + + ctx =3D damon_sample_mtier_build_ctx(true); + if (!ctx) + return -ENOMEM; + ctxs[0] =3D ctx; + ctx =3D damon_sample_mtier_build_ctx(false); + if (!ctx) { + damon_destroy_ctx(ctxs[0]); + return -ENOMEM; + } + ctxs[1] =3D ctx; + return damon_start(ctxs, 2, true); +} + +static void damon_sample_mtier_stop(void) +{ + damon_stop(ctxs, 2); + damon_destroy_ctx(ctxs[0]); + damon_destroy_ctx(ctxs[1]); +} + +static int damon_sample_mtier_enable_store( + const char *val, const struct kernel_param *kp) +{ + bool enabled =3D enable; + int err; + + err =3D kstrtobool(val, &enable); + if (err) + return err; + + if (enable =3D=3D enabled) + return 0; + + if (enable) + return damon_sample_mtier_start(); + damon_sample_mtier_stop(); + return 0; +} + +static int __init damon_sample_mtier_init(void) +{ + return 0; +} + +module_init(damon_sample_mtier_init); --=20 2.39.5