From nobody Thu Oct 2 19:25:11 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 5C4A41F8724; Fri, 12 Sep 2025 02:39:52 +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=1757644792; cv=none; b=uYit3cpVCGpEqRWaMa6V9nQhoFL0GlqxxT1mXWItwyApjHIM5hWTjkk9A3QJAatJLX0wE6rF4guAKMxXHQjJMQuHrsZ0GRBLrahNrZN2zkcdS2jzMOntEzLSud7J3erjlBS1iv3+VeZdJJ5pst2gMr3njMY3xtKEoADiQdockyU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644792; c=relaxed/simple; bh=X2mkDImsPjBINJD3elmssAm/a5Bzpioz6UMPDraKGoo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yj9bFYAxDJCjIHi6CZn85iEZ4Gc1T2kv86VmmqAvARNhVbA9stv3h+YqMW/Q4iVNl4Z8t8g2bWJ1/i+3Cwv0e1dDyBBXEP6sb8VqlpyMCygcEfA9YQFyjFX6FLsSIOByGJ6ZoukOGLNUsxThfByGekRZNkB/2FrOfulEpX5MnPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lSFaup3y; 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="lSFaup3y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA746C4CEF0; Fri, 12 Sep 2025 02:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644791; bh=X2mkDImsPjBINJD3elmssAm/a5Bzpioz6UMPDraKGoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lSFaup3yhbErLVVcQ3JyDhD3QgThJ2y/eTwsFKLs0Ew79FKwirbcC9NP6wWR0A1hv td6a3pMnN00+mIowonlZID9hCkErNLHCUObHEwyl0AEtufejVPAUFsjpmhXYackAQh Ets31DFr9uiO+/XuTvwzVLG+oceoOfgjEF8UDdsnVHaZOVA0rt3bD2UtW4zLmS3EZU IxB1XsFYXHOFTaXEVwyH09yiN2Hp0Czb2WJpSSqYgQH8Du99cSTlkr91uN8nrAwsSz IaPUyA3pamU3Z11yLLN1B9XLq4fGHxuJLCEyEWc+usaiPyNERwenytHnXtZ+Ay5Lv5 lUneBtoIis7Jg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/7] mm/damon/core: implement damon_initialized() function Date: Thu, 11 Sep 2025 19:39:40 -0700 Message-Id: <20250912023946.62337-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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" If DAMON is tried to be used when it is not yet successfully initialized, the caller could be crashed. DAMON core layer is not providing a reliable way to see if it is successfully initialized and therefore ready to be used, though. As a result, DAMON API callers are implementing their own hacks to see it. The hacks simply assume DAMON should be ready on module init time. It is not reliable as DAMON initialization can indeed fail if KMEM_CACHE() fails, and difficult to maintain as those are duplicates. Implement a core layer API function for better reliability and maintainability to replace the hacks with followup commits. Signed-off-by: SeongJae Park --- include/linux/damon.h | 1 + mm/damon/core.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 484b0558f426..0f012b1e39fa 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -941,6 +941,7 @@ static inline unsigned int damon_max_nr_accesses(const = struct damon_attrs *attrs } =20 =20 +bool damon_initialized(void); int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive); int damon_stop(struct damon_ctx **ctxs, int nr_ctxs); bool damon_is_running(struct damon_ctx *ctx); diff --git a/mm/damon/core.c b/mm/damon/core.c index f32034973cc1..38ff417f4eb9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2880,6 +2880,16 @@ void damon_update_region_access_rate(struct damon_re= gion *r, bool accessed, r->nr_accesses++; } =20 +/** + * damon_initialized() - Return if DAMON is ready to be used. + * + * Return: true if DAMON is ready to be used, false otherwise. + */ +bool damon_initialized(void) +{ + return damon_region_cache !=3D NULL; +} + static int __init damon_init(void) { damon_region_cache =3D KMEM_CACHE(damon_region, 0); --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 F080621771C; Fri, 12 Sep 2025 02:39:53 +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=1757644794; cv=none; b=H9yrRg814pAPppKKVxO0Ivs642qwDuvGIwMQxr+IIgkyfbrwpbM4oOytQ6PUJobZzck23hFnaFXv6QSbNXou4nCMO41zzknqOadm0JP2oxL+nhQJcHpRZS4HJAoukjd7Z7B+wrIXXvTqDi3IDvzWNTXpcYRN3lUP78r3JKYJuRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644794; c=relaxed/simple; bh=R6gFcrBZzKhA783iYWMpRMpyvk2yh72AuYFVIUrkO4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=C9RQslIWOv3m8HJMIBi31ABr3ZKsVnrduaoZalOYKL0SYwLRDWS7B0Htt52hbYKA5aQVA4515VdWP/VKx0a79ouWMFVySTHhQOUHPbyRDTXXfa/OibfP+b3M/ApJX7FsJWW0XE3B2B23qM6IqY6IwE7XSP2n6bwAlGr8rqdiWEk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rnqoLcU1; 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="rnqoLcU1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7F47C4CEFA; Fri, 12 Sep 2025 02:39:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644793; bh=R6gFcrBZzKhA783iYWMpRMpyvk2yh72AuYFVIUrkO4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnqoLcU1HwAB3uvX7ReqKrUa2MOea8r/MNoj6WTGGW8PpUYZ5uTjJuKOhBBbMJHxJ /JpGCWYr2X29FYDZhFC/FgHZPEC23na/YaL3P1qHSvAB4vH4dAaBbxk1f6/ixa2shg hFh+a5tFt7YKuLwZ+b6QnTO8Ad04AzaGw6rMQSsABuBeVSgBEEeswPgzpscVI/XJg2 TJNr7DJiLa6cc0ghDf5y3skZGm9pndE+gLeh0Cfnjn6QHIhbT13MGVbr+pFk6btTkc 6xA0vI70JTxkX8ut4Q7cBzANJaO2O3WXpjgXaOP/JFEfjcXFz6wdAE+3NqvP/lxyo6 9XJJF49U7/mHg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/7] mm/damon/stat: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:41 -0700 Message-Id: <20250912023946.62337-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_STAT is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- mm/damon/stat.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/damon/stat.c b/mm/damon/stat.c index c33df0ade183..d8010968bbed 100644 --- a/mm/damon/stat.c +++ b/mm/damon/stat.c @@ -220,8 +220,6 @@ static void damon_stat_stop(void) damon_destroy_ctx(damon_stat_context); } =20 -static bool damon_stat_init_called; - static int damon_stat_enabled_store( const char *val, const struct kernel_param *kp) { @@ -235,7 +233,7 @@ static int damon_stat_enabled_store( if (is_enabled =3D=3D enabled) return 0; =20 - if (!damon_stat_init_called) + if (!damon_initialized()) /* * probably called from command line parsing (parse_args()). * Cannot call damon_new_ctx(). Let damon_stat_init() handle. @@ -256,12 +254,16 @@ static int __init damon_stat_init(void) { int err =3D 0; =20 - damon_stat_init_called =3D true; + if (!damon_initialized()) { + err =3D -ENOMEM; + goto out; + } =20 /* probably set via command line */ if (enabled) err =3D damon_stat_start(); =20 +out: if (err && enabled) enabled =3D false; return err; --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 092F122126D; Fri, 12 Sep 2025 02:39:56 +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=1757644796; cv=none; b=KgKGlu8H4rtahGBfYXODTMO4/GgMq9U5NRC8ITpKxQnp5+MKgv2t5dYKnxyOxIyS5ZHxLXUQA1kW3ex4RzEfwzCjaoFIWyYjLpF1kFMrHBuN6NFfWPApNVxxHy7XFB5/5LUkZtO76u4Z5CgY2rBx+36xwQRnODcU8RSASxEET+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644796; c=relaxed/simple; bh=AfFc3OpSjbhPeNbz+Yb9iOakhYwHCt/NFSR70/mcjZU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RsfjlD8JxEbgjuvuhxHgOfF0OY8d/yeQLjnJJZche3NN7BL9rASkcbneVqkcgOnB45f0EO1bHM/IiNJWeS7LO1PIjIXScSKl34NjjZgywyqIaS1PYmLYpoCm0hlmdKoke5bOXodvDUlHVkdDfbp8cno3smxXdOIMWOVn7EUNeTs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gWP+WhWq; 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="gWP+WhWq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B90A3C4AF09; Fri, 12 Sep 2025 02:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644795; bh=AfFc3OpSjbhPeNbz+Yb9iOakhYwHCt/NFSR70/mcjZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gWP+WhWquO1WX/W82rEURByg7atdHpB5ysqv89RaQhsnxbQvxZStdufL/uh1AoBZu vpCPX9mYSki8cWAg92PU0HBLGnpBT+PpOiEw76eKNpifgDBK1S8oxx+qBZEoHFbVV2 ILgkJTv48hnheIbuLKsm6tthD5Q5wO/swgwyNB0GYv5n0tTgMnavb/bY9PagPYmmj7 XU332+wz2ZApEFqPxkVu2iOsU7V5sidMbjGVUvwxCGFZOKS04OHojuSfhr67nyHIgR 72nIMdLxnC/XsTafgc6MQV86p9xZYKqbi43D/G01ckF9f7eRMLaZDMl0uqv+2wcugw p5ZN6U3uoaYpg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 3/7] mm/damon/reclaim: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:42 -0700 Message-Id: <20250912023946.62337-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_RECLAIM is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- mm/damon/reclaim.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 590f9d6c55ef..7ba3d0f9a19a 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -349,7 +349,7 @@ static int damon_reclaim_enabled_store(const char *val, return 0; =20 /* Called before init function. The function will handle this. */ - if (!ctx) + if (!damon_initialized()) goto set_param_out; =20 err =3D damon_reclaim_turn(enable); @@ -372,8 +372,13 @@ MODULE_PARM_DESC(enabled, =20 static int __init damon_reclaim_init(void) { - int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); + int err; =20 + if (!damon_initialized()) { + err =3D -ENOMEM; + goto out; + } + err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); if (err) goto out; =20 --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 152971D54E3; Fri, 12 Sep 2025 02:39:57 +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=1757644797; cv=none; b=gOVr0N3Pz/Oz/cK/CDTY+tZgIX1L4wrmFxLvJ35uqYRXSlRaAZwM7Vbji+sDIf2A2rNZ8HSHvgYSnZjdl3htQB9aEYG6X3tOyxooEz2DiPlekKPrvvfcR/IUGv1okk7MOJ0olT22m/UaOr91FUyDOdgoTzsdUl6hH1EPGQBHCTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644797; c=relaxed/simple; bh=jSyChxhp2q57cPUh41M0fEVHkYfztaaT3v+fVBcDkyE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DNmJSbCJrta81Ci6WOXYp4TYhsMMzI3xweAX+uspMWdf9HQa6gzcDDkkVuaum6P8v1QeLMMCH5IjqUtdFs1RAJSmv54qPdvdcoLbCAxVQu3ePogiCDodLVQm54vr6bOp4PUaBuy3r2e+jVSgCZdGEF6Bm0B1QEv8orf3cJxrrHc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pIZejVwd; 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="pIZejVwd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C407EC4CEF5; Fri, 12 Sep 2025 02:39:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644796; bh=jSyChxhp2q57cPUh41M0fEVHkYfztaaT3v+fVBcDkyE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pIZejVwd7XS4Ox9Am4KGnyKBX3HhSNWV+MeIMCEHwd+JisNA8vBa+ZoK/xxPCS566 NtoaYCUPFFoYgYs7gkzrx4XBtTfEjQYdXf+O5Zj85rWQBJk2nnEmQAIV0qvmMS1NhW YhYLy1w4PGuqxbyn1HyR2OA6DoKZdie75UduINMCXVwfpKZ6jh3vVBHWQkPcLFXJoS exO532i/QkVnkBu/8B1xOeYqKqZFUiHlvfVzHQevIw5WSuFdinlIjwDDQsuclhYPgT otf7PQvW9yeN4NGD6cCozpavPfP7/QLxd9OmlMIbPdq20xiMfsvoK14UxlfPRAysex 2PyMn7solWsag== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 4/7] mm/damon/lru_sort: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:43 -0700 Message-Id: <20250912023946.62337-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_LRU_SORT is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index ab6173a646bd..42b9a656f9de 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -345,7 +345,7 @@ static int damon_lru_sort_enabled_store(const char *val, return 0; =20 /* Called before init function. The function will handle this. */ - if (!ctx) + if (!damon_initialized()) goto set_param_out; =20 err =3D damon_lru_sort_turn(enable); @@ -368,8 +368,13 @@ MODULE_PARM_DESC(enabled, =20 static int __init damon_lru_sort_init(void) { - int err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); + int err; =20 + if (!damon_initialized()) { + err =3D -ENOMEM; + goto out; + } + err =3D damon_modules_new_paddr_ctx_target(&ctx, &target); if (err) goto out; =20 --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 352522264CC; Fri, 12 Sep 2025 02:39:58 +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=1757644798; cv=none; b=DHBPgItbNrjRQquwMwI+6OiHjLBsOfmd19xdS2Ni9SR+/hNbIPYBDz1kHv2hSxWhYpfAYq/tLToiFfVhtOrXU8MXjJN2eDahcFZV3g7krpJZNlXMUAcEfC3dlNwLTRjJrJyrCzx/YM5xkJJEb6Rc2vKYBqgSswc6NaRHGK28wOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644798; c=relaxed/simple; bh=2demp7SZfocNtJOdY3h9yRpOtgZXlewJOxyAe06bXV0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SA76tR0PBMOfpYqCDwoNlpeG2rL9WGzEak0COE0kLSYcQVHJh2himvjrQbtV+M3rvwsyXqMR+TLSqAv5PuwZakse7vxJp0apy8wp/fW/b5yy5zNpVc2kvxIBLkCWEEBAjjfVANzhdhbrENUDe7Z6f3p6wrkYh0Ij+kqSgT/H7mI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gOIbux2e; 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="gOIbux2e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D87F9C4CEF5; Fri, 12 Sep 2025 02:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644798; bh=2demp7SZfocNtJOdY3h9yRpOtgZXlewJOxyAe06bXV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gOIbux2e0xlvP/53qMivwnlzSiSL0JxQL4XPTJ4+nyltrcm+59hn/qclLbE38UyAW M8LgW3jzBIZzUHayt/fyxX28Imlt5+C1IwEzf5Nm1RLLCPYUdxlebddkLPkM5vrWz3 88pdwTGRsQJpFW2P8Y6WCZ78ygE3mfEtfi6sQmRvboSCcTFNraK8887PPkiDk/lZzh W0UZ/fvLYHfpbDadSfsJUAUCxUCwe5kYdr7qIICUkkpQnfF1Tt79jC0OA6OWvt4Bgm 7t2YWtwEkf0Gmpq4hb+TaQUPltp7fSaUz5XFHu5q/DPWtx+qBSPfagidJWW/vTfLPJ MnWtxgppmk1SA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 5/7] samples/damon/wsse: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:44 -0700 Message-Id: <20250912023946.62337-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_sample_wsse is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 21eaf15f987d..799ad4443943 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -102,8 +102,6 @@ static void damon_sample_wsse_stop(void) } } =20 -static bool init_called; - static int damon_sample_wsse_enable_store( const char *val, const struct kernel_param *kp) { @@ -117,10 +115,10 @@ static int damon_sample_wsse_enable_store( if (enabled =3D=3D is_enabled) return 0; =20 - if (enabled) { - if (!init_called) - return 0; + if (!damon_initialized()) + return 0; =20 + if (enabled) { err =3D damon_sample_wsse_start(); if (err) enabled =3D false; @@ -134,7 +132,12 @@ static int __init damon_sample_wsse_init(void) { int err =3D 0; =20 - init_called =3D true; + if (!damon_initialized()) { + err =3D -ENOMEM; + if (enabled) + enabled =3D false; + } + if (enabled) { err =3D damon_sample_wsse_start(); if (err) --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 7598C2356C7; Fri, 12 Sep 2025 02:39:59 +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=1757644799; cv=none; b=Xws2CB0NQumvExc/zRl8YxYcfiglDn+sVsXml7JEIxzTRmZUawHr/9blRQFdiceQUM9Jflmo5UdqT9regEVlgOt6aFFnY6pAFQNZMR50PR9p/QV37cpXxHU6Gbfq0Nlo89MtzeNGBdJyJRr4k+rUpBLw2yo0RAgDcQzKEReP5dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644799; c=relaxed/simple; bh=8oAmMgNUvcFWbF3KtriZccsEdzvp1RE+WJ1o1RTAqkA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WF4ORJzaOy4Ov3acJ/ZCJsc6aqfyq4ne1xA0KkOED+PtYEozIXbq95Vh/gsYSYyFL8QfRvtQExwb7XU3BzNw3jrrcjw3TPALIO8XWM62rQyGf3wSPUKNzlF8ZS/HYk6BgubvbXU7L41cXs7rrgZFEyRCj0JjgRIgBszkjPGkeVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nrQP2Ut0; 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="nrQP2Ut0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3470C4CEF9; Fri, 12 Sep 2025 02:39:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644799; bh=8oAmMgNUvcFWbF3KtriZccsEdzvp1RE+WJ1o1RTAqkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nrQP2Ut0hwY/MhhOlAvITAVSfwisKYhr7P7gIhhQlAo5rvPkQWR+COGMkiiKG0wrC mixl2/Kg283jtZRQ4BPLkmIlSZwe+tJOR7Bv7RZVMAmG+eggPJPeCPGR/sjik3HL7O GVtgRbvPCXn8Rid6/18Sr0DMDkMexf42L8UYny9Bvw0GT7bxJd5fpVOpkPzfDUB1/Y +HICj2zVncflQ9k0b6LVXkKdJrXNRG0NGbFAYvD9k25ohKppNBb2UHiGlevfSXbupv z/i9Eb3uKUPZ8rn4dsShJZ4+yOFbtllaswJuTDs847cTDOFdL1YqTyLLKybieSop8z BqpNelbbs3EQQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 6/7] samples/damon/prcl: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:45 -0700 Message-Id: <20250912023946.62337-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_sample_prcl is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- samples/damon/prcl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c index 0226652f94d5..b7c50f2656ce 100644 --- a/samples/damon/prcl.c +++ b/samples/damon/prcl.c @@ -122,8 +122,6 @@ static void damon_sample_prcl_stop(void) } } =20 -static bool init_called; - static int damon_sample_prcl_enable_store( const char *val, const struct kernel_param *kp) { @@ -137,7 +135,7 @@ static int damon_sample_prcl_enable_store( if (enabled =3D=3D is_enabled) return 0; =20 - if (!init_called) + if (!damon_initialized()) return 0; =20 if (enabled) { @@ -154,7 +152,12 @@ static int __init damon_sample_prcl_init(void) { int err =3D 0; =20 - init_called =3D true; + if (!damon_initialized()) { + if (enabled) + enabled =3D false; + return -ENOMEM; + } + if (enabled) { err =3D damon_sample_prcl_start(); if (err) --=20 2.39.5 From nobody Thu Oct 2 19:25:11 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 7553F23ABBE; Fri, 12 Sep 2025 02:40:00 +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=1757644800; cv=none; b=N3OsCwWR/KgrPy5nzKIo4L4Q2DCte+b2aH+gMg38Uh/1Lq1bm5z5Ba1GqFKxDS3FEOWPKYDvd1XDiO2ZOJ1dsPFJmE16ZJQScOVmDbFxfBDKXvGO3pA+3cBJkXq1gBvwKGcgSD9qSMHiLM8FXgVNbixedj9790Vg0kaMUv+R5bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757644800; c=relaxed/simple; bh=4uQscG4mYr4g+dERacoLlCCtLcp3o3ScovLzzqmdpAo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OM3qbs12yywPnKKYsGR9eunq3iItubpUWof/BpFe/ArXHNvbui0/xm/zRvSdgNpGPPfQLXdFuhXZA7fcEU95VM6ge8M3uADhpQDWJlxWufxUMV7lhlJ9YxCuEgwIsUPk/+bh+gcCLWMoJgeukxcLV1Fb5t32TeqmRrH2fWZzoRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jknMytDh; 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="jknMytDh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CF9CC4CEF1; Fri, 12 Sep 2025 02:40:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757644800; bh=4uQscG4mYr4g+dERacoLlCCtLcp3o3ScovLzzqmdpAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jknMytDhn7nH98vCJ2dHC23SjVhQsA7hX+cBhn4LpIR29BoB46OaU5hnMA1/Qzgo9 nqj+qbImVWHWeUwPwbCQReUvKwxq89ndr53Z2gXBpCFQl2J4S0zkQo0OPuWvgnjuUL 7czcLLS3K1iZjTLeysSyJJGWTkmWo+HPNar+zD7snR/EhsfupSTmRtMpVjfQJnkkd5 AUvtI55YVd0NxkNULBTEWG8CDdyzULDgdmO78DOe2uPNFYWt+UV68i61p5MficOXMX eKGaW5X4GzuKz+bZAqTAXUga9ErisdgD3M4JpamvPRA0i0gkJzDIO9XxAZ+fPUjoy2 N2iNk7JcRnxMg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 7/7] samples/damon/mtier: use damon_initialized() Date: Thu, 11 Sep 2025 19:39:46 -0700 Message-Id: <20250912023946.62337-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250912023946.62337-1-sj@kernel.org> References: <20250912023946.62337-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_sample_mtier is assuming DAMON is ready to use in module_init time, and uses its own hack to see if it is the time. Use damon_initialized(), which is a way for seeing if DAMON is ready to be used that is more reliable and better to maintain instead of the hack. Signed-off-by: SeongJae Park --- samples/damon/mtier.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c index beaf36657dea..775838a23d93 100644 --- a/samples/damon/mtier.c +++ b/samples/damon/mtier.c @@ -193,8 +193,6 @@ static void damon_sample_mtier_stop(void) damon_destroy_ctx(ctxs[1]); } =20 -static bool init_called; - static int damon_sample_mtier_enable_store( const char *val, const struct kernel_param *kp) { @@ -208,7 +206,7 @@ static int damon_sample_mtier_enable_store( if (enabled =3D=3D is_enabled) return 0; =20 - if (!init_called) + if (!damon_initialized()) return 0; =20 if (enabled) { @@ -225,7 +223,12 @@ static int __init damon_sample_mtier_init(void) { int err =3D 0; =20 - init_called =3D true; + if (!damon_initialized()) { + if (enabled) + enabled =3D false; + return -ENOMEM; + } + if (enabled) { err =3D damon_sample_mtier_start(); if (err) --=20 2.39.5