From patchwork Fri Apr 29 16:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12832412 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 24155C433EF for ; Fri, 29 Apr 2022 16:06:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AFF76B007B; Fri, 29 Apr 2022 12:06:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E97E6B007E; Fri, 29 Apr 2022 12:06:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAE356B0080; Fri, 29 Apr 2022 12:06:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id C3D226B007D for ; Fri, 29 Apr 2022 12:06:18 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9AE7D20956 for ; Fri, 29 Apr 2022 16:06:18 +0000 (UTC) X-FDA: 79410393636.30.922587D Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf25.hostedemail.com (Postfix) with ESMTP id AF4AEA0071 for ; Fri, 29 Apr 2022 16:06:08 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E8690B83645; Fri, 29 Apr 2022 16:06:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CE22C385AF; Fri, 29 Apr 2022 16:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651248375; bh=9dkrDs1lmfWKgDNH59hI5csjK0CcBiTmC6kvCAvLDMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NCspm9dZ2M+ek44LP0LupjNE7TVEZk4ijJkrNvgqpINcHPf95daej1QVmP7hIg5YT jnHP5xhvhMgogEqwDjz+oLlh2sTXMh7tL4IOm8sWFgafYLvirR4pPaff4rCXPAOapr N8MyNAtjHtGFGMb1bl38C8mspKPFV7azs9wzDfF4E2OKldFomUdkvgOYvKqWXD2Ob+ Bnghf4C3sEvDjNYGTXYj0IgdZgb46xeOSOVYtC1p0Lb9X42Mf+Ueb7Xf4IDGvGgLcl VxF/2bUkJBjFPzMcm1AHJULeqBiu8Fiajb2v6Yk7gsR2SsTmFEhu+hNmoMbY0ftY7q j++0Lcm+3pY6w== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 01/14] mm/damon/core: add a new callback for watermarks checks Date: Fri, 29 Apr 2022 16:05:53 +0000 Message-Id: <20220429160606.127307-2-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429160606.127307-1-sj@kernel.org> References: <20220429160606.127307-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: 4rjdwouinc1km1zo58qodpzcezq3zc7u Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=NCspm9dZ; spf=pass (imf25.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AF4AEA0071 X-HE-Tag: 1651248368-707958 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: SeongJae Park For updating input parameters for running DAMON contexts, DAMON kernel API users can use the contexts' callbacks, as it is the safe place for context internal data accesses. When the context has DAMON-based operation schemes and all schemes are deactivated due to their watermarks, however, DAMON does nothing but only watermarks checks. As a result, no callbacks will be called back, and therefore the kernel API users cannot update the input parameters including monitoring attributes, DAMON-based operation schemes, and watermarks. To let users easily update such DAMON input parameters in such a case, this commit adds a new callback, 'after_wmarks_check()'. It will be called after each watermarks check. Users can do the online input parameters update in the callback even under the schemes deactivated case. Signed-off-by: SeongJae Park --- include/linux/damon.h | 7 +++++++ mm/damon/core.c | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 09a5d0d02c00..6cb5ab5d8e9d 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -343,6 +343,7 @@ struct damon_operations { * struct damon_callback - Monitoring events notification callbacks. * * @before_start: Called before starting the monitoring. + * @after_wmarks_check: Called after each schemes' watermarks check. * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. * @before_terminate: Called before terminating the monitoring. @@ -353,6 +354,11 @@ struct damon_operations { * respectively. Therefore, those are good places for installing and cleaning * @private. * + * The monitoring thread calls @after_wmarks_check after each DAMON-based + * operation schemes' watermarks check. If users need to make changes to the + * attributes of the monitoring context while it's deactivated due to the + * watermarks, this is the good place to do. + * * The monitoring thread calls @after_sampling and @after_aggregation for each * of the sampling intervals and aggregation intervals, respectively. * Therefore, users can safely access the monitoring results without additional @@ -365,6 +371,7 @@ struct damon_callback { void *private; int (*before_start)(struct damon_ctx *context); + int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); void (*before_terminate)(struct damon_ctx *context); diff --git a/mm/damon/core.c b/mm/damon/core.c index 5c1331f93c2e..e28fbc3a1969 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1103,6 +1103,10 @@ static int kdamond_wait_activation(struct damon_ctx *ctx) return 0; kdamond_usleep(min_wait_time); + + if (ctx->callback.after_wmarks_check && + ctx->callback.after_wmarks_check(ctx)) + break; } return -EBUSY; } @@ -1129,8 +1133,10 @@ static int kdamond_fn(void *data) sz_limit = damon_region_sz_limit(ctx); while (!kdamond_need_stop(ctx) && !done) { - if (kdamond_wait_activation(ctx)) + if (kdamond_wait_activation(ctx)) { + done = true; continue; + } if (ctx->ops.prepare_access_checks) ctx->ops.prepare_access_checks(ctx);