From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6B4CC71153 for ; Mon, 11 Sep 2023 18:19:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F9406B02D1; Mon, 11 Sep 2023 14:19:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A9236B02D2; Mon, 11 Sep 2023 14:19:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4983F6B02D3; Mon, 11 Sep 2023 14:19:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3D3046B02D1 for ; Mon, 11 Sep 2023 14:19:44 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0BEEFC0B2F for ; Mon, 11 Sep 2023 18:19:44 +0000 (UTC) X-FDA: 81225129888.26.1C2C87C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 30D3440029 for ; Mon, 11 Sep 2023 18:19:41 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of "SRS0=M4tJ=E3=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=M4tJ=E3=goodmis.org=rostedt@kernel.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694456382; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Au+ojZp/1RM66dDEpB0CXLeX2U3Gq72XfEszb9JSiOg=; b=f72S3cnkdW7PSk1Tf+68Z+h9JmjG8lpJDvMXF+CMobPIubpEck95y5u4SaG1IsNy8xwlSd MBqQ0Gn8g/g3Gxpfi0lQ9ybX+nNfm7VctfVsM0HaPUGwaEFxqUUastaunMa7DCSs+sCO0U B26/xIcq0xUv6Qv9/anR9V2QJR9hhEc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf04.hostedemail.com: domain of "SRS0=M4tJ=E3=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=M4tJ=E3=goodmis.org=rostedt@kernel.org" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694456382; a=rsa-sha256; cv=none; b=HD56YnPMzURclutt+7Tm0reIchgjIJW/amE7Iyq1n8L83gEVyrJIsG5cG/hvaeCYPGDyBu iJRHi4Pxqcfb74X7zXQ3FRh/K9q/3BIXL2g11KxoL2kFmzQIaPx7xzNbGsaeA9yfsC8nMv nTzKWTQqBdpu070iHkbJX8/3jR4U64o= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C2B56123E; Mon, 11 Sep 2023 18:19:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F40BAC433C8; Mon, 11 Sep 2023 18:19:39 +0000 (UTC) Date: Mon, 11 Sep 2023 14:19:55 -0400 From: Steven Rostedt To: SeongJae Park Cc: Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] mm/damon/core: add a tracepoint for damos apply target regions Message-ID: <20230911141955.245d1397@gandalf.local.home> In-Reply-To: <20230911045908.97649-2-sj@kernel.org> References: <20230911045908.97649-1-sj@kernel.org> <20230911045908.97649-2-sj@kernel.org> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: apsyteah55i491tea7unrirdihtxpph5 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 30D3440029 X-HE-Tag: 1694456381-889225 X-HE-Meta: U2FsdGVkX18epU/T08+Vx0TeQTYJ1GaIUiZ+FYaVGJ8PJPbKsCqN30ZLB/uR1NaPws/Lr4hIZVPTzu3LNOoH3mj3+2LhVNWPg4I54loW4eqZr4uvkZeWnsYskiZQCnn7k73wcMDXmJ4deooE4XokuB9/Jv+NK84p22So6ICJms/caV0kAhMQgnjwmihLW9nlbUtc1/p2DO+P99YcekxmTgfFJkp13tjeKZOIcX4lpYJSGoMDQbE4G9SGVwpTxHF0vmJbMN+uAxmh0EdbMo77+8NOj0PT6a/v7tRQOCnTwCL91ZyMyVcHSPlUZyIARqTGByeQ2wGaAReQcBMj8LmVGvlBCPAaemD+hyfD5keH0NQLyXzeDagIxwCmeIaswcS7Y8tqZJTahrWqUrJU2bOX96FpATcNv4b2WiAZsPvv5PcJ6mUqKHluLn8Uibcz6CPOwq4VA883i7tad1uKvE2//clg6x3DJyTABJItpvsPD8oM8VSkKzEprZxQn+ev0/WxACAaC000mNmC0V8pDfKwJGied2glN6EOFm+9Y8CtK4UqrBKCxWWzEg+WWIg+GQEPPUdAjOrsLDIzvYl+K+l/AfEmiWs/hEMCwazXu9jxzyQ5L4KgjCz0rBk20spLimLgrCDPhwIuyMK5+9x8XBbzwPZIZ28d9Ys8+xSxbQejL6o08Ux5d3HL5CMvEmu+DZ6jQBBy3qmYfIZRoX9xRTmvFgoIOB+QCdm2XuZrqOAZEdmRJNYp5hKICTsOyJUBaSdtYx7gBMR9PWt9/4Z+Gkn13YJL+fN6tuqn5WxPcm/r5So4TF7evsCrYcuA4N0I3XUZNOLMuXag8BvGKhSfyYBkOQ3HQN8vJx78n7xh6EGG5EIbLaGslDYN/Rgqhs942qVQ+w8J+3FPwJDOVZ7yIBdn1K7yaz0Au7qPXm0tHw0FRb9GhDT5nnU1taLsGf2bNYo8btmrs1vNKgJ/4y8Q+4O DFUinRMA KHU/YSJqUrEkwre+wpY+Y0FSJudDLHh0BAVTLKdpSKVKAtY7GCJsbvS80BarTE+bLLISmxqjle8D1iAXlE1x6FG01hOY159Kpn+ui7Px2sE5N4aRHp+ZxJK8h5xrlU+MMKoaL53Jla8CpGspq8LHN1FwP5EArk2/qNFN1ojCVw68cwn7gvsF3mGWb8MaNuFMIOOd+PvawjFrPWeuoHiFgGlDzHSAzbXOUoUApi0PR+36S4WHzSl4/FejYnZ9EHkWnEpdDrEXhUYVL2S5X5BtkIYS9nglyNt5ZlDA/xqEYHkx8RiFclFllQQ+rreUFAdDVEbA6Inwy0eT/QaDbT2vgMj+F16oECuFVBNlxeHvRV5KarSKtH7D4vaMlnXIRaNhUqk5xDsJHsavpijJqf45f4P9ZnQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000814, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 11 Sep 2023 04:59:07 +0000 SeongJae Park wrote: > --- a/mm/damon/core.c > +++ b/mm/damon/core.c > @@ -950,6 +950,28 @@ 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; > + If this loop is only for passing sidx and tidx to the trace point, you can add around it: 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++; > + } } And then this loop will only be done if that trace event is enabled. To prevent races, you may also want to add a third parameter, or initialize them to -1: sidx = -1; if (trace_damo_before_apply_enabled()) { sidx = 0; [..] } And you can change the TRACE_EVENT() TO TRACE_EVENT_CONDITION(): TRACE_EVENT_CONDITION(damos_before_apply, TP_PROTO(...), TP_ARGS(...), TP_CONDITION(sidx >= 0), and the trace event will not be called if sidx is less than zero. Also, this if statement is only done when the trace event is enabled, so it's equivalent to: if (trace_damos_before_apply_enabled()) { if (sdx >= 0) trace_damos_before_apply(cidx, sidx, tidx, r, damon_nr_regions(t)); } -- Steve > > if (c->ops.apply_scheme) { > if (quota->esz && quota->charged_sz + sz > quota->esz) { > @@ -964,8 +986,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)); > 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); > --