From patchwork Tue Dec 10 21:50:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902109 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 16622E77180 for ; Tue, 10 Dec 2024 21:50:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 948CF6B0273; Tue, 10 Dec 2024 16:50:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F86F6B0274; Tue, 10 Dec 2024 16:50:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D4F46B0275; Tue, 10 Dec 2024 16:50:40 -0500 (EST) 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 529126B0273 for ; Tue, 10 Dec 2024 16:50:40 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ED03880B39 for ; Tue, 10 Dec 2024 21:50:39 +0000 (UTC) X-FDA: 82880393778.04.123CADE Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf28.hostedemail.com (Postfix) with ESMTP id C28FBC0014 for ; Tue, 10 Dec 2024 21:50:12 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PNReYWYc; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1733867415; 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=ZJAcYVY3ECrAn0UyjyCl461B8wzMDmiike+meJPc/Fc=; b=0mwmjsGmIgVhjsN9y0/G141JuL/iBoIQY2mxtbYlroP6qI9AGOJ2KNQmy26ylgKSFuh5UB w3eyxa9MLOLpb4gnYuNIXm2L9ZoFsXvdU3VY8+0eOi+f/nNB4RCNLEqxcCqiB42CCxOKCz xGgXQm7zSLEKq8dmyIhPd/G9WzIOUNM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867415; a=rsa-sha256; cv=none; b=7+xPINSUZskSAs0cq6MzVWXl8URpGDaQQlVCHKauuRCXIgd0S3qBPH9q8906gTAU/R4otF uDDvN0+CEa5aPUpOCOYkot1ITQGKfPgXDvFlbE13gOtSYaIuOEAphchfMUH6CS8URWmBLF eeLUpzTtRqIQ/4PMBZkyE+Bd/0yeCus= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PNReYWYc; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 51367A41A2A; Tue, 10 Dec 2024 21:48:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A3A2C4CED6; Tue, 10 Dec 2024 21:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867437; bh=jB3IdYIaZt6diKe0C9b6i8dd46f2ua9DxU6E12pOiyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNReYWYc6t6JPmtGOCpuSkxP8a/ufQVYtC4vVsoaWJcdcEW212jts0kBclf3jFszr /2HuzNHpYAKsjcWYBlwteMlCTwfTjIPQ/6eMmgV9mY0VDr9tUnjS2qN1j3s9ZLyUQZ LbGnkrxvhaEEwpVPIoYqJAAW4/PPNpzvCy9qE2dDzxeFJy8eWHOYBjbJZXUx9tM6JK giskQ8rX1qZ9t+Z+NliBXXK4Kj0eEZldVkxlzG99L1q8zQGoUFxgXXWxxLa5N2nXr7 cV+rSMecRabVS0IS9Yz7u/yPNemmi4qLGKSdcQpiolcQk6Lr5rxeqpGEnCPK5m3x/J WDvC2woiHovbA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 1/5] samples: add a skeleton of a sample DAMON module for working set size estimation Date: Tue, 10 Dec 2024 13:50:26 -0800 Message-Id: <20241210215030.85675-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241210215030.85675-1-sj@kernel.org> References: <20241210215030.85675-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C28FBC0014 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: dx8irbfhfw53m91i3adgi5uao7j4rix4 X-HE-Tag: 1733867412-433156 X-HE-Meta: U2FsdGVkX1+UJ3btLWDmfa9l6YQkKCA1ncVXoPWwiCBGIkZHCGU2hdif2DPelyPvxNWmafm8oExNoXoKfW93EUjXWLYmt+obkh5MhY+G1LEs4FBAu5Y2fcS9tHVlBUsgYWMZrR620kLpohNImhteDaO0HyaA0cHsFNuTgN3/TNUhoK7BjFR52Vb0wBe9vO1Y1ke/zb+3YvWcUs/UPjfiVRVULRCqtFwI3dHCD/0DZBaZlsF9fHAuPnRrTw2Cu3pXGpxOuWWaMx4D0fWUMdfpKcOYd1+Rfc9YGb118nAXgQF/lUcemo43hpGjPz6Kx8CeQlLKICod59a75vYXUlZKuxF4AgyXCBPZHRVqz4wPlFXU36y0hb/9+cqWSgFqQJ1rqnCXe+k+5n5ZFRr5+eZUPIaROE2A8+H+lqbxpvNK+mYZTIUtrY/9u1Th7C/92p0x8MyRMMh4Ii6QchxAoVeBomxPlASx1dhR/qsK9Hikww4GDNLRVoxCc6hlS0o7Kq2piGuB76asQc6PVFUrBtgxOIoxdGw3Q30vF3QFNndwB8wHl+0pMZlYY8FM/aKr82k49StINeN7G3TJmwZeh3oyuj4pCiFle8oN23UEIHw9IcB/6Pqyf84qJzjLgQ74VM3u6wbQmDrpJeBFLE7NHim5lQtssGMqcIEwpL//Pq48po3JAnk2H7w2kWI1JrXjVl9KKNN+1GfQmbUt6oec2QpzbVDL6RpGGeAwi+MaOUxjW3V9AUvjhSnbrA8S3GXZeduBkY6QAP0Y7yRVCf84U5i+92wmEkt2TG679SALfUeX3TcGEt0NIP9Y37PUOBI++6KtIrZ7emaRbEI7C3qb7UNJWmZ0GEoODTAzIwGoE9o/Alr9rRGzIhioUHUDdjjVGDrVQvMTlguYXzrSuGwRetaGWL6pI1Vt/zN0a6cjFkwe+AR4bcPskTaGZ5GuRQlZyzWyEFC3oVFAzYwaPhKedlZ MOOAFaZQ L2VezYD0D1wpjhn2A43jOh90PERPZkrLA2n3T9u870tkGAwz1yucPwE7Ul2U1c82NyGWUFbWe4T+9nte+kP90os109G+sHFWinJ9S9S0eUttXteMnFhjrd2DgWUj4VowTu/ehUKlDFAGTZ0DjPq2JRxxhfYqanY8j95pdpNNm/xQFkvOmsCgtkBmIr+GxwfPNcYirEPfCHrcL7+UBr02MsTbBzDj5oxqXwJAgjq9qrB/GDL0TubyYKiMOQF5RtxeV1Htjw9m4SU769neLpm9sslI5SMFpZuQhAJH3o1zPw63cYfU= 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 static module that can be used for estimating working set size of a given process. Note that it is a static module since DAMON is not exporting symbols to loadable modules for now. It exposes two module parameters, namely 'pid' and 'enable'. 'pid' will specify the process that the module will estimate the working set size of. 'enable' will receive whether to start or stop the estimation. Because this is just a skeleton, the parameters do nothing, though. The functionalities 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 | 65 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 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 1e930c7a58b1..68d825a4c69c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -6328,6 +6328,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..7f2cb76a1a70 --- /dev/null +++ b/samples/damon/wsse.c @@ -0,0 +1,65 @@ +// 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);