From nobody Fri Dec 19 04:23:33 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 F0D891DE2DF; Fri, 28 Feb 2025 22:03:32 +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=1740780213; cv=none; b=CyKE7jnvagJrEE1pmD2u1IyIkZnxehHkXSped+t3pZPuQDNomKUWiX/IlqJWaPsELna2zrQ0nCKgsts3VilKMHkBmhkbszUP65W3rBQ++vGz4zNPmpCbypYEt3tXMaLmxHxC9oJykU2Es7eTxzilH+lql+uR2yghI2Rkf4dDwPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780213; c=relaxed/simple; bh=WFfBywqImxG6v/56XXskkWPj4/LAxcRbv+8nhLsSUtU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mg3hdgurwceyviKnk08PSUDv4XJ5ny02srXBiTlU2kKVl3DAoNt35f57XCTEPuTzsOqxDgI1G3DdcoC0WK34QY3trm7nekjsTJ4Zo6Q6/urvsCkGUzYchtLeI4CFyG43/rk/B4N6ch3W5QQ6dJ+kG6PM8KF+E7KcT0jqePXmQ2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qolasen7; 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="Qolasen7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45DD2C4CEE2; Fri, 28 Feb 2025 22:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780212; bh=WFfBywqImxG6v/56XXskkWPj4/LAxcRbv+8nhLsSUtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qolasen77R4AKPul7302i/J/jc8m4WE1xtdK4RjnK3EFxeh9+4t71+pj9Z2eSeEdT woOrrZeEfGUNT2vNx7Gb4lkglQ8b4ISsvdsp/GEW/mG6ru7MgqV4z8JcaKmY2ElFgl 6MwBJQ6yxN+kyFlfctzeiQk0632wQ+iiBriNfSTVX/vy3042/Zg5KS/5v7hGCGS+1r uTRbplH9kcsuqWh5CC2AxegMw8s2Bs3ZrrfnVrWGyDIk1JnP7tVOMoFBP7/FmsNlNF l+4A8q1lKR6HjvEaxmwVujZkk/bHiReBrHC5gUsX37bU6D1LztW1c4Go5Ro/05v2HW RdIpeOQy5BPwQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 1/8] mm/damon: add data structure for monitoring intervals auto-tuning Date: Fri, 28 Feb 2025 14:03:21 -0800 Message-Id: <20250228220328.49438-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add data structures for DAMON sampling and aggregation intervals automatic tuning that aims specific amount of DAMON-observed access events per snapshot. In more detail, define the data structure for the tuning goal, link it to the monitoring attributes data structure so that DAMON kernel API callers can make the request, and update parameters setup DAMON function to respect the new parameter. Signed-off-by: SeongJae Park --- include/linux/damon.h | 27 +++++++++++++++++++++++++++ mm/damon/core.c | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 8264e9f1db7e..130c3e01089c 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -664,12 +664,38 @@ struct damon_call_control { bool canceled; }; =20 +/** + * struct damon_intervals_goal - Monitoring intervals auto-tuning goal. + * + * @access_bp: Access events observation ratio to achieve in bp. + * @aggrs: Number of aggregations to acheive @access_bp within. + * @min_sample_us: Minimum resulting sampling interval in microseconds. + * @max_sample_us: Maximum resulting sampling interval in microseconds. + * + * DAMON automatically tunes &damon_attrs->sample_interval and + * &damon_attrs->aggr_interval aiming the ratio in bp (1/10,000) of + * DAMON-observed access events to theoretical maximum amount within @aggrs + * aggregations be same to @access_bp. The logic increases + * &damon_attrs->aggr_interval and &damon_attrs->sampling_interval in same + * ratio if the current access events observation ratio is lower than the + * target for each @aggrs aggregations, and vice versa. + * + * If @aggrs is zero, the tuning is disabled and hence this struct is igno= red. + */ +struct damon_intervals_goal { + unsigned long access_bp; + unsigned long aggrs; + unsigned long min_sample_us; + unsigned long max_sample_us; +}; + /** * struct damon_attrs - Monitoring attributes for accuracy/overhead contro= l. * * @sample_interval: The time between access samplings. * @aggr_interval: The time between monitor results aggregations. * @ops_update_interval: The time between monitoring operations updates. + * @intervals_goal: Intervals auto-tuning goal. * @min_nr_regions: The minimum number of adaptive monitoring * regions. * @max_nr_regions: The maximum number of adaptive monitoring @@ -689,6 +715,7 @@ struct damon_attrs { unsigned long sample_interval; unsigned long aggr_interval; unsigned long ops_update_interval; + struct damon_intervals_goal intervals_goal; unsigned long min_nr_regions; unsigned long max_nr_regions; }; diff --git a/mm/damon/core.c b/mm/damon/core.c index 4bf8fb4e7ab2..b11595c01c37 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -638,6 +638,25 @@ static void damon_update_monitoring_results(struct dam= on_ctx *ctx, r, old_attrs, new_attrs); } =20 +/* + * damon_valid_intervals_goal() - return if the intervals goal of @attrs is + * valid. + */ +static bool damon_valid_intervals_goal(struct damon_attrs *attrs) +{ + struct damon_intervals_goal *goal =3D &attrs->intervals_goal; + + /* tuning is disabled */ + if (!goal->aggrs) + return true; + if (goal->min_sample_us > goal->max_sample_us) + return false; + if (attrs->sample_interval < goal->min_sample_us || + goal->max_sample_us < attrs->sample_interval) + return false; + return true; +} + /** * damon_set_attrs() - Set attributes for the monitoring. * @ctx: monitoring context @@ -658,6 +677,9 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damon= _attrs *attrs) attrs->sample_interval : 1; struct damos *s; =20 + if (!damon_valid_intervals_goal(attrs)) + return -EINVAL; + if (attrs->min_nr_regions < 3) return -EINVAL; if (attrs->min_nr_regions > attrs->max_nr_regions) --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 C02001DE4C7; Fri, 28 Feb 2025 22:03:33 +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=1740780213; cv=none; b=EyS8kRee2mwU2aOmnkEaqldRLJr5EJD1GOAi0xpmM0s4lBUNYmIyEJfqZQdGgqXhXnlUNQovu8eenlgihnBgDaZKby7PhiMUUOVg3qja/GQDAw9UQghlHQyFOd3zmmnGEaaUvytZGLbOrH3uLsUIZjcaXJdsEctsESW4lAN0oac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780213; c=relaxed/simple; bh=w21tstzzb4FfHupcVwHDLvqkq/QXU7C/Es38OxUzGJE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kDRoVDhNiixbCxXbND9qsXwv6OMUbzuGMpxbGmfhhYVgSoNCeHdawxcdK6XL4xOBz7IHytXg7AOtGMMLstkOtsoR+0OvmUW9CyIExKJu2Jb5xUWVgDOdlV/GZyp21rLMO7CMRWcH0v8iLaONjOZm/erN/FLBliX1RYx8WwDW9Ok= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vGfRkR+Y; 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="vGfRkR+Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 781B7C4CEE2; Fri, 28 Feb 2025 22:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780213; bh=w21tstzzb4FfHupcVwHDLvqkq/QXU7C/Es38OxUzGJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vGfRkR+YJIBl3Vea7jC1iBcMljBOVbkTePmmNC8lkKlsV7rX0LY8snKXVd+qbhs/0 uMu5P8J3qPX6bnBq+lua2Djqx6g/S5QxO6G2/wGhW9ze/UmZOUqmW27vQbSnQPyp8v AxZUiJSIOp5uGFJDYsRcTrIi4aSBY9Se+BZeT9HplmzY02OL3VR512RWaaQgVeWCZ4 G+r3xT2IcgOR1AAilvNuSDoEb1zLS5rW6Vop0tRrfA6lauWKbkTwho6XF5uqmjcP3u BH2nWDJZD6DegKZqBfPB2ulMTD1R+0JGgNmUT/ks4s9JK36V76ceRgGMbp5BWR1ujv sv1J4TYVU+Y+g== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 2/8] mm/damon/core: implement intervals auto-tuning Date: Fri, 28 Feb 2025 14:03:22 -0800 Message-Id: <20250228220328.49438-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the DAMON sampling and aggregation intervals auto-tuning mechanism as briefly described on 'struct damon_intervals_goal'. The core part for deciding the direction and amount of the changes is implemented reusing the feedback loop function which is being used for DAMOS quotas auto-tuning. Unlike the DAMOS quotas auto-tuning use case, limit the maximum decreasing amount after the adjustment to 50% of the current value, though. This is because the intervals have no good merits at rapid reductions since it could unnecessarily increase the monitoring overhead. Signed-off-by: SeongJae Park --- include/linux/damon.h | 16 +++++++++ mm/damon/core.c | 76 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index 130c3e01089c..eed008b64a23 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -718,6 +718,17 @@ struct damon_attrs { struct damon_intervals_goal intervals_goal; unsigned long min_nr_regions; unsigned long max_nr_regions; +/* private: internal use only */ + /* + * @aggr_interval to @sample_interval ratio. + * Core-external components call damon_set_attrs() with &damon_attrs + * that this field is unset. In the case, damon_set_attrs() sets this + * field of resulting &damon_attrs. Core-internal components such as + * kdamond_tune_intervals() calls damon_set_attrs() with &damon_attrs + * that this field is set. In the case, damon_set_attrs() just keep + * it. + */ + unsigned long aggr_samples; }; =20 /** @@ -766,6 +777,11 @@ struct damon_ctx { * update */ unsigned long next_ops_update_sis; + /* + * number of sample intervals that should be passed before next + * intervals tuning + */ + unsigned long next_intervals_tune_sis; /* for waiting until the execution of the kdamond_fn is started */ struct completion kdamond_started; /* for scheme quotas prioritization */ diff --git a/mm/damon/core.c b/mm/damon/core.c index b11595c01c37..d4fc2c907cfc 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -687,6 +687,10 @@ int damon_set_attrs(struct damon_ctx *ctx, struct damo= n_attrs *attrs) if (attrs->sample_interval > attrs->aggr_interval) return -EINVAL; =20 + /* calls from core-external doesn't set this. */ + if (!attrs->aggr_samples) + attrs->aggr_samples =3D attrs->aggr_interval / sample_interval; + ctx->next_aggregation_sis =3D ctx->passed_sample_intervals + attrs->aggr_interval / sample_interval; ctx->next_ops_update_sis =3D ctx->passed_sample_intervals + @@ -1392,6 +1396,65 @@ static void kdamond_reset_aggregated(struct damon_ct= x *c) } } =20 +static unsigned long damon_get_intervals_score(struct damon_ctx *c) +{ + struct damon_target *t; + struct damon_region *r; + unsigned long sz_region, max_access_events =3D 0, access_events =3D 0; + unsigned long target_access_events; + unsigned long goal_bp =3D c->attrs.intervals_goal.access_bp; + + damon_for_each_target(t, c) { + damon_for_each_region(r, t) { + sz_region =3D damon_sz_region(r); + max_access_events +=3D sz_region * c->attrs.aggr_samples; + access_events +=3D sz_region * r->nr_accesses; + } + } + target_access_events =3D max_access_events * goal_bp / 10000; + return access_events * 10000 / target_access_events; +} + +static unsigned long damon_feed_loop_next_input(unsigned long last_input, + unsigned long score); + +static unsigned long damon_get_intervals_adaptation_bp(struct damon_ctx *c) +{ + unsigned long score_bp, adaptation_bp; + + score_bp =3D damon_get_intervals_score(c); + adaptation_bp =3D damon_feed_loop_next_input(100000000, score_bp) / + 10000; + /* + * adaptaion_bp ranges from 1 to 20,000. Avoid too rapid reduction of + * the intervals by rescaling [1,10,000] to [5000, 10,000]. + */ + if (adaptation_bp <=3D 10000) + adaptation_bp =3D 5000 + adaptation_bp / 2; + return adaptation_bp; +} + +static void kdamond_tune_intervals(struct damon_ctx *c) +{ + unsigned long adaptation_bp; + struct damon_attrs new_attrs; + struct damon_intervals_goal *goal; + + adaptation_bp =3D damon_get_intervals_adaptation_bp(c); + if (adaptation_bp =3D=3D 10000) + return; + + new_attrs =3D c->attrs; + goal =3D &c->attrs.intervals_goal; + new_attrs.sample_interval =3D min(goal->max_sample_us, + c->attrs.sample_interval * adaptation_bp / 10000); + new_attrs.sample_interval =3D max(goal->min_sample_us, + new_attrs.sample_interval); + new_attrs.aggr_interval =3D new_attrs.sample_interval * + c->attrs.aggr_samples; + damon_set_attrs(c, &new_attrs); +} + static void damon_split_region_at(struct damon_target *t, struct damon_region *r, unsigned long sz_r); =20 @@ -2300,6 +2363,8 @@ static void kdamond_init_intervals_sis(struct damon_c= tx *ctx) ctx->next_aggregation_sis =3D ctx->attrs.aggr_interval / sample_interval; ctx->next_ops_update_sis =3D ctx->attrs.ops_update_interval / sample_interval; + ctx->next_intervals_tune_sis =3D ctx->next_aggregation_sis * + ctx->attrs.intervals_goal.aggrs; =20 damon_for_each_scheme(scheme, ctx) { apply_interval =3D scheme->apply_interval_us ? @@ -2384,6 +2449,17 @@ static int kdamond_fn(void *data) sample_interval =3D ctx->attrs.sample_interval ? ctx->attrs.sample_interval : 1; if (ctx->passed_sample_intervals >=3D next_aggregation_sis) { + if (ctx->attrs.intervals_goal.aggrs && + ctx->passed_sample_intervals >=3D + ctx->next_intervals_tune_sis) { + ctx->next_intervals_tune_sis +=3D + ctx->attrs.aggr_samples * + ctx->attrs.intervals_goal.aggrs; + kdamond_tune_intervals(ctx); + sample_interval =3D ctx->attrs.sample_interval ? + ctx->attrs.sample_interval : 1; + + } ctx->next_aggregation_sis =3D next_aggregation_sis + ctx->attrs.aggr_interval / sample_interval; =20 --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 5398B1DED55; Fri, 28 Feb 2025 22:03:34 +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=1740780216; cv=none; b=lF9k9Xrh8o1BAQIql2JqI+7wh4H45I1qQ0S3jbjN2lAVNQz6vMfwHdEf5q3qLc1jhUGHEyUQkP+aKYRI7ywyUS8IcG4+wqu3SIxFG1Kjw4VI9+0+B9kEriAI5kTpHjb3c7I1WFjsw2xQ+VBlBr68KsEvjUfJkrqLMQPZJg9GvyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780216; c=relaxed/simple; bh=oYTrlxmiR5BNoFrioFop/hpnftvDsKcm3PmL/H0/UqA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EzAMPL5UoCk/8BhdRPm/b6oA/TV/QyhACGWiilKsEbINOLiK4j3cIKGW4tcrhOs7/kttA7ECc1e/uiY/ZrCue4JRJVWe6iI1yDdB8BbiqCqK+pD5ESI+7nkLBClcIiaVW+ajaRCRx2Nj2C0fl8wpkoWKQbbjCwi7o/YDLgm6yMY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e/FphRjd; 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="e/FphRjd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96286C4AF09; Fri, 28 Feb 2025 22:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780214; bh=oYTrlxmiR5BNoFrioFop/hpnftvDsKcm3PmL/H0/UqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e/FphRjdGqDtr0R0HIkMrG187LEe7z469tMGPI07zZ54hj1kb7AgXUVnoFoTGPK7I tgnafQKOapIxO1YQszMqW1Y0QlZtSphOc/TYJdCb6hut5LvcL2v1DC/gASdD+9KVhv 9GWkNI9qH12ebwRByk2InerJEWBorZDbo0vHUnAO8X2kGYozCZZSPzyOMAiWHOfzCl AMwVQEXD7G2+ui63OTvUeghCyhujwrf7KtfkPX5J3EDroNetug/pRduK9yNplTXyn6 gFAJRK3rsetI3uZ+h7WGbC/XtbLbIzmCcnrSbtSZFQodT+Xrc/zICc3Zuk5OdYlAmk 5Rd2++9FJieEA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 3/8] mm/damon/sysfs: implement intervals tuning goal directory Date: Fri, 28 Feb 2025 14:03:23 -0800 Message-Id: <20250228220328.49438-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement DAMON sysfs interface directory and its files for setting DAMON sampling and aggregation intervals auto-tuning goal. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index deeab04d3b46..a772060300b4 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -408,6 +408,164 @@ static const struct kobj_type damon_sysfs_targets_kty= pe =3D { .default_groups =3D damon_sysfs_targets_groups, }; =20 +/* + * intervals goal directory + */ + +struct damon_sysfs_intervals_goal { + struct kobject kobj; + unsigned long access_bp; + unsigned long aggrs; + unsigned long min_sample_us; + unsigned long max_sample_us; +}; + +static struct damon_sysfs_intervals_goal *damon_sysfs_intervals_goal_alloc( + unsigned long access_bp, unsigned long aggrs, + unsigned long min_sample_us, unsigned long max_sample_us) +{ + struct damon_sysfs_intervals_goal *goal =3D kmalloc(sizeof(*goal), + GFP_KERNEL); + + if (!goal) + return NULL; + + goal->kobj =3D (struct kobject){}; + goal->access_bp =3D access_bp; + goal->aggrs =3D aggrs; + goal->min_sample_us =3D min_sample_us; + goal->max_sample_us =3D max_sample_us; + return goal; +} + +static ssize_t access_bp_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->access_bp); +} + +static ssize_t access_bp_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + unsigned long nr; + int err =3D kstrtoul(buf, 0, &nr); + + if (err) + return err; + + goal->access_bp =3D nr; + return count; +} + +static ssize_t aggrs_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->aggrs); +} + +static ssize_t aggrs_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + unsigned long nr; + int err =3D kstrtoul(buf, 0, &nr); + + if (err) + return err; + + goal->aggrs =3D nr; + return count; +} + +static ssize_t min_sample_us_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->min_sample_us); +} + +static ssize_t min_sample_us_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + unsigned long nr; + int err =3D kstrtoul(buf, 0, &nr); + + if (err) + return err; + + goal->min_sample_us =3D nr; + return count; +} + +static ssize_t max_sample_us_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + + return sysfs_emit(buf, "%lu\n", goal->max_sample_us); +} + +static ssize_t max_sample_us_store(struct kobject *kobj, + struct kobj_attribute *attr, const char *buf, size_t count) +{ + struct damon_sysfs_intervals_goal *goal =3D container_of(kobj, + struct damon_sysfs_intervals_goal, kobj); + unsigned long nr; + int err =3D kstrtoul(buf, 0, &nr); + + if (err) + return err; + + goal->max_sample_us =3D nr; + return count; +} + +static void damon_sysfs_intervals_goal_release(struct kobject *kobj) +{ + kfree(container_of(kobj, struct damon_sysfs_intervals_goal, kobj)); +} + +static struct kobj_attribute damon_sysfs_intervals_goal_access_bp_attr =3D + __ATTR_RW_MODE(access_bp, 0600); + +static struct kobj_attribute damon_sysfs_intervals_goal_aggrs_attr =3D + __ATTR_RW_MODE(aggrs, 0600); + +static struct kobj_attribute damon_sysfs_intervals_goal_min_sample_us_attr= =3D + __ATTR_RW_MODE(min_sample_us, 0600); + +static struct kobj_attribute damon_sysfs_intervals_goal_max_sample_us_attr= =3D + __ATTR_RW_MODE(max_sample_us, 0600); + +static struct attribute *damon_sysfs_intervals_goal_attrs[] =3D { + &damon_sysfs_intervals_goal_access_bp_attr.attr, + &damon_sysfs_intervals_goal_aggrs_attr.attr, + &damon_sysfs_intervals_goal_min_sample_us_attr.attr, + &damon_sysfs_intervals_goal_max_sample_us_attr.attr, + NULL, +}; +ATTRIBUTE_GROUPS(damon_sysfs_intervals_goal); + +static const struct kobj_type damon_sysfs_intervals_goal_ktype =3D { + .release =3D damon_sysfs_intervals_goal_release, + .sysfs_ops =3D &kobj_sysfs_ops, + .default_groups =3D damon_sysfs_intervals_goal_groups, +}; + /* * intervals directory */ @@ -417,6 +575,7 @@ struct damon_sysfs_intervals { unsigned long sample_us; unsigned long aggr_us; unsigned long update_us; + struct damon_sysfs_intervals_goal *intervals_goal; }; =20 static struct damon_sysfs_intervals *damon_sysfs_intervals_alloc( @@ -436,6 +595,32 @@ static struct damon_sysfs_intervals *damon_sysfs_inter= vals_alloc( return intervals; } =20 +static int damon_sysfs_intervals_add_dirs(struct damon_sysfs_intervals *in= tervals) +{ + struct damon_sysfs_intervals_goal *goal; + int err; + + goal =3D damon_sysfs_intervals_goal_alloc(0, 0, 0, 0); + if (!goal) + return -ENOMEM; + + err =3D kobject_init_and_add(&goal->kobj, + &damon_sysfs_intervals_goal_ktype, &intervals->kobj, + "intervals_goal"); + if (err) { + kobject_put(&goal->kobj); + intervals->intervals_goal =3D NULL; + return err; + } + intervals->intervals_goal =3D goal; + return 0; +} + +static void damon_sysfs_intervals_rm_dirs(struct damon_sysfs_intervals *in= tervals) +{ + kobject_put(&intervals->intervals_goal->kobj); +} + static ssize_t sample_us_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -569,6 +754,9 @@ static int damon_sysfs_attrs_add_dirs(struct damon_sysf= s_attrs *attrs) err =3D kobject_init_and_add(&intervals->kobj, &damon_sysfs_intervals_ktype, &attrs->kobj, "intervals"); + if (err) + goto put_intervals_out; + err =3D damon_sysfs_intervals_add_dirs(intervals); if (err) goto put_intervals_out; attrs->intervals =3D intervals; @@ -599,6 +787,7 @@ static int damon_sysfs_attrs_add_dirs(struct damon_sysf= s_attrs *attrs) static void damon_sysfs_attrs_rm_dirs(struct damon_sysfs_attrs *attrs) { kobject_put(&attrs->nr_regions_range->kobj); + damon_sysfs_intervals_rm_dirs(attrs->intervals); kobject_put(&attrs->intervals->kobj); } =20 --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 41F2D1DE2DF; Fri, 28 Feb 2025 22:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780216; cv=none; b=NsZm8Se2SnJCB5t7bZTtWft0na6qSc+Om03wyLAvbH+9Rkprqp/+IfmsiwJfCIBT5UxIf2PfM7ZPap3vRVbIOT1Gx0xql+a1teoygBEXJUE36KW+Vj3rhuaRLotUz4pH0GYLT1MtVUjrPghpBSF0k/a5EXQgoAYgEy/GL7plsSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780216; c=relaxed/simple; bh=0K6yd3M1vKE/q1zzJCXy7CoQ3azMzfYHIkHl3bOjRxs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uTRs8vk/nEFXGNLU6FD6v6JvGbS5fIMIyds+XgeXo4gTSO+9g4f18iZeLnHclmh9HOU81iSoNG3UW6SvkcbisEido29H8lHLq6PBTEoDSVwruz7J70DqGKwsUdd20PBP/RNH0TVedB5h0rk99shvHd0NlMveHkF7rBECU2Vw59E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RcCtkQaE; 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="RcCtkQaE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E878BC4CED6; Fri, 28 Feb 2025 22:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780216; bh=0K6yd3M1vKE/q1zzJCXy7CoQ3azMzfYHIkHl3bOjRxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RcCtkQaESFf5y1g5mOXKOhQCuzU0QktIpwpSJaWldsKbKMwcF+S0oFoQ6Y8G1knlH fTjzAAZ/DpjUf7jjF5IbgcGZLXhnqPkEu2hUf/UCy4LCTaqE2kfxirOuWKGe/J59gw oFnaoWl8vZcTfvZJH/4/vI2aCZ+s5hPB6Qbxj8YdKtleklCm6dJ4P55adsA1VAbjY5 iKzsa02CZc3r3vjfLJt9Hzx8UHr+2B/E5yhqqxLLCeBdCMLeZGri51wLi6Q5u+wDuj uV4EA/ERkJx4Fzrp4TkmlwFogk98r6AVOtmBb2hxSGVpEllwkEnuGgXKfk36s+95nr ZhvKbvfDpl5WA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 4/8] mm/damon/sysfs: commit intervals tuning goal Date: Fri, 28 Feb 2025 14:03:24 -0800 Message-Id: <20250228220328.49438-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-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" Connect DAMON sysfs interface for sampling and aggregation intervals auto-tuning with DAMON core API, so that users can really use the feature using the sysfs files. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index a772060300b4..fa5f004f0670 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1273,11 +1273,18 @@ static int damon_sysfs_set_attrs(struct damon_ctx *= ctx, struct damon_sysfs_attrs *sys_attrs) { struct damon_sysfs_intervals *sys_intervals =3D sys_attrs->intervals; + struct damon_sysfs_intervals_goal *sys_goal =3D + sys_intervals->intervals_goal; struct damon_sysfs_ul_range *sys_nr_regions =3D sys_attrs->nr_regions_range; struct damon_attrs attrs =3D { .sample_interval =3D sys_intervals->sample_us, .aggr_interval =3D sys_intervals->aggr_us, + .intervals_goal =3D { + .access_bp =3D sys_goal->access_bp, + .aggrs =3D sys_goal->aggrs, + .min_sample_us =3D sys_goal->min_sample_us, + .max_sample_us =3D sys_goal->max_sample_us}, .ops_update_interval =3D sys_intervals->update_us, .min_nr_regions =3D sys_nr_regions->min, .max_nr_regions =3D sys_nr_regions->max, --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 CC2911DEFE6; Fri, 28 Feb 2025 22:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780217; cv=none; b=hlBhxFYnp/a2iD/hIlvqa7vDSAaqGyrY6JScfGylfQOZygrl3QjfLPKzV/0uHWpgskv/AvyCIX++Os8VNL/DkPFfAjWFQpdGTuml1wBL1rhlcddwzMJGZd9Wlm/CvGcuWuyn2NivuASfn8Ctzq6n/66vr325hQcDKQTQlqa8Y1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780217; c=relaxed/simple; bh=LSjpeMzXWVkQm84u7Pg3DRD/aAE+XvDLQxgeGEMx2JU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rU6OCc8+r3sjrGZGlCQ2SABvTinSc7/CI8vSacWi/GL2dVPsbkKbUVqlyvXhTqw5btuwvR6trH/FioTViR9i3U1hRvRhOVMqoQOMAvjBpB+h6P1aqSrW0yV6qPQnc9V6XvdCVQAwmCcNlBzt15JgF4RT8jXwZ6INUHkBttZR+PY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyUvQ5RC; 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="ZyUvQ5RC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26C68C4CEE5; Fri, 28 Feb 2025 22:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780217; bh=LSjpeMzXWVkQm84u7Pg3DRD/aAE+XvDLQxgeGEMx2JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZyUvQ5RCMFQwflA+TMO8dM7S8jYiryk86Led7r9AWzRFl7xTVycCaRQSn1iJo6WYv jztKcAwB8eAZ0Mkw/Tp1l2SfKnkW5IgmEZjQsG+pC3+R0t2eFqcLFn+SkJW2s+YPgT Fq8ncuwkI7PWynynSVOXwUSMbMxEipKUZXQRZI8ClmQP3EewaVcrxLoybZrBGiWNHa W6EPURqnOVVydku6UCehBFEThJRRLqGY0/9ZDtcGz2xiVRznycPdk/dAcUNjQjaDIb ryk+5js4ai70mv6qkGpCl6Fa1PEi/gHMcPPqChg0z3KCjS8gloBVy2iDJXgealPOjR 0cOIV0q2sQX0Q== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 5/8] mm/damon/sysfs: implement a command to update auto-tuned monitoring intervals Date: Fri, 28 Feb 2025 14:03:25 -0800 Message-Id: <20250228220328.49438-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-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 kernel API callers can show auto-tuned sampling and aggregation intervals from the monmitoring attributes data structure. That can be useful for debugging or tuning of the feature. DAMON user-space ABI users has no way to see that, though. Implement a new DAMON sysfs interface command, namely 'update_tuned_intervals', for the purpose. If the command is written to the kdamond state file, the tuned sampling and aggregation intervals will be updated to the corresponding sysfs interface files. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index fa5f004f0670..ccd435d234b9 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1213,6 +1213,11 @@ enum damon_sysfs_cmd { * effective size quota of the scheme in bytes. */ DAMON_SYSFS_CMD_UPDATE_SCHEMES_EFFECTIVE_QUOTAS, + /* + * @DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS: Update the tuned monitoring + * intevals. + */ + DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS, /* * @NR_DAMON_SYSFS_CMDS: Total number of DAMON sysfs commands. */ @@ -1230,6 +1235,7 @@ static const char * const damon_sysfs_cmd_strs[] =3D { "update_schemes_tried_regions", "clear_schemes_tried_regions", "update_schemes_effective_quotas", + "update_tuned_intervals", }; =20 /* @@ -1502,6 +1508,17 @@ static int damon_sysfs_upd_schemes_effective_quotas(= void *data) return 0; } =20 +static int damon_sysfs_upd_tuned_intervals(void *data) +{ + struct damon_sysfs_kdamond *kdamond =3D data; + struct damon_ctx *ctx =3D kdamond->damon_ctx; + + kdamond->contexts->contexts_arr[0]->attrs->intervals->sample_us =3D + ctx->attrs.sample_interval; + kdamond->contexts->contexts_arr[0]->attrs->intervals->aggr_us =3D + ctx->attrs.aggr_interval; + return 0; +} =20 /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling reques= ts. @@ -1723,6 +1740,9 @@ static int damon_sysfs_handle_cmd(enum damon_sysfs_cm= d cmd, return damon_sysfs_damon_call( damon_sysfs_upd_schemes_effective_quotas, kdamond); + case DAMON_SYSFS_CMD_UPDATE_TUNED_INTERVALS: + return damon_sysfs_damon_call( + damon_sysfs_upd_tuned_intervals, kdamond); default: break; } --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 0BFD61DF721; Fri, 28 Feb 2025 22:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780219; cv=none; b=JAmVq6dns/jmFzD2jjWWI9uWML7399Xo+XM+7efzdIqs0Vlc3LXJDrelRbLCWcDUzAyVrFC6v6/UDGurcENjiS0lzQqsySRAWCLjrutXYqVejAaR/7rKv6quLUHxC3OmB7UgemcTR7UzOs/+WWhLpNJeHltMZbtLpwOaCOSY6fs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780219; c=relaxed/simple; bh=lz38ZfaiLRvrAxvubSW+sgoHg1CnZkQRWxBUnqzdWlw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U+uh2dOT6d9Yi7vV3bisuMeMVKzMj19/wc3tGuvaIkRl6RTYsUZyu1htjW+K2zbFO+h68DtBuoIo2OvV3Kgx47D3dYEeNwWYb6zSSXZAXFIQo1PFFC2YvMvrY0AJqedI2P6OIoceIi73w5nPlv38/ZDMxVHqYeS9WGSrTRzDoRc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ajQa2jtK; 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="ajQa2jtK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B641C4CEE9; Fri, 28 Feb 2025 22:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780218; bh=lz38ZfaiLRvrAxvubSW+sgoHg1CnZkQRWxBUnqzdWlw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ajQa2jtKMbyi6nxzW5Lc6EVqDsUDtcxOIO2hfWYywHFkfkP4rbp5RZAMPZNmG715S UCM+wPFTFQPTDm/5EebwAntpeZuspJtiJg3R0GIstymjrCq/0YiyKgkqa8t5mtloPf yWMUNq/SIWdWFIeunONR3vARkdI03fGWwnyBf3PftIGIvaH5ZDm6iHeH62oJQc3MPe k41CHY3GqcGlVpqcMzvu34bAin6xmou7DwaWGJSOlvagKbejFCNrVGb3UKuH8gHjJU RsgiZzZm7vJg6aVneFZD4mAccNKMnXuSN1VaocW4xg6nl48Vcp38nBo6oZA8cpED5i g6VUMB9GkbSfA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 6/8] Docs/mm/damon/design: document for intervals auto-tuning Date: Fri, 28 Feb 2025 14:03:26 -0800 Message-Id: <20250228220328.49438-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-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" Document the design of DAMON sampling and aggregation intervals auto-tuning. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index ffea744e4889..0cc9f6441354 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -313,6 +313,10 @@ sufficient for the given purpose, it shouldn't be unne= cessarily further lowered. It is recommended to be set proportional to ``aggregation interv= al``. By default, the ratio is set as ``1/20``, and it is still recommended. =20 +Based on the manual tuning guide, DAMON provides more intuitive knob-based +intervals auto tuning mechanism. Please refer to :ref:`the design documen= t of +the feature ` for detail. + Refer to below documents for an example tuning based on the above guide. =20 .. toctree:: @@ -321,6 +325,48 @@ Refer to below documents for an example tuning based o= n the above guide. monitoring_intervals_tuning_example =20 =20 +.. _damon_design_monitoring_intervals_autotuning: + +Monitoring Intervals Auto-tuning +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +DAMON provides automatic tuning of the ``sampling interval`` and ``aggrega= tion +interval`` based on the :ref:`the tuning guide idea +`. The tuning mechanism allo= ws +users to set the aimed amount of access events to observe via DAMON within +given time interval. The target can be specified by the user as a ratio of +DAMON-observed access events to the theoretical maximum amount of the even= ts +(``access_bp``) that measured within a given number of aggregations +(``aggrs``). + +The DAMON-observed access events are calculated in byte granularity based = on +DAMON :ref:`region assumption `. For +example, if a region of size ``X`` bytes of ``Y`` ``nr_accesses`` is found= , it +means ``X * Y`` access events are observed by DAMON. Theoretical maximum +access events for the region is calculated in same way, but replacing ``Y`` +with theoretical maximum ``nr_accesses``, which can be calculated as +``aggregation interval / sampling interval``. + +The mechanism calculates the ratio of access events for ``aggrs`` aggregat= ions, +and increases or decrease the ``sampleing interval`` and ``aggregation +interval`` in same ratio, if the observed access ratio is lower or higher = than +the target, respectively. The ratio of the intervals change is decided in +proportion to the distance between current samples ratio and the target ra= tio. + +The user can further set the minimum and maximum ``sampling interval`` tha= t can +be set by the tuning mechanism using two parameters (``min_sample_us`` and +``max_sample_us``). Because the tuning mechanism changes ``sampling inter= val`` +and ``aggregation interval`` in same ratio always, the minimum and maximum +``aggregation interval`` after each of the tuning changes can automaticall= y set +together. + +The tuning is turned off by default, and need to be set explicitly by the = user. +As a rule of thumbs and the Parreto principle, 4% access samples ratio tar= get +is recommended. Note that Parreto principle (80/20 rule) has applied twic= e. +That is, assumes 4% (20% of 20%) DAMON-observed access events ratio (sourc= e) +to capture 64% (80% multipled by 80%) real access events (outcomes). + + .. _damon_design_damos: =20 Operation Schemes --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 0ED3E1DE2C9; Fri, 28 Feb 2025 22:03:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780223; cv=none; b=PyuOjnTXX6088x32NX2LipzPntZvoeJ6LBe2+zbw91WWU8Sj81r7qYP/pkeOvCrLwPrgAplV/qaeRwRdFyuxrmVH5ZNO5MeVUyamr/dY79pFfWngPxPSbinN2CHA9JoivGMChCZSMP8aPllBKP7vRw0h6+di/BROUPpSqnjSDaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780223; c=relaxed/simple; bh=B70HmhIJO7Eh/CP1TQGw5euMpvWBGHv7eOKxBRU5Z5w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tMpi+zzxrsyxy3GtSJbUatR/nNy1khOI4AM0VHcj+3J6QJRG3pFXsf0hrxO1UeXJj8Lx/lzZAAMpNrcj0FIqU2tsp2DFnYXSwwSFZJJNNDe441CrS2TNcEr/JkqkTArhLFV7fh+uKgITReZ5CKYLgs56S+NlA2Tg0sB/AqmHcSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IwbR1DRq; 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="IwbR1DRq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA81AC4CEE2; Fri, 28 Feb 2025 22:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780222; bh=B70HmhIJO7Eh/CP1TQGw5euMpvWBGHv7eOKxBRU5Z5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwbR1DRqnyn+hhaN7l8cEj7lEPg+iYG8BDSQFmBJ0uc5SgEbwpsfOS+vQ3X/N1P1R FKmdUpSI67JyQy+A6WTma7/nvUtqicF4UABpFa5V2aeuOVDBdxHivm37a2hKwqw4nt tKW2Qh5r9agqTfUF/0H0Setjo1SPsIUDp17vQTZC22SXxEP/XAtHHcShJhgcJhmkSd bgKtbzzJEiOgwK4tdCnrNEXwkLnOfK8IGDTi4B0YG3Ayqn/eOwxQWp3rTXmT47E9yj KsSbhVijI3bcFHkr6kiWd0oGvVZ+s1K/E+5J/WO78bPVdZxxbSFxfmGqL6HC0aU82H 7/ZFu9VMp1Tvg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 7/8] Docs/ABI/damon: document intervals auto-tuning ABI Date: Fri, 28 Feb 2025 14:03:27 -0800 Message-Id: <20250228220328.49438-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-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" Document the DAMON user-space ABI for DAMON sampling and aggregation intervals auto-tuning. Signed-off-by: SeongJae Park --- .../ABI/testing/sysfs-kernel-mm-damon | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-damon b/Documentatio= n/ABI/testing/sysfs-kernel-mm-damon index 9666074f06f3..293197f180ad 100644 --- a/Documentation/ABI/testing/sysfs-kernel-mm-damon +++ b/Documentation/ABI/testing/sysfs-kernel-mm-damon @@ -91,6 +91,36 @@ Description: Writing a value to this file sets the updat= e interval of the DAMON context in microseconds as the value. Reading this file returns the value. =20 +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/intrvals_goal/access_bp +Date: Feb 2025 +Contact: SeongJae Park +Description: Writing a value to this file sets the monitoring intervals + auto-tuning target DAMON-observed access events ratio within + the given time interval (aggrs in same directory), in bp + (1/10,000). Reading this file returns the value. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/intrvals_goal/aggrs +Date: Feb 2025 +Contact: SeongJae Park +Description: Writing a value to this file sets the time interval to achieve + the monitoring intervals auto-tuning target DAMON-observed + access events ratio (access_bp in same directory) within. + Reading this file returns the value. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/intrvals_goal/min_sample_us +Date: Feb 2025 +Contact: SeongJae Park +Description: Writing a value to this file sets the minimum value of + auto-tuned sampling interval in microseconds. Reading this + file returns the value. + +What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/intervals/intrvals_goal/max_sample_us +Date: Feb 2025 +Contact: SeongJae Park +Description: Writing a value to this file sets the maximum value of + auto-tuned sampling interval in microseconds. Reading this + file returns the value. + What: /sys/kernel/mm/damon/admin/kdamonds//contexts//monitoring_att= rs/nr_regions/min =20 WDate: Mar 2022 --=20 2.39.5 From nobody Fri Dec 19 04:23:33 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 CF1761DE3A3; Fri, 28 Feb 2025 22:03:43 +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=1740780223; cv=none; b=SfmyC/bSIZvyGF7v1UoA7i40ymZ0NY92GesBp2KlUBoSnHv+1P/nJJN7pHD5TMrf6Dub1h1ja91VBHfaTQdIL454KzDzrcroyf7OtpqAmrnEUZKUYQuJnmVTzH2QaUO42aTAhMxwMLY9SCY+5htgJeh65OQjVjgDplr8w0fLzJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740780223; c=relaxed/simple; bh=/MYVJ3rlbtoAJvOWV+07+WHhI+Q9ZMyJiRshemc3Pdc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Ag8JLQ0wQEu2GNZnEWhGP0gr7jbSz6fXJCbyjKfLA1cqYTLyXriRaC98tvEtqP30ag+pYYQ+fe8fsm2XukOLNqNOQvYfxSwoGjbsKzA9GcnVUZvU10gbPOXE51y/eoRBv7eptL4p+euXPOHLkwoDy8xp3tHV/NL9eCLFtcYu2fs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Nq2iiPk2; 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="Nq2iiPk2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8453CC4CED6; Fri, 28 Feb 2025 22:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740780223; bh=/MYVJ3rlbtoAJvOWV+07+WHhI+Q9ZMyJiRshemc3Pdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nq2iiPk2X5wTDN1rEOhOJnEv7NUqTZJOvlOPuG4MMW8vwgYUrCmBJZr0xIR1yo67p d62wq7xVOamZeT/26kiOHlRTUgVUh+AKnoUpbQvikp9/ocZxHLXyjbkLd3hq84CNsr itckDfPhKA/XUHOR/oCEIecXteOvOtfPEAVZ+dJlAW9cT0J9Otlla234ZkzQuJFEyR ICpB0TrNmaOreR88REGBcrAGzRMAo5KqlM4PuuNKBWE2GJES9v5cdNsU8Op9pvsHTT xy80Iro2FNyawVskSDN6LLFepAILtO1ZerHnL5MBoetcI+LH4E19VwtbKEPXLQDT/s FgfKKuVTQLcTQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, kernel-team@meta.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 8/8] Docs/admin-guide/mm/damon/usage: add intervals_goal directory on the hierarchy Date: Fri, 28 Feb 2025 14:03:28 -0800 Message-Id: <20250228220328.49438-9-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250228220328.49438-1-sj@kernel.org> References: <20250228220328.49438-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Document DAMON sysfs interface usage for DAMON sampling and aggregation intervals auto-tuning. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 25 ++++++++++++++++++++ Documentation/mm/damon/design.rst | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index 4b25c25d4f4f..8f01ad8792e7 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -64,6 +64,7 @@ comma (","). =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`0 `/avail= _operations,operations =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`monitoring_att= rs `/ =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 intervals/= sample_us,aggr_us,update_us + =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 = intervals_goal/access_bp,aggrs,min_sample_us,max_sample_us =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 nr_regions= /min,max =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`targets `/nr_targets =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 =E2=94=82 :ref:`0 `/pid_target @@ -132,6 +133,11 @@ Users can write below commands for the kdamond to the = ``state`` file. - ``off``: Stop running. - ``commit``: Read the user inputs in the sysfs files except ``state`` file again. +- ``update_tuned_intervals``: Update the contents of ``sample_us`` and + ``aggr_us`` files of the kdamond with the auto-tuning applied ``sampling + interval`` and ``aggregation interval`` for the files. Please refer to + :ref:`intervals_goal section ` + for more details. - ``commit_schemes_quota_goals``: Read the DAMON-based operation schemes' :ref:`quota goals `. - ``update_schemes_stats``: Update the contents of stats files for each @@ -213,6 +219,25 @@ writing to and rading from the files. For more details about the intervals and monitoring regions range, please = refer to the Design document (:doc:`/mm/damon/design`). =20 +.. _damon_usage_sysfs_monitoring_intervals_goal: + +contexts//monitoring_attrs/intervals/intervals_goal/ +------------------------------------------------------- + +Under the ``intervals`` directory, one directory for automated tuning of +``sample_us`` and ``aggr_us``, namely ``intervals_goal`` directory also ex= ists. +Under the directory, four files for the auto-tuning control, namely +``access_bp``, ``aggrs``, ``min_sample_us`` and ``max_sample_us`` exist. +Please refer to the :ref:`design document of the feature +` for the internal of the tu= ning +mechanism. Reading and writing the four files under ``intervals_goal`` +directory shows and updates the tuning parameters that described in the +:ref:design doc ` with the s= ame +names. The tuning starts with the user-set ``sample_us`` and ``aggr_us``.= The +tuning-applied current values of the two intervals can be read from the +``sample_us`` and ``aggr_us`` files after writing ``update_tuned_intervals= `` to +the ``state`` file. + .. _sysfs_targets: =20 contexts//targets/ diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index 0cc9f6441354..0cf678d98b1b 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -366,6 +366,10 @@ is recommended. Note that Parreto principle (80/20 ru= le) has applied twice. That is, assumes 4% (20% of 20%) DAMON-observed access events ratio (sourc= e) to capture 64% (80% multipled by 80%) real access events (outcomes). =20 +To know how user-space can use this feature via :ref:`DAMON sysfs interface +`, refer to :ref:`intervals_goal ` part of +the documentation. + =20 .. _damon_design_damos: =20 --=20 2.39.5