From nobody Sat Nov 23 08:49:22 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19B211632D3; Wed, 13 Nov 2024 16:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515190; cv=none; b=BKZePmtfp2jJByuHfLKIF0KCld1GEBMYk+sIusHN+SyG5MIV7wBNnZNikV/h1f7xJQkYDmb3itys/9pPBExSrzzbho5ORaiWLdcstCTEQjVhS54WKFcrsQEnY1NcN4VgHMbeAmXSXNqu6WKuqowPbdZYTwrYLBUtT0bJORgTxgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515190; c=relaxed/simple; bh=BtvEp8Hm0X4D/xEUdKSvN4oIcwKIlo21XvAkEr+HAVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nUxF3e3td0j/9TcLFDZgQ9eOyzMNCevhnesqUMEjoG6pHkAFhOL61j/GF11uzJ3GVvImefW1yKAisbjyP7YemSNWE1QA2CCBZJkjzk3yp+U7bgUDVSvDiXd65RkRcv9GUxHqIN0Q30fV80UCHPJfa/e2PWXwqXZ2FEIwrvzw4gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AYlow0+U; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AYlow0+U" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBEF9C4CECD; Wed, 13 Nov 2024 16:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515190; bh=BtvEp8Hm0X4D/xEUdKSvN4oIcwKIlo21XvAkEr+HAVY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AYlow0+U+zO+aZXFbzwnd2OZtD+GE1+1VHKHCBaOrZOupvzfnbZdIb0euKEF6f3DW 5kfguUwtgM01VM4jOY223QyQIrLAk4i5A/rj9LpC9q1xclbtlOktOguask3j01aiCS ZytVYb2FVyh6gVIKErHiqL1WCujCStmIkhjO8TXLkXlT93afkYD6Ze1V+jaZ0VxUjn n4jDaj+To31z1/Ym/XQ1AfcG9Bmnin7XdGsaWpe7puLMxTLLRNGFPbN+T2Gp25sef6 6VA7QkuEFHga2/argeI5lNYX5TN7PxLVPeZVB6lMQeIDNV+aREBy7904it3sQu6SU9 a7ebxVB/nHapQ== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 1/5] samples: introduce a skeleton of a sample DAMON module for working set size estimation Date: Wed, 13 Nov 2024 08:26:20 -0800 Message-Id: <20241113162624.48973-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a skeleton for a sample DAMON module that can be used for estimating working set size of a given process. It exposes two module parameters, namely 'pid' and 'enable', which receives what process the module should estimate the working set size of, and whether to start the work or not. Nonetheless, because this is just a skeleton, no real work is implemented. The functionality will be implemented by following commits. Signed-off-by: SeongJae Park --- MAINTAINERS | 1 + samples/Kconfig | 2 ++ samples/Makefile | 1 + samples/damon/Kconfig | 17 +++++++++++ samples/damon/Makefile | 3 ++ samples/damon/wsse.c | 69 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 samples/damon/Kconfig create mode 100644 samples/damon/Makefile create mode 100644 samples/damon/wsse.c diff --git a/MAINTAINERS b/MAINTAINERS index 0383fd7e0a40..d61f4f76c3d5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6256,6 +6256,7 @@ F: Documentation/mm/damon/ F: include/linux/damon.h F: include/trace/events/damon.h F: mm/damon/ +F: samples/damon/ F: tools/testing/selftests/damon/ =20 DAVICOM FAST ETHERNET (DMFE) NETWORK DRIVER diff --git a/samples/Kconfig b/samples/Kconfig index b288d9991d27..8d5a36f0e5d6 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -293,6 +293,8 @@ config SAMPLE_CGROUP =20 source "samples/rust/Kconfig" =20 +source "samples/damon/Kconfig" + endif # SAMPLES =20 config HAVE_SAMPLE_FTRACE_DIRECT diff --git a/samples/Makefile b/samples/Makefile index b85fa64390c5..726bb5293486 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -39,3 +39,4 @@ obj-$(CONFIG_SAMPLE_KMEMLEAK) +=3D kmemleak/ obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) +=3D coresight/ obj-$(CONFIG_SAMPLE_FPROBE) +=3D fprobe/ obj-$(CONFIG_SAMPLES_RUST) +=3D rust/ +obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D damon/ diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig new file mode 100644 index 000000000000..b799e01345c8 --- /dev/null +++ b/samples/damon/Kconfig @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "DAMON Samples" + +config SAMPLE_DAMON_WSSE + bool "DAMON sameple module for working set size estimation" + depends on DAMON && DAMON_VADDR + help + This builds DAMON sample module for working set size estimation. + + The module receives a pid, monitor access to the virtual address + space of the process, estimate working set size of the process, and + repeatedly prints the size on the kernel log. + + If unsure, say N. + +endmenu diff --git a/samples/damon/Makefile b/samples/damon/Makefile new file mode 100644 index 000000000000..ccbe93d40130 --- /dev/null +++ b/samples/damon/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D wsse.o diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c new file mode 100644 index 000000000000..5912f15181c8 --- /dev/null +++ b/samples/damon/wsse.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * working set size estimation: monitor access pattern of given process and + * print estimated working set size (total size of regions that showing so= me + * access). + */ + +#define pr_fmt(fmt) "damon_sample_wsse: " fmt + +#include +#include +#include +#include + +static int target_pid __read_mostly; +module_param(target_pid, int, 0600); + +static int damon_sample_wsse_enable_store( + const char *val, const struct kernel_param *kp); + +static const struct kernel_param_ops enable_param_ops =3D { + .set =3D damon_sample_wsse_enable_store, + .get =3D param_get_bool, +}; + +static bool enable __read_mostly; +module_param_cb(enable, &enable_param_ops, &enable, 0600); +MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); + +static int damon_sample_wsse_start(void) +{ + pr_info("start\n"); + return 0; +} + +static void damon_sample_wsse_stop(void) +{ + pr_info("stop\n"); +} + +static int damon_sample_wsse_enable_store( + const char *val, const struct kernel_param *kp) +{ + bool enabled =3D enable; + int err; + + err =3D kstrtobool(val, &enable); + if (err) + return err; + + if (enable =3D=3D enabled) + return 0; + + if (enable) + return damon_sample_wsse_start(); + damon_sample_wsse_stop(); + return 0; +} + +static int __init damon_sample_wsse_init(void) +{ + return 0; +} + +module_init(damon_sample_wsse_init); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("SeongJae Park"); +MODULE_DESCRIPTION("DAMON sample module for working set size estimation"); --=20 2.39.5 From nobody Sat Nov 23 08:49:22 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 813631DED49; Wed, 13 Nov 2024 16:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515192; cv=none; b=rGPgd96uLQkXt9fQfFP4NMsxqXao2+8371UTUEvHQ1Pcu/76VC5rz4x3mo9Cu3CZfM7RL1XRfVJv7hvXpgR4ckRji9sMM2pAU6x2cskzNiBUM2JyejkxhZqbbaI+NZyVAkzdplMelm5U1c9wwXuDPkb9IUWXFq2XfSCHahFz0tQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515192; c=relaxed/simple; bh=6Kv8j6GXmb5OgoQ5xsiPf6fy1wOOGSi9iB0lHZRsXOs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q+svLScKa8qJHKpizUKbF+SMh3e0kKgQK/541qg4dShmpJdOsLssIUYqQ9TcvOtePj3ej77ISdUgYBiWaGk/uImXEX07gdvo7mEGi5k0uoNkL+KqlnuEqVmYWQbIJGTjz8Frqvt1TPLoNT+avBwX7hRMJ9PviowSQ+wq0SE+m48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o1/agY4m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o1/agY4m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D835AC4CECF; Wed, 13 Nov 2024 16:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515191; bh=6Kv8j6GXmb5OgoQ5xsiPf6fy1wOOGSi9iB0lHZRsXOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1/agY4mtPOWPXWZBhVsqgjbwv8NMsbuCUP2I9qvZ5wF/90hlRy8DhVmtSg7OSDku pyz5low1w7vWU5yo3CU8zLSdJN1o8MSsS3I2p2hjntM+ji1MCf6jxv/FGD3c9WR45R nlkG1pMI5X2xqnwEOgSI4x4QVzEztAoLpK7iZ/PDyGTg4wx1D3TikN6WqGsS5c4IJm Hn9QIr+XYSv+fITSvjfkqh4pNORtFhSDmsXJ2zNlfaYhYlWX8EDv7UVUUKnCTkB6tK ghKzb432jDLcwBmImZJ48ywfO1qpdiQ6Q/rkxubKlBHBadv0EAxiruqVgFSCQzleZE Jrm7ClSIAvi4g== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 2/5] samples/damon/wsse: implement DAMON starting and stopping Date: Wed, 13 Nov 2024 08:26:21 -0800 Message-Id: <20241113162624.48973-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Start running DAMON for the process that user requested to estimate the process via 'pid' parameter, when 'y' is passed to 'enable' parameter. If 'n' is passed, stop running DAMON. Iterating the DAMON monitoring results and estimating the working set side is not yet implemented. It will be implemented by the following commit. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 5912f15181c8..119ac8a2c901 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -27,15 +27,48 @@ static bool enable __read_mostly; module_param_cb(enable, &enable_param_ops, &enable, 0600); MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); =20 +static struct damon_ctx *ctx; +static struct pid *target_pidp; + static int damon_sample_wsse_start(void) { + struct damon_target *target; + pr_info("start\n"); - return 0; + + ctx =3D damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target =3D damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp =3D find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid =3D target_pidp; + + return damon_start(&ctx, 1, true); } =20 static void damon_sample_wsse_stop(void) { pr_info("stop\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); } =20 static int damon_sample_wsse_enable_store( --=20 2.39.5 From nobody Sat Nov 23 08:49:22 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47654178CC8; Wed, 13 Nov 2024 16:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515192; cv=none; b=jXeecypSs7dBXWmdfb+pheug+aNx63Ct0i2DtPbZFydbLtPwHVwUU42W6ZUvJyMgAZhmZjepzN6V+lMKJQvU8VrAlPo929StEZ5dnhujz2PR0xKwbwZLXApTEoHTuZXCTS71vXiF76VQhBHo2KY9iFuX/ezScCxBnV6TdIdtmVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515192; c=relaxed/simple; bh=WP1gX/xo4x64pFwAnpa4+qlhjEolC1jxzqSRjjY1A0I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EDPhEdB5fyuz/d4l8cMCEBSEElmdOfiwwI5iVMe1TLkQNv0Aq9FKdO6BmwRtUjejoWIaqe1BJMwH6aMMTvAITr0CA8CHbo1o1HRLz7xz7Znd6pRwpqJNSQ3jMQaTNnDO+vS/CmK4YL7p/gP93fCADEvPagnUBxx7lSqlB7I0Kiw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nN9kf5OF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nN9kf5OF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECA66C4CECD; Wed, 13 Nov 2024 16:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515192; bh=WP1gX/xo4x64pFwAnpa4+qlhjEolC1jxzqSRjjY1A0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nN9kf5OFlgu4dQr8kCgt11CeEmO3VjWDz9PPNEL9PiWAWkorJg3cQDh8o7rskgdSs cn+ZKCIsnVwh+8dDZO4Zbyur1MW45QSGn8txRaDsySqSV7KIMmfUKA5PWQ1Dv3NHmv +N+s+m3m/WrVUHwd5kcgs7cL+OxACk/rGNf0EmWGQOVxp0vp7tt78QGYKr46jUlIvE NOTMsBSNsx0g5Ie9rDombMvKqIbh7Nyju6A3ZegmdGTOr9s5LdvlzbdX0wltREHHny 3qbGbMDgb7mTKOD9Et9doc+jpde1E3Wt42dbzEXoOmxjsTZX2KM5B2RTwzhiT1mwTz nVlaC5Lb/NTtg== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 3/5] samples/damon/wsse: implement working set size estimation and logging Date: Wed, 13 Nov 2024 08:26:22 -0800 Message-Id: <20241113162624.48973-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the DAMON-based working set size estimation logic. The logic simply iterates memory regions in DAMON-generated access pattern snapshot for every aggregation, and get the total sum of the size of any region having one or higher 'nr_accesses' count. That is, it assumes any region having one or higher 'nr_accesses' to be a part of the working set. The estimated value is printed to the kernel log. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 119ac8a2c901..a2a94c505938 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -30,6 +30,23 @@ MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE= _WSSE"); static struct damon_ctx *ctx; static struct pid *target_pidp; =20 +static int damon_sample_wsse_after_aggregate(struct damon_ctx *c) +{ + struct damon_target *t; + + damon_for_each_target(t, c) { + struct damon_region *r; + unsigned long wss =3D 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + wss +=3D r->ar.end - r->ar.start; + } + pr_info("wss: %lu\n", wss); + } + return 0; +} + static int damon_sample_wsse_start(void) { struct damon_target *target; @@ -57,6 +74,7 @@ static int damon_sample_wsse_start(void) } target->pid =3D target_pidp; =20 + ctx->callback.after_aggregation =3D damon_sample_wsse_after_aggregate; return damon_start(&ctx, 1, true); } =20 --=20 2.39.5 From nobody Sat Nov 23 08:49:22 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC3411FF7C6; Wed, 13 Nov 2024 16:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515194; cv=none; b=d0aoQBHJncGN84AAM6WQKf2DRbiq0Cb6hfsVbxQGKgesn5MYNMchW8SWHG2KDZaPbVBOt63XpvG65+8Wv4t92Zp4aipvjc6aKtPXk0f57e3w/Qs/7SDwx52G6ouQlas2APOmv6MkJt9m89wF73FDAvTh2d345HS+K8wYCTnKpZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515194; c=relaxed/simple; bh=nvp2mMbvRyEYpGGB8GVuStSGx5/+sBiAwPQ8jRBowzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K+1uDVirKQlAOEBbBmJQ6z7ZaEzfJPL/FDOgL2ah0fVHGkiSPTLRDAeK8bAvM9csT2FlzhwlwNbNpi5WiSQhgwpC3jtF6W5AqRgp0HDA0zBoTvRrrAc47BkqXCyaE5/D/4zIpPC+ahNo8zwcEgJASl2wAJcSIbrNlKKN01EMXj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tzYlZYVW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tzYlZYVW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F09AEC4CEDA; Wed, 13 Nov 2024 16:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515193; bh=nvp2mMbvRyEYpGGB8GVuStSGx5/+sBiAwPQ8jRBowzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tzYlZYVWfpmFdoSg5mqCA2/vMt8lNAryL/Qeyopf1laH1M7ZHFQ8p0ykW9VOdcJh8 QERHe9jyUv6PPQWlcy+OZQmMaVZUKzvcTAtpSDf8U1phkVpOe2bzKcf+6Qiqk0Btm0 ZjRmiMhGClDT1cBdOeFLeNqM0iHlUF2cs56Wu4r0rTvkZ1vZ+Q3FnemvCgZ7aiIIFK NFwiOxsY/h4+PN42u737de7plor3eb0vrolvMCpzzIuiubuDelDYWAUqvwUPy4V1pP FBL0v4F4mKXSEs1Sc94U7GsviRoyS7F/h8vtH3Js7xQrYCZSBNaaKRlUM/h/Arvj6V shacV75K8YH0Q== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 4/5] samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation Date: Wed, 13 Nov 2024 08:26:23 -0800 Message-Id: <20241113162624.48973-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a skeleton for a sample DAMON module that can be used for proactively reclaiming cold memory regions of a given process. The skeleton is actually same to working set size estimation sample module, but only the names of the file and symbols are changed. Signed-off-by: SeongJae Park --- samples/Makefile | 1 + samples/damon/Kconfig | 13 +++++ samples/damon/Makefile | 1 + samples/damon/prcl.c | 120 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 samples/damon/prcl.c diff --git a/samples/Makefile b/samples/Makefile index 726bb5293486..5af6bb8afb07 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -40,3 +40,4 @@ obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) +=3D coresight/ obj-$(CONFIG_SAMPLE_FPROBE) +=3D fprobe/ obj-$(CONFIG_SAMPLES_RUST) +=3D rust/ obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D damon/ +obj-$(CONFIG_SAMPLE_DAMON_PRCL) +=3D damon/ diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig index b799e01345c8..63f6dcd71daa 100644 --- a/samples/damon/Kconfig +++ b/samples/damon/Kconfig @@ -14,4 +14,17 @@ config SAMPLE_DAMON_WSSE =20 If unsure, say N. =20 +config SAMPLE_DAMON_PRCL + bool "DAMON sameple module for access-aware proactive reclamation" + depends on DAMON && DAMON_VADDR + help + This builds DAMON sample module for access-aware proactive + reclamation. + + The module receives a pid, monitor access to the virtual address + space of the process, find memory regions that not accessed, and + proactively reclaim the regions. + + If unsure, say N. + endmenu diff --git a/samples/damon/Makefile b/samples/damon/Makefile index ccbe93d40130..7f155143f237 100644 --- a/samples/damon/Makefile +++ b/samples/damon/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 =20 obj-$(CONFIG_SAMPLE_DAMON_WSSE) +=3D wsse.o +obj-$(CONFIG_SAMPLE_DAMON_PRCL) +=3D prcl.o diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c new file mode 100644 index 000000000000..32ccdd91cf55 --- /dev/null +++ b/samples/damon/prcl.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * proactive reclamation: monitor access pattern of a given process, find + * regiosn that seems not accessed, and proactively page out the regions. + */ + +#define pr_fmt(fmt) "damon_sample_prcl: " fmt + +#include +#include +#include +#include + +static int target_pid __read_mostly; +module_param(target_pid, int, 0600); + +static int damon_sample_prcl_enable_store( + const char *val, const struct kernel_param *kp); + +static const struct kernel_param_ops enable_param_ops =3D { + .set =3D damon_sample_prcl_enable_store, + .get =3D param_get_bool, +}; + +static bool enable __read_mostly; +module_param_cb(enable, &enable_param_ops, &enable, 0600); +MODULE_PARM_DESC(enable, "Enable of disable DAMON_SAMPLE_WSSE"); + +static struct damon_ctx *ctx; +static struct pid *target_pidp; + +static int damon_sample_prcl_after_aggregate(struct damon_ctx *c) +{ + struct damon_target *t; + + damon_for_each_target(t, c) { + struct damon_region *r; + unsigned long wss =3D 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + wss +=3D r->ar.end - r->ar.start; + } + pr_info("wss: %lu\n", wss); + } + return 0; +} + +static int damon_sample_prcl_start(void) +{ + struct damon_target *target; + + pr_info("start\n"); + + ctx =3D damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target =3D damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp =3D find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid =3D target_pidp; + + ctx->callback.after_aggregation =3D damon_sample_prcl_after_aggregate; + + return damon_start(&ctx, 1, true); +} + +static void damon_sample_prcl_stop(void) +{ + pr_info("stop\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); +} + +static int damon_sample_prcl_enable_store( + const char *val, const struct kernel_param *kp) +{ + bool enabled =3D enable; + int err; + + err =3D kstrtobool(val, &enable); + if (err) + return err; + + if (enable =3D=3D enabled) + return 0; + + if (enable) + return damon_sample_prcl_start(); + damon_sample_prcl_stop(); + return 0; +} + +static int __init damon_sample_prcl_init(void) +{ + return 0; +} + +module_init(damon_sample_prcl_init); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("SeongJae Park"); +MODULE_DESCRIPTION("DAMON sample module for proactive reclamation"); --=20 2.39.5 From nobody Sat Nov 23 08:49:22 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC3E8200123; Wed, 13 Nov 2024 16:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515194; cv=none; b=sMHCe6MlHRpwCKmfXhajmQF6lCL7rbWhCnufxApQd+8VGbfEU+X55aMOVk/nXv2/R5QrL7ZXvsNQ4/VPjcT8qebkOSTPBoggt9FZk1/NiqHBsZj7QKr7ILobUDmlm3Zq5CE4seSLHRipXGKH7qKXqxjd6bl+9IJgZITgGXhS+f4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731515194; c=relaxed/simple; bh=f5G64UqwzMEmnAbYFpT0izlILG/ACPrrbDzbSfum1w0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N4fZp3QG8XaosRHSR3RPqwWGXFviQdh5u6cksyDoQXvtZIjDKnLbPduRVmbuzlvFncTgLhxTri2FMXwMBn5+7IjDqGSiVAkRVLwautvgwvPQoK3Mh4yOqBsgQT4z/bGrODSS570ibgdCH+EPhTVNE+r36B0xpb7dgPDD+AEj1ng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rk5i0Kre; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rk5i0Kre" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DB50C4CECD; Wed, 13 Nov 2024 16:26:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515194; bh=f5G64UqwzMEmnAbYFpT0izlILG/ACPrrbDzbSfum1w0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rk5i0KreF7flYadabrj+EGCJCsLTTGhajaATGds4Av2dLFB0ET5NvC82TjBJvxycS 3F8B3QAS6ZhPWnO9ZPIMKlxRAiDVZD43qKCgcswmHDjsxDUt7FdvPsdRgCCnNF5f0Q nGsxcUiUXI3EBRNq4mGalvtz3KFT4U2fWWmau6RdFhPU87dw0wVaz34G9equ3oi1Xr xEtAoBju34QRz8l6yzGQUtToGKT66VZWojsuE2QRXF0yMMgYeBNeuJX1Q7W44KrNca LKUAIEWOzRsLZxxDEX0rKCfNkJ5cXx8nZ/TRa+cLJTebBn0njV5enL1Bhugdqy8ZlJ wTsUAyssqsUIQ== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 5/5] samples/damon/prcl: implement schemes setup Date: Wed, 13 Nov 2024 08:26:24 -0800 Message-Id: <20241113162624.48973-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement the DAMOS-based cold memory regions proactive reclamation logic. The logic treats memory regions that assumed to not be accessed at all for five or more seconds as cold, and reclaim as soon as found. Signed-off-by: SeongJae Park --- samples/damon/prcl.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c index 32ccdd91cf55..cf8c6f29d8a3 100644 --- a/samples/damon/prcl.c +++ b/samples/damon/prcl.c @@ -49,6 +49,7 @@ static int damon_sample_prcl_after_aggregate(struct damon= _ctx *c) static int damon_sample_prcl_start(void) { struct damon_target *target; + struct damos *scheme; =20 pr_info("start\n"); =20 @@ -75,6 +76,23 @@ static int damon_sample_prcl_start(void) =20 ctx->callback.after_aggregation =3D damon_sample_prcl_after_aggregate; =20 + scheme =3D damon_new_scheme( + &(struct damos_access_pattern) { + .min_sz_region =3D PAGE_SIZE, + .max_sz_region =3D ULONG_MAX, + .min_nr_accesses =3D 0, + .max_nr_accesses =3D 0}, + DAMOS_PAGEOUT, + 0, + &(struct damos_quota){}, + &(struct damos_watermarks){}, + NUMA_NO_NODE); + if (!scheme) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_set_schemes(ctx, &scheme, 1); + return damon_start(&ctx, 1, true); } =20 --=20 2.39.5