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"); From patchwork Wed Nov 13 16:26:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13873998 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 45321D462D0 for ; Wed, 13 Nov 2024 16:26:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B53A6B009D; Wed, 13 Nov 2024 11:26:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 360F26B00A0; Wed, 13 Nov 2024 11:26:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2040C6B00AB; Wed, 13 Nov 2024 11:26:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 020CC6B009D for ; Wed, 13 Nov 2024 11:26:33 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ABEAD140BCC for ; Wed, 13 Nov 2024 16:26:33 +0000 (UTC) X-FDA: 82781599404.02.066A332 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf28.hostedemail.com (Postfix) with ESMTP id 24FD0C0020 for ; Wed, 13 Nov 2024 16:25:47 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="o1/agY4m"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.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=1731515062; a=rsa-sha256; cv=none; b=2SroM9AjiTzskqP+ARRdYv/5Qt2YYvGkHFtcjonLDp6QxTCZfY0I2FhN17M91xzf/x62d+ i/74mWaiBcRI4eq5etC8BfIntFrRcPsT7298XPnd4Uz8cXQlesTw9NLG4QfxPBydbWYzsZ NctYgOcHGKQ90R8376p60TAp7hB5QUA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="o1/agY4m"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf28.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731515062; 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=HZwQtdqqdVsLGqaVZ9sRV3Acq7QAqpRdBrtcWh/BJJI=; b=DX66Tn619/UYzTHMW/hhsA2V4cvM9Dno7FnoBTF9RXO25WBuvEZ220l87KAZSab/8LBPM7 pygwVdM0+taRVv2h8tv/Zdy9aCE9irOopuKZv492B6kFfZDN1j+j4RZCLXMdgxkgp2ByLI Y1wStzRnnv4h+CpWS26FS0d4rDkFUhA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 022B15C58BD; Wed, 13 Nov 2024 16:25:47 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 24FD0C0020 X-Stat-Signature: s7j9imtyg6s57hye3mkwrbqda59ts9ku X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731515147-276868 X-HE-Meta: U2FsdGVkX18JAq8Lk3sqG8B5G4QScHVyWQoCsp0nYbTJ9Fz/q7Mqul89kgahM6+RPdOV4v/gbCBhi5AoG/6P5LQzoC6L/n2c/QTqQJ8MWOPPT5ckX7aniISkHhBQLRO9xGsvVtGecNLY3WIIFd2XcEe3S+ZpKKMNgqVE5o/qTKXGB/T+KVof9eQwJ3b3Y34PSy3vs0We6840wbhm9OMHymxuUmityIPFsrY2dTdP2K6EJ4OVorkbN1qLiXutPifagq6sLzcwWgWIbjpD7nfUPOn+tQiANvYo5ks6BcS0RxndNPcGa8rU1StiGZbdtOfkR+G9aj7kRYg0hgvqs3u04JnLHRdia4VGiVjqhqEufm9qre2PWgfyb92/M8DZOW+jQ9VIu29Vf7WENs+Buef346GPf8cjoKva5abFMyO7nIEVHrsyiBv7kfdkEX9qFX0GkLPcbk+uwg57GdmoOioSC+anc8/kWDiqOxibfEBtm+clZHGkYU8yFlhyfnWBAmhUIOyzOGXe34dsiXHPYpaK1JLkAYP8DsO9uxN5zHsGlxEeB6HGifpzKUsn2mIwXTJsYuFx4klnkQi5HOqo+z9QB/2Ut+SoDkOcM9/vjufzGHxKqasHmOV03a+EjrFTlsn6g2vUGpPNs8uANTk/YWwze2MztYhJy98rtvSKqiC/hH/ib+iwq3wxTIS+SoaGXj0qP4VhSspYPaFz1FeHsbH4UorVhtVIu3dyE3mRDE1jN1jJXVdpNED6uIfglNsiqyTBnbm/jgk18LTQbwLbwW5n0BXKS43nuBsoUdMihaILeH5QsxOG20/NQ8f+0K8eOVGlL6VKKcQH9O/At1yeCEPLmAmKYaBR35//YEkp8lNHTz0fBnIxikJrCtNC+nCg/Vz7NRnLv0xuYdvbxY1AOQ3ptYmbJ+gEQZ7hjRNJ33aqwDi4kTHHy3zGBgURAHXbHRTgkj9RnIH4Kpm2ms6AX8f 6xIsG3Ix h98EAMVSEFDMrme+7wcAiGY++3TYfoRNyUW3mBeZclSUbv3K9QbWGtXDrkY/BwwY6VUegZQW698VgMJl7bSjDxF7GOwdWBgdNp6EqUIfLsACPkO25BY2vhAxwr9z51nhZdlWMRF2+jiMgKQbZASajyBx/BjXavhYtdwvgWP7asWrv5V0BwUlzEfPbDE0Dg8dyoS+kdYpQcDns2n5CeBAx6WlH4a+Yogz1LkbeS9TKQSTBXaU= 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: 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"); +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 = damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target = damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp = find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid = target_pidp; + + return damon_start(&ctx, 1, true); } 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); } static int damon_sample_wsse_enable_store( From patchwork Wed Nov 13 16:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13873999 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 B76C7D462D6 for ; Wed, 13 Nov 2024 16:26:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 364626B00AB; Wed, 13 Nov 2024 11:26:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECE36B00AC; Wed, 13 Nov 2024 11:26:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18E046B00AD; Wed, 13 Nov 2024 11:26:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA8CE6B00AB for ; Wed, 13 Nov 2024 11:26:34 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A339D160A7D for ; Wed, 13 Nov 2024 16:26:34 +0000 (UTC) X-FDA: 82781598648.24.ED448E2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id E1A51C0010 for ; Wed, 13 Nov 2024 16:26:13 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nN9kf5OF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@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=ZO+enpc9GWnlEjI1jOf0Kr1GZNP9yxke2vQ6rNIE7HY=; b=diR75iNDxmogN86nZyFNINBFDP0A206dT8jk5kfkR3htd+WASUZuSKA1vyY4xxi1wcOM/u Nhcdcvhy4eabWFSQx4CocpEE4Apd5PNBhoAg8NwgixszFGMM20dLkqGDitY3+WiXa5WMPC 4WSGtHwPUBrY/x9NRNtfwqNnH+1F0XI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nN9kf5OF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.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=1731515016; a=rsa-sha256; cv=none; b=g9qAMgoSq+yu3ZEHNqw4LiIxgKyNLHFRjjeMjTOMnp8eKa75RjD1ClsD1QyAj27iZ9nYYy VIaZq0dEelF/H+BtN+3iMdxPoZdK4EKCTMMfOpxHWMliE6nhuLvVBpSVlxkWnwxNK1ZDcA 8ZTpMYt9nxyRsL0or6iUz6ahFiCkGRk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 023905C58C0; Wed, 13 Nov 2024 16:25:48 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E1A51C0010 X-Stat-Signature: 8j8t6iwjbya6hbng4fkdyow7sfp5wqff X-Rspam-User: X-HE-Tag: 1731515173-260291 X-HE-Meta: U2FsdGVkX1/eQv7ROGi6pv7pGxhHfV0VCfw3yqENUa2GzVJ9sCTf2c6S/n9F3ipq15RrpyzSQZerjPSYfv01gB5nE9TiPCE2Y0+JY/nFNrogDaHjFdyrm0uKR0+44TUymxDzs1OfL3ZbCk3ZDT49VvS3e2NRf65YiWbopgpPJeMFlYXJmvf7MktsDJoex3s4zfmvNBRqQuEGqjq/5Pzjwysc+90Tre6xWXfy2jz4QqJRZ0Zru4erNbxOuEmVSqOmtEM40dpfFoLYN+Uv+4cROAXnuJofeexckCQEKxkLhKUiHrufH5jFtuBDtCC0xMnFoVb5f0DB8cMCehFWo0CjeGmI1xUVeLKpavnBcTH0EjejS9AesO44vBmLUH35IQ+Lot7EFJeA1QRG6MlXDvkYQUkcmA5h1u2egv1kykhBaPIvZuY1jtuelkL081PxWXcFEVttNXykxRxhYWx6+y5wb5uR5RbMnQomDpi6766TZ8z+QWqCqRjNlyjBlIFkWAyDzhgEgWCmJ4sKJK21J1xwWZT5iOoY+KEpvOZ5nj8YdQsi4rgA6F+xzYwzjShfGwC8+R9QP0UiJ0JKot/y3PYY1u9NxmyP7ecBvYksHlemnW3eQdsPqqOA1pIE2pK9Td5lqXsjNqJZg952oY8MBwRMvC9RMeSrXswvAclHm69v7ClQpB4PVavRzEAzOLyaBiBhppJ79X8jRPLHTVIcR4bxa5d51+URaaRQtZl7QW2DhAHesB/zUHeG3OSgqLLG/m7c0cTKKwoqNXCVQ7NGFJ0sZB88oyeedWvSRvX2QGSg0CQaGPRGS4VyRH6tQDrnPi53mzEL7SgKpg+XRPBpsfXcQYEiWaTyfsIy1LgSCMatzXxvsTsFGfKc22hTLn2KO1123luPiDOj/a4enKm7DJkaL7Yy65GuNH7sdK/LIZmJDVwlh6NznVsTXU0BxRpq1suU6bsrpT9qlB4HmI8LSs+ yTfRLSPW gzRKxNML+Tsrb5bK/F7DsjBgqp/MSlPEFf5lkomu0DA6EIC6jdWN3EbZazxfeajoAIYZ8sRhx6zwe6PfECa6nvRmjv3M5Cuad4C5xEK4gfqz7Y0/T2ur0IbEBESScE/JkHNFTaomg7pUEenXaDApvtPiWm035kfSU3JPaHQmOVOipQ/Lg0nDKNUWU3MNrN40QSEYOCTlrudEw1D52ocH63/CW3H8PwGKoX+QuSJOekErkypY= 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: 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; +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 = 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + wss += 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 = target_pidp; + ctx->callback.after_aggregation = damon_sample_wsse_after_aggregate; return damon_start(&ctx, 1, true); } From patchwork Wed Nov 13 16:26:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13874000 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 0A21AD462D3 for ; Wed, 13 Nov 2024 16:26:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 710096B00AE; Wed, 13 Nov 2024 11:26:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BFC66B00AF; Wed, 13 Nov 2024 11:26:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49C156B00B0; Wed, 13 Nov 2024 11:26:36 -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 248FE6B00AE for ; Wed, 13 Nov 2024 11:26:36 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DAE63140BBE for ; Wed, 13 Nov 2024 16:26:35 +0000 (UTC) X-FDA: 82781599488.02.CD3D0A6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 57910180006 for ; Wed, 13 Nov 2024 16:25:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tzYlZYVW; spf=pass (imf16.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=1731514959; 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=wadKFwZTLfnao1fH9keMi+FTI4wW4tk3hkTRL9IV7a0=; b=8qo6RHgo/C3BDyVYwTr0DNS+qU9jDSFzz1PnrvARpkS97e1+dRn4ITfPkCef1EYtRH74nV iAnRq6g5hQ8QD1E2Kn7NmXyBbiz8l++blaqFjwNMdjyH+VA6oZCGlGLQ+RFmYX4S4HQ9eu z6n6Lj383qHGtzOr3AZJMzLHWDgDuqs= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=tzYlZYVW; spf=pass (imf16.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=1731514959; a=rsa-sha256; cv=none; b=PgRbZNHn5wQnQWNDrJU/ydZdiL3ad1r2fIR8BaC1b6o3D1H/mLVZSfuRmOfGoWJ5cndbcK aUrC59H0kKxcrqKtqQ0vV6/WfNI5+eLTZbj9SAN9/6LBByfLNxy2r+l4WlyZiGa5YT/DYq T5lLKN63zixaGsDTunfvgpDwerB0hrc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 05EC55C598C; Wed, 13 Nov 2024 16:25:49 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 57910180006 X-Stat-Signature: 8a6k7s9t4yucbawqdr9qmgntdtzkcanp X-Rspam-User: X-HE-Tag: 1731515151-977252 X-HE-Meta: U2FsdGVkX18MGlwSndkWcPyICH5Tmxz+yVnbTxhUMzwByd+aXXjMcZw9/oGrpv55EIlvL4XAaMZf8A226J2XZZtPJTLWrjqXsw+gGbdKuam5JUU4uwBXwcmR/S00MmVv/PPg13BAZsTPO86naWvlJEWRBqHcR9rN3kRLJYu0mgN3nXZB9BT+bKhtZ6uVZz+Q7VB9to3FIwM7NpsIUsm1Ay1RS/qIghJpVm6+L/DSmr/XdbhmdkkTGHPmZ7gUrpfz6DpQbjdzANwRwrKVrSY2vkCIBfVp8qogVayzMB0YmebUJMLUYzGXQG4P6FDf9mskNA6D57FCVgEI2OMN/ust8nAdRJ3oGmEdapVkXQhROVQFvU0tAjnAwnxOaBSUM2xEl9vN9kPeghG9ZVqjkFlq9UDRmgEWHC3THLbeGu1jH9L1574LHHoQDHnwCkvt6uoUzjUt0kQAtq6wNE9s+Ms0rQLB59h2GHQ2QjuBV9spwbWYW21ioge6D+wAofk8IMg+tLJEs9arKEinKuSDyiRubmsWTMiDw3xffZk0qHOCSn2EjhhC9UUgN0TSPG9AtEpxqYPGOSbBZf306mtB7vVXmBAkXded44vTddZS+tVIsnjiTW87Oi13KVuwdzrFgEsikJWaEuBfvHNAWKuGGdGMcEbGCZDaNK91jIp40PYO4bB4yBqYD3KVB8TaeMD0mMAqAnF+J27sV3gllV3zPIKM6ef4VVNH8Cu+umm4K+1VE6cqQmwOTRBmXSn4TjwNX01ieiSjFIH+sL+nzU5lOwAb8OlNTymkQ9vyZdBmZiYYwE5GqSkwDck5TsHqz/YE/2H9qw0tlFdfRJm9zcbOjvV3yZz98+fSkGZSqrFp1tqiGAsfJP0Ndp8KaustkmrhmKMniMXD1t9y+Kd3CuMWKu7nHjYeH6xUK/bRzV5Y+GfrElN4pQdC/Zi+rIP47jR2YE0UwypT9ZOQQ762P5kA02Q 1q2smHqf ZPkr1nkInISTA6Cg9Y41Ijw7PyMCLi9tPdZZuYTmgWpukblzYpslLWyQnuMOiTWmxoPjCQiKpyOGUjrrufVsxn4kuAFTIdWu+B1Ss+FhkWfcAl04egHlOW80UphEY3TSppvOlgs6PqN7uAebI6AdycRcdxK4DNNnMmmGyq7B1yPCRUSMOvjbKIpIUT9ae5CWhpMCFkuhZCe1l78bL2BTS9KmUgYr/s+ejXhNsVMkyp5FynNY0V7RahQ5d7EGAkWC19ZI3U9MI29QwpzA= 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 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) += coresight/ obj-$(CONFIG_SAMPLE_FPROBE) += fprobe/ obj-$(CONFIG_SAMPLES_RUST) += rust/ obj-$(CONFIG_SAMPLE_DAMON_WSSE) += damon/ +obj-$(CONFIG_SAMPLE_DAMON_PRCL) += 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 If unsure, say N. +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 obj-$(CONFIG_SAMPLE_DAMON_WSSE) += wsse.o +obj-$(CONFIG_SAMPLE_DAMON_PRCL) += 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 = { + .set = damon_sample_prcl_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 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 = 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + wss += 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 = damon_new_ctx(); + if (!ctx) + return -ENOMEM; + if (damon_select_ops(ctx, DAMON_OPS_VADDR)) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + + target = damon_new_target(); + if (!target) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_add_target(ctx, target); + target_pidp = find_get_pid(target_pid); + if (!target_pidp) { + damon_destroy_ctx(ctx); + return -EINVAL; + } + target->pid = target_pidp; + + ctx->callback.after_aggregation = 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 = enable; + int err; + + err = kstrtobool(val, &enable); + if (err) + return err; + + if (enable == 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"); From patchwork Wed Nov 13 16:26:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13874001 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 A1229D462D3 for ; Wed, 13 Nov 2024 16:26:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 736496B00AF; Wed, 13 Nov 2024 11:26:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E5CF6B00B3; Wed, 13 Nov 2024 11:26:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5859F6B00B4; Wed, 13 Nov 2024 11:26:37 -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 226C16B00AF for ; Wed, 13 Nov 2024 11:26:37 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D323A1C6879 for ; Wed, 13 Nov 2024 16:26:36 +0000 (UTC) X-FDA: 82781599110.18.E4CAC67 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 96871180027 for ; Wed, 13 Nov 2024 16:26:04 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rk5i0Kre; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.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=1731515065; a=rsa-sha256; cv=none; b=JoEQc/Szdke3PtqJw38g20GNOBjWmr2wFs4+e8O5TMZyv/O+Oaiwk0tOu3wKseMiz/8pIx Cl+3ELz899J1Q2OeTL8l2IjZyot7pv2nkinWYtIODnYqKxVJOs35HfgbrmZfY1Gt3CAxbR far7as9KoDTliF5vYr2R9iHi3yEZjxE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rk5i0Kre; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731515065; 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=aUS25Ln9Gm2Fa4MIDhefrr1kJGhoBnhlzzNityKKtm8=; b=M2M6jvWVD3pyV7ZbTMZ1y81cGsHG+Va9187AP8y/1YOUsgnES5CNrZXfsMmq2DhrOjpGRs c0VyFavb5k1oLJjmiJW+MWekqQo+GTpfYuzPYxvXzopCZO2GaiRBVhl2YmqAWoDQqKDPAZ BUUIA38fffwuLeibTMhwZ14N2tAK8lg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 1A5CE5C5934; Wed, 13 Nov 2024 16:25:50 +0000 (UTC) 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 96871180027 X-Stat-Signature: qb8ti4wa6ra76kbrkea8n9qr7rttubhd X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1731515164-58730 X-HE-Meta: U2FsdGVkX197EvaNSKuFkT+YHWMtt5EhqCpRHBFgFfsEcAJ88wthYj7CZHVpNcgqgrji8YGY2ugc0FlLZ3QNEaR2yDViq6EjNypOM4hRLaB/et6e1vUvp9ReZPwDSAsWbZug5XiRj4orWW1wjxBkdra+nC0jVR4SdA4/ZVARvWz17HLkBJTdnP6woyXmsOZyIs5kIIG4fajb696trHS+MEqX3kBzaDv58fmKZBkLSky3WD+PV1WlpWMkAWEuSGtchVZJwXGPDW0Oayn6Q+GHML8U1wstTZ3COcKO2OchFR+Yz8TMBATjFDr7z4KmchnoFLjE7WG+Kddg1KQm30YwLcryJ6+KyZEO709qoIdJMyTU5N+WpuFZg3KDlHFiWgzRIiZpD5BjdZ7HpQJr4kxzo81iorYqKPoG3sftjIT9ykfaJMGf/Xqf/9sKmvlMCwCqpmzcdnqV+92WAYWtx3gNngAJ+fEmKB/OnkAbTo104RkxFLALmu+RYPtzKnoz93dN5s9h5JBJguSVPFb/d8Qbm2XHswwj606opq+Il1QCG2D5AVVHdPSAeDcxBcCs6oJeCn0E9WVQJx6TCDX7AHJmp8lZFmH5hwGuPsWsd7eDpFkYXuk15nPLgwGiGQfhYBl0UZYaR/aLKwMH8BQCVC/zmjGuBLXF1rHFlcL7vcWU7Sb36zaeoEKHrhfo1ysT51J8Oy7vo19rrGYDA5Q12f0cDsqDcSw6YlEw55R+n/qaVPUavTRzZrqp0zTPHQUtS5djNUtt/xaGrCnx39svT6NAjBbqJWK0sEHBq00EtfOVjMB+OG/BMf7uKaG7iaE9A+fNpxwNb855IwczDeKVlwr3YM8o0RHHUgV35WZbgK7PutnWmJuQ9uY8RwDT2S2Fwpn0Dcot3cPJ++OPL889sR395kvUCeF1adtYDaiK3U/gBM/o9q3/cDFRGuv+lGn10b0M2dKzse8IaCTz/mIdt0c kqD7d89s dIF4KcuYADmP1cp03D2I4joZW6i12Bhn4ZmZU/q2e4XmWj9OpajFce1jl/nHoVW4U16fnAY5tkBBomcJtXQP/D2H0R5dCRyc92DnGtnG+2uuIbFG4yPWQzf9y/drPwkaziailD5Ss1/Y5CHbNVPHvRNO3LIPWSdbQJsS6xHVi4cYaXMtc1VsLxcs7MT6w7DGyjg4LlVAbN/S7vYfbOLLQIgjL+TST2GUPHoASQtofqS4a2+8= 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: 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; pr_info("start\n"); @@ -75,6 +76,23 @@ static int damon_sample_prcl_start(void) ctx->callback.after_aggregation = damon_sample_prcl_after_aggregate; + scheme = damon_new_scheme( + &(struct damos_access_pattern) { + .min_sz_region = PAGE_SIZE, + .max_sz_region = ULONG_MAX, + .min_nr_accesses = 0, + .max_nr_accesses = 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); }