From nobody Sat Feb 7 20:44:04 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 EF0E8233711; Sat, 17 Jan 2026 17:53:04 +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=1768672385; cv=none; b=ZZrYjBNJiRnmEAu+P7iCNyEhzs0ad97Ff7Zi/nJVz5CN90oTK5UOiYONWaVf38SRUC8gYIi5oI7nVFGT5/E0ffdluC2kduCf2XWMulh1sME7JkkoF2PcaXc0UkTMIcNlbArFwyFS09VGUf4wBsbqbm2yz9oZB5ckLXk+p+anrag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672385; c=relaxed/simple; bh=AH/DZBwYEbnLl/A558vtilxxCPLZZlZguhHUqR5KoKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LxjLyFCr71TAxk/oxqUxjCH0KR2PkvVicmGx4wnJSquSX1qNb9fRxQM20ymXZSHt0xLLkiTtzYhjwIc4usdfSizjU1jQUsVK1CIB79Zm7QcTHbvYn68qCHo2AUBkAldW+mHBBhptupPePKaUPqpvNTmlWFQS1/vFZusQnV2LrkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uRo/RGFb; 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="uRo/RGFb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3594C19424; Sat, 17 Jan 2026 17:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672384; bh=AH/DZBwYEbnLl/A558vtilxxCPLZZlZguhHUqR5KoKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uRo/RGFb2F1Gvvj5IoUxCZoRDJzJrhCdh704F49bhGjp7psN3RSMgSFfPTx5V5gxX O8huFE/LLrRSypF/OgWTE4yjXVLTV6Sa4MQ+ylPhEPONuEpHmZEMqm7j2g0B6HKAlf diUk1K/CyqRrUiJA7e5RM2L9/nnMN1M/GcGi7+PThcGvG/8yNEJbniYaYg6sw0Yg3b MylR0Xq7YxkgxsHm06EYJ7Cx8kI/sjKrlJhfy2Lo6kycV6JkenhPbFQvy27aoDBf2/ ypSdQJ2r+AGAjcP817uLI0hkpjCeABas7o6uHL7wdA4fqjk9yUl5PJP8nn3AslCz7V 5s8mqpq/NrGRA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/8] mm/damon: remove damon_operations->cleanup() Date: Sat, 17 Jan 2026 09:52:48 -0800 Message-ID: <20260117175256.82826-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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_operations->cleanup() was added for a case that an operation set implementation requires additional cleanups. But no such implementation exists at the moment. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 3 --- mm/damon/core.c | 2 -- mm/damon/paddr.c | 1 - mm/damon/vaddr.c | 1 - 4 files changed, 7 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index e6930d8574d3..bd4c76b126bd 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -607,7 +607,6 @@ enum damon_ops_id { * @apply_scheme: Apply a DAMON-based operation scheme. * @target_valid: Determine if the target is valid. * @cleanup_target: Clean up each target before deallocation. - * @cleanup: Clean up the context. * * DAMON can be extended for various address spaces and usages. For this, * users should register the low level operations for their target address @@ -640,7 +639,6 @@ enum damon_ops_id { * @target_valid should check whether the target is still valid for the * monitoring. * @cleanup_target is called before the target will be deallocated. - * @cleanup is called from @kdamond just before its termination. */ struct damon_operations { enum damon_ops_id id; @@ -656,7 +654,6 @@ struct damon_operations { struct damos *scheme, unsigned long *sz_filter_passed); bool (*target_valid)(struct damon_target *t); void (*cleanup_target)(struct damon_target *t); - void (*cleanup)(struct damon_ctx *context); }; =20 /* diff --git a/mm/damon/core.c b/mm/damon/core.c index 81b998d32074..53514cb712cf 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2859,8 +2859,6 @@ static int kdamond_fn(void *data) damon_destroy_region(r, t); } =20 - if (ctx->ops.cleanup) - ctx->ops.cleanup(ctx); kfree(ctx->regions_score_histogram); kdamond_call(ctx, true); =20 diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 4c2c935d82d6..9bfe48826840 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -373,7 +373,6 @@ static int __init damon_pa_initcall(void) .prepare_access_checks =3D damon_pa_prepare_access_checks, .check_accesses =3D damon_pa_check_accesses, .target_valid =3D NULL, - .cleanup =3D NULL, .apply_scheme =3D damon_pa_apply_scheme, .get_scheme_score =3D damon_pa_scheme_score, }; diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 23ed738a0bd6..40c73adf1946 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -1014,7 +1014,6 @@ static int __init damon_va_initcall(void) .check_accesses =3D damon_va_check_accesses, .target_valid =3D damon_va_target_valid, .cleanup_target =3D damon_va_cleanup_target, - .cleanup =3D NULL, .apply_scheme =3D damon_va_apply_scheme, .get_scheme_score =3D damon_va_scheme_score, }; --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 49EFE299AB1; Sat, 17 Jan 2026 17:53:05 +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=1768672385; cv=none; b=EPVx9FSzS3QTjo/8RAXI9VVTxa2qONJOKAIqLJcgvn4b9mznu4np7knQtZhxlUnMQuIKqAzxqqQa0CwZ4J78qpnQ0t1x5IBdZusTNaxmJ3lqTLsE2c7FayA6o3Nq0k5GGCgWuP7NBwrb5RtdB4Z1R6INOXbL1AXKz3HlKxSE1V0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672385; c=relaxed/simple; bh=KFdeOU1Cqynn16FGkaHhjOKt5M+h0bd+XluHiDK/WQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KdtsSnZo4VTA2k9wP7YlLnHoy6Cttdx/CuptSZZ9kSTCdXNoTDtkZnaJx+g3Ff9Q4TIMtxY4Pg+BKKUmOaL0ywJHNncpXVhct/THFa5yH9KVx7nIrbBl9ftwZbIBpNCTd5c27paj45lJvhkeEj/FInq9xwqbnZkEzDmGNZ+SdsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mJTU5Bsm; 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="mJTU5Bsm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBFEBC2BC86; Sat, 17 Jan 2026 17:53:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672385; bh=KFdeOU1Cqynn16FGkaHhjOKt5M+h0bd+XluHiDK/WQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJTU5BsmjgSpWiQ4aBcyH4NoTiDDamTXPlbz+OYyNaiO4LtArWbnSEFsp9LSoj9t2 BFhSaVj/s2oJEvv8OPmFUxC+wN2SnMf55tmnkKQg+NxGOKLdWqXr2Lh88pYSqWF6k9 MiryKagHnXH6+9+K+F+TQDJdgV2D0HI3SAjXJvdCEYAbjNys02TkwQN6U7ss4osRbF xdFzz3AHs4KVIIbeEbXgUaEauGh/KAUhlWUVwOew5jn6H/ULP+KltyueEh62pkxjZX cv/iQGwQn3Fax2eoIVtcafhXSdeU2edAkWbOtuu/PDuBF5p4dvpoTuTb7cQ5sRXrKl qzMeg+eode2jA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/8] mm/damon/core: cleanup targets and regions at once on kdamond termination Date: Sat, 17 Jan 2026 09:52:49 -0800 Message-ID: <20260117175256.82826-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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" When kdamond terminates, it destroys the regions of the context first, and the targets of the context just before the kdamond main function returns. Because regions are linked inside targets, doing them separately is only inefficient and looks weird. A more serious problem is that the cleanup of the targets is done after damon_ctx->kdamond reset, which is the event that lets DAMON API callers know the kdamond is no longer actively running. That is, some DAMON targets could still exist while kdamond is not running. There are no real problems from this, but this implicit fact could cause subtle racy issues in future. Destroy targets and regions at one. Adding contexts on how the code has evolved in the way. Doing only regions destruction was because putting pids of the targets were done on DAMON API callers. Commit 7114bc5e01cf ("mm/damon/core: add cleanup_target() ops callback") moved the role to be done via operations set on each target destruction. Hence it removed the reason to do only regions cleanup. Commit 3a69f1635769 ("mm/damon/core: destroy targets when kdamond_fn() finish") therefore further destructed targets on kdamond termination time. It was still separated from regions destruction because damon_operations->cleanup() may do additional targets cleanup. Placing the targets destruction after damon_ctx->kdamond reset was just an unnecessary decision of the commit. The previous commit removed damon_operations->cleanup(), so there is no more reason to do destructions of regions and targets separately. Signed-off-by: SeongJae Park --- mm/damon/core.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 53514cb712cf..0c8ac11a49f9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2748,8 +2748,6 @@ static void kdamond_init_ctx(struct damon_ctx *ctx) static int kdamond_fn(void *data) { struct damon_ctx *ctx =3D data; - struct damon_target *t; - struct damon_region *r, *next; unsigned int max_nr_accesses =3D 0; unsigned long sz_limit =3D 0; =20 @@ -2854,10 +2852,7 @@ static int kdamond_fn(void *data) } } done: - damon_for_each_target(t, ctx) { - damon_for_each_region_safe(r, next, t) - damon_destroy_region(r, t); - } + damon_destroy_targets(ctx); =20 kfree(ctx->regions_score_histogram); kdamond_call(ctx, true); @@ -2875,7 +2870,6 @@ static int kdamond_fn(void *data) running_exclusive_ctxs =3D false; mutex_unlock(&damon_lock); =20 - damon_destroy_targets(ctx); return 0; } =20 --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 77CCC29B8DB; Sat, 17 Jan 2026 17:53:05 +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=1768672385; cv=none; b=BvWw1xLcGXYuJzBOUu5s3nqVKd/CUlMQtsQILVhPxAdmiEZEZrqn7D3zb40XphslItt1kggVA+0cPyegxLdS2eumJ0gCAx0gA7Ts2wP32E/FnZa52rlokuTS1yzPXxWLrMDQYUInUsAEfoKFp4bZPv51cZbwUfAooUEZnZ5A8lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672385; c=relaxed/simple; bh=VahmTvFk2dGc/ONa7UpYlxUiKSb/QYQK+lIo3yfJ+G4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lGGmr/Kop8Odsq0Mc86pbfcR6XicgO3eW0e9So1RidNsjqalH1h9Mgta7b/mnVDFNePcDL0qJ1C+x1RwTqLjYlIVb0WXxj59hZrB2A8KSfL+RoqJ6V8scnOEWByw7BRh6GhGnL3nmJ6QbzpBB+0ltaOMmhYObvlzjeyAFf1Dj9o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ifXrQOLf; 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="ifXrQOLf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30628C4CEF7; Sat, 17 Jan 2026 17:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672385; bh=VahmTvFk2dGc/ONa7UpYlxUiKSb/QYQK+lIo3yfJ+G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ifXrQOLf5teMOEqaYYzrF0RAErBT5uPf5a3CvMwFrMrPZwREODTvdkpagpJoa4cc/ qh9vBxRvkgpvUVdl5eEf3RYIWXcNFgsSL3gtHw7AFl+aECUOQ9NEtQOlOcjhiMInoq btOY2x+wHjYy9p1wNRSDsdpRgHDW2mFhIlOltZixLt9ArWBuxqiCRiyVXof4fiOFyg KQA+maCXs2EDprxLbSkr+pI7tQl0X8sAsFeLpM0jv51WbPEE8CeIoeRkK2ta6xw5LV aYTx0paCEOobXX3ahMcUBTMFtdX5Omhs6fZA/mESVDGYXSyQd/MlnjSabFvv2SA9cq TcLcM4DzeWlGA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/8] mm/damon/core: cancel damos_walk() before damon_ctx->kdamond reset Date: Sat, 17 Jan 2026 09:52:50 -0800 Message-ID: <20260117175256.82826-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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_walk() request is canceled after damon_ctx->kdamond is reset. This can make weird situations where damon_is_running() returns false but the DAMON context has the damos_walk() request linked. There was a similar situation for damon_call() requests handling [1], which _was_ able to cause a racy use-after-free bug. Unlike the case of damon_call(), because damos_walk() is always synchronously handled and allows only single request at time, there is no such problematic race cases. But, keeping it as is could stem another subtle race condition bug in future. Avoid that by cancelling the requests before the ->kdamond reset. Note that this change also makes all damon_ctx dependent resource cleanups consistently done before the damon_ctx->kdamond reset. [1] https://lore.kernel.org/20251230014532.47563-1-sj@kernel.org Signed-off-by: SeongJae Park --- mm/damon/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 0c8ac11a49f9..0bed937b1dce 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2856,14 +2856,13 @@ static int kdamond_fn(void *data) =20 kfree(ctx->regions_score_histogram); kdamond_call(ctx, true); + damos_walk_cancel(ctx); =20 pr_debug("kdamond (%d) finishes\n", current->pid); mutex_lock(&ctx->kdamond_lock); ctx->kdamond =3D NULL; mutex_unlock(&ctx->kdamond_lock); =20 - damos_walk_cancel(ctx); - mutex_lock(&damon_lock); nr_running_ctxs--; if (!nr_running_ctxs && running_exclusive_ctxs) --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 2E24F2BE7CD; Sat, 17 Jan 2026 17:53:06 +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=1768672386; cv=none; b=IYV2+x5OeQVsEO6WpNPoqRPRJOaW2AZeKfAF49BzEGQ1DgsgcVap3nymzsQptqoY04zj2+gR4HrIUDLE50+yxJi92oz/eA8V/RHQkSYx7Z7quDDEtSVN1WEw4tD3YEKPv4T592N9siBFeVsL2aVTPnBL67xG10NKNh18mtcXxuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672386; c=relaxed/simple; bh=OpNBmjSVIXZeLwKSC0iBB/4oylJS3GFwqsmSW7MYMwo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z/0d89h3TAsX1fS/aSdhsgUzaGKp8CWu3JB9xwf/vXvyEOwGFXs0dbUjb46EwAbqgS7UKBbRPYblO0wTzU8Z5WbMNKkX4zC5vUVqpN6oX8mY+xkj2W0boxQyEevneSGVC87ZFPJhQLpCwCHShn0zTbVJMc+RK6lDHG8uaRbJ2L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZD+CWFO2; 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="ZD+CWFO2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75CA0C19423; Sat, 17 Jan 2026 17:53:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672386; bh=OpNBmjSVIXZeLwKSC0iBB/4oylJS3GFwqsmSW7MYMwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZD+CWFO2bByzHP1/Ma1LCn2h64LHsI2D7NRiTxOT21csK0eerKc4/8LCnGXSMglka rjIN1W5CEsFQr1PmX7TzAa8uHeMsXK/2T6FnIZQ58Vc2wqOkK7K7C4RoK7iC1oVRX2 skBjw6qjxQjlMTloFm4wiomgLW225lxj0gDjqudo+RhQjxQLirUaT1zhiA+4zX/3lp iiR1FO9o2EkHskCXr/cCc2v4LxzxqJeJAlIdLN4yOO9otcGAOn6VVtkjMX5e/vSLE3 3OvgWAlo5ucZ+lPqpLGMdJGu+QEcw7w0cqhdQ++w3wYsIddpZ5u62oyQSK3N/T7A90 n9hJM8a3GkHcA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/8] mm/damon/core: process damon_call_control requests on a local list Date: Sat, 17 Jan 2026 09:52:51 -0800 Message-ID: <20260117175256.82826-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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" kdamond_call() handles damon_call() requests on the ->call_controls list of damon_ctx, which is shared with damon_call() callers. To protect the list from concurrent accesses while letting the callback function independent of the call_controls_lock, the function does complicated locking operations. For each damon_call_control object on the list, the function removes the control object from the list under locking, invoke the callback of the control object without locking, and then puts the control object back to the list if needed, under locking. It is complicated, and can contend the locks more frequently with other DAMON API caller threads as the number of concurrent callback requests increases. Contention overhead is not a big deal, but the increased race opportunity can make headaches. Simplify the locking sequence by moving all damon_call_control objects from the shared list to a local list at once under the single lock protection, processing the callback requests without locking, and adding back repeat mode controls to the shared list again at once again, again under the single lock protection. This change makes the number of locking in kdamond_call() be always two, regardless of the number of the queued requests. Signed-off-by: SeongJae Park --- mm/damon/core.c | 59 ++++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 0bed937b1dce..54a7ea98340a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2649,48 +2649,31 @@ static void kdamond_usleep(unsigned long usecs) */ static void kdamond_call(struct damon_ctx *ctx, bool cancel) { - struct damon_call_control *control; - LIST_HEAD(repeat_controls); - int ret =3D 0; - - while (true) { - mutex_lock(&ctx->call_controls_lock); - control =3D list_first_entry_or_null(&ctx->call_controls, - struct damon_call_control, list); - mutex_unlock(&ctx->call_controls_lock); - if (!control) - break; - if (cancel) { + struct damon_call_control *control, *next; + LIST_HEAD(controls); + + mutex_lock(&ctx->call_controls_lock); + list_splice_tail_init(&ctx->call_controls, &controls); + mutex_unlock(&ctx->call_controls_lock); + + list_for_each_entry_safe(control, next, &controls, list) { + if (!control->repeat || cancel) + list_del(&control->list); + + if (cancel) control->canceled =3D true; - } else { - ret =3D control->fn(control->data); - control->return_code =3D ret; - } - mutex_lock(&ctx->call_controls_lock); - list_del(&control->list); - mutex_unlock(&ctx->call_controls_lock); - if (!control->repeat) { + else + control->return_code =3D control->fn(control->data); + + if (!control->repeat) complete(&control->completion); - } else if (control->canceled && control->dealloc_on_cancel) { + else if (control->canceled && control->dealloc_on_cancel) kfree(control); - continue; - } else { - list_add(&control->list, &repeat_controls); - } - } - while (true) { - control =3D list_first_entry_or_null(&repeat_controls, - struct damon_call_control, list); - if (!control) - break; - /* Unlink from the repeate_controls list. */ - list_del(&control->list); - if (cancel) - continue; - mutex_lock(&ctx->call_controls_lock); - list_add(&control->list, &ctx->call_controls); - mutex_unlock(&ctx->call_controls_lock); } + + mutex_lock(&ctx->call_controls_lock); + list_splice_tail(&controls, &ctx->call_controls); + mutex_unlock(&ctx->call_controls_lock); } =20 /* Returns negative error code if it's not activated but should return */ --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 9416E2C0F96; Sat, 17 Jan 2026 17:53:06 +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=1768672386; cv=none; b=tk0vd4cZL/gxv1pXif7c+5sfbKSaoLytHa9bmFuYbmDk8GeQPI0rX6+dGdAUdidBklH7k7AOltlsVxb4+yEPjSV9kUyVZobwU3cFfOpt7/27a8UeqDqmVfDMpk5f1aCtYOjRqln7i8UQQeupJx8zdFnJyakGkOITu1/7xVvJGAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672386; c=relaxed/simple; bh=7VEEVzVbGPHB0sjJISOx5ncW5ljPkQ2sov44I7vDx9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdAZI6DXnaWQN7n3GTn+aqY47xPHfvCq2lJajccHcSKlSxLILBrEAsjawYkKg6/D1YbwkuVLlK9J8NzJP4vVMkeOwDPb94cXapgGTCLViiNQIENedeZMGEF4K4RM7l4CHv/RhnWNVNhuqbnsAKH6aaICNntuCmF+XUCqnfpoCng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UfM8M+SM; 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="UfM8M+SM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 315A4C2BC86; Sat, 17 Jan 2026 17:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672386; bh=7VEEVzVbGPHB0sjJISOx5ncW5ljPkQ2sov44I7vDx9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UfM8M+SMAF0BMH7Y/czx8wjsNtMjpK6qxKcFNDq1uAuro2RDz5SmQDhDZgxVcckxW oHwmY7YY24ge4I3TSAexHakUPVxF5vrAGp5nP8D4XeSv7VKXxnUgoDWTcUymeAffMx 0NckojFCHUHeb8fLIHrcNu6uq/iJ2IqsPmeo2Ekf+ivL3Urr9xf+aYwfjF8Aw0lY3t lcmGsuS3MyaIInwmrHaNRVCAmyE81i3+iB9PmT0+XE8giU96meslckBAKAeATVN4Xd h2BPRGje3+TCWCE2KqFOv4VBYRyLAlpGQDPE/IpVlT424mWtGJ8btmG2+kyINbbx4u EpPLhEyy2tD5A== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/8] mm/damon: document damon_call_control->dealloc_on_cancel repeat behavior Date: Sat, 17 Jan 2026 09:52:52 -0800 Message-ID: <20260117175256.82826-6-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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_call_control->dealloc_on_cancel works only when ->repeat is true. But the behavior is not clearly documented. DAMON API callers can understand the behavior only after reading kdamond_call() code. Document the behavior on the kernel-doc comment of damon_call_control. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index bd4c76b126bd..bdca28e15e40 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -663,7 +663,7 @@ struct damon_operations { * @data: Data that will be passed to @fn. * @repeat: Repeat invocations. * @return_code: Return code from @fn invocation. - * @dealloc_on_cancel: De-allocate when canceled. + * @dealloc_on_cancel: If @repeat is true, de-allocate when canceled. * * Control damon_call(), which requests specific kdamond to invoke a given * function. Refer to damon_call() for more details. --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 DCDF72BE647; Sat, 17 Jan 2026 17:53:06 +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=1768672388; cv=none; b=awzpZaQ/vxsVTpuGxHS9RkWUKqPhqZzBH7fNofzd+ttyT2D1oYVtRA5P/a09ozi24AHd8EoU8TZm3GPUCd91C8orejyc9P2BU9mBuhUZHz1AcdVmn0Y3buKsFzGsPdQIyJ9KjBbyzg005ZFkw+kvTTKcSgqtmjlsdOi0zS13b1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672388; c=relaxed/simple; bh=Xy1TOQuzIdfvAfcqzCUwqYv5IDB5V3zJCVUE3twZeQk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p7kA/RXnJ5FCwPEt3Rtf7k+ZnCvEJ3Z988QGyD6fyT6YfgfMzbLzmTZ+iCMG1B5FIABogVzQpELhSxwVoHJmZ6WT0EiQBmAz74NTQ8QV7NFsV3cXfDr0+wei03MT2uZuvt3ha1IGdE4RddPUX3yj+giYsQ8pMuOnC9B4mxqcyIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qXkEbTix; 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="qXkEbTix" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70CCFC19424; Sat, 17 Jan 2026 17:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672386; bh=Xy1TOQuzIdfvAfcqzCUwqYv5IDB5V3zJCVUE3twZeQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qXkEbTixnHyVk3yJ9OgZjXGoQK/cD+60CYlgn4UQIR1mT4RWUQ1VZZtgKDtOaYWEe PgkdBDHBhhevYJxLxqBcMTAd838PemlUmYF8UKzpKQN5QST+zvbt7T47T45BYOTn/9 H8EguF1uJ1LCzMMnEC6aP3qqPi29keM2Uks89J72aYmyEJQ1jBI4CFD2cniIhNsI/7 hPy6murXrIEMhpIHETC4ca7PtuCoxcmkyVYDZIjr3jfYlRMMLnHBl3Gg26tdg8wllO sGFI7862/JoifkJKccnKRTNhv4E3JKTKWETqq9EbDWXFvzTVfvIqsSGSCljrgrDUe8 daGnWPZk1fztA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/8] mm/damon/core: rename damos_filter_out() to damos_core_filter_out() Date: Sat, 17 Jan 2026 09:52:53 -0800 Message-ID: <20260117175256.82826-7-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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 filters are processed on the core layer and operations layer, depending on their types. damos_filter_out() in core.c, which is for only core layer handled filters, can confuse the fact. Rename it to damos_core_filter_out(), to be more explicit about the fact. Signed-off-by: SeongJae Park --- mm/damon/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 54a7ea98340a..ae5b772ceffb 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1813,7 +1813,7 @@ static bool damos_filter_match(struct damon_ctx *ctx,= struct damon_target *t, return matched =3D=3D filter->matching; } =20 -static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, +static bool damos_core_filter_out(struct damon_ctx *ctx, struct damon_targ= et *t, struct damon_region *r, struct damos *s) { struct damos_filter *filter; @@ -1960,7 +1960,7 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, goto update_stat; damon_split_region_at(t, r, sz); } - if (damos_filter_out(c, t, r, s)) + if (damos_core_filter_out(c, t, r, s)) return; ktime_get_coarse_ts64(&begin); trace_damos_before_apply(cidx, sidx, tidx, r, --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 E24E02C159E; Sat, 17 Jan 2026 17:53:06 +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=1768672387; cv=none; b=b4CXmh3nUJPbpTGtdM1NAcfhfPvqqGHpeQz2X+cnvljxlCwljd9AWxXxGLm/uuNZV141ux7KHi2y77FEPZLqpQNN0V8hprMvizaVjYZ3IVini4wXDyGdWl4ni4wSQL5vxrrCWCzeZpFZYVYCHz5pQncsrErbJHKjgcz25QPITOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672387; c=relaxed/simple; bh=euB34KBwMNH0Wmqe09qNX0ZCrnsNrl1erm4orWgN94Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tZbQ4hL7sqDSAXee3JBb81g9cXXPzJcS6jp5w/P2G1vMzjmfw434fa9iCuxXbCE9cGeI/2ebtEgew8OVm7b0OJlVo/LWtXsfo+RG9RmAlCOKwEieyEFpCavcDadjRIRSqeYsxjmqQfaK1IOCnkNSUmPjh5YGcENjzr5KsJkC8/E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XboQCrWp; 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="XboQCrWp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF5BCC4CEF7; Sat, 17 Jan 2026 17:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672386; bh=euB34KBwMNH0Wmqe09qNX0ZCrnsNrl1erm4orWgN94Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XboQCrWpygsXWUjCYZVHfl5v6h5r9fiD6ifKt80zLkTMGFDUSmCGP5PYKYDhHFTgM Tt/u0qYPIMoD+UclftBK5uQdkLia/RsRXVgGT9nS1fqqL2pWnqNKhVmB2tCMQPUXxx OHsj9gfoZnPkc84FvGPlNg4gcIOvFUA9Y0MSuIGZ4r2oDPBhgiEwHq0zANajbp+RLN 3Ex1lNfEyplsnndPlWjavIo2BNqiOo3L5d6eLZ3bgrlQyY9VwogwMFowiI8eyS2XA5 Pje3NQ5m2nDj9V5cv5xVaUUmzrZ977ne5oN+COC1hWjwiHVRsosiuJYL8xF5DJYAEX SqlZ4IPbsCEyg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/8] mm/damon: rename DAMON_MIN_REGION to DAMON_MIN_REGION_SZ Date: Sat, 17 Jan 2026 09:52:54 -0800 Message-ID: <20260117175256.82826-8-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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" The macro is for the default minimum size of each DAMON region. There was a case that a reader was confused if it is the minimum number of total DAMON regions, which is set on damon_attrs->min_nr_regions. Make the name more explicit. Signed-off-by: SeongJae Park --- include/linux/damon.h | 2 +- mm/damon/core.c | 2 +- mm/damon/lru_sort.c | 2 +- mm/damon/reclaim.c | 2 +- mm/damon/sysfs.c | 2 +- mm/damon/tests/vaddr-kunit.h | 2 +- mm/damon/vaddr.c | 24 ++++++++++++------------ 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index bdca28e15e40..5bf8db1d78fe 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -15,7 +15,7 @@ #include =20 /* Minimal region size. Every damon_region is aligned by this. */ -#define DAMON_MIN_REGION PAGE_SIZE +#define DAMON_MIN_REGION_SZ PAGE_SIZE /* Max priority score for DAMON-based operation schemes */ #define DAMOS_MAX_SCORE (99) =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index ae5b772ceffb..5508bc794172 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -553,7 +553,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->attrs.max_nr_regions =3D 1000; =20 ctx->addr_unit =3D 1; - ctx->min_sz_region =3D DAMON_MIN_REGION; + ctx->min_sz_region =3D DAMON_MIN_REGION_SZ; =20 INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index bedb9134d286..9dde096a9064 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -298,7 +298,7 @@ static int damon_lru_sort_apply_parameters(void) if (!monitor_region_start && !monitor_region_end) addr_unit =3D 1; param_ctx->addr_unit =3D addr_unit; - param_ctx->min_sz_region =3D max(DAMON_MIN_REGION / addr_unit, 1); + param_ctx->min_sz_region =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); =20 if (!damon_lru_sort_mon_attrs.sample_interval) { err =3D -EINVAL; diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 55df43e241c5..c343622a2f52 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -208,7 +208,7 @@ static int damon_reclaim_apply_parameters(void) if (!monitor_region_start && !monitor_region_end) addr_unit =3D 1; param_ctx->addr_unit =3D addr_unit; - param_ctx->min_sz_region =3D max(DAMON_MIN_REGION / addr_unit, 1); + param_ctx->min_sz_region =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); =20 if (!damon_reclaim_mon_attrs.aggr_interval) { err =3D -EINVAL; diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 4de25708b05a..57d36d60f329 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1470,7 +1470,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx = *ctx, /* addr_unit is respected by only DAMON_OPS_PADDR */ if (sys_ctx->ops_id =3D=3D DAMON_OPS_PADDR) ctx->min_sz_region =3D max( - DAMON_MIN_REGION / sys_ctx->addr_unit, 1); + DAMON_MIN_REGION_SZ / sys_ctx->addr_unit, 1); err =3D damon_sysfs_set_attrs(ctx, sys_ctx->attrs); if (err) return err; diff --git a/mm/damon/tests/vaddr-kunit.h b/mm/damon/tests/vaddr-kunit.h index 30dc5459f1d2..cfae870178bf 100644 --- a/mm/damon/tests/vaddr-kunit.h +++ b/mm/damon/tests/vaddr-kunit.h @@ -147,7 +147,7 @@ static void damon_do_test_apply_three_regions(struct ku= nit *test, damon_add_region(r, t); } =20 - damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION); + damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ); =20 for (i =3D 0; i < nr_expected / 2; i++) { r =3D __nth_region_of(t, i); diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 40c73adf1946..83ab3d8c3792 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -19,8 +19,8 @@ #include "ops-common.h" =20 #ifdef CONFIG_DAMON_VADDR_KUNIT_TEST -#undef DAMON_MIN_REGION -#define DAMON_MIN_REGION 1 +#undef DAMON_MIN_REGION_SZ +#define DAMON_MIN_REGION_SZ 1 #endif =20 /* @@ -78,7 +78,7 @@ static int damon_va_evenly_split_region(struct damon_targ= et *t, =20 orig_end =3D r->ar.end; sz_orig =3D damon_sz_region(r); - sz_piece =3D ALIGN_DOWN(sz_orig / nr_pieces, DAMON_MIN_REGION); + sz_piece =3D ALIGN_DOWN(sz_orig / nr_pieces, DAMON_MIN_REGION_SZ); =20 if (!sz_piece) return -EINVAL; @@ -161,12 +161,12 @@ static int __damon_va_three_regions(struct mm_struct = *mm, swap(first_gap, second_gap); =20 /* Store the result */ - regions[0].start =3D ALIGN(start, DAMON_MIN_REGION); - regions[0].end =3D ALIGN(first_gap.start, DAMON_MIN_REGION); - regions[1].start =3D ALIGN(first_gap.end, DAMON_MIN_REGION); - regions[1].end =3D ALIGN(second_gap.start, DAMON_MIN_REGION); - regions[2].start =3D ALIGN(second_gap.end, DAMON_MIN_REGION); - regions[2].end =3D ALIGN(prev->vm_end, DAMON_MIN_REGION); + regions[0].start =3D ALIGN(start, DAMON_MIN_REGION_SZ); + regions[0].end =3D ALIGN(first_gap.start, DAMON_MIN_REGION_SZ); + regions[1].start =3D ALIGN(first_gap.end, DAMON_MIN_REGION_SZ); + regions[1].end =3D ALIGN(second_gap.start, DAMON_MIN_REGION_SZ); + regions[2].start =3D ALIGN(second_gap.end, DAMON_MIN_REGION_SZ); + regions[2].end =3D ALIGN(prev->vm_end, DAMON_MIN_REGION_SZ); =20 return 0; } @@ -259,8 +259,8 @@ static void __damon_va_init_regions(struct damon_ctx *c= tx, sz +=3D regions[i].end - regions[i].start; if (ctx->attrs.min_nr_regions) sz /=3D ctx->attrs.min_nr_regions; - if (sz < DAMON_MIN_REGION) - sz =3D DAMON_MIN_REGION; + if (sz < DAMON_MIN_REGION_SZ) + sz =3D DAMON_MIN_REGION_SZ; =20 /* Set the initial three regions of the target */ for (i =3D 0; i < 3; i++) { @@ -299,7 +299,7 @@ static void damon_va_update(struct damon_ctx *ctx) damon_for_each_target(t, ctx) { if (damon_va_three_regions(t, three_regions)) continue; - damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION); + damon_set_regions(t, three_regions, 3, DAMON_MIN_REGION_SZ); } } =20 --=20 2.47.3 From nobody Sat Feb 7 20:44:04 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 2E8F62C21DF; Sat, 17 Jan 2026 17:53: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=1768672387; cv=none; b=Y2ssD0kLVfF14XlVvtM3EZRMUqkPBfP/t7IdMCAc0AwWxdEdGOufV9xE6eDyXHYEk482OmKEvauBb+PU/lPjmQnA02k4Gfamf28UnXQLqEx/rOGUMIVt1h/wqPlLsTVdRgNJW7qBU+7Elim2p+Rw47dM0Z5Wa7SWsvTsgaPTn5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768672387; c=relaxed/simple; bh=eZLadMFQedwAgPWbni+zR0dV+mf8L1sym/xg/ZsD0/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mkZDMpORQLri/dlO4OCPRQKADMsAfEBsev7DsH4hJGn1oQNciofxdtQ/kmO0rCFqPCO1ZDgnWJ+2nPzmcO7kUzwciWWTPDGedJCttC1AVIVEmf8/Q3C6/ycl8r+2IU0Qz/9rsgXa2PSt3IAI8/b5aXmSqdlo1XUITm4eo6iN848= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=egHs3dir; 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="egHs3dir" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8FA9C19423; Sat, 17 Jan 2026 17:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1768672387; bh=eZLadMFQedwAgPWbni+zR0dV+mf8L1sym/xg/ZsD0/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=egHs3dirRF59oNlIYE7tn5Q1hvvkWUAw0w2lN8id4ucjKdiBK1l52DipnrBUqbhSG fs8aSqHBsNQkr5PBOQHb/u5jRiqT9z3dVTLMKs3uYG49dD51he3FYN2BUO0WafX2rJ VH3jbV9+BWgsndWIyOD7dbC3iLZ7nq/bKnEOPgj8nFnr+hnC5NXG9zCqBPuxliUps7 vw21zpSlAkGnXKDQXhVpZsj3ZAo7m/v2Jzzkgc+eWYt6jkwfPohZpU2udwWOnxCj+l IfnbwDvddBUx6TwkqOVFpxC9dxpqlrPlxmFp+yZsprkM6jljiNANlQqVOS4cdD+KRH 4fdYMRWResdPQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 8/8] mm/damon: rename min_sz_region of damon_ctx to min_region_sz Date: Sat, 17 Jan 2026 09:52:55 -0800 Message-ID: <20260117175256.82826-9-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260117175256.82826-1-sj@kernel.org> References: <20260117175256.82826-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" 'min_sz_region' field of 'struct damon_ctx' represents the minimum size of each DAMON region for the context. 'struct damos_access_pattern' has a field of the same name. It confuses readers and makes 'grep' less optimal for them. Rename it to 'min_region_sz'. Signed-off-by: SeongJae Park --- include/linux/damon.h | 8 ++--- mm/damon/core.c | 69 ++++++++++++++++++++++--------------------- mm/damon/lru_sort.c | 4 +-- mm/damon/reclaim.c | 4 +-- mm/damon/stat.c | 2 +- mm/damon/sysfs.c | 9 +++--- 6 files changed, 49 insertions(+), 47 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 5bf8db1d78fe..a4fea23da857 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -773,7 +773,7 @@ struct damon_attrs { * * @ops: Set of monitoring operations for given use cases. * @addr_unit: Scale factor for core to ops address conversion. - * @min_sz_region: Minimum region size. + * @min_region_sz: Minimum region size. * @adaptive_targets: Head of monitoring targets (&damon_target) list. * @schemes: Head of schemes (&damos) list. */ @@ -818,7 +818,7 @@ struct damon_ctx { /* public: */ struct damon_operations ops; unsigned long addr_unit; - unsigned long min_sz_region; + unsigned long min_region_sz; =20 struct list_head adaptive_targets; struct list_head schemes; @@ -907,7 +907,7 @@ static inline void damon_insert_region(struct damon_reg= ion *r, void damon_add_region(struct damon_region *r, struct damon_target *t); void damon_destroy_region(struct damon_region *r, struct damon_target *t); int damon_set_regions(struct damon_target *t, struct damon_addr_range *ran= ges, - unsigned int nr_ranges, unsigned long min_sz_region); + unsigned int nr_ranges, unsigned long min_region_sz); void damon_update_region_access_rate(struct damon_region *r, bool accessed, struct damon_attrs *attrs); =20 @@ -975,7 +975,7 @@ int damos_walk(struct damon_ctx *ctx, struct damos_walk= _control *control); =20 int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end, - unsigned long min_sz_region); + unsigned long min_region_sz); =20 #endif /* CONFIG_DAMON */ =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 5508bc794172..70efbf22a2b4 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -203,7 +203,7 @@ static int damon_fill_regions_holes(struct damon_region= *first, * @t: the given target. * @ranges: array of new monitoring target ranges. * @nr_ranges: length of @ranges. - * @min_sz_region: minimum region size. + * @min_region_sz: minimum region size. * * This function adds new regions to, or modify existing regions of a * monitoring target to fit in specific ranges. @@ -211,7 +211,7 @@ static int damon_fill_regions_holes(struct damon_region= *first, * Return: 0 if success, or negative error code otherwise. */ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ran= ges, - unsigned int nr_ranges, unsigned long min_sz_region) + unsigned int nr_ranges, unsigned long min_region_sz) { struct damon_region *r, *next; unsigned int i; @@ -248,16 +248,16 @@ int damon_set_regions(struct damon_target *t, struct = damon_addr_range *ranges, /* no region intersects with this range */ newr =3D damon_new_region( ALIGN_DOWN(range->start, - min_sz_region), - ALIGN(range->end, min_sz_region)); + min_region_sz), + ALIGN(range->end, min_region_sz)); if (!newr) return -ENOMEM; damon_insert_region(newr, damon_prev_region(r), r, t); } else { /* resize intersecting regions to fit in this range */ first->ar.start =3D ALIGN_DOWN(range->start, - min_sz_region); - last->ar.end =3D ALIGN(range->end, min_sz_region); + min_region_sz); + last->ar.end =3D ALIGN(range->end, min_region_sz); =20 /* fill possible holes in the range */ err =3D damon_fill_regions_holes(first, last, t); @@ -553,7 +553,7 @@ struct damon_ctx *damon_new_ctx(void) ctx->attrs.max_nr_regions =3D 1000; =20 ctx->addr_unit =3D 1; - ctx->min_sz_region =3D DAMON_MIN_REGION_SZ; + ctx->min_region_sz =3D DAMON_MIN_REGION_SZ; =20 INIT_LIST_HEAD(&ctx->adaptive_targets); INIT_LIST_HEAD(&ctx->schemes); @@ -1142,7 +1142,7 @@ static struct damon_target *damon_nth_target(int n, s= truct damon_ctx *ctx) * If @src has no region, @dst keeps current regions. */ static int damon_commit_target_regions(struct damon_target *dst, - struct damon_target *src, unsigned long src_min_sz_region) + struct damon_target *src, unsigned long src_min_region_sz) { struct damon_region *src_region; struct damon_addr_range *ranges; @@ -1159,7 +1159,7 @@ static int damon_commit_target_regions(struct damon_t= arget *dst, i =3D 0; damon_for_each_region(src_region, src) ranges[i++] =3D src_region->ar; - err =3D damon_set_regions(dst, ranges, i, src_min_sz_region); + err =3D damon_set_regions(dst, ranges, i, src_min_region_sz); kfree(ranges); return err; } @@ -1167,11 +1167,11 @@ static int damon_commit_target_regions(struct damon= _target *dst, static int damon_commit_target( struct damon_target *dst, bool dst_has_pid, struct damon_target *src, bool src_has_pid, - unsigned long src_min_sz_region) + unsigned long src_min_region_sz) { int err; =20 - err =3D damon_commit_target_regions(dst, src, src_min_sz_region); + err =3D damon_commit_target_regions(dst, src, src_min_region_sz); if (err) return err; if (dst_has_pid) @@ -1198,7 +1198,7 @@ static int damon_commit_targets( err =3D damon_commit_target( dst_target, damon_target_has_pid(dst), src_target, damon_target_has_pid(src), - src->min_sz_region); + src->min_region_sz); if (err) return err; } else { @@ -1225,7 +1225,7 @@ static int damon_commit_targets( return -ENOMEM; err =3D damon_commit_target(new_target, false, src_target, damon_target_has_pid(src), - src->min_sz_region); + src->min_region_sz); if (err) { damon_destroy_target(new_target, NULL); return err; @@ -1272,7 +1272,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct da= mon_ctx *src) } dst->ops =3D src->ops; dst->addr_unit =3D src->addr_unit; - dst->min_sz_region =3D src->min_sz_region; + dst->min_region_sz =3D src->min_region_sz; =20 return 0; } @@ -1305,8 +1305,8 @@ static unsigned long damon_region_sz_limit(struct dam= on_ctx *ctx) =20 if (ctx->attrs.min_nr_regions) sz /=3D ctx->attrs.min_nr_regions; - if (sz < ctx->min_sz_region) - sz =3D ctx->min_sz_region; + if (sz < ctx->min_region_sz) + sz =3D ctx->min_region_sz; =20 return sz; } @@ -1696,7 +1696,7 @@ static bool damos_valid_target(struct damon_ctx *c, s= truct damon_target *t, * @t: The target of the region. * @rp: The pointer to the region. * @s: The scheme to be applied. - * @min_sz_region: minimum region size. + * @min_region_sz: minimum region size. * * If a quota of a scheme has exceeded in a quota charge window, the schem= e's * action would applied to only a part of the target access pattern fulfil= ling @@ -1714,7 +1714,8 @@ static bool damos_valid_target(struct damon_ctx *c, s= truct damon_target *t, * Return: true if the region should be entirely skipped, false otherwise. */ static bool damos_skip_charged_region(struct damon_target *t, - struct damon_region **rp, struct damos *s, unsigned long min_sz_region) + struct damon_region **rp, struct damos *s, + unsigned long min_region_sz) { struct damon_region *r =3D *rp; struct damos_quota *quota =3D &s->quota; @@ -1736,11 +1737,11 @@ static bool damos_skip_charged_region(struct damon_= target *t, if (quota->charge_addr_from && r->ar.start < quota->charge_addr_from) { sz_to_skip =3D ALIGN_DOWN(quota->charge_addr_from - - r->ar.start, min_sz_region); + r->ar.start, min_region_sz); if (!sz_to_skip) { - if (damon_sz_region(r) <=3D min_sz_region) + if (damon_sz_region(r) <=3D min_region_sz) return true; - sz_to_skip =3D min_sz_region; + sz_to_skip =3D min_region_sz; } damon_split_region_at(t, r, sz_to_skip); r =3D damon_next_region(r); @@ -1766,7 +1767,7 @@ static void damos_update_stat(struct damos *s, =20 static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target = *t, struct damon_region *r, struct damos_filter *filter, - unsigned long min_sz_region) + unsigned long min_region_sz) { bool matched =3D false; struct damon_target *ti; @@ -1783,8 +1784,8 @@ static bool damos_filter_match(struct damon_ctx *ctx,= struct damon_target *t, matched =3D target_idx =3D=3D filter->target_idx; break; case DAMOS_FILTER_TYPE_ADDR: - start =3D ALIGN_DOWN(filter->addr_range.start, min_sz_region); - end =3D ALIGN_DOWN(filter->addr_range.end, min_sz_region); + start =3D ALIGN_DOWN(filter->addr_range.start, min_region_sz); + end =3D ALIGN_DOWN(filter->addr_range.end, min_region_sz); =20 /* inside the range */ if (start <=3D r->ar.start && r->ar.end <=3D end) { @@ -1820,7 +1821,7 @@ static bool damos_core_filter_out(struct damon_ctx *c= tx, struct damon_target *t, =20 s->core_filters_allowed =3D false; damos_for_each_core_filter(filter, s) { - if (damos_filter_match(ctx, t, r, filter, ctx->min_sz_region)) { + if (damos_filter_match(ctx, t, r, filter, ctx->min_region_sz)) { if (filter->allow) s->core_filters_allowed =3D true; return !filter->allow; @@ -1955,7 +1956,7 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { sz =3D ALIGN_DOWN(quota->esz - quota->charged_sz, - c->min_sz_region); + c->min_region_sz); if (!sz) goto update_stat; damon_split_region_at(t, r, sz); @@ -2003,7 +2004,7 @@ static void damon_do_apply_schemes(struct damon_ctx *= c, if (quota->esz && quota->charged_sz >=3D quota->esz) continue; =20 - if (damos_skip_charged_region(t, &r, s, c->min_sz_region)) + if (damos_skip_charged_region(t, &r, s, c->min_region_sz)) continue; =20 if (s->max_nr_snapshots && @@ -2496,7 +2497,7 @@ static void damon_split_region_at(struct damon_target= *t, =20 /* Split every region in the given target into 'nr_subs' regions */ static void damon_split_regions_of(struct damon_target *t, int nr_subs, - unsigned long min_sz_region) + unsigned long min_region_sz) { struct damon_region *r, *next; unsigned long sz_region, sz_sub =3D 0; @@ -2506,13 +2507,13 @@ static void damon_split_regions_of(struct damon_tar= get *t, int nr_subs, sz_region =3D damon_sz_region(r); =20 for (i =3D 0; i < nr_subs - 1 && - sz_region > 2 * min_sz_region; i++) { + sz_region > 2 * min_region_sz; i++) { /* * Randomly select size of left sub-region to be at * least 10 percent and at most 90% of original region */ sz_sub =3D ALIGN_DOWN(damon_rand(1, 10) * - sz_region / 10, min_sz_region); + sz_region / 10, min_region_sz); /* Do not allow blank region */ if (sz_sub =3D=3D 0 || sz_sub >=3D sz_region) continue; @@ -2552,7 +2553,7 @@ static void kdamond_split_regions(struct damon_ctx *c= tx) nr_subregions =3D 3; =20 damon_for_each_target(t, ctx) - damon_split_regions_of(t, nr_subregions, ctx->min_sz_region); + damon_split_regions_of(t, nr_subregions, ctx->min_region_sz); =20 last_nr_regions =3D nr_regions; } @@ -2902,7 +2903,7 @@ static bool damon_find_biggest_system_ram(unsigned lo= ng *start, * @t: The monitoring target to set the region. * @start: The pointer to the start address of the region. * @end: The pointer to the end address of the region. - * @min_sz_region: Minimum region size. + * @min_region_sz: Minimum region size. * * This function sets the region of @t as requested by @start and @end. I= f the * values of @start and @end are zero, however, this function finds the bi= ggest @@ -2914,7 +2915,7 @@ static bool damon_find_biggest_system_ram(unsigned lo= ng *start, */ int damon_set_region_biggest_system_ram_default(struct damon_target *t, unsigned long *start, unsigned long *end, - unsigned long min_sz_region) + unsigned long min_region_sz) { struct damon_addr_range addr_range; =20 @@ -2927,7 +2928,7 @@ int damon_set_region_biggest_system_ram_default(struc= t damon_target *t, =20 addr_range.start =3D *start; addr_range.end =3D *end; - return damon_set_regions(t, &addr_range, 1, min_sz_region); + return damon_set_regions(t, &addr_range, 1, min_region_sz); } =20 /* diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 9dde096a9064..7bc5c0b2aea3 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -298,7 +298,7 @@ static int damon_lru_sort_apply_parameters(void) if (!monitor_region_start && !monitor_region_end) addr_unit =3D 1; param_ctx->addr_unit =3D addr_unit; - param_ctx->min_sz_region =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); + param_ctx->min_region_sz =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); =20 if (!damon_lru_sort_mon_attrs.sample_interval) { err =3D -EINVAL; @@ -345,7 +345,7 @@ static int damon_lru_sort_apply_parameters(void) err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, &monitor_region_end, - param_ctx->min_sz_region); + param_ctx->min_region_sz); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index c343622a2f52..43d76f5bed44 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -208,7 +208,7 @@ static int damon_reclaim_apply_parameters(void) if (!monitor_region_start && !monitor_region_end) addr_unit =3D 1; param_ctx->addr_unit =3D addr_unit; - param_ctx->min_sz_region =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); + param_ctx->min_region_sz =3D max(DAMON_MIN_REGION_SZ / addr_unit, 1); =20 if (!damon_reclaim_mon_attrs.aggr_interval) { err =3D -EINVAL; @@ -251,7 +251,7 @@ static int damon_reclaim_apply_parameters(void) err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, &monitor_region_end, - param_ctx->min_sz_region); + param_ctx->min_region_sz); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); diff --git a/mm/damon/stat.c b/mm/damon/stat.c index 5e18b164f6d8..536f02bd173e 100644 --- a/mm/damon/stat.c +++ b/mm/damon/stat.c @@ -181,7 +181,7 @@ static struct damon_ctx *damon_stat_build_ctx(void) goto free_out; damon_add_target(ctx, target); if (damon_set_region_biggest_system_ram_default(target, &start, &end, - ctx->min_sz_region)) + ctx->min_region_sz)) goto free_out; return ctx; free_out: diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 57d36d60f329..b7f66196bec4 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1365,7 +1365,7 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ct= x, =20 static int damon_sysfs_set_regions(struct damon_target *t, struct damon_sysfs_regions *sysfs_regions, - unsigned long min_sz_region) + unsigned long min_region_sz) { struct damon_addr_range *ranges =3D kmalloc_array(sysfs_regions->nr, sizeof(*ranges), GFP_KERNEL | __GFP_NOWARN); @@ -1387,7 +1387,7 @@ static int damon_sysfs_set_regions(struct damon_targe= t *t, if (ranges[i - 1].end > ranges[i].start) goto out; } - err =3D damon_set_regions(t, ranges, sysfs_regions->nr, min_sz_region); + err =3D damon_set_regions(t, ranges, sysfs_regions->nr, min_region_sz); out: kfree(ranges); return err; @@ -1409,7 +1409,8 @@ static int damon_sysfs_add_target(struct damon_sysfs_= target *sys_target, return -EINVAL; } t->obsolete =3D sys_target->obsolete; - return damon_sysfs_set_regions(t, sys_target->regions, ctx->min_sz_region= ); + return damon_sysfs_set_regions(t, sys_target->regions, + ctx->min_region_sz); } =20 static int damon_sysfs_add_targets(struct damon_ctx *ctx, @@ -1469,7 +1470,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx = *ctx, ctx->addr_unit =3D sys_ctx->addr_unit; /* addr_unit is respected by only DAMON_OPS_PADDR */ if (sys_ctx->ops_id =3D=3D DAMON_OPS_PADDR) - ctx->min_sz_region =3D max( + ctx->min_region_sz =3D max( DAMON_MIN_REGION_SZ / sys_ctx->addr_unit, 1); err =3D damon_sysfs_set_attrs(ctx, sys_ctx->attrs); if (err) --=20 2.47.3