From patchwork Wed Nov 13 16:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13873997 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 BD243D462D0 for ; Wed, 13 Nov 2024 16:26:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E9306B009A; Wed, 13 Nov 2024 11:26:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 499B46B009D; Wed, 13 Nov 2024 11:26:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29E3A6B00A0; Wed, 13 Nov 2024 11:26:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0AB9B6B009A for ; Wed, 13 Nov 2024 11:26:33 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A737480BA7 for ; Wed, 13 Nov 2024 16:26:32 +0000 (UTC) X-FDA: 82781598816.05.B6D6ACB Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 531FCC0028 for ; Wed, 13 Nov 2024 16:25:37 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AYlow0+U; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731515016; 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=Ym5uInOI1suGwQhgKSbHPyedclhbEIHYKvRU1ph8vwQ=; b=NvSnRR0z22J4SFLfJjj/Y896VAAT0Rn8XjYIOPfqZHqtqz4G8BCMxF3C5na2yqv/njzFyo NscBS2xrS1AGkRQbSkkV0ZrQIwGTxNZR5YuSLTj86nqP4h78oCa+eqcQhpejCmRJE/U4lS UHIfXjTNzoY/eZlMJhX3K8VNkkuiudw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AYlow0+U; spf=pass (imf22.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731515016; a=rsa-sha256; cv=none; b=ZZ1hvrbozU77zOjfS0v7FxTprkKNS3T3M1ySyoKuYZXYUk8KeZMuUsSIbrSzKRkRMWZPlU BtBCSzbrc0J3t7bwQZLaYrsP/qedVjSvzci8AEkQEOVUWNhYSlVXuqghOaQ0NsdDbMtF/3 8IRrJskIP8cSz3b/NQ3I6lVd8boFJKs= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id EA41A5C581A; Wed, 13 Nov 2024 16:25:45 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 531FCC0028 X-Stat-Signature: wjcjmmy5h8wrkap97q1yrkbthfuiy1f9 X-Rspam-User: X-HE-Tag: 1731515137-954320 X-HE-Meta: U2FsdGVkX1+Tan5YJ9jcQGh3uXf747NzpUEGSgSwmQUuEyf8F2wXSOuGYs8ItMlQwIguyiu/Y5n8N+duObK2taUZf0lGjrFgoh3zvfUDPxdYiUh6E8ScmVV9yJNXwNEdcyuo30Qc2fUrvwM+6SAS4i3zjkg06UJGyx1C8CQ5RIdZH/6kk+gd/qGSaiaaDiU+6DgTiZLJzZAlF16pSU9oiw78kRKc/QNWm0jtiUWkhv4SBRnX5thSAoXestlimxeaCb9cqQv3ggaEo5JaFMVozyralDXhClpyqFt7OjvjJkZdj3aTlY89QIu/oRA2xLKxBhjEHSrqOsCRibTOsH5yBLzCtz+FBmitiRUHXGs/PDyQ8zpxE9ycXdU1GlSOHtlgqLyEZQ2ph0EgWvdC0EVp0VHTPRzAUaPF53CobvKmhmGDPLpE0bR7AEJgQCpaxmtenPkPtKwmsNrK/GAPDU6JmLujV2YWXRFTsluPDFXI8zWM/wEUkRxy4+b7al3+VtOjfXrTzU+5WMHfPYPAwKXJZGePfB0yyBTpsDN4d/DFzJijZ2p9NsSjivU4lgo77rOJJjGAo47dg6GD8tP2AWVuLMJ81gz4aDTB+PZwbltsh4k0MjB4KjZubLg55+eLGcc/KTbBb3A1ckIwzCb+XoKj8S9eGX9SbrQ+CsRR+sK2Xkl4KB8lEQgSOfKu7jEYufHahfutdfbNpVwUdRxc//hH4Nj0gjJVV0EzOkQogIdtcJX7lc5u1A/w5gIBeP9On4hjgFubJouf2OwWAfrksYaQn8qBO7cqUe3p2N3JRFbt943CA+Jyxhm+dglNrT3oU6Jeu9Ng+x6UBt6Pp3UxCsGaaANoPpR5HUPSIKD1rbzlyAkAdgJAMy4tMREC8og/hkuhoGelehmJXmFMmyXZK9JdY+LedeHqsht33OODWSk2j64BmeW25l9V3L6TKmv9MP6rapeYXLQkTEHkQWT/9i1 JDFio4Oe D2ADC6Qn3ed4v9kMwnmyQfRnHbg3GeWj4QG3tyada4pQGqlo0DvrvMImKhMlsIXtQ0mPruJ64UanWNIV/Uo9SgQ3KNathN84cI0AynjZ0vkZmgcekMYhbCqByQtG114ACe8gtQB1aI+rvEww42zwyDBn9j3U8tnGv2k/MosicBHsIBHg81atsSF0zzspWw1GIioqY2acX2fSZth7a2FtOW8P1niatVdybWx06/CYTPFAGLHUi73bhiRsZdbtw8UqLYZ9nD9WxnlnhQzqzfd/MlTP4Y0pXafvJMtwN+hgtp/lqTbA= 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: List-Subscribe: List-Unsubscribe: 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/ 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 source "samples/rust/Kconfig" +source "samples/damon/Kconfig" + endif # SAMPLES 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) += kmemleak/ obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) += coresight/ obj-$(CONFIG_SAMPLE_FPROBE) += fprobe/ obj-$(CONFIG_SAMPLES_RUST) += rust/ +obj-$(CONFIG_SAMPLE_DAMON_WSSE) += 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) += 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 some + * 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 = { + .set = damon_sample_wsse_enable_store, + .get = 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 = enable; + int err; + + err = kstrtobool(val, &enable); + if (err) + return err; + + if (enable == 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");