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); From patchwork Tue Dec 10 21:50:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902110 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 6AEF8E77183 for ; Tue, 10 Dec 2024 21:50:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 996776B0274; Tue, 10 Dec 2024 16:50:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91E2F6B0275; Tue, 10 Dec 2024 16:50:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E6FF8D0013; Tue, 10 Dec 2024 16:50:41 -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 592856B0274 for ; Tue, 10 Dec 2024 16:50:41 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 04B8B120F25 for ; Tue, 10 Dec 2024 21:50:41 +0000 (UTC) X-FDA: 82880393610.26.149DC10 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 595B020008 for ; Tue, 10 Dec 2024 21:50:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bl7caDxm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1733867429; 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=/WUPRywr9T2lNCgWCZ770NBeqkLMpVh9VEeQt8UmtbM=; b=3B1rBywAdYP/WRitmK+DrBoFP64fJh754uFFYLsf2xl64GQ7FklLAdLudlMqUSbBKXP62p atgpovORBIoT8sdzqzEo6kv/hHSQArRb/yFBvVZgmqHiZMEEXXmxgHclhe9X5rZ+tiC3KP iVaBJxZxSjKQkanUIHNseoQ/bJVbSWY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867429; a=rsa-sha256; cv=none; b=Xv7xXtrqus4au6e2XL2FEnOGVX3oNzAUTCCQcxD0HfDopQpz7jfqhVteOArgkBR4TsNh+6 3xj/OMu1bIs2qAs9TrG+km3or6JPg9pgfluoRxzvFxM437OIAFncMDsReTcCvCofkPEnE5 5EXoZ6bitToV48El2LITYTUPCDV1qP4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=bl7caDxm; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 71194A41AC9; Tue, 10 Dec 2024 21:48:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55444C4CED6; Tue, 10 Dec 2024 21:50:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867438; bh=hoi3YSqqOR9ePv9N3p8sOerDMAcJ+RMcuGrppxt+mz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bl7caDxmLeYr/o8tpYrjKbJRh6DULZtvH6VaBGKNqJ9E7gVsm/G00XYnAtxCqsxPn i8J260Ruy88dw6OYY3lGAg0E+gPFiX7P5FIql/AG4y/rdPuOCUkqofbaK0livJSP44 lwYtDlRNDcM0D6j4hpOKd0DlDK8F98uiP5Iddddck8qscsnNbCo3RUVg++r9aEOsug THFGw1CoXBGjE/CMQNAwPlr8y0Hxqd2cNI+M2WQhks2hZ6VLsa6Tf2KY/qYE3+rQkO /5P71yilA08C4due9Nrh6c5J3NjAq2SAnay8Iq1do/5xn6/R9cKK0BPbzJcR/kDF2w 0bx+PLksRF9iw== 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 2/5] samples/damon/wsse: start and stop DAMON as the user requests Date: Tue, 10 Dec 2024 13:50:27 -0800 Message-Id: <20241210215030.85675-3-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-Stat-Signature: w5xn5fcp8w4y47hytiz5h56d137hde5a X-Rspamd-Queue-Id: 595B020008 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733867429-609690 X-HE-Meta: U2FsdGVkX18s9Tm39Op5P/W3GzFWLEwqE9EAHaetf7Nl35IsI1udqp91AQJgFd60nA+ecMA0xIctdOmnD4QhtfC7alpuEDQw5J6wey0EWVwczkczPP5bZif9odPWdpQXZmBxT+tHepY15ny1in+IvDRfn9mCCxSlvhDNLcy+uOziHmOkJIhQU+ff3se72sc8gyupEEPeFQZD47lJXOVTBNFNewybspCqu7s4Sb/B6IUgVKCJ50rZQb9WogPUm0w2DGk4bvgUdo4a9ogYArFcxDJv/0wvwqOEGJ4wdpMTDCwsEEiMGqzSTRFfrap/A7mRIt33vpuiyJLEf5KKKeJR7N5RJlJ+BbpH4c43zetw993XlUaiAl+aRaBqwEr0TmPR4pRjB8VutWH+8PmkWailjF0y0P2UxEBEKs90CcSuVlxkFgkEoEPNwPaWMzWTD+EZWHb0Nid84t97EQT//8BCmxyc21tZYWzDVzq5n1QbZJrzy+jzPk/bW1aGDHUhQH9rUb0QGvXFWFWnp3ZRZnOtPGAasIB3AL+Guh/Moxeo0Xu0lwH71ntj6PeWzsYDOQdaFBqjF06+bVZbM+Q5l24l0qpPww0WcDA6L+vCGwyXm6EM99sVjIdjGJRqbYoZ8ThJOux2lfrtxe18X7Bj5a0gqONG6l3p+nKDPGvyWRUU7vq+Goch0PYecVJLlMRoXjDG0MhC/FE2vCtsVo30of5alnoT7VtZFj3bcVStFRA/9LfmPPz26Jc5C1cZOc2jp2FGoBC1qrXgL2VpZeQG9JLHU2czUoI/ozgdnrab5aZKBezhA5tEs/j+78mWCuaTZLvGNftYkP8REFal0B+PymjmyaDcQeLmnfxO2bqfXN0xGLSttClT8VjG5XhDyq4EbU85Bbp+2mJSH1TuWQyrSdQqsmwWtmEoTOI6Fo1xIcESO/iZPJGy4+lIS8DTvOGezEapGSw7BcYrRXG2G8QJkyv LzMcAL/I btw4e9ibUVRt9wL4xdo2YwctaemIB7gxm4nbzZwX9P/JaujB2SilHd48JrKq8nQeOpivuhAe/W1Isak4oFOfU5gF6eTu2S8fi3Z4mW73XtDwmUIRBmuMUHj1v8fRGLZ/cTQM0C3ZR5Cgn/hDoqzVaQ9gDkgOwl2DMTOR/2REpAqOUk+mJZkZ1EfyWWIhZqiPG8pLqF3wwO0NZ3/FUx9XXUR0sr089FJt6ZrlawoGizYBuDxg= 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 to monitor accesses of a process that the user specified via 'target_pid' parameter, when 'y' is passed to 'enable' parameter. Stop running DAMON when 'n' is passed to 'enable' parameter. Estimating the working set size from DAMON's monitoring results and reporting it to the user 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 7f2cb76a1a70..2ba0c91baad9 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 Tue Dec 10 21:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902111 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 EE0A0E77182 for ; Tue, 10 Dec 2024 21:50:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9200B6B0275; Tue, 10 Dec 2024 16:50:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 881D78D0013; Tue, 10 Dec 2024 16:50:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 723F86B027A; Tue, 10 Dec 2024 16:50:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 566D86B0275 for ; Tue, 10 Dec 2024 16:50:42 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 15457160B91 for ; Tue, 10 Dec 2024 21:50:42 +0000 (UTC) X-FDA: 82880393316.01.1C0CAA4 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id C16E31A0011 for ; Tue, 10 Dec 2024 21:50:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EmMRqjDE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 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=1733867430; 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=erE1a+6ZDJtWpOYrLI3UZndddOJa2v/uUKQM7Slf8PA=; b=5QYEXVRQe4Hfk4DdXV/QmcmKN64fIRGejEhk1nmLN6+OaLSR1LaakosmqK30JCTpuQGQyg jmsM3cVGyMlWaGOB68acNQUkKWhfpcafz4eMlUmGUzIetUtgTUDGuDtiWMeArM+PcfoFmU PijKi+p7regNv8VP2/hEZqlfuIbJZ68= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867430; a=rsa-sha256; cv=none; b=c1fouQ9ojbo98B3z08hdnVOirvNJ3UyOg0Mqb+yY7WvvVH2WiyKz6332tT+AN5fVNcatKy Bk7XcNIHVD0CDELXNCj5y79rzuEm7/zGN0GR8Ck1QTLdL9Nbve9yRJnXoS04TD2KIVff7N 8lxp2O6am+bLLRwng/xbZVYhMee+obM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EmMRqjDE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 8B807A419DF; Tue, 10 Dec 2024 21:48:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74FDFC4CEDF; Tue, 10 Dec 2024 21:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867439; bh=WhKbvDPjbuIBA/Td7/ebEpkfZLrMJgwOSAMpKKqqUME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EmMRqjDEmysTyaTfmY/VxeGmtYNZm7cToJf/5OuUA/BWeBb5Wcre05Ccqb5qdayLZ 7F93iFBLS8q4pebZnd/TYpcySoLYarrtciHg4Hge3+ZALTkxtye8utueT89EXUmQed OjrhDQ4wm84CWa1Ew1Cx3L7FsYZ+QwTVgFGZlpHikj5RITpsTDj4fU0UJp+NEtTUJl N+mOlxI9BbGqSpB+c1dJJmuHPjcdhvfJfe8qcT0Ihx73vIc6wk//JUEaMt7K43Zahf ixcOYKt7CNRTpQwjuhbbl8+XHlgtOna/Kdv2pT36zEQgvfyMmvcBDycQaSbaPc2/ny uc/F7vl7pyvFg== 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 3/5] samples/damon/wsse: implement working set size estimation and logging Date: Tue, 10 Dec 2024 13:50:28 -0800 Message-Id: <20241210215030.85675-4-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-Stat-Signature: kcqf5xsrjzt93n9xz4jx6e7aztbbzji4 X-Rspamd-Queue-Id: C16E31A0011 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733867416-73139 X-HE-Meta: U2FsdGVkX1+NE2Bsan4Ip/BIk1ceWhjBcRJDNwChJQ51AmhZEfNZTWHBAMQ5e/atORfNN446TpXregXbYBkQj/voSdJZmE7bM+quF5TNWZV3+XbMzXLfQuZLH9hVFPan5tXFm69LFHiZqJ4MFcbu/CCspFDzhW7eOAv0DXvOCbCZCoiTM+D/NoKYyjUeqjK4YSlHuhG1R+Q4ZuWu20TlJWWDhGxTsiJfJPTma9n2gq1qsYPvFdxnmkfs81mmgJTk+zl5JOd9Fz8oTtoBRzC7mTpo3hXaQviWBaNBWsWpG6aP2SUEEPwdsdk3QqLesV01mV41XBvGkZ64m/PudTOd1VCHYuZDyy+Lq+OrXhQ3DwwDUkPW13tjaWhMuPlgB/nIryoniVperwQ6rH+z24dplby0ixVgQJvAW9e2LJLO6iUsNkr/qAOs4Dv1d6m27MisTZ1MQUh0X7PXEpzbChxfM3rv9V9mHKXL1t6m8cfM3e2ChhBIiDyy7mPohg70sXWXM2ntFnv6B8HyhyUh9g8xS26+gUA9pOMMbEVxcDn8tgW2x7zCXoKOgrrwkfo84zU8NGylO8T56/aOtkdJFHfmisNq015NvbRwRHB060RwdAwGjxX3d6kC35lxxjPnnkhBhJUMF5OTuNY2gWXia2CN9x1Z1aRfq3UhuBYEcvKY6Exz8+sNYLldPDNQBjLBlDngWSJDRGeaIX8J11iFyBZrKF9JzHK4DDAnKJI5r7tp7ewEupiX5BQDzDFJh3m6miho1EZpW85LrcqGsasTVZRcYgWyPtSlOrdGDqhrSWTSwCAt10Ct1f4/OHo8XhMCPrh3lQV4c8Lspzw+oGRS8jbcIInA7FrFBHbY0kNRmXaiJqvFa5GPA77/HczmW85eQ+KOwz5kGHYoEz3ukxCIGgq06/gmv96ILrEX+pQlHAzyRK8RwnDqAWxdK7kmG6JhS47Ojxe/fc0WbDbA0DXYk9C t/jIsJgp iP7EXTtiOPqhMmPWEPQ6XnK97BpwfdBLP9tjNzCj32HKUia1I5TdhXLX8+MZr76hAfG9e8W/NshEUZpV+40+bY+pxM5+RRyKz4X+/993uhQU3Ht9hXa9tVic4B67m940dOYOAulTt1O5hDrvVnpyL5kBsZB6cagJuzl3osyqPbJFq3Wjj88CyIn9oxXCDSLjmyVTNxqO2qTQ63QkVrVE01Uu7P5cp+r/zd2MlbpgLmdmkPww= 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 iterates memory regions in DAMON-generated access pattern snapshot for every aggregation interval 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 reported to the user by printing it 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 2ba0c91baad9..11be25803274 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 Tue Dec 10 21:50:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902112 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 B4DDFE77180 for ; Tue, 10 Dec 2024 21:50:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 529B56B027C; Tue, 10 Dec 2024 16:50:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D9178D0015; Tue, 10 Dec 2024 16:50:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A1768D0013; Tue, 10 Dec 2024 16:50:44 -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 14F3A6B027C for ; Tue, 10 Dec 2024 16:50:44 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD97E140B46 for ; Tue, 10 Dec 2024 21:50:43 +0000 (UTC) X-FDA: 82880393358.19.A46B629 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 5E4EA1A0003 for ; Tue, 10 Dec 2024 21:50:18 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=D15Zzayf; spf=pass (imf19.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=1733867426; 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=DuzyJcswBf9jWR7yuAK6RUfkkDL4ys1ZA7CmNccAvPA=; b=nJ6GK+FJQC2xn//uMR+IoTQXagQK8JooE0tsc56I/UzhY9We9yUXzmYmcZea2tmucSttvB EFmfscX2CcqbriQrYNwuY59VWCHQXbVqavR7sQNqsxU7PKJVi+VlEc/e6pfb3WbKdaCFLK EFHhpUj0oe0haX/VpPxZo71jfBzF5zs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=D15Zzayf; spf=pass (imf19.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=1733867427; a=rsa-sha256; cv=none; b=6FP1pC3yxuKZdxmvwCaV/KtiGdCXtgcuOZcMN2Ryt0JyjlSO4sdD9XcAOqNYNpngrLPqr6 b0jEY+MxIXRTqSgPi2h3nv2gUBRebYoX9uafAwqrKD+P+VgLuDmJMN75l/SnRTpXQuz8pf yu4GbvmIzx2Mstbfw1z+4RG2jyMsTiA= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7DDE35C62B9; Tue, 10 Dec 2024 21:49:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 865A5C4CED6; Tue, 10 Dec 2024 21:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867440; bh=7FEsy6E4p0WwhU+DV5aMiawHvgrRCnoGLK5GZ2jkVJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D15ZzayfcegIah0G2/GjTG3mOixo+knKcaGLxl3qTlHsz1ye8cAFdYef2OgA7Rjxy qswkyU7NMOc8lTa3B/lHqiAgrX6D3M7EQufPx/+1d/5nbdYJv4l/GRAPsU7NiC9DOG 65rq7/frDYJQg/agSTFvwoVtW9Yhx2karjpOzP2pqUZmK16YJa4pJisysczCaeNSmH VBoCynKIjHOGkTzVHPEgFJk+xwsaq0+e1QyD/L84EOYQYaxLXXJc/onZ6cRbajfejQ AkfpJgJLBm+4ZIc03oL6MQIeHOXMSgDkvtgAWI2Uodunac0jT/9OhQ02S/0SOdDLIU /mlgSJMIdkKAA== 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 4/5] samples/damon: introduce a skeleton of a smaple DAMON module for proactive reclamation Date: Tue, 10 Dec 2024 13:50:29 -0800 Message-Id: <20241210215030.85675-5-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-Server: rspam05 X-Stat-Signature: 3dwux7wxcef373s755zi4k9c7896udhd X-Rspamd-Queue-Id: 5E4EA1A0003 X-Rspam-User: X-HE-Tag: 1733867418-18263 X-HE-Meta: U2FsdGVkX18qfYRVmWiFTpbw3ZkEpN7GagmSLrZPsXxi34ek4t30/uhWpaME5CxsiTK39jzDAa6KZn7Qcy+CCU6YtAg9lbnSmXYDlLngPmB6Xz2qo35ySk+gj+yFO7VwN9XQeV3lpFZDzvsX39xCoUms41GUhEIhIuvLNwEmaTNoBnDSwVWIRyLLa67h1m54aZWOX9oHesvA5j41Y964olZzCj8wCczYyiQ4Piwe4U7V5mDuxeWYzIgKn+GgVP3voK7wYeWhmfYydB2LAkQRxpFJz4g3GlsMYxa04x7S+YWMsUpFohFFmTkwdryCreg0sm5xrIfu0jNxoNQK+TejdaVDMC1yyYQtygyL3WPjN96b0tuAhwfg/ZBHN4zDS/js1yIIXB+4koxbE+uWBqXyLV856/2jMEqSxG5O/+4T7rKSQZ/i8FGxX8wzVR2SDJ68h3Yt9zNXxTbATK6QQBdzD6EJgbgrr+mn8T9rkPPUGOCll2XEFzJ33GWAfu2Ruzea2ECqvb9OrFPsygg3Gm1uNHRKXeFrROkKD+PnloedU2MQWxaUZ0WCIN5n2JPqE/KTG0BQKRU9Do4/w8eLZi0RLto1pcU4UalkC8nn1tEkHkfyK3H2KebGhq920UojiYiuWQlo5pTlcpWs7s8NMzTxx2mJ01vPOxDVfkpdoCONNvnjvrcJBur6nrTBLJQ6lnymB6ozB5C0K5kyj9Y3y/yGyMPLdNYY0Yb3RM0h+SBtLfSTSxs4+OIqLEFTl9G4kmLqLGwtaqbL/FRvrvP/6moj7dzJUNZL+SiY0FnvbwPmBZhpe/fnSNy/jv2irXR4uB8DWSzfH9/sVreourSI2YlMXkp5yZncuYMiQv4AGHzRm0Nnsf6IvBBDT9eWbHgte86wbbjQXjhYkYvVQYVO7V9tH8uye+/kKjjAF0544rATQHmxY2Bd9/dD+1ZK9OsR5SiHqaMtWbH2G9NZ8UwHcrn IsQf8dfI xHJ83QEXSPypB8/s+Md7xO4HviVpHF8flIbFFI5zmSll89GSP3NoIDf2tzvXPsSfJ1MKVn4V7jvlCM6TDUtwM52JYQRRQoCOjJfhwtzlAVzVEaONjO4K+aWQFB3G36v+wI2M3+JCFlxtmgOwPehnflEvaQpCPgUV1OFgl7wNB2VCMt5HnktjzDmra6Xtdg3i0amy4uGZlgqsIBGb5M9sl4xP8y6Okd4wgJFiPJEwC3LwnQIk8UrtK2C80vEDsuRpQHc9LaVE+plvOgk8= 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: DAMON is not only for monitoring of access patterns, but also for access-aware system operations. For the system operations, DAMON provides a feature called DAMOS (Data Access Monitoring-based Operation Schemes). There is no sample API usage of DAMOS, though. Copy the working set size estimation sample modules with changed names of the module and symbols, to use it as a skeleton for a sample module showing the DAMOS API usage. The following commit will make it proactively reclaim cold memory of the given process, using DAMOS. Signed-off-by: SeongJae Park --- samples/Makefile | 1 + samples/damon/Kconfig | 13 +++++ samples/damon/Makefile | 1 + samples/damon/prcl.c | 116 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 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..b34b9bfed532 --- /dev/null +++ b/samples/damon/prcl.c @@ -0,0 +1,116 @@ +// 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); From patchwork Tue Dec 10 21:50:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902113 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 49A80E7717F for ; Tue, 10 Dec 2024 21:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 616216B027F; Tue, 10 Dec 2024 16:50:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C9A8D0015; Tue, 10 Dec 2024 16:50:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C9958D0013; Tue, 10 Dec 2024 16:50:45 -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 16F476B027F for ; Tue, 10 Dec 2024 16:50:45 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CDF791C6664 for ; Tue, 10 Dec 2024 21:50:44 +0000 (UTC) X-FDA: 82880394198.14.51017C7 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id ADAF11C0010 for ; Tue, 10 Dec 2024 21:50:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=A3prnbLf; spf=pass (imf21.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=1733867419; 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=FpkqOwQPBGZqnzmP0TJR8MVcBAardtSsc4lZUvhgG2o=; b=aXFaeG6CcYPlcF9VSXbG0Ae6AbLMmkP2/pJqvO4aRybz+LoBa+vjm/drmwk14Tp4zAczYC qApy+TrIc0o32OIkml+uYaYbxJkjhG7rEloYr8X1ypqe3kQ52a3Sw3R6AmGvE0pqCkuLuD 8DLJ1vUFvvC1nOhUJZMloxvt1sHVrzQ= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=A3prnbLf; spf=pass (imf21.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867419; a=rsa-sha256; cv=none; b=c/9J04jsM+kNUH9jZW9eMq5BGQoWgPIXGDPnzdVQAEnOrpbjlrteqVXkpvn8xRGfON7ln7 ZwItW5oHucsfMkZVLi3Pd82BRQECiei5pOHt47eSHVhp6oNx4KHtPlIBdrCdHpx5Db6TkF 2ZgDxaHKH7c7E99kBINBSF6C6HkIBuI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 05539A41AC1; Tue, 10 Dec 2024 21:48:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B94CDC4CEE4; Tue, 10 Dec 2024 21:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867441; bh=RRBl+ZZMmihwq3svB0M1vQmUUPQ7A6rMW0M3h5PQx34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A3prnbLfsY6KQzK//CrrzVTSX2P1eXC45Vr/x+G6mRozoJeC3hWO6Wn96Lt/kSN3R kuBCaznCZi/tcBYunW1jZhdpQIhdru1DGjJOeg7RKBqcAIPt4eNnkl33vmahTl6qDn gLLXKiYxnJx+hNAtADXtJUpwO2z92wVn9Joeoh1M5Nk3eRPSPDd3sTZHDv8WS2b8BA NlG8jmbhwla0yQoLpZ+dEsFJKrPfR1fJlWRQFFilwze64VEHfAsBFxICiAqZDKd6O1 df5yX0VKr8vDPUoY+PucGaICMPCBKi5EN5GkHVYlSRrQ9xN7v4CgpJpMHBAXyjvGDv +D0X/+nWEBc6A== 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 5/5] samples/damon/prcl: implement schemes setup Date: Tue, 10 Dec 2024 13:50:30 -0800 Message-Id: <20241210215030.85675-6-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-Server: rspam06 X-Rspamd-Queue-Id: ADAF11C0010 X-Rspam-User: X-Stat-Signature: zdjwghscitxa8am33juinrz3tnyrfxxj X-HE-Tag: 1733867400-871436 X-HE-Meta: U2FsdGVkX18NlVcIoAsiOkils085vTtLMK3cNAIQsU0ftyXaVCH/H4I7hMsvjYHjm0jUuN7CYOGeaLQXmNiG4Xgwh44o4bhxIhCeUJl216P1PrW6Ak6o4+Yvgkoo3L3CpjvnGh1GmoKoq91h10NKlnv6cosWjx6UtuLc20aSjhTwmyxZeaZLp/H5Yk+YWqtmjnd3mEsINqTizr/UmpMxua0NcVOesowWYeISgI5JUbuuSAKwD3jnDOCGrT9ltQXxl3CDy8bT7y8Bgp/j1AtNCWu2xFq2QoKC2WjE1eT90ZuuxwxZ3KxoTwkafQohKAuiLVKzsdrlSCgb9KDzJXRZ45wiSqQG8eAhHaxOYhO1VIm1vk17+tlSOI05Z12d5Gs26b6uRuR3YknZD3WFt/GtULjoRTRURJegNrvXTDDYuUsFxwGJmRALAhPMafBCVTwEBu8tJD8LCzj92Em1jlzPgKs0M4qSMktzXeFdJesqiVacRbgB6ewf9Fv0zYeh6uCf3QVqWIj1f3bNbHw5uCeU0h4Yd9Ju/P7qw51S3ca5HLy0nbPPP/zaO47yJMr+wfOMuWK8EcoL0wUAv8grn5uai3ma3QPEni8FTS8GwfaDeUe/X2LgrkrrontUPf6+0BMrIwbhGxfuLy+tgq49AdEhgvcA1rug8sCSRFxyN5lgvcn54/91BtGNj9SOOZWZv67jWAHTghZfXzOD9VhQ34jj0qGRLnMatZY8W3YuOkbo/Zyuv5gBJKBr60zInQJsj3UMc7/t/2rPStO1h9sfPqjxOBtIsWvmDdLnE4wLH2Hh/jPvAK0R+puZjiMaOIeU7j3u58P/Z0nqVWcVF4xKWU2tQIUD1ztTaQwy3WaA/iM9UW1WSDaNYUE60HkQFcxY/q0zuYSW22r4qhl38LhwyrKZBe3rF1+nMSIx7Mmk4RZRCA91VnQ/wUGh2VGl2waNFtzeYxUVEcXY8F70xC7DPnA P6u7b5x+ zsFMOJr++ZdKzowZ3Yms9t+HUkJSAi47jhuupfMOEPmu8WLw3nJTyyPyley5acspGW5g04stRejacdpGW0QNYqaiJkLvLFWk/6t/nvu/KUYuPD2xMijk4Y9RSCRLmakYaFZv8bnZPvmHZqLPf5vgh5Udt8wKtXt5v1/FFQkLtfZKAqDDHGdyVnaWrwgjGKKyrKNy09bEzoMrJNLx9v8Loz3EJMY0Er1dh+KZCV9zXzjroaNM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 a proactive cold memory regions reclaiming logic of prcl sample module using DAMOS. The logic treats memory regions that not accessed at all for five or more seconds as cold, and reclaim those as soon as found. Signed-off-by: SeongJae Park --- samples/damon/prcl.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/samples/damon/prcl.c b/samples/damon/prcl.c index b34b9bfed532..c3acbdab7a62 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,25 @@ 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, + .min_age_region = 50, + .max_age_region = UINT_MAX}, + 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); }