From nobody Fri Jan 2 17:09:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F721CD68E6 for ; Tue, 10 Oct 2023 01:26:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379289AbjJJB0N (ORCPT ); Mon, 9 Oct 2023 21:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379251AbjJJB0I (ORCPT ); Mon, 9 Oct 2023 21:26:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 205D291 for ; Mon, 9 Oct 2023 18:26:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50667C433C8; Tue, 10 Oct 2023 01:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696901166; bh=tkpBuPAHcXxVtnYMQEIhabnoxptCyM9g6IJhkHy1SMg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tAWQTp/K52moV1cPuIjdEwQJ611H9Xy78nBYCj90TW3I4Ov5uPdLOFPNqJYK3VXAw +Ll4igPCl10aeRmwGmu+DHjgv08wOmOQnBGquWSiyOwjVkyU5kwz6VG35hAUTxFH8K f8KTLiado7LKukenztqwf8o17fVXIAEb73doXRJgHbgOTxzJN4mVRFatJlxSjI7Bxk qR1+S0Y6NMcIOJdjIMZL7PrPU7rS0HH/3Wh/0Le67RiElATC2oJrBpt8heZ6JaVPDS TVZCQHhFbEQqHjYysEhkeyr2R2d810evFOuASv+otwr6W4Jx3TF3+7v9YBY7zHqMjB uV1ETgeQCVyxw== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/3] mm/damon/sysfs-schemes: do not update tried regions more than one DAMON snapshot Date: Tue, 10 Oct 2023 01:25:58 +0000 Message-Id: <20231010012600.83140-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010012600.83140-1-sj@kernel.org> References: <20231010012600.83140-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" DAMON_SYSFS exposes every DAMON-found region that eligible for applying the scheme action for one aggregation interval. However, each DAMON-based operation scheme has its own apply interval. Hence, for a scheme that having its apply interval much smaller than the aggregation interval, DAMON_SYSFS will expose the scheme regions that applied to more than one DAMON monitoring results snapshots. Since the purpose of DAMON tried regions is exposing single snapshot, this makes no much sense. Track progress of each scheme's tried regions update and avoid the case. Signed-off-by: SeongJae Park --- mm/damon/sysfs-schemes.c | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index a7d70b95c4dd..b07a5c544b34 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -113,11 +113,47 @@ static const struct kobj_type damon_sysfs_scheme_regi= on_ktype =3D { * scheme regions directory */ =20 +/* + * enum damos_sysfs_regions_upd_status - Represent DAMOS tried regions upd= ate + * status + * @DAMOS_TRIED_REGIONS_UPD_IDLE: Waiting for next request. + * @DAMOS_TRIED_REGIONS_UPD_STARTED: Update started. + * @DAMOS_TRIED_REGIONS_UPD_FINISHED: Update finished. + * + * Each DAMON-based operation scheme (&struct damos) has its own apply + * interval, and we need to expose the scheme tried regions based on only + * single snapshot. For this, we keep the tried regions update status for= each + * scheme. The status becomes 'idle' at the beginning. + * + * Once the tried regions update request is received, the request handling + * start function (damon_sysfs_scheme_update_regions_start()) sets the sta= tus + * of all schemes as 'idle' again, and register ->before_damos_apply() and + * ->after_sampling() callbacks. + * + * Then, the first followup ->before_damos_apply() callback + * (damon_sysfs_before_damos_apply()) sets the status 'started'. The first + * ->after_sampling() callback (damon_sysfs_after_sampling()) after the ca= ll + * is called only after the scheme is completely applied + * to the given snapshot. Hence the callback knows the situation by showi= ng + * 'started' status, and sets the status as 'finished'. Then, + * damon_sysfs_before_damos_apply() understands the situation by showing t= he + * 'finished' status and do nothing. + * + * Finally, the tried regions request handling finisher function + * (damon_sysfs_schemes_update_regions_stop()) unregisters the callbacks. + */ +enum damos_sysfs_regions_upd_status { + DAMOS_TRIED_REGIONS_UPD_IDLE, + DAMOS_TRIED_REGIONS_UPD_STARTED, + DAMOS_TRIED_REGIONS_UPD_FINISHED, +}; + struct damon_sysfs_scheme_regions { struct kobject kobj; struct list_head regions_list; int nr_regions; unsigned long total_bytes; + enum damos_sysfs_regions_upd_status upd_status; }; =20 static struct damon_sysfs_scheme_regions * @@ -130,6 +166,7 @@ damon_sysfs_scheme_regions_alloc(void) INIT_LIST_HEAD(®ions->regions_list); regions->nr_regions =3D 0; regions->total_bytes =3D 0; + regions->upd_status =3D DAMOS_TRIED_REGIONS_UPD_IDLE; return regions; } =20 @@ -1777,6 +1814,10 @@ static int damon_sysfs_before_damos_apply(struct dam= on_ctx *ctx, return 0; =20 sysfs_regions =3D sysfs_schemes->schemes_arr[schemes_idx]->tried_regions; + if (sysfs_regions->upd_status =3D=3D DAMOS_TRIED_REGIONS_UPD_FINISHED) + return 0; + if (sysfs_regions->upd_status =3D=3D DAMOS_TRIED_REGIONS_UPD_IDLE) + sysfs_regions->upd_status =3D DAMOS_TRIED_REGIONS_UPD_STARTED; sysfs_regions->total_bytes +=3D r->ar.end - r->ar.start; if (damos_regions_upd_total_bytes_only) return 0; @@ -1793,6 +1834,29 @@ static int damon_sysfs_before_damos_apply(struct dam= on_ctx *ctx, return 0; } =20 +/* + * DAMON callback that called after each accesses sampling. While this + * callback is registered, damon_sysfs_lock should be held to ensure the + * regions directories exist. + */ +static int damon_sysfs_after_sampling(struct damon_ctx *ctx) +{ + struct damon_sysfs_schemes *sysfs_schemes =3D + damon_sysfs_schemes_for_damos_callback; + struct damon_sysfs_scheme_regions *sysfs_regions; + int i; + + for (i =3D 0; i < sysfs_schemes->nr; i++) { + sysfs_regions =3D sysfs_schemes->schemes_arr[i]->tried_regions; + if (sysfs_regions->upd_status =3D=3D + DAMOS_TRIED_REGIONS_UPD_STARTED) + sysfs_regions->upd_status =3D + DAMOS_TRIED_REGIONS_UPD_FINISHED; + } + + return 0; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_clear_regions( struct damon_sysfs_schemes *sysfs_schemes, @@ -1816,6 +1880,16 @@ int damon_sysfs_schemes_clear_regions( return 0; } =20 +static void damos_tried_regions_init_upd_status( + struct damon_sysfs_schemes *sysfs_schemes) +{ + int i; + + for (i =3D 0; i < sysfs_schemes->nr; i++) + sysfs_schemes->schemes_arr[i]->tried_regions->upd_status =3D + DAMOS_TRIED_REGIONS_UPD_IDLE; +} + /* Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock */ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, @@ -1823,8 +1897,10 @@ int damon_sysfs_schemes_update_regions_start( { damon_sysfs_schemes_clear_regions(sysfs_schemes, ctx); damon_sysfs_schemes_for_damos_callback =3D sysfs_schemes; + damos_tried_regions_init_upd_status(sysfs_schemes); damos_regions_upd_total_bytes_only =3D total_bytes_only; ctx->callback.before_damos_apply =3D damon_sysfs_before_damos_apply; + ctx->callback.after_sampling =3D damon_sysfs_after_sampling; return 0; } =20 @@ -1837,6 +1913,7 @@ int damon_sysfs_schemes_update_regions_stop(struct da= mon_ctx *ctx) { damon_sysfs_schemes_for_damos_callback =3D NULL; ctx->callback.before_damos_apply =3D NULL; + ctx->callback.after_sampling =3D NULL; damon_sysfs_schemes_region_idx =3D 0; return 0; } --=20 2.34.1 From nobody Fri Jan 2 17:09:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6721ACD68E2 for ; Tue, 10 Oct 2023 01:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379319AbjJJB0Q (ORCPT ); Mon, 9 Oct 2023 21:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379264AbjJJB0I (ORCPT ); Mon, 9 Oct 2023 21:26:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B680E9D for ; Mon, 9 Oct 2023 18:26:07 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0390C433CA; Tue, 10 Oct 2023 01:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696901167; bh=yWXWsEsp+bNgfqib0es1oavC1e2n/ntLxLviyD7crcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IV6y0JX+4rigSdZUd1hRuiKh2HaDEEjIDljRDMOeW3AB7wxj72XOAJc5kYFlY5w2S 6PJMuETlqeosgA3sjPLApwudm850uFTqJPJ0j4OWEx1F+Pu/1On7KhLpiVnGqjsVJA U919sGnrb5xWyy5fBHtR73Lxdef0AhDjAWfeT2+QjS0hrJAQEBnAVdtA6AphxFOok5 BYhVIM1RMW9qvCFCEvcBK2Pp44sWxKZU62mLlJjSI0foETCl6z0Rxl4fFvX6sbEWw8 5fFJYuZwgmxG5HJcTrU1FXI3VbuRvFTXe9ksDIQHOM/TkM8tFfDcWK54+oYPBBdc1n vUksMtObrMpBg== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/3] mm/damon/sysfs: avoid empty scheme tried regions for large apply interval Date: Tue, 10 Oct 2023 01:25:59 +0000 Message-Id: <20231010012600.83140-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010012600.83140-1-sj@kernel.org> References: <20231010012600.83140-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" DAMON_SYSFS assumes all schemes will be applied for at least one DAMON monitoring results snapshot within one aggregation interval, or makes no sense to wait for it while DAMON is deactivated by the watermarks. That for deactivated status still makes sense, but the aggregation interval based assumption is invalid now because each scheme can has its own apply interval. For schemes having larger than the aggregation or watermarks check interval, DAMOS tried regions update request can be finished without the update. Avoid the case by explicitly checking the status of the schemes tried regions update and watermarks based DAMON deactivation. Signed-off-by: SeongJae Park --- mm/damon/sysfs-common.h | 2 ++ mm/damon/sysfs-schemes.c | 16 ++++++++++++++++ mm/damon/sysfs.c | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mm/damon/sysfs-common.h b/mm/damon/sysfs-common.h index fd482a0639b4..5ff081226e28 100644 --- a/mm/damon/sysfs-common.h +++ b/mm/damon/sysfs-common.h @@ -49,6 +49,8 @@ int damon_sysfs_schemes_update_regions_start( struct damon_sysfs_schemes *sysfs_schemes, struct damon_ctx *ctx, bool total_bytes_only); =20 +bool damos_sysfs_regions_upd_done(void); + int damon_sysfs_schemes_update_regions_stop(struct damon_ctx *ctx); =20 int damon_sysfs_schemes_clear_regions( diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c index b07a5c544b34..45bd0fd4a8b1 100644 --- a/mm/damon/sysfs-schemes.c +++ b/mm/damon/sysfs-schemes.c @@ -1904,6 +1904,22 @@ int damon_sysfs_schemes_update_regions_start( return 0; } =20 +bool damos_sysfs_regions_upd_done(void) +{ + struct damon_sysfs_schemes *sysfs_schemes =3D + damon_sysfs_schemes_for_damos_callback; + struct damon_sysfs_scheme_regions *sysfs_regions; + int i; + + for (i =3D 0; i < sysfs_schemes->nr; i++) { + sysfs_regions =3D sysfs_schemes->schemes_arr[i]->tried_regions; + if (sysfs_regions->upd_status !=3D + DAMOS_TRIED_REGIONS_UPD_FINISHED) + return false; + } + return true; +} + /* * Called from damon_sysfs_cmd_request_callback under damon_sysfs_lock. C= aller * should unlock damon_sysfs_lock which held before diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index e6b8e90bd450..71bdc51bea6e 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1336,12 +1336,13 @@ static int damon_sysfs_commit_input(struct damon_sy= sfs_kdamond *kdamond) =20 /* * damon_sysfs_cmd_request_callback() - DAMON callback for handling reques= ts. - * @c: The DAMON context of the callback. + * @c: The DAMON context of the callback. + * @active: Whether @c is not deactivated due to watermarks. * * 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) +static int damon_sysfs_cmd_request_callback(struct damon_ctx *c, bool acti= ve) { struct damon_sysfs_kdamond *kdamond; bool total_bytes_only =3D false; @@ -1373,6 +1374,13 @@ static int damon_sysfs_cmd_request_callback(struct d= amon_ctx *c) goto keep_lock_out; } } else { + /* + * Continue regions updating if DAMON is till + * active and the update for all schemes is not + * finished. + */ + if (active && !damos_sysfs_regions_upd_done()) + goto keep_lock_out; err =3D damon_sysfs_upd_schemes_regions_stop(kdamond); damon_sysfs_schemes_regions_updating =3D false; } @@ -1392,6 +1400,24 @@ static int damon_sysfs_cmd_request_callback(struct d= amon_ctx *c) return err; } =20 +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); +} + +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); +} + static struct damon_ctx *damon_sysfs_build_ctx( struct damon_sysfs_context *sys_ctx) { @@ -1407,8 +1433,8 @@ static struct damon_ctx *damon_sysfs_build_ctx( return ERR_PTR(err); } =20 - ctx->callback.after_wmarks_check =3D damon_sysfs_cmd_request_callback; - ctx->callback.after_aggregation =3D damon_sysfs_cmd_request_callback; + ctx->callback.after_wmarks_check =3D damon_sysfs_after_wmarks_check; + ctx->callback.after_aggregation =3D damon_sysfs_after_aggregation; ctx->callback.before_terminate =3D damon_sysfs_before_terminate; return ctx; } --=20 2.34.1 From nobody Fri Jan 2 17:09:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 776ECCD68E3 for ; Tue, 10 Oct 2023 01:26:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379310AbjJJB0T (ORCPT ); Mon, 9 Oct 2023 21:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379272AbjJJB0J (ORCPT ); Mon, 9 Oct 2023 21:26:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C499E; Mon, 9 Oct 2023 18:26:08 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93F91C433CD; Tue, 10 Oct 2023 01:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696901168; bh=PRMNaWi4eLwEr1ddca0C6ItteLnRKdFxcFRimSLMbuo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DinnA0mIa0xXyxJyvyJPWRn0gfhZL4OuTtZEyU3zDNJ24JTTZMqczCXaW2VxkR2HD 9/SCzw1uhvAFQOO25rh75JnffxCNj6eyVIgAoSbetEBVXf7UZoouWyNpUYRhKPVzFL hsXezDNiIK/6jDuO3EJf2XG2trq4vlFHii7KB+umOOp6rlfwtGkO7RikibyFV9WOgB fBwpcMEJb+9ze5Mn8+zY9PMJoZiDp0LrwO/3PNxkdUjxCJ2TVeuVbNIBjl8+upxgTH Mag4Z3w65XlP8fXvzuI0flSiII5ELHCFKiSEEtuzTZqS65EarNJLY/SLDy6g5Xp3Cg LgwoNZvdyVH6Q== From: SeongJae Park Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/3] Docs/admin-guide/mm/damon/usage: update for tried regions update time interval Date: Tue, 10 Oct 2023 01:26:00 +0000 Message-Id: <20231010012600.83140-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010012600.83140-1-sj@kernel.org> References: <20231010012600.83140-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The documentation says DAMOS tried regions update feature of DAMON sysfs interface is doing the update for one aggregation interval after the request is made. Since the introduction of the per-scheme apply interval, that behavior makes no much sense. Hence the implementation has changed to update the regions for each scheme for only its apply interval. Further update the document to reflect the real behavior. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index 8507a6e45d86..da94feb97ed1 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -432,9 +432,9 @@ that reading it returns the total size of the scheme tr= ied regions, and creates directories named integer starting from ``0`` under this directory. Each directory contains files exposing detailed information about each of the m= emory region that the corresponding scheme's ``action`` has tried to be applied = under -this directory, during next :ref:`aggregation interval -`. The information includes address range, -``nr_accesses``, and ``age`` of the region. +this directory, during next :ref:`apply interval ` of = the +corresponding scheme. The information includes address range, ``nr_access= es``, +and ``age`` of the region. =20 Writing ``update_schemes_tried_bytes`` to the relevant ``kdamonds//stat= e`` file will only update the ``total_bytes`` file, and will not create the --=20 2.34.1