From patchwork Tue Sep 12 18:35:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 138376 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp611610vqx; Tue, 12 Sep 2023 11:49:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCbKHxGdWwpa7FweKZ89sRXlUMWPjfYczItKFa7CYeCviPTLdE0AItDJ0v6CWYvcvwkVkV X-Received: by 2002:a05:6358:7209:b0:13c:eef8:dec0 with SMTP id h9-20020a056358720900b0013ceef8dec0mr601520rwa.3.1694544558836; Tue, 12 Sep 2023 11:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694544558; cv=none; d=google.com; s=arc-20160816; b=0mB5p1m8Cz5RLfkHAkTJyPf2vTiR/4TvvfqDbBxdZ/B8nfwFILheyFJzDN9QdxL37Q 8rSLqKtuNalEaIcjQ455EI4eAa+xKvZqN3mxwFWPrW1RlqFQokAncxfiWxycKZKWfezd WoUnztWwOvXzn/3JGS5C19oCta8i/iL+E3fRyjBVRhwPoPsw7gJtUK5ruvrVB4H9dbq9 V4nX92XRMPcjqFg635tsxqHJ0vrVYEfAxo/BqIRyRFadWyWGOiPHqTb4sFKA+gLPhuOu yiOwGMLT8Dy7GrTDHZL/EYwUDkY+B52U3PT0dPlicdrPj8iL21shGb7pHB+p6V42N7bU PGTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=br6RxcKd/TjTkbpaCnmw6891aLjmucVBm8/AaQUAbqY=; fh=BtCI6lkGDJTtX/kUKY7W1m6QbhCosJAsbhe/Uk6QBzA=; b=RoG2AiSBunoJHzMM7dGrF4xJP8v0DFYYItjVuZ4AA18Pls0vDMYRIlx5ppzmAkVleR 1GVGCAqUGCkoim7Ywo74ZFr4Dm7o7RCGeq+n3p156z5FC8zylgQk2GP237m2H9FrJraV Sc4zSMFzeX6r59IDFzhPH+WHYbmEX4MH5hQtKh7KRrqvHsQ/y9GCqebg6IutardPaNQV VvEm94yckkrE7Xt1l3eMr4CuKJ1aAo+RN5sNnzq89wwtqTeNvlxZDC6wexBLldm36rS1 Ok1MUTAUQlaZM/mUtf96YGqxpyJ30+SChURruDfa9wN7a1nXwnClzXM0ajlOokuGB2od 5OdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOqHbiv4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id s1-20020a656901000000b0056c14d298b8si8061313pgq.373.2023.09.12.11.49.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOqHbiv4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0E6D480C5FA4; Tue, 12 Sep 2023 11:36:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237492AbjILSgK (ORCPT + 36 others); Tue, 12 Sep 2023 14:36:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237481AbjILSgI (ORCPT ); Tue, 12 Sep 2023 14:36:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D10461702; Tue, 12 Sep 2023 11:36:03 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED624C433C8; Tue, 12 Sep 2023 18:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694543763; bh=Ux09g9gvrxiM7e96gBaO1VxVbWHC7sVtSUZj+woij6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOqHbiv48YSWBMbvRN6vZU8YWfJ0YC6DosroZx3A9M/67BNe2s8yE+t+ld33U9+Ed yKQ0j/iIsfTFVUpjQceMWRN4+KJ+yGz/oPfLgYD6T7ESKSy57+wsRBHH/D0fIXWTrg mWwQH0/AviNOCk2et9ZKEZcf2sXer7c4xxzOofCwPLg75IkVptfYLTPbnEJVn4oBxV d+0ZMia0W2b3jC6/BO5wmTuxhh14bR8DrpKf43skAtdrDpMqSa/HBGML5WUkthZEAZ FqfnnIUKGKUKFyRSeTuR8eX6JU0ttzoub0B6fA3D9F0k9pTKpYsUBWMQNRWsPpmF8S 0qU87pY7zDxTg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Steven Rostedt , damon@lists.linux.dev, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] mm/damon/core: add a tracepoint for damos apply target regions Date: Tue, 12 Sep 2023 18:35:58 +0000 Message-Id: <20230912183559.4733-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230912183559.4733-1-sj@kernel.org> References: <20230912183559.4733-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:36:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776858755173621710 X-GMAIL-MSGID: 1776858755173621710 DAMON provides damon_aggregated tracepoint, which exposes details of each region and its access monitoring results. It is useful for getting whole monitoring results, e.g., for recording purposes. For investigations of DAMOS, DAMON Sysfs interface provides DAMOS statistics and tried_regions directory. But, those provides only statistics and snapshots. If the scheme is frequently applied and if the user needs to know every detail of DAMOS behavior, the snapshot-based interface could be insufficient and expensive. As a last resort, userspace users need to record the all monitoring results via damon_aggregated tracepoint and simulate how DAMOS would worked. It is unnecessarily complicated. DAMON kernel API users, meanwhile, can do that easily via before_damos_apply() callback field of 'struct damon_callback', though. Add a tracepoint that will be called just after before_damos_apply() callback for more convenient investigations of DAMOS. The tracepoint exposes all details about each regions, similar to damon_aggregated tracepoint. Please note that DAMOS is currently not only for memory management but also for query-like efficient monitoring results retrievals (when 'stat' action is used). Until now, only statistics or snapshots were supported. Addition of this tracepoint allows efficient full recording of DAMOS-based filtered monitoring results. Signed-off-by: SeongJae Park --- include/trace/events/damon.h | 39 ++++++++++++++++++++++++++++++++++++ mm/damon/core.c | 32 ++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/include/trace/events/damon.h b/include/trace/events/damon.h index 0b8d13bde17a..19930bb7af9a 100644 --- a/include/trace/events/damon.h +++ b/include/trace/events/damon.h @@ -9,6 +9,45 @@ #include #include +TRACE_EVENT_CONDITION(damos_before_apply, + + TP_PROTO(unsigned int context_idx, unsigned int scheme_idx, + unsigned int target_idx, struct damon_region *r, + unsigned int nr_regions, bool do_trace), + + TP_ARGS(context_idx, target_idx, scheme_idx, r, nr_regions, do_trace), + + TP_CONDITION(do_trace), + + TP_STRUCT__entry( + __field(unsigned int, context_idx) + __field(unsigned int, scheme_idx) + __field(unsigned long, target_idx) + __field(unsigned long, start) + __field(unsigned long, end) + __field(unsigned int, nr_accesses) + __field(unsigned int, age) + __field(unsigned int, nr_regions) + ), + + TP_fast_assign( + __entry->context_idx = context_idx; + __entry->scheme_idx = scheme_idx; + __entry->target_idx = target_idx; + __entry->start = r->ar.start; + __entry->end = r->ar.end; + __entry->nr_accesses = r->nr_accesses; + __entry->age = r->age; + __entry->nr_regions = nr_regions; + ), + + TP_printk("ctx_idx=%u scheme_idx=%u target_idx=%lu nr_regions=%u %lu-%lu: %u %u", + __entry->context_idx, __entry->scheme_idx, + __entry->target_idx, __entry->nr_regions, + __entry->start, __entry->end, + __entry->nr_accesses, __entry->age) +); + TRACE_EVENT(damon_aggregated, TP_PROTO(unsigned int target_id, struct damon_region *r, diff --git a/mm/damon/core.c b/mm/damon/core.c index ca631dd88b33..3ca34a252a3c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -950,6 +950,33 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, struct timespec64 begin, end; unsigned long sz_applied = 0; int err = 0; + /* + * We plan to support multiple context per kdamond, as DAMON sysfs + * implies with 'nr_contexts' file. Nevertheless, only single context + * per kdamond is supported for now. So, we can simply use '0' context + * index here. + */ + unsigned int cidx = 0; + struct damos *siter; /* schemes iterator */ + unsigned int sidx = 0; + struct damon_target *titer; /* targets iterator */ + unsigned int tidx = 0; + bool do_trace = false; + + /* get indices for trace_damos_before_apply() */ + if (trace_damos_before_apply_enabled()) { + damon_for_each_scheme(siter, c) { + if (siter == s) + break; + sidx++; + } + damon_for_each_target(titer, c) { + if (titer == t) + break; + tidx++; + } + do_trace = true; + } if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { @@ -964,8 +991,11 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, ktime_get_coarse_ts64(&begin); if (c->callback.before_damos_apply) err = c->callback.before_damos_apply(c, t, r, s); - if (!err) + if (!err) { + trace_damos_before_apply(cidx, sidx, tidx, r, + damon_nr_regions(t), do_trace); sz_applied = c->ops.apply_scheme(c, t, r, s); + } ktime_get_coarse_ts64(&end); quota->total_charged_ns += timespec64_to_ns(&end) - timespec64_to_ns(&begin); From patchwork Tue Sep 12 18:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 138372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp609285vqx; Tue, 12 Sep 2023 11:44:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJnyKdMzmQ8AbHSa6sCfEchGXkB9L6rqz93EWYIed1KONaLG1P2jYpyLtntAQM1i+bz5Bn X-Received: by 2002:a05:6a20:3d1d:b0:14c:5dc2:650c with SMTP id y29-20020a056a203d1d00b0014c5dc2650cmr289836pzi.40.1694544293304; Tue, 12 Sep 2023 11:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694544293; cv=none; d=google.com; s=arc-20160816; b=pjgSGCgER0U6ch/+ko4FbXwlsDbTxl7KvwdgpBj+v2cGPIycwYuQMZFrTsAD4zUMWm UVx7vXB2vqDKRPi4+qpaocHibP66diLc0kL/MS2IuHquB9seZa4DXdYyX5uJ14NHcSYJ VPVXG0F4scdvjlTNKo2I2kItM72KzyjzMLUScXnkhrQvj7F/ZiqQcRVMRBiwjLDPqWs+ 7YlIzAPBvWWFvguaDrCJ8eQqWbkqdpMQzgRG09CRW+8ACBqgR/E4e2PAFshqoZ2JuDfP ePpVdbzfWjIZdRzy3hAMud9OxXhVJEqVj2poxdYdI0tunKY8+4VJqC2tAxip68sab4/x k7sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uOx8ScWSHBi0cBUuCTXtnmBmYJYt+uGhSfTmXKZCMoM=; fh=jKijsxc1Z2CHKVFf4S4lB42jMLcn6gTpewOn4Tq1/VM=; b=rwyZwaJu7SS3IrPtgFoMh5Nj6flvg9GeCPaYFkqsnVDq6oBU5BYfdo7MglM0j+K8pI rW4Dd9nMG8FSg6FZL8SzxIdj/tkVXR7JTkQV7E2e/CUn2B9td3d0UsK1i8zGw5NcS7CV emLHBicFMVc5P9c5iR2yBKHcyozHsubW5BKr+O2PQQbrmjK+h0r71rnZD5Ce8OoTiCu7 jXDpq01rNq5LLso11V/u1wUeM8EjaxqvceO8mlsd4t6IfyL+yynjseBODNRZTjzLa2wx 8/Wim6diecXYZgml1EwTXCxo7S8xJngovUFd6Zg3FJLzGBtlO97YDDHXtFcNydB693ue kabA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s5JuUHrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b19-20020a63d313000000b00565dd108fd4si8077443pgg.115.2023.09.12.11.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:44:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s5JuUHrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 75D4F8020B5A; Tue, 12 Sep 2023 11:36:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237495AbjILSgM (ORCPT + 36 others); Tue, 12 Sep 2023 14:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237484AbjILSgJ (ORCPT ); Tue, 12 Sep 2023 14:36:09 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F6AA10E9; Tue, 12 Sep 2023 11:36:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0063C433CB; Tue, 12 Sep 2023 18:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694543764; bh=yCdyENSSr2jBoqcU5uuhQp9Eg5ZiZzpyIfgAEWQFG08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s5JuUHrpz8KMHLkg8aMJ3PtViMENNhZOAtLD6nysZlBWl+uyrhv3zSqqpvNWONwQv QIYEUB0E3w2F8W8SuVnlt4LiU46fzpWpTcGR1gDv0470uUcu68m82Tfb5IOmyGa66v Hgdbt+Em7BmjNyVFjcxWVozqsAVTzx7b/rjX+alJW6jVjsuZIgNTXpXgyaW3GKKxeK PMHGe7U7hSnxaxc51DtQj/mkPe9NSLEC3QTWMD00ClWL2m6C6AGJPKSvg3hCYdOnHn jzuAi2lVeOsQD4elxE82Ev28fTLi035QaPSuhabGm/E8Y0dak2rqeJ+VYu3WK1UTlm /p3a8NJIx8bow== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] Docs/admin-guide/mm/damon/usage: document damos_before_apply tracepoint Date: Tue, 12 Sep 2023 18:35:59 +0000 Message-Id: <20230912183559.4733-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230912183559.4733-1-sj@kernel.org> References: <20230912183559.4733-1-sj@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:36:25 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776858476631745691 X-GMAIL-MSGID: 1776858476631745691 Document damos_before_apply tracepoint on the usage document. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 37 ++++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/admin-guide/mm/damon/usage.rst index 282062b6f134..6272cd36590a 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -496,15 +496,24 @@ the files as above. Above is only for an example. .. _tracepoint: -Tracepoint for Monitoring Results -================================= +Tracepoints for Monitoring Results +================================== Users can get the monitoring results via the :ref:`tried_regions -` or a tracepoint, ``damon:damon_aggregated``. -While the tried regions directory is useful for getting a snapshot, the -tracepoint is useful for getting a full record of the results. While the -monitoring is turned on, you could record the tracepoint events and show -results using tracepoint supporting tools like ``perf``. For example:: +`. The interface is useful for getting a +snapshot, but it could be inefficient for fully recording all the monitoring +results. For the purpose, two trace points, namely ``damon:damon_aggregated`` +and ``damon:damos_before_apply``, are provided. ``damon:damon_aggregated`` +provides the whole monitoring results, while ``damon:damos_before_apply`` +provides the monitoring results for regions that each DAMON-based Operation +Scheme (:ref:`DAMOS `) is gonna be applied. Hence, +``damon:damos_before_apply`` is more useful for recording internal behavior of +DAMOS, or DAMOS target access +:ref:`pattern ` based query-like efficient +monitoring results recording. + +While the monitoring is turned on, you could record the tracepoint events and +show results using tracepoint supporting tools like ``perf``. For example:: # echo on > monitor_on # perf record -e damon:damon_aggregated & @@ -527,6 +536,20 @@ counter). Finally the tenth field (``X``) shows the ``age`` of the region (refer to :ref:`design ` for more details of the counter). +If the event was ``damon:damos_beofre_apply``, the ``perf script`` output would +be somewhat like below:: + + kdamond.0 47293 [000] 80801.060214: damon:damos_before_apply: ctx_idx=0 scheme_idx=0 target_idx=0 nr_regions=11 121932607488-135128711168: 0 136 + [...] + +Each line of the output represents each monitoring region that each DAMON-based +Operation Scheme was about to be applied at the traced time. The first five +fields are as usual. It shows the index of the DAMON context (``ctx_idx=X``) +of the scheme in the list of the contexts of the context's kdamond, the index +of the scheme (``scheme_idx=X``) in the list of the schemes of the context, in +addition to the output of ``damon_aggregated`` tracepoint. + + .. _debugfs_interface: debugfs Interface (DEPRECATED!)