From patchwork Wed Oct 19 00:13:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 4379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp48915wrs; Tue, 18 Oct 2022 17:17:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6im83Ty0VE6tKqAIsu9yj0cO7QBmp0ToJPf2KeRhgyd5YawCibX0sNHDOB9sPSqS+tfNBv X-Received: by 2002:a17:907:3d9e:b0:791:8933:f9fc with SMTP id he30-20020a1709073d9e00b007918933f9fcmr4564377ejc.111.1666138619943; Tue, 18 Oct 2022 17:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666138619; cv=none; d=google.com; s=arc-20160816; b=yhqu12JzuzwiwRA2HvTtXbX6czAiuECHVBtQwHL0WQGXFxh0iZK1hK0aN2Kmycvtsd kbSP5lW44ShS1M6vXx0qxb00YWb5R+/CnYvinLdC5uFlNk0AYW3v4zsuHP/WJtXnxePq ZMl5V/hbzSXVVBfImkvPnp+nuur0IHSaq1bdOB4QuewA7zmGozlIxHQWDql/4bT/rs3I d/qjZOj36z9XKJHzDW02+bCzqyYuGVAd+FntQqF9buvyLYmBBCOREdQn9BBOknhxA/TG I5lgUfMhXQef0JnPAgd9RuopDQX6A48cP3h3KOxVoLtW7lfpLVh5Ryn21pzWnPFPuCA5 rnGQ== 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=otZ3cZsdN0eVOTuuk0C5+zLbtmVk0Bql1jChYjKXVEU=; b=VMV+SNe5KUGJ+pWQ3Ax4KpJ/W7pfmqcnc8Qg9zC8IXyXpjT8r8CYsipDXE2Nx1/kPe P9RwLl/g8C2akNHOiXqHm+opB7d6y9ASdVIkLMo5k/UJahcBiAgkdNMyy2gTOgvIXev3 iGfHZZXSHEQiH2gLsvoLc1ryWPxnB7j1GLwuJvgbm1nuV30qIBWotbxa44li04ek6GKO 26uoN8+aXmk9y/7CMRLZBGyIb9uEQAjbzMeT8lL6Cyi4HB4WzbDCjY221IKg8abV6pcU CQh6pJfN33GQWNxeZuEYVrtHbP38pth9jbK/KBddtBy4/kUMjcNTkDnQdZtn8b0caRBZ bGig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U9pp1b7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a170906114600b007824b741e7asi10965711eja.236.2022.10.18.17.16.34; Tue, 18 Oct 2022 17:16:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U9pp1b7B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbiJSANm (ORCPT + 99 others); Tue, 18 Oct 2022 20:13:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiJSAN1 (ORCPT ); Tue, 18 Oct 2022 20:13:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5412D2CE4 for ; Tue, 18 Oct 2022 17:13:26 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id C69CF6173B for ; Wed, 19 Oct 2022 00:13:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D03CFC43146; Wed, 19 Oct 2022 00:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666138406; bh=FnyAkoXR3zSbYAw0fdOEm9Hg5cxYpV4uLYPmPdFOaDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U9pp1b7B09qVbPCdp+4zdVt9V5ewegwADs3h5rc8ucicXlgPsvkz2CjkKSzuL6RdD NwTo5CMgWJO11aSxsC+KXSYUHhN3MDHG2o9AXjV+hL35Zu7R1E5vLFGRH4XCA+cBPL 08cwrpif8ixxP1EemyWHiLIlC/PdlcOTs3yghqwG7+GmpkGfAwe/uSgx71CtComf56 M+cFzMkO405uvyi1p+TuUvQoiN16YsqOARcTswB60HGG0+cqTSj5gJhsgURfh95/s2 ndw1xlA49AAckKl+7aaDCaZbhtCyBWV82+/uiRmy+KIOo43mPn4FwWL3/yrQCs7Dv5 B6A6o6Gbv4jdw== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 06/18] mm/damon/core: add a DAMON callback for scheme target regions check Date: Wed, 19 Oct 2022 00:13:05 +0000 Message-Id: <20221019001317.104270-7-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221019001317.104270-1-sj@kernel.org> References: <20221019001317.104270-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747072969695678599?= X-GMAIL-MSGID: =?utf-8?q?1747072969695678599?= For deep level investigation of DAMON, knowing exactly to what regions each DAMON-based operation scheme is applied is helpful. It can also be very helpful for efficient monitoring results passing when the user has interest in regions of specific access patterns. Add a new DAMON callback that will be called before each scheme is applied to each region, to provide the functionality to the kernel API users. Signed-off-by: SeongJae Park --- include/linux/damon.h | 5 +++++ mm/damon/core.c | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index 620ada094c3b..35630634d790 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -357,6 +357,7 @@ struct damon_operations { * @after_wmarks_check: Called after each schemes' watermarks check. * @after_sampling: Called after each sampling. * @after_aggregation: Called after each aggregation. + * @before_damos_apply: Called before applying DAMOS action. * @before_terminate: Called before terminating the monitoring. * @private: User private data. * @@ -385,6 +386,10 @@ struct damon_callback { int (*after_wmarks_check)(struct damon_ctx *context); int (*after_sampling)(struct damon_ctx *context); int (*after_aggregation)(struct damon_ctx *context); + int (*before_damos_apply)(struct damon_ctx *context, + struct damon_target *target, + struct damon_region *region, + struct damos *scheme); void (*before_terminate)(struct damon_ctx *context); }; diff --git a/mm/damon/core.c b/mm/damon/core.c index 9ee9f752f6fc..f196feed78c7 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -765,6 +765,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, unsigned long sz = damon_sz_region(r); struct timespec64 begin, end; unsigned long sz_applied = 0; + int err = 0; if (c->ops.apply_scheme) { if (quota->esz && quota->charged_sz + sz > quota->esz) { @@ -775,7 +776,10 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, damon_split_region_at(t, r, sz); } ktime_get_coarse_ts64(&begin); - sz_applied = c->ops.apply_scheme(c, t, r, s); + if (c->callback.before_damos_apply) + err = c->callback.before_damos_apply(c, t, r, s); + if (!err) + 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);