From nobody Thu Dec 18 19:05:18 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 DC38825D1FA; Thu, 6 Mar 2025 17:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283953; cv=none; b=looke3+2iPGn9J1iSNq41hzEidANhXgNPDx/peM0JkjY8U3YM9ciim3NHkakLaCuHL1nrdNVGF2yvfCQveuU1nwZXYge7S2cgAWWDm3D1szqZVSc5U8I0Grhiz3mGE4zUwFNdmrK6fgX+CHNB5kDUxLvwwK1f4pEVq3Z2jnUrWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283953; c=relaxed/simple; bh=s3K1j/KtFWFlfZ4nT5daB6KeJd16T5I6BVsvRI8TnBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sCcycR+c/mr5mjiqwZwSiozhziz2vIO4IccWBjI0JdOLEXtq+7pdgTcnZat/Kv8YGY/8DtMfYXVkt9h5be1wNPekJTnADUKwH3DgxSo4i6s9ZDWZk7fKdEOZd8WoKNT+7nqJlmtVA/6KiJTYIeH60NgHVOH6XQ6sBmcPWHLqbhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r2YlYirJ; 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="r2YlYirJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 891C2C4AF09; Thu, 6 Mar 2025 17:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283953; bh=s3K1j/KtFWFlfZ4nT5daB6KeJd16T5I6BVsvRI8TnBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2YlYirJHFp/wJtVUL7tffYgMhDwY2Ik+mZkg4cYEO2+Cp0OBou2I0OjZMh+T4caT ypz2HqLqrukRM8jMWJkTsEofWtapkCQog8j6CZJcSiDFoik7gQASwHwRfMlN/kSN06 MDivW6nDcqzWWg+Xnn68/8X5BHHcGc9m2FUz1CuKZghmvpUD+rZNwYLdN9yq/CX+sF AstH6vhqHhTlpRiuh593cNXH7v0O3dnKFQqhnnUudFiGGrONwzfjrrM79OGKegO2g2 zmyK+gfhK+3oHGsyKk7aTz9wVbF/zubx1wZW7wku1tS9NSPtyLwvcSi8633R6LJdFc ZE3c5WwcJUyXA== 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 01/13] mm/damon/sysfs: validate user inputs from damon_sysfs_commit_input() Date: Thu, 6 Mar 2025 09:58:56 -0800 Message-Id: <20250306175908.66300-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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" Online DAMON parameters commit via DAMON sysfs interface can make kdamond stop. This behavior was made because it can make the implementation simpler. The implementation tries committing the parameter without validation. If it finds something wrong in the middle of the parameters update, it returns error without reverting the partially committed parameters back. It is safe though, since it immediately breaks kdamond main loop in the case of the error return. Users can make the wrong parameters by mistake, though. Stopping kdamond in the case is not very useful behavior. Also this makes it difficult to utilize damon_call() instead of damon_callback hook for online parameters update, since damon_call() cannot immediately break kdamond main loop in the middle. Validate the input parameters and return error when it fails before starting parameters updates. In case of mistakenly wrong parameters, kdamond can continue running with the old and valid parameters. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index ccd435d234b9..87e4c6e3614e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1449,11 +1449,11 @@ static struct damon_ctx *damon_sysfs_build_ctx( * damon_sysfs_commit_input() - Commit user inputs to a running kdamond. * @kdamond: The kobject wrapper for the associated kdamond. * - * If the sysfs input is wrong, the kdamond will be terminated. + * Returns error if the sysfs input is wrong. */ static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) { - struct damon_ctx *param_ctx; + struct damon_ctx *param_ctx, *test_ctx; int err; =20 if (!damon_sysfs_kdamond_running(kdamond)) @@ -1465,7 +1465,15 @@ static int damon_sysfs_commit_input(struct damon_sys= fs_kdamond *kdamond) param_ctx =3D damon_sysfs_build_ctx(kdamond->contexts->contexts_arr[0]); if (IS_ERR(param_ctx)) return PTR_ERR(param_ctx); + test_ctx =3D damon_new_ctx(); + err =3D damon_commit_ctx(test_ctx, param_ctx); + if (err) { + damon_sysfs_destroy_targets(test_ctx); + damon_destroy_ctx(test_ctx); + goto out; + } err =3D damon_commit_ctx(kdamond->damon_ctx, param_ctx); +out: damon_sysfs_destroy_targets(param_ctx); damon_destroy_ctx(param_ctx); return err; --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 75D14269B12; Thu, 6 Mar 2025 17:59:15 +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=1741283956; cv=none; b=oM/AdyqCmNv0xo5RLnOfQLVsGTHdod3kpaC/XJlxNo5626sdRySsmXgrfvHC/ErXf5dOtZht7n6eLXXeyrjJAXPb7mg6i6YOqSIeAsYgknqXc4y83XtUCKhF8OTa5oBcUZ4fSDLPvAFWJ/B//ugRzfE+IuC10079GWUlKJfD3JM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283956; c=relaxed/simple; bh=6yhiLeZVnkzlh7XNHP1rZ66eAWt0hQYEE7Tzfoyu2CA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZoKAKP1MUrXE5ABdGXmFJhB68vm92td9X6NEMMsnqeoSRQaoUDaltkWXfdBLipwKXbEq5dm3gBKkCwQgq1tHsqS1OeKpq1Dn4MVhsL8gVUzzftbm44Jr7kdcH2q9BUk3GRNYGjAgZKXas7OkzcUshA3Aq2blnf/6jnh5iVEwLOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IcOdR4Zg; 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="IcOdR4Zg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEA6DC4CEED; Thu, 6 Mar 2025 17:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283954; bh=6yhiLeZVnkzlh7XNHP1rZ66eAWt0hQYEE7Tzfoyu2CA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IcOdR4ZgX3pF0zydkdFYbvcNF8I6BWC4h0hLsZ4eAATAfrwMOQ8iPaGtVgc2B78JK ndPixVzJSQS3l48cnI+td3Sz0FbmKXrIUocmqDhFloYJIoyUliNhCM4MKvVov0a9u+ yOc7JlG8NHMx1bE7fl73nGp5PkU5AY/BblnWeivpN4h8qlrhha5n8LS2Gh9+U0xqI0 RxsI/AxsEpEIBZjnWOTsgdv9pik+TtS7FumTIOnWaCUTo5rL2PmROIPb18mbZAdSNl w9Vy+uFxq+f3VfdpjXtjZVCUlBS0J8dOBwGtsIdEnFk6d+EftvapsfFgk5EVOLq+QV aw5oOYQqHKVdQ== 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 02/13] mm/damon/core: invoke kdamond_call() after merging is done if possible Date: Thu, 6 Mar 2025 09:58:57 -0800 Message-Id: <20250306175908.66300-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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() callers may iterate the regions, so better to call it when the number of regions is as small as possible. It is when kdamond_merge_regions() is finished. Invoke it on the point. This change is also aimed to make future changes for carrying online parameters commit with damon_call() easier. The commit operation should be able to make sequence between other aggregation interval based operations including regioins merging and aggregation reset. Placing damon_call() invocation after the regions merging makes the sequence handling simpler. Signed-off-by: SeongJae Park --- mm/damon/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index d4fc2c907cfc..0f359b4ebf1a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2420,7 +2420,6 @@ static int kdamond_fn(void *data) if (ctx->callback.after_sampling && ctx->callback.after_sampling(ctx)) break; - kdamond_call(ctx, false); =20 kdamond_usleep(sample_interval); ctx->passed_sample_intervals++; @@ -2438,9 +2437,10 @@ static int kdamond_fn(void *data) } =20 /* - * do kdamond_apply_schemes() after kdamond_merge_regions() if - * possible, to reduce overhead + * do kdamond_call() and kdamond_apply_schemes() after + * kdamond_merge_regions() if possible, to reduce overhead */ + kdamond_call(ctx, false); if (!list_empty(&ctx->schemes)) kdamond_apply_schemes(ctx); else --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 9661426A1D8; Thu, 6 Mar 2025 17:59:16 +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=1741283957; cv=none; b=t94e05hfsWqE0scMD4PXOtL6lKAgUJe4xYVUiBfvrLw/kMiNXMbZOSV8OZtvFwdKcYsILNCd3wT8iIB6LvjRoMudRYWvt15VF04M49ejpMh09BH0KiygYa0SdEDgyxF3oK6ZIqRMllbKyNujEAGxnchDCuCkZvKwynRialbiTN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283957; c=relaxed/simple; bh=xWjhCxNDcVvgRyq+QB/ZEVdI2Y9i2Y/Y3beU15kO7Bg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i5OG51IzPULIwEbidHeZSvihie4fylgs2tduts9ZDdBYdV+/WAYpQKhIFg9bER+j59KkQPvJcKmPPmRxocMa3ukxZKZzg+uY/oMSWdelI4o9WPxWq7wfhKbc6VL+RJIJrIq+KQBYCXeCE6dmYzm+6Fz5UeOQJ6UbAz4u20rKLfA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OAqr6+Ts; 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="OAqr6+Ts" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6772C4CEEB; Thu, 6 Mar 2025 17:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283956; bh=xWjhCxNDcVvgRyq+QB/ZEVdI2Y9i2Y/Y3beU15kO7Bg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OAqr6+TsOPNYIpJLR2VqTCMMLcMDQrYmEIqMUWvCJAJiKhrVo5H30b4CCRxLVnSJk GJWKg6sOMW+nVChnR6VIdqyq2KagbdswAvM+w+vRrNbmMiT6d45hmb0rcGfUEUzQxV gS+zjda5aMT7X5IB9FReABTZAdT3IGynshnJXABmCvsmM+1vIxpdRq7IdhAVT3EJ58 lDRPM1awE5pI6M8H+GTXvxm1Abob0R0yBi3E7IWDl+QhcFXVLarK7m4vrN6GbXipXV dfi6cFKhw3lt+34rTPZdYO7DOUMFnxUoefthMnPoVcquiy0SQCMZ+4xo2jyAu1geEr 3PcvV0K/H7SQg== 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 03/13] mm/damon/core: make damon_set_attrs() be safe to be called from damon_call() Date: Thu, 6 Mar 2025 09:58:58 -0800 Message-Id: <20250306175908.66300-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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" Currently all DAMON kernel API callers do online DAMON parameters commit from damon_callback->after_aggregation because only those are safe place to call the DAMON monitoring attributes update function, namely damon_set_attrs(). Because damon_callback hooks provide no synchronization, the callers work in asynchronous ways or implement their own inefficient and complicated synchronization mechanisms. It also means online DAMON parameters commit can take up to one aggregation interval. On large systems having long aggregation intervals, that can be too slow. The synchronization can be done in more efficient and simple way while removing the latency constraint if it can be done using damon_call(). The fact that damon_call() can be executed in the middle of the aggregation makes damon_set_attrs() unsafe to be called from it, though. Two real problems can occur in the case. First, converting the not yet completely aggregated nr_accesses for new user-set intervals can arguably degrade the accuracy or at least make the logic complicated. Second, kdamond_reset_aggregated() will not be called after the monitoring results update, so next aggregation starts from unclean state. This can result in inconsistent and unexpected nr_accesses_bp. Make it safe as follows. Catch the middle-of-the-aggregation case from damon_set_attrs() by checking the passed_sample_intervals and next_aggregationsis of the context. And pass the information to nr_accesses conversion logic. The logic works as before if it is not the case (called after the current aggregation is completed). If it is the case (committing parameters in the middle of the aggregation), it drops the nr_accesses information that so far aggregated, and make the status same to the beginning of this aggregation, but as if the last aggregation was started with the updated sampling/aggregation intervals. The middle-of-aggregastion check introduce yet another edge case, though. This happens because kdamond_tune_intervals() can also call damon_set_attrs() with the middle-of-aggregation check. Consider damon_call() for parameters commit and kdamond_tune_intervals() are called in same iteration of kdamond main loop. Because kdamond_tune_interval() is called for aggregation intervals, it should be the end of the aggregation. The first damon_set_attrs() call from kdamond_call() understands it is the end of the aggregation and correctly handle it. But, because the damon_set_attrs() updated next_aggregation_sis of the context. Hence, the second damon_set_attrs() invocation from kdamond_tune_interval() believes it is called in the middle of the aggregation. It therefore resets aggregated information so far. After that, kdamond_reset_interval() is called and double-reset the aggregated information. Avoid this case, too, by setting the next_aggregation_sis before kdamond_tune_intervals() is invoked. Signed-off-by: SeongJae Park --- mm/damon/core.c | 56 +++++++++++++++++++++++++++++-------- mm/damon/tests/core-kunit.h | 6 ++-- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 0f359b4ebf1a..de30b788e13a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -603,11 +603,25 @@ static unsigned int damon_nr_accesses_for_new_attrs(u= nsigned int nr_accesses, } =20 static void damon_update_monitoring_result(struct damon_region *r, - struct damon_attrs *old_attrs, struct damon_attrs *new_attrs) + struct damon_attrs *old_attrs, struct damon_attrs *new_attrs, + bool aggregating) { - r->nr_accesses =3D damon_nr_accesses_for_new_attrs(r->nr_accesses, - old_attrs, new_attrs); - r->nr_accesses_bp =3D r->nr_accesses * 10000; + if (!aggregating) { + r->nr_accesses =3D damon_nr_accesses_for_new_attrs( + r->nr_accesses, old_attrs, new_attrs); + r->nr_accesses_bp =3D r->nr_accesses * 10000; + } else { + /* + * if this is called in the middle of the aggregation, reset + * the aggregations we made so far for this aggregation + * interval. In other words, make the status like + * kdamond_reset_aggregated() is called. + */ + r->last_nr_accesses =3D damon_nr_accesses_for_new_attrs( + r->last_nr_accesses, old_attrs, new_attrs); + r->nr_accesses_bp =3D r->last_nr_accesses * 10000; + r->nr_accesses =3D 0; + } r->age =3D damon_age_for_new_attrs(r->age, old_attrs, new_attrs); } =20 @@ -620,7 +634,7 @@ static void damon_update_monitoring_result(struct damon= _region *r, * ->nr_accesses and ->age of given damon_ctx's regions for new damon_attr= s. */ static void damon_update_monitoring_results(struct damon_ctx *ctx, - struct damon_attrs *new_attrs) + struct damon_attrs *new_attrs, bool aggregating) { struct damon_attrs *old_attrs =3D &ctx->attrs; struct damon_target *t; @@ -635,7 +649,7 @@ static void damon_update_monitoring_results(struct damo= n_ctx *ctx, damon_for_each_target(t, ctx) damon_for_each_region(r, t) damon_update_monitoring_result( - r, old_attrs, new_attrs); + r, old_attrs, new_attrs, aggregating); } =20 /* @@ -662,10 +676,10 @@ static bool damon_valid_intervals_goal(struct damon_a= ttrs *attrs) * @ctx: monitoring context * @attrs: monitoring attributes * - * This function should be called while the kdamond is not running, or an - * access check results aggregation is not ongoing (e.g., from - * &struct damon_callback->after_aggregation or - * &struct damon_callback->after_wmarks_check callbacks). + * This function should be called while the kdamond is not running, an acc= ess + * check results aggregation is not ongoing (e.g., from &struct + * damon_callback->after_aggregation or &struct + * damon_callback->after_wmarks_check callbacks), or from damon_call(). * * Every time interval is in micro-seconds. * @@ -676,6 +690,8 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon= _attrs *attrs) unsigned long sample_interval =3D attrs->sample_interval ? attrs->sample_interval : 1; struct damos *s; + bool aggregating =3D ctx->passed_sample_intervals < + ctx->next_aggregation_sis; =20 if (!damon_valid_intervals_goal(attrs)) return -EINVAL; @@ -696,7 +712,7 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon= _attrs *attrs) ctx->next_ops_update_sis =3D ctx->passed_sample_intervals + attrs->ops_update_interval / sample_interval; =20 - damon_update_monitoring_results(ctx, attrs); + damon_update_monitoring_results(ctx, attrs, aggregating); ctx->attrs =3D *attrs; =20 damon_for_each_scheme(s, ctx) @@ -2452,6 +2468,24 @@ static int kdamond_fn(void *data) if (ctx->attrs.intervals_goal.aggrs && ctx->passed_sample_intervals >=3D ctx->next_intervals_tune_sis) { + /* + * ctx->next_aggregation_sis might be updated + * from kdamond_call(). In the case, + * damon_set_attrs() which will be called from + * kdamond_tune_interval() may wrongly think + * this is in the middle of the current + * aggregation, and make aggregation + * information reset for all regions. Then, + * following kdamond_reset_aggregated() call + * will make the region information invalid, + * particularly for ->nr_accesses_bp. + * + * Reset ->next_aggregation_sis to avoid that. + * It will anyway correctly updated after this + * if caluse. + */ + ctx->next_aggregation_sis =3D + next_aggregation_sis; ctx->next_intervals_tune_sis +=3D ctx->attrs.aggr_samples * ctx->attrs.intervals_goal.aggrs; diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 532c6a6f21f9..be0fea9ee5fc 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -348,19 +348,19 @@ static void damon_test_update_monitoring_result(struc= t kunit *test) =20 new_attrs =3D (struct damon_attrs){ .sample_interval =3D 100, .aggr_interval =3D 10000,}; - damon_update_monitoring_result(r, &old_attrs, &new_attrs); + damon_update_monitoring_result(r, &old_attrs, &new_attrs, false); KUNIT_EXPECT_EQ(test, r->nr_accesses, 15); KUNIT_EXPECT_EQ(test, r->age, 2); =20 new_attrs =3D (struct damon_attrs){ .sample_interval =3D 1, .aggr_interval =3D 1000}; - damon_update_monitoring_result(r, &old_attrs, &new_attrs); + damon_update_monitoring_result(r, &old_attrs, &new_attrs, false); KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); KUNIT_EXPECT_EQ(test, r->age, 2); =20 new_attrs =3D (struct damon_attrs){ .sample_interval =3D 1, .aggr_interval =3D 100}; - damon_update_monitoring_result(r, &old_attrs, &new_attrs); + damon_update_monitoring_result(r, &old_attrs, &new_attrs, false); KUNIT_EXPECT_EQ(test, r->nr_accesses, 150); KUNIT_EXPECT_EQ(test, r->age, 20); =20 --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 A927B26A1DF; Thu, 6 Mar 2025 17:59:17 +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=1741283957; cv=none; b=MufOHF2z22/6dOvUGeLxwyhQEjDPkUOvSEBOOuQzR6a0BUeXKqnozG1OhLqSfg/P38Yprz4sv8oPdEn2QHW+blQFi96mBRomgTQIi7oUENYAFeDKm0ogicSEnZ4RYnI65Jnj83gbpJrh02Ya8Vyqb2dF3Me3OBOmN5yp3NlQ/vU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283957; c=relaxed/simple; bh=kjRBOvHWNbdf/mQwA1XYqEBxVUEwRjN/LUXLXxN91ho=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M7h8bnulPr5tlVJBeGnJnHMXtEPvqTxiOZd3ZeZytm0GFsvuLIpLDBunMZQNaEAu7mXpoveOlsMJr/rbjcxLpA+/ngjFKEJniuZWmYAIdRU/CnQ6HR/g3Hzi81CR8i0mBqqQTNIZTxNX8wHG+x5+XHrCK8+MlPxI9bumL7cahrM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bmBJepJD; 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="bmBJepJD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1CFEC4CEE9; Thu, 6 Mar 2025 17:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283957; bh=kjRBOvHWNbdf/mQwA1XYqEBxVUEwRjN/LUXLXxN91ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bmBJepJD665aLJmGQxhQbg3r5uCZI03NRdxNpdG+KwHddc86qPBdSRAQMFQ3yfnD5 09FCigyvExD6n59jKLLfJQFgVHXaekyCo6Xxgu9m01Lfm5jpm3mqHwHQ40bZxrmGpN 1Aef85s16/6RGAPVPLckJ8/8Il0wJShRPayR0ziXlJNWe2oEzYM8a/1Soix28O8znn iLRgp53OMwhf35xMdsEndfPegP/HRBVMiQorpbOYyCukclBrIiy27d2Wt9h2HWurOI UpoGbqg6MBK9TFXQhiYZVs2s0oRLfTryt6K3wb0VRCAkrg9w1THC6kFWRNiYevY7KX eNxld9XLVJ0Zg== 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 04/13] mm/damon/sysfs: handle commit command using damon_call() Date: Thu, 6 Mar 2025 09:58:59 -0800 Message-Id: <20250306175908.66300-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 is using damon_callback->after_aggregation hook with its self-implemented synchronization mechanism for the hook. It is inefficient, complicated, and take up to one aggregation interval to complete, which can be long on some configs. Use damon_call() instead. It provides a synchronization mechanism that built inside DAMON's core layer, so more efficient than DAMON sysfs interface's own one. Also it isolates the implementation inside the core layer, and hence it makes the code easier to maintain. Finally, it takes up to one sampling interval, which is much shorter than the aggregation interval in common setups. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 87e4c6e3614e..c55a2cee4b74 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1451,8 +1451,9 @@ static struct damon_ctx *damon_sysfs_build_ctx( * * Returns error if the sysfs input is wrong. */ -static int damon_sysfs_commit_input(struct damon_sysfs_kdamond *kdamond) +static int damon_sysfs_commit_input(void *data) { + struct damon_sysfs_kdamond *kdamond =3D data; struct damon_ctx *param_ctx, *test_ctx; int err; =20 @@ -1550,11 +1551,6 @@ static int damon_sysfs_cmd_request_callback(struct d= amon_ctx *c, bool active, if (!kdamond || kdamond->damon_ctx !=3D c) goto out; switch (damon_sysfs_cmd_request.cmd) { - case DAMON_SYSFS_CMD_COMMIT: - if (!after_aggregation) - goto out; - err =3D damon_sysfs_commit_input(kdamond); - break; default: break; } @@ -1712,11 +1708,7 @@ static int damon_sysfs_update_schemes_tried_regions( * @cmd: The command to handle. * @kdamond: The kobject wrapper for the associated kdamond. * - * This function handles a DAMON sysfs command for a kdamond. For commands - * that need to access running DAMON context-internal data, it requests - * handling of the command to the DAMON callback - * (@damon_sysfs_cmd_request_callback()) and wait until it is properly han= dled, - * or the context is completed. + * This function handles a DAMON sysfs command for a kdamond. * * Return: 0 on success, negative error code otherwise. */ @@ -1730,6 +1722,9 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cm= d cmd, return damon_sysfs_turn_damon_on(kdamond); case DAMON_SYSFS_CMD_OFF: return damon_sysfs_turn_damon_off(kdamond); + case DAMON_SYSFS_CMD_COMMIT: + return damon_sysfs_damon_call( + damon_sysfs_commit_input, kdamond); case DAMON_SYSFS_CMD_COMMIT_SCHEMES_QUOTA_GOALS: return damon_sysfs_damon_call( damon_sysfs_commit_schemes_quota_goals, --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 6598E26B0A2; Thu, 6 Mar 2025 17:59:18 +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=1741283958; cv=none; b=r788AEXfCLuRIKxJWffFfZ7nMlfKjO0d1SpEmK35TayE1EethG310/aXo9wJqTOOqDsmA1G3dE3GVxRhqdNOHgr56ZQ48HOprvvt7jy49uyFmvv6l9x9whGH5R8En83HRC/OCeOnKlIrJBmlLBywvUlGSXIfCf0LldNnGj7v2Dw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283958; c=relaxed/simple; bh=g+YGDmMK4WZf3RuQVlcd3/9Gf6V3dNg6yLBZ2nBENG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Vj7tEO2x78n1KMGBj0LbOVq4seNvuxZhihwi3LV83yWLBSAOJD9YTlQqLKA+JYFvj93LZW+scyFbik+titAtP7N9zdzUsMUz7QX3F8MinUK30a8GKn9UDIuPQ22i6pAW1yuevdDe82xvl9jJSzY/oKRknM7mLF4oRbyIKSL3R74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U92VK0EN; 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="U92VK0EN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B34BC4CEEA; Thu, 6 Mar 2025 17:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283958; bh=g+YGDmMK4WZf3RuQVlcd3/9Gf6V3dNg6yLBZ2nBENG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U92VK0ENbWqUUQoPbn23XTVjzA2f3hQRg686NR8ALpfRhCiiFF2CE4pPZe18I36rV OKJL6pEqlDm81rvi2XhwTgYQjQS7uJFF5l/uXzrBV8deKBVUNjzmjXQ45h4O3zjSdR laRIc/fAq3x3hZiv0f/V9hT3jSVbCQTYPeOnph9DnsuW1jiJI2K9cEasacTM2TQBd4 pem2cXI9CUhEp38yhj+98a4t25rQ1WqWEf8PMlbRozNhz8dCH35JqdUDkUWJszIq7A FxucxW7LQ76j0isDQpQZ1BgxDxHAERvhBFUWsAxe4M02PEX4a3mkuGu+/jmfR7kPAX kLrrLXQJlZkpA== 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 05/13] mm/damon/sysfs: remove damon_sysfs_cmd_request code from damon_sysfs_handle_cmd() Date: Thu, 6 Mar 2025 09:59:00 -0800 Message-Id: <20250306175908.66300-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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_handle_cmd() handles user requests that it can directly handle on its own. For requests that need to be handled from damon_callback hooks, it uses DAMON sysfs interface's own synchronous damon_callback hooks management mechanism, namely damon_sysfs_cmd_request. Now all user requests are handled without damon_callback hooks, so damon_sysfs_cmd_request client code in damon_sysfs_andle_cmd() does nothing in real. Remove the unnecessary code. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index c55a2cee4b74..166161f12c26 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1715,8 +1715,6 @@ static int damon_sysfs_update_schemes_tried_regions( static int damon_sysfs_handle_cmd(enum damon_sysfs_cmd cmd, struct damon_sysfs_kdamond *kdamond) { - bool need_wait =3D true; - switch (cmd) { case DAMON_SYSFS_CMD_ON: return damon_sysfs_turn_damon_on(kdamond); @@ -1747,38 +1745,8 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_c= md cmd, return damon_sysfs_damon_call( damon_sysfs_upd_tuned_intervals, kdamond); default: - break; - } - - /* Pass the command to DAMON callback for safe DAMON context access */ - if (damon_sysfs_cmd_request.kdamond) - return -EBUSY; - if (!damon_sysfs_kdamond_running(kdamond)) return -EINVAL; - damon_sysfs_cmd_request.cmd =3D cmd; - damon_sysfs_cmd_request.kdamond =3D kdamond; - - /* - * wait until damon_sysfs_cmd_request_callback() handles the request - * from kdamond context - */ - mutex_unlock(&damon_sysfs_lock); - while (need_wait) { - schedule_timeout_idle(msecs_to_jiffies(100)); - if (!mutex_trylock(&damon_sysfs_lock)) - continue; - if (!damon_sysfs_cmd_request.kdamond) { - /* damon_sysfs_cmd_request_callback() handled */ - need_wait =3D false; - } else if (!damon_sysfs_kdamond_running(kdamond)) { - /* kdamond has already finished */ - need_wait =3D false; - damon_sysfs_cmd_request.kdamond =3D NULL; - } - mutex_unlock(&damon_sysfs_lock); } - mutex_lock(&damon_sysfs_lock); - return 0; } =20 static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *at= tr, --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 E2F8326BDA6; Thu, 6 Mar 2025 17:59:19 +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=1741283960; cv=none; b=eJqwzVNwZM/1tb9MdcnUYm4pmsqYNbcxMtrx1AGeEP/+wkqPzLUUtoHKVrHKEpKxM7Kl6NpExe5M430nlutRysQ2MQfCLFPQmFDv9UIg8c2ju4CBBJ0Qvhbo4bPS3sRg7sa2jaqUJ+JeJr7BjZpHtqHrhrJhhhp5upqeZv4eT7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283960; c=relaxed/simple; bh=T05PHV/b/RY6SE79bGJVruG1lJQyvBwcsDSu/WYUE0U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f8/cA7xmXrVgm3c6UoqL4X+0+16/7eyeLXK72OkKXMxhG89x2w6J56/LjP/Lu9N+gnsZ3/cUKSBbQgwY80zRWvhvzk7TxuTDzKIpyM0+KyP5TgATUlBYy19S2txrVqMjVSQNTS+micOBOU3hsSUvUf1l3+fiqZFyUtILregFYyk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jfv74gGj; 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="jfv74gGj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C533C4CEED; Thu, 6 Mar 2025 17:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283959; bh=T05PHV/b/RY6SE79bGJVruG1lJQyvBwcsDSu/WYUE0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfv74gGjwJwOzARB71Z3kiafD2XrxR+FBGWh46b6W92enZzckMZ/RfqhldIzQyAsB EuyTB/WjbejaSlS+HpfG19pNGGEQWSU+erqB7cOPWDpxsPgWkVm+2KiKVKBvA5i+JP dEUw92P7TFRXUR88EmfDcqc1VfLEqqY/CJ/KCYqdAv1ZOE6e/6BQG/dEIRFOgVWwBw CiDj/v3AhV17AbIbDobtTPKMJmeIUnuDjIqdvjV2bNWcd2dfagZz8B1XA18spApTEq onjO1JALR0bjADcA8Cb08a0ywegLPi9sm1gbyWQ6Q/C9FWPsbrbXBLxb6RzMUpnfVz cxAObq6TqHqZA== 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 06/13] mm/damon/sysfs: remove damon_sysfs_cmd_request_callback() and its callers Date: Thu, 6 Mar 2025 09:59:01 -0800 Message-Id: <20250306175908.66300-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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_cmd_request_callback() is the damon_callback hook functions that were used to handle user requests that need to read and/or write DAMON internal data. All the usages are now updated to use damon_call() or damos_walk(), though. Remove it and its callers. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 62 ------------------------------------------------ 1 file changed, 62 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 166161f12c26..e5bcf019086f 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1529,65 +1529,6 @@ static int damon_sysfs_upd_tuned_intervals(void *dat= a) return 0; } =20 -/* - * damon_sysfs_cmd_request_callback() - DAMON callback for handling reques= ts. - * @c: The DAMON context of the callback. - * @active: Whether @c is not deactivated due to watermarks. - * @after_aggr: Whether this is called from after_aggregation() callback. - * - * This function is periodically called back from the kdamond thread for @= c. - * Then, it checks if there is a waiting DAMON sysfs request and handles i= t. - */ -static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool acti= ve, - bool after_aggregation) -{ - struct damon_sysfs_kdamond *kdamond; - int err =3D 0; - - /* avoid deadlock due to concurrent state_store('off') */ - if (!mutex_trylock(&damon_sysfs_lock)) - return 0; - kdamond =3D damon_sysfs_cmd_request.kdamond; - if (!kdamond || kdamond->damon_ctx !=3D c) - goto out; - switch (damon_sysfs_cmd_request.cmd) { - default: - break; - } - /* Mark the request as invalid now. */ - damon_sysfs_cmd_request.kdamond =3D NULL; -out: - mutex_unlock(&damon_sysfs_lock); - return err; -} - -static int damon_sysfs_after_wmarks_check(struct damon_ctx *c) -{ - /* - * after_wmarks_check() is called back while the context is deactivated - * by watermarks. - */ - return damon_sysfs_cmd_request_callback(c, false, false); -} - -static int damon_sysfs_after_sampling(struct damon_ctx *c) -{ - /* - * after_sampling() is called back only while the context is not - * deactivated by watermarks. - */ - return damon_sysfs_cmd_request_callback(c, true, false); -} - -static int damon_sysfs_after_aggregation(struct damon_ctx *c) -{ - /* - * after_aggregation() is called back only while the context is not - * deactivated by watermarks. - */ - return damon_sysfs_cmd_request_callback(c, true, true); -} - static struct damon_ctx *damon_sysfs_build_ctx( struct damon_sysfs_context *sys_ctx) { @@ -1603,9 +1544,6 @@ static struct damon_ctx *damon_sysfs_build_ctx( return ERR_PTR(err); } =20 - ctx->callback.after_wmarks_check =3D damon_sysfs_after_wmarks_check; - ctx->callback.after_sampling =3D damon_sysfs_after_sampling; - ctx->callback.after_aggregation =3D damon_sysfs_after_aggregation; ctx->callback.before_terminate =3D damon_sysfs_before_terminate; return ctx; } --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 31F9926E976; Thu, 6 Mar 2025 17:59:20 +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=1741283962; cv=none; b=NJF4H9mwRjQ/KUmBZs8Grqql83DKVT/O9pJ7/AXJKN2uCFkglRyJfi/UxDdVyg6LlOY8i3xSMX9MJLkswdRH+6PGiAb5EWCjXU2NOTKk3PmHpeEkw4FXp5+ny5CIcSLDvctDlpa3IxEHx8BtqH9do/5xE+d2C/+rne3UhM2OHV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283962; c=relaxed/simple; bh=GLzNjNzoqFiPhTNA5KWvEmI61gvwVWoLHB2Kc36Fd2k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=M2MjxyqEMsla+kMpp2xHHTOCzaUBxNOF2vAmrbXehTE4OaVhZVnAs0Pld1QskJ4lAXIXpjOFhjQeNbQ+rdeP+NgXK/5DBP4oYQcXOW6bl51CrICwODRV3LJ6FOz9pKcLD7WMUHir72+M6ZU+wePjJJ+FRV8LkDE0fLvfuqfvipw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=erZYTq86; 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="erZYTq86" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 648EDC4CEE9; Thu, 6 Mar 2025 17:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283960; bh=GLzNjNzoqFiPhTNA5KWvEmI61gvwVWoLHB2Kc36Fd2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=erZYTq86Muoe+ngK+l8uFZkQmK24b0sIV9xkOZI/wHdKgAlqF07w3QclG8rJUEtt8 azNg2lsCWGWyyEVOh2ak4BD5Io128WbCrygzc3VC9UX3mmg4z0nbeqAsdZIUTuzcxD hG84wS3cy6s1nK7AFt/uQaGaFILjk74/2GkbNcrpDKsef91CysP4SGpiDYXw+MlCF0 hGtD4DsYsf2qA9K4v14hBqp1GE0GXtsAVGkkezSyTMNlKvCMFt6GoEJDIsAR8CTjgn eELoCkIQRv7gn9Bj+qMd90PhpcARNPlobRsIjOb2VcQEdd1i0bjZMDSRUFsDyaDVHT eZqtABr7ZuxxA== 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 07/13] mm/damon/sysfs: remove damon_sysfs_cmd_request and its readers Date: Thu, 6 Mar 2025 09:59:02 -0800 Message-Id: <20250306175908.66300-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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_cmd_request is DAMON sysfs interface's own synchronization mechanism for accessing DAMON internal data via damon_callback hooks. All the users are now migrated to damon_call() and damos_walk(), so nobody really uses it. No one writes to the data structure but reading code is still remained. Remove the reading code and the entire data structure. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e5bcf019086f..1af6aff35d84 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1238,25 +1238,6 @@ static const char * const damon_sysfs_cmd_strs[] =3D= { "update_tuned_intervals", }; =20 -/* - * struct damon_sysfs_cmd_request - A request to the DAMON callback. - * @cmd: The command that needs to be handled by the callback. - * @kdamond: The kobject wrapper that associated to the kdamond thread. - * - * This structure represents a sysfs command request that need to access s= ome - * DAMON context-internal data. Because DAMON context-internal data can be - * safely accessed from DAMON callbacks without additional synchronization= , the - * request will be handled by the DAMON callback. None-``NULL`` @kdamond = means - * the request is valid. - */ -struct damon_sysfs_cmd_request { - enum damon_sysfs_cmd cmd; - struct damon_sysfs_kdamond *kdamond; -}; - -/* Current DAMON callback request. Protected by damon_sysfs_lock. */ -static struct damon_sysfs_cmd_request damon_sysfs_cmd_request; - static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *att= r, char *buf) { @@ -1555,8 +1536,6 @@ static int damon_sysfs_turn_damon_on(struct damon_sys= fs_kdamond *kdamond) =20 if (damon_sysfs_kdamond_running(kdamond)) return -EBUSY; - if (damon_sysfs_cmd_request.kdamond =3D=3D kdamond) - return -EBUSY; /* TODO: support multiple contexts per kdamond */ if (kdamond->contexts->nr !=3D 1) return -EINVAL; @@ -1796,8 +1775,7 @@ static bool damon_sysfs_kdamonds_busy(struct damon_sy= sfs_kdamond **kdamonds, int i; =20 for (i =3D 0; i < nr_kdamonds; i++) { - if (damon_sysfs_kdamond_running(kdamonds[i]) || - damon_sysfs_cmd_request.kdamond =3D=3D kdamonds[i]) + if (damon_sysfs_kdamond_running(kdamonds[i])) return true; } =20 --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 8EA6D26F479; Thu, 6 Mar 2025 17:59:22 +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=1741283962; cv=none; b=UD9gk4z8+/Y9bIggpaD2oCn7OrsBwMBVDgAvliNzMcp1mzlik7qBKJXVxKHSi1qJigiw40s7jpG3VWSyg+hsuSMkBOxDltidIWLvBFEI9ic+ZlxdF2o09mIbVmg8V+pAKzea1+gF/z6eeCKJYA4cElsofL4XroPPnNCgUB9VAaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283962; c=relaxed/simple; bh=CtrMG3b7XVPdT3oTv/pTE3ihT4fR44kaP9KWdR8X7yY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eobsiX67XdOaw7W9xOzfeYP52fVzpP56+Kb5PJjTk3RSG+R3aPs89X8eCyny/grmxgpI+7liCYbRH1S1666EDCxCICAL36e07U3PDJ7ZYtTKtZ509Pyeuk8zw7y/4nnz4KG3SfrW1CvANzRosObtv2Aa96ojfjkW8Prqu5GLNfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bNjKFFQ4; 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="bNjKFFQ4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1518C4CEEC; Thu, 6 Mar 2025 17:59:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283962; bh=CtrMG3b7XVPdT3oTv/pTE3ihT4fR44kaP9KWdR8X7yY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bNjKFFQ4rDBT0cqCm2AT0D+nqoXZvgts3+W3NqHzMf1U+oxW+TcglOC35LUdQVkVp Z936/lHqyHUi4YxJG4dD50mQKP4qakrLcVT5pXJ0XO+kNUsJpkRas/SSW8DeU2fNZf AWMXL2m6qztdxSIityXOiu3DFiRYCDXnsjBLbsFcHrewWvPMAxPwhTRRLd/3U6m1e4 AAFDj7tRbac5H8cybPSMKqrsjRwPOOAjYUo8wFOHIKqEr9MN6o95+MiWjBvBEFLrQX 6oOl5M6C6zzj3KSSN7CWNxh8zicOJITZ28nDjso82JMSnkW4hzudWVWqDTw2s/k5P6 yPOXj7lQmJmCg== 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 08/13] mm/damon/sysfs-schemes: remove obsolete comment for damon_sysfs_schemes_clear_regions() Date: Thu, 6 Mar 2025 09:59:03 -0800 Message-Id: <20250306175908.66300-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 comment on damon_sysfs_schemes_clear_regions() function is obsolete, since it has updated to directly called from DAMON sysfs interface code. Remove the outdated comment. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index ed834622df2a..d50f37ef4eb8 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -2341,7 +2341,6 @@ void damos_sysfs_populate_region_dir(struct damon_sys= fs_schemes *sysfs_schemes, } } =20 -/* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes) { --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 CDCEE2702B8; Thu, 6 Mar 2025 17:59:23 +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=1741283963; cv=none; b=pKrJZ3bgQCyhVsECLt3VUDySan+n2PSZkWsozmVAj0H/iqEJ6TY2wbCRDHuP+BYQWzWBuxUx+HFERXaBcUQINfIZdG4jl37K/QRfVOVGcrYH1Hil6QIDVaD2x9kTDJuzj7okOALz/tQcFlnj5sPlMW851AtN/VDAoCVmoxNMvUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283963; c=relaxed/simple; bh=MsBfeedR0E0avwOTjpu2VsFxt43snXdrtNBJJKsBtYo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jUfmnqPwWhcsrdbzQzRk720/6RI+Ql8UhHjdPvMk1ROTw2ET06ufMoYtttI9B1+6/sGtNCohhNwoDPSGpNpiYyRzVZEqqSjrovXAYF9b+oUsRSaQK/LWzwMNpdqJGodIAWwFZ5lP6MMLPijR6L8isnpRJoAnnzbUy9HkkRbJh0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G/nQTPBz; 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="G/nQTPBz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1167BC4CEEA; Thu, 6 Mar 2025 17:59:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283963; bh=MsBfeedR0E0avwOTjpu2VsFxt43snXdrtNBJJKsBtYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G/nQTPBzQrtpc5jfIx22kSnzs/KBPP9QCYN85wNLoqhwXrsVCXcSEy5U+RE50RNnl W7dqDVpn1T1x5/GZwFQTa0Uew+C/LSV/h/l5T07mMca38oJUdAJJYEQuq7HXQxrcKJ gypqc4h2FpWf0bqO7keCsYhEEP7IuJBBQIejEhxuZiq7v9EjFPGK2Gp3n5TAQsn4E6 ZSQVQCW+INhCa0N1HUhw2mMqzA2wiXsYqGCM3e2yYvLKhXMZ7Sc1tFMQUYW2Wmzf9P LS/b7ym8umSgYcZRIpoy6mswvy0yiAv/3qfwagcc/JgcaMpFQW0YnSzblrJF7pVLVO t18FzFkNOb65w== 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 09/13] mm/damon: remove damon_callback->private Date: Thu, 6 Mar 2025 09:59:04 -0800 Message-Id: <20250306175908.66300-10-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 field was added to let users keep their personal data to use inside of the callbacks. However, no one is actively using that now. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index eed008b64a23..dab4bb0fe39d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -609,12 +609,10 @@ struct damon_operations { * @after_aggregation: Called after each aggregation. * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. - * @private: User private data. * * The monitoring thread (&damon_ctx.kdamond) calls @before_start and * @before_terminate just before starting and finishing the monitoring, - * respectively. Therefore, those are good places for installing and clea= ning - * @private. + * respectively. * * The monitoring thread calls @after_wmarks_check after each DAMON-based * operation schemes' watermarks check. If users need to make changes to = the @@ -630,8 +628,6 @@ struct damon_operations { * If any callback returns non-zero, monitoring stops. */ struct damon_callback { - void *private; - int (*before_start)(struct damon_ctx *context); int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 7BA4C270EC9; Thu, 6 Mar 2025 17:59:24 +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=1741283964; cv=none; b=BVWRtzL1SfBxdP9p+/n4WLOknk3S1LkD1PTPHOgHeL1Dn7ocY3+dHoR/yKHU19NPL+HZG5VlU/W2O3vQKAiiJ8tONEeW+r8cS2iQDhQOM/A8vxoEuZol15ovXp6+uVywdLiFDKqiySvGX5bTPuKQ356hGIkd6G55YIfVtD1c3n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283964; c=relaxed/simple; bh=S+TNIBRN6YsZ8tOcYDy9gAmvy6YsqhXhgFNOQBl/SdM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aN0RyuaZGbRh/jilwUQA4gmpIwnYEuPrlZ1dPWhpZMUmTmrfZzwS/UQtys0eN89co1+3sQbSXWyoARNRET7guVHq9JDRhN8PGxKqmsYzIBwrhrxqXGeEPjVUANfRetekIEXbm14W0ncV8BQ0AulTC7TsQcRnGqaT/rw+qVqVNEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S14s7Ljy; 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="S14s7Ljy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3196FC4CEEB; Thu, 6 Mar 2025 17:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283964; bh=S+TNIBRN6YsZ8tOcYDy9gAmvy6YsqhXhgFNOQBl/SdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S14s7LjyIEJw6vYOzHXcs45rJA5HM0smXIDKTwtGIGtVg5j4Sxt57Tb2BNY0Wgjwn xdgaz6Fw4jpwFIPd5XPf6KLq/W/hF9v2XhGQIy3gCw0x3sdRU4rGi4SwT91xRrwwOH KX3cZ0lWMRUJhp+OpdXdF4cviM/flmortjg5iANDvX4Ia+0gNzA/yQqhLzEY8LBBDp TY27V/oidghlrJ2674LYT4BZqSH+9+a2LBo+rApY0WnHbBOcSemaaayM0B11vDngc9 z0arz79RE8XCm17cIDz6LQwfsUJD3k6SJEWsh4QHFeKFBgHxYxBZQlfaPzrPXSg7IK V1xIHhSvP40rw== 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 10/13] mm/damon: remove ->before_start of damon_callback Date: Thu, 6 Mar 2025 09:59:05 -0800 Message-Id: <20250306175908.66300-11-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 function pointer field was added to be used as a place to do some initialization works just before DAMON starts working. However, nobody is using it now. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 ++----- mm/damon/core.c | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index dab4bb0fe39d..043de2408c65 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -603,16 +603,14 @@ struct damon_operations { /** * struct damon_callback - Monitoring events notification callbacks. * - * @before_start: Called before starting the monitoring. * @after_wmarks_check: Called after each schemes' watermarks check. * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. * - * The monitoring thread (&damon_ctx.kdamond) calls @before_start and - * @before_terminate just before starting and finishing the monitoring, - * respectively. + * The monitoring thread (&damon_ctx.kdamond) calls @before_terminate just + * before finishing the monitoring. * * The monitoring thread calls @after_wmarks_check after each DAMON-based * operation schemes' watermarks check. If users need to make changes to = the @@ -628,7 +626,6 @@ struct damon_operations { * If any callback returns non-zero, monitoring stops. */ struct damon_callback { - int (*before_start)(struct damon_ctx *context); int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); diff --git a/mm/damon/core.c b/mm/damon/core.c index de30b788e13a..8904b3c079e6 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2407,8 +2407,6 @@ static int kdamond_fn(void *data) =20 if (ctx->ops.init) ctx->ops.init(ctx); - if (ctx->callback.before_start && ctx->callback.before_start(ctx)) - goto done; ctx->regions_score_histogram =3D kmalloc_array(DAMOS_MAX_SCORE + 1, sizeof(*ctx->regions_score_histogram), GFP_KERNEL); if (!ctx->regions_score_histogram) --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 A387927426C; Thu, 6 Mar 2025 17:59:25 +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=1741283965; cv=none; b=jPChwwLpbBmaNeyF/W1XfPNNW13dRroKnIhZ/SLYtN4kpmvn3Ij/p2S5dwudQSgl9E2hCIDr029zPfyqkiUpcX1N4XKEBPf+b6zzd2OL34sL1E91m+S88IL3vDIyrm/C75nHaqelyq1coCEIgdHs9Z3hn1W4+d5/vl6fZzipDqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283965; c=relaxed/simple; bh=I/JHvzw57UoJPSQTgW4gksymyJzz98SL8NUvb1KKOF0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hHDjZGkfK2+GdJ/Zip86Sk5nXB/oHPyt3L3SD5scxGLoJ3r/l2JCKDIfiDANM0ooht76J39OrvWbZR2QtWoAmvMaqY88UF8QT4Bg882J/lb7cqMtSFx5OKoNf5l9R0JjMgZ3BK7N2LDFD4ZkJJ1i6rRBrsYNmudeDFSY6qLmBTk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t43p2Qrd; 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="t43p2Qrd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56B46C4CEE9; Thu, 6 Mar 2025 17:59:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283965; bh=I/JHvzw57UoJPSQTgW4gksymyJzz98SL8NUvb1KKOF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t43p2Qrd5Bb7hd33jVdLTrPc3yYngQWh01UWIUXiyNaUQsIeXBmLhrndvro9mNHv2 zfYl/VNQsqQJu0YBC9jinTCv46wgeHwLPdii9KyhU2jcPmfRG6y2LcrX2uvE4TEbA5 /oN5lHeLwafXy7EMGqRii5igXdClJvOyse25zjqBjKief9JXj9/AszDV4bcSHwSs34 RYnmA0VahnP38wsXOymiSLn9KTZvrou8KkPEIqHOIi3gfAQJQBMyX9cod5fMyeIedR vdLmClx/gxJoJLGVb0B2OpPlU2i88kWJzEG5BgOglyKaE8EmtibgkEq+DG67WP2bAW rMfnSYuiw1a3w== 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 11/13] mm/damon: remove damon_callback->after_sampling Date: Thu, 6 Mar 2025 09:59:06 -0800 Message-Id: <20250306175908.66300-12-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 callback was used by DAMON sysfs interface for reading DAMON internal data. But it is no more being used, and damon_call() can do similar works in a better way. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 11 ++++------- mm/damon/core.c | 3 --- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 043de2408c65..5aa277f4c948 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -604,7 +604,6 @@ struct damon_operations { * struct damon_callback - Monitoring events notification callbacks. * * @after_wmarks_check: Called after each schemes' watermarks check. - * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. @@ -617,17 +616,15 @@ struct damon_operations { * attributes of the monitoring context while it's deactivated due to the * watermarks, this is the good place to do. * - * The monitoring thread calls @after_sampling and @after_aggregation for = each - * of the sampling intervals and aggregation intervals, respectively. - * Therefore, users can safely access the monitoring results without addit= ional - * protection. For the reason, users are recommended to use these callbac= k for - * the accesses to the results. + * The monitoring thread calls @after_aggregation for each of the aggregat= ion + * intervals. Therefore, users can safely access the monitoring results + * without additional protection. For the reason, users are recommended t= o use + * these callback for the accesses to the results. * * If any callback returns non-zero, monitoring stops. */ struct damon_callback { int (*after_wmarks_check)(struct damon_ctx *context); - int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); int (*before_damos_apply)(struct damon_ctx *context, struct damon_target *target, diff --git a/mm/damon/core.c b/mm/damon/core.c index 8904b3c079e6..726e581904e5 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2431,9 +2431,6 @@ static int kdamond_fn(void *data) =20 if (ctx->ops.prepare_access_checks) ctx->ops.prepare_access_checks(ctx); - if (ctx->callback.after_sampling && - ctx->callback.after_sampling(ctx)) - break; =20 kdamond_usleep(sample_interval); ctx->passed_sample_intervals++; --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 18B522780E6; Thu, 6 Mar 2025 17:59:29 +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=1741283971; cv=none; b=uomG3EPSsaTK9XlEsyJR2J0y2ewsptAUjyS/uOsSRG3rTJWbWLE4/MY4FhUOQvF5028XXHG01Op8M9XjnSVxh8SySoSEjDAs+dg+rxRxS/DoX7uUOfUTl3sm6OIfbOG8znK3KseF2E5IOjUEWOeQ5A7FKeAebZpzvQFG046p0q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283971; c=relaxed/simple; bh=QHuacpUAdZsjxvC6RVrkNf1AvYwnsyKAd7KvFaeWUTk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gfSoThKORySf7nMsUhKnKcXbMOXUd4L9BxqCwkakWBQgF971iH1LlY4qf2CcyWRdTDl0PIxPeKJudcDhI4Pcbt0Hp+vrWGxkXA3utbsE49zFaYYpOEJEy/GEFVdw9zgglRBtD3Si0Fm4R/GrEz3dsc4O3ozdhn0m5S00RuhJi18= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sk3x0+u4; 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="Sk3x0+u4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FAEAC4CEE8; Thu, 6 Mar 2025 17:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283969; bh=QHuacpUAdZsjxvC6RVrkNf1AvYwnsyKAd7KvFaeWUTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sk3x0+u4ZcspuwW/TvqCwEpHahJE8ZVI25fbwQsbquSG42WFrMto0jBxMQxX0igvi 1jZHAa8jDMwg3U60RsOYxGmdAo7yFx9Y7f5NBx+WMFILCvhl/WgabpvPfI+KY9PZiT dA7wyZ6xfhjD6x3JJg8n643rVm26DxgS+xtQnBwYLRHCSdYSTloha9kmSxomVWg54x Q19q6sw4KIw4dKyoLqU94Gp9mEVkAieXW6kKFgIn1Gk+EFmk2t8sTH7w5GThOTqkgr BkiaP/5lOMx9kAq8uwLj8LUWn43Nl3RcV28Rc0VN1jW4R5LDkNlQkHR0T6oyJo8L6Z NajMWp8fAR+UQ== 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 12/13] mm/damon: remove damon_callback->before_damos_apply Date: Thu, 6 Mar 2025 09:59:07 -0800 Message-Id: <20250306175908.66300-13-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 hook was introduced to let DAMON kernel API users access DAMOS schemes-eligible regions in a safe way. Now it is no more used by anyone, and the functionality is provided in a better way by damos_walk(). Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 ----- mm/damon/core.c | 13 ++++--------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 5aa277f4c948..be7b281fb922 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -605,7 +605,6 @@ struct damon_operations { * * @after_wmarks_check: Called after each schemes' watermarks check. * @after_aggregation: Called after each aggregation. - * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. * * The monitoring thread (&damon_ctx.kdamond) calls @before_terminate just @@ -626,10 +625,6 @@ struct damon_operations { struct damon_callback { int (*after_wmarks_check)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); - int (*before_damos_apply)(struct damon_ctx *context, - struct damon_target *target, - struct damon_region *region, - struct damos *scheme); void (*before_terminate)(struct damon_ctx *context); }; =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 726e581904e5..d6271fae4dd4 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1731,7 +1731,6 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, struct timespec64 begin, end; unsigned long sz_applied =3D 0; unsigned long sz_ops_filter_passed =3D 0; - int err =3D 0; /* * We plan to support multiple context per kdamond, as DAMON sysfs * implies with 'nr_contexts' file. Nevertheless, only single context @@ -1771,14 +1770,10 @@ static void damos_apply_scheme(struct damon_ctx *c,= struct damon_target *t, if (damos_filter_out(c, t, r, s)) return; ktime_get_coarse_ts64(&begin); - if (c->callback.before_damos_apply) - err =3D c->callback.before_damos_apply(c, t, r, s); - if (!err) { - trace_damos_before_apply(cidx, sidx, tidx, r, - damon_nr_regions(t), do_trace); - sz_applied =3D c->ops.apply_scheme(c, t, r, s, - &sz_ops_filter_passed); - } + trace_damos_before_apply(cidx, sidx, tidx, r, + damon_nr_regions(t), do_trace); + sz_applied =3D c->ops.apply_scheme(c, t, r, s, + &sz_ops_filter_passed); damos_walk_call_walk(c, t, r, s, sz_ops_filter_passed); ktime_get_coarse_ts64(&end); quota->total_charged_ns +=3D timespec64_to_ns(&end) - --=20 2.39.5 From nobody Thu Dec 18 19:05:18 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 18AE22780E3; Thu, 6 Mar 2025 17:59:30 +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=1741283971; cv=none; b=a/+5qCaVnR29UjoV7daLxPN3sohn5Oii7ZFAuRaBwtpOsCugicDLzQskV6gJHhniwlq6DiQhvL5srg/49/xFy8+hdNM/R6bwkJjBUlz+IGLnEuqj9N7Pa2wxDql2ghHyhjHsAAwnS1LQMzrKMNAMoeryBsY9TIVSv4lJyViVdmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741283971; c=relaxed/simple; bh=Rn+6YydnhrV6FETkcIfmvP4YuDQr4oebn96i4+L/goY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X/aTumtGoGqvUx67dM3vXlueEsoX28guKqhKfo1gd7YhpE8Kl8mNdNI3Uig9ENy6omPiFgJuWYZy4ltXIKyjkCKzNSOuydxzvCQlsdAUr+M2xA6McxjZ/t40vnvaw0YfId2hoRxUV0pcjxPZ26CHkuX0jbuKheSAxgGUcth8ZxU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KLOqrOWm; 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="KLOqrOWm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E640C4CEE4; Thu, 6 Mar 2025 17:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741283970; bh=Rn+6YydnhrV6FETkcIfmvP4YuDQr4oebn96i4+L/goY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLOqrOWmjdNfeRf4uTFfilXrUOaL0GSy6hMQWsxUT2If3kQvq6UTPuQULqnbC0NZn 9fo5jXUGPK0CFGpdYaOcnKVIAEj6wx/i3uexc3urCzkplgnA6CiTAnvtxiq2JRXyGR uqK60K9LqCudw0fkFgiyspQa41ohjAmBNmgVfh4u0/PSzjxTlek38b8SFnPpeGeThw FKTmWUH3bxOdyCiVdpMeDsqqEZ0uZuTRsCAbxd5XT8+O2SXNfC/BjX2GgyMl8iM27O gCjMozI7x4UUkqFr3/B1s+4nUS32ekumybJfXPGl99tntavBZW6wAgYyJt+HG5U1Sn hOgCwGYkq6fZA== 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 13/13] mm/damon: remove damon_operations->reset_aggregated Date: Thu, 6 Mar 2025 09:59:08 -0800 Message-Id: <20250306175908.66300-14-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250306175908.66300-1-sj@kernel.org> References: <20250306175908.66300-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 operations layer hook was introduced to let operations set do any aggregation data reset if needed. But it is not really be used now. Remove it. Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 +------ mm/damon/core.c | 2 -- mm/damon/paddr.c | 1 - mm/damon/vaddr.c | 1 - 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index be7b281fb922..3db4f77261f5 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -542,7 +542,6 @@ enum damon_ops_id { * @update: Update operations-related data structures. * @prepare_access_checks: Prepare next access check of target regions. * @check_accesses: Check the accesses to target regions. - * @reset_aggregated: Reset aggregated accesses monitoring results. * @get_scheme_score: Get the score of a region for a scheme. * @apply_scheme: Apply a DAMON-based operation scheme. * @target_valid: Determine if the target is valid. @@ -554,8 +553,7 @@ enum damon_ops_id { * (&damon_ctx.kdamond) calls @init and @prepare_access_checks before star= ting * the monitoring, @update after each &damon_attrs.ops_update_interval, and * @check_accesses, @target_valid and @prepare_access_checks after each - * &damon_attrs.sample_interval. Finally, @reset_aggregated is called aft= er - * each &damon_attrs.aggr_interval. + * &damon_attrs.sample_interval. * * Each &struct damon_operations instance having valid @id can be register= ed * via damon_register_ops() and selected by damon_select_ops() later. @@ -570,8 +568,6 @@ enum damon_ops_id { * last preparation and update the number of observed accesses of each reg= ion. * It should also return max number of observed accesses that made as a re= sult * of its update. The value will be used for regions adjustment threshold. - * @reset_aggregated should reset the access monitoring results that aggre= gated - * by @check_accesses. * @get_scheme_score should return the priority score of a region for a sc= heme * as an integer in [0, &DAMOS_MAX_SCORE]. * @apply_scheme is called from @kdamond when a region for user provided @@ -589,7 +585,6 @@ struct damon_operations { void (*update)(struct damon_ctx *context); void (*prepare_access_checks)(struct damon_ctx *context); unsigned int (*check_accesses)(struct damon_ctx *context); - void (*reset_aggregated)(struct damon_ctx *context); int (*get_scheme_score)(struct damon_ctx *context, struct damon_target *t, struct damon_region *r, struct damos *scheme); diff --git a/mm/damon/core.c b/mm/damon/core.c index d6271fae4dd4..db357892da74 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2489,8 +2489,6 @@ static int kdamond_fn(void *data) =20 kdamond_reset_aggregated(ctx); kdamond_split_regions(ctx); - if (ctx->ops.reset_aggregated) - ctx->ops.reset_aggregated(ctx); } =20 if (ctx->passed_sample_intervals >=3D next_ops_update_sis) { diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index fba8b3c8ba30..b08847ef9b81 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -621,7 +621,6 @@ static int __init damon_pa_initcall(void) .update =3D NULL, .prepare_access_checks =3D damon_pa_prepare_access_checks, .check_accesses =3D damon_pa_check_accesses, - .reset_aggregated =3D NULL, .target_valid =3D NULL, .cleanup =3D NULL, .apply_scheme =3D damon_pa_apply_scheme, diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index a6174f725bd7..e6d99106a7f9 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -710,7 +710,6 @@ static int __init damon_va_initcall(void) .update =3D damon_va_update, .prepare_access_checks =3D damon_va_prepare_access_checks, .check_accesses =3D damon_va_check_accesses, - .reset_aggregated =3D NULL, .target_valid =3D damon_va_target_valid, .cleanup =3D NULL, .apply_scheme =3D damon_va_apply_scheme, --=20 2.39.5