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: 13011218 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 AD567C433FE for ; Wed, 19 Oct 2022 00:13:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CEBC6B007D; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41D916B007E; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 246B16B0080; Tue, 18 Oct 2022 20:13:28 -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 04D446B007E for ; Tue, 18 Oct 2022 20:13:28 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D0997160403 for ; Wed, 19 Oct 2022 00:13:27 +0000 (UTC) X-FDA: 80035774854.14.05960A3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf26.hostedemail.com (Postfix) with ESMTP id 79A8B140034 for ; Wed, 19 Oct 2022 00:13:27 +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 dfw.source.kernel.org (Postfix) with ESMTPS id BFB9361739; 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 ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U9pp1b7B; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666138407; a=rsa-sha256; cv=none; b=zzkVHMh+/NaK8AjJ1q26yfnrABC4wvT/xK9u5bfmkffMSfTKZgc76V8pl/O2TKf9yLrkgO 7p8KWiRQ0Dqnk1MZPgk8lDkaB1WjrfSwImg7wmIz0kPBH0u39bf80ikbIb5LQA/yHBlAyV NqMiGFK8vBbfROdsvXp+X2O1ixjxa+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666138407; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=otZ3cZsdN0eVOTuuk0C5+zLbtmVk0Bql1jChYjKXVEU=; b=7i7hykoTcWYNDLSsV4KN87KEP1/l0NbpwmuAX5g/LZqVKGgYBRndOgXulQm2VmpmPRnoSp mU7GYjnrwN9kZe28+Jh412Zgu1BpQ1Lc2OQAI4h6WmqXEfKs8TIYBa6nAv9W0+jma06d7E ckphmTmNzLbCxSBGHyzoBe4UX4kX460= Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=U9pp1b7B; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: msbcpsra8mi4tbae5ii4mifxz7or3qm1 X-Rspamd-Queue-Id: 79A8B140034 X-HE-Tag: 1666138407-293306 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: 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);