From patchwork Tue Dec 5 02:28:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13479310 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 EE6BBC4167B for ; Tue, 5 Dec 2023 02:29:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83F7C6B0080; Mon, 4 Dec 2023 21:29:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C85D6B0081; Mon, 4 Dec 2023 21:29:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6907D6B0083; Mon, 4 Dec 2023 21:29:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 58C136B0080 for ; Mon, 4 Dec 2023 21:29:11 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 350231A03CD for ; Tue, 5 Dec 2023 02:29:11 +0000 (UTC) X-FDA: 81531182502.06.41A4027 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf23.hostedemail.com (Postfix) with ESMTP id 140BD14000C for ; Tue, 5 Dec 2023 02:29:08 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J6aY+O82; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701743349; 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=RbnZDQn17mlTBLITgMkCXl6q3Gb9LyY0eTRhgOneHZA=; b=MW7fICwQOlucANLr3EuTnac0t69Og+s0XGTYxK08kRUlTvwJRTdDMcmLA6DK9998QdeGh7 Ey3ed7sOxuGiTa4UNqSY1Qq1dv6vL/r/+bAEegXB8VfYEiZqGA0qvPaP1OEVwFLfZzwAg2 ZFPa/6gThkFCFU1s8xWSFTyVL+hIqIE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=J6aY+O82; spf=pass (imf23.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701743349; a=rsa-sha256; cv=none; b=8hFq2sQsXOU1E5pgmRTeii2Erx4TA1/WKQJ6Py9fOliSUQhJwKSycS6FKr/oOQ/VBf85GE VJbBPS+GLKEv32Y3PUrYsgjiEQEBBZVu43MwzZs4ES5Rl5iGSDRan4SCOohmFODrpscFw5 5/rQfaAH38Ws9em/NxhRT6cnhViOFcg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CC286CE1400; Tue, 5 Dec 2023 02:29:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4127C433C9; Tue, 5 Dec 2023 02:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701743345; bh=hl6U6OugfgCPU2deKjlNge8ZmSL6lB/DjRx+v2yMHcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J6aY+O82JRLvi9ZiWWCgNK9dzhk/rfbzFntuVc90rQCW/Qz98hD+qf1B+yrS8lvYu XUIDJKNblYxLPqmArrgtOb4NxmUhlPnUNpFSomqcHGzLHD5JVDiUduOhmugOvLbPuG WXOEHM3IGOGqXhKGrZP+kJjf38+ykbHuleoo3E2+2yRd/8nRjGgl0uDINgj1OVDnk7 fTsDY58oxNXjT2WKpZZNi8iSjrAKre/9np2NhgNBqh9iA11U2kLCJMxhTbSk7qKbNk EjaY/ejgRFM9qz4Bh/64/9Hk5OeEN3dcCKJ8PT/UHgvKQ6lFDxvOOsNwUmnw+bC2jq FLJrF+YB+LCKw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm/damon/core: export symbols for supporting loadable modules Date: Tue, 5 Dec 2023 02:28:56 +0000 Message-Id: <20231205022858.1540-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231205022858.1540-1-sj@kernel.org> References: <20231205022858.1540-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 140BD14000C X-Rspam-User: X-Stat-Signature: s8n7k6icsxwzciks1spykugfrjup1iqn X-Rspamd-Server: rspam01 X-HE-Tag: 1701743348-32119 X-HE-Meta: U2FsdGVkX1+iqwMJKIoagPpSXI9PF+RZSyvmGOFvwl45wZsfO7pnVQgK7ehQqWYpzaR/B9BFeXU+MDTBP2vW7lhJ33MNO1c6rmaQ8VkWeAjGnsFe/rnbjMRlRqGm6TBjXekGy2Fru6JmVpJRHHCLVPs6s1V5/LHB5PMGsE8TezNtkZ7c4qYXUGANGqwPU4BNP8g6pTLatGdzTlkHuqc1Deyh2FsU5FZDJIGdTsUfXSldiUDWYQ973jx7U+Lh52PHmpBd722UNXxIJixr/jmB4IOFroBRYQFiXGCftl1XqOsmHJxMCQ6pvUs3ZZYz3nBmrom1iFWqKkb9zFmvAVMzvoT7yC9NHAqBRkwV0KQ+bcxipV6R92jNcyOUnwS56Y0T+R4a2bschuKmWz52NzYo0ZbXUhJDr6dkWogHb2/+cKAP6jyk0cG647T6b+hHKlBM3WxHNQ5rz0QJ2N1VRlT/exUCN8nK+H5kvg5Jr7IbhAJb9n139RLmRPZlphkgm/+zpbFFvuqfN/Rtwdj5eiD4TL/opfC40BwAkVYPPGG3mVuHhXSg9E0y/Xqpxx7TMiChwxcuWyfKwuwARUwnHertIp+xNBRPSojvORa1ZYJp9aT7Hf63azlQmvsXkOsQeZTWFWGMFUpbPXYLaUgwMxhh8vC34W6l0s4adzcPuJICv0rmBrGuMvbUPoPKT3iAR/CxoKwhlSSH58ESCsY6RrRm27OVJefz2/HW0UKt82N2BuN2DhZJyoxjiUf8I2Q+EcTGVzJIoMrxvnb2CZ5fqOfK7bdE/vN6AORem+mPVWdWJ8CLKAOEr65fdKEhIQ/No+VRS3yVFAuolrVbqZisahiHjWp7yX0c1WumjWxGLl7Fw912W8/GgY6Eo+Hxtp0KXBBSwT4WRAcbcGS/rwQPYsAyHnR55jp+Btbo3/PqT/lGrVusmxrqrslzzyuIPmgNplARTYDZ+5ZSO48swxF3zqs F9nRkIxY sHB5hKeYM7SHd565t1ltg2+iSRuZhyCgz3AxvioQVoexE+b88SiwE+M/ruda4GTYbZCo9cmVpt15zohItZMsbu4q+MwWFEamkLEhdTJsDUf0MGmqnr7pYSVF3s7w7QKa1+DLySrBR9ZIUIUSPrjED0QebywfpCFYm1VxPSNIkbHSHWQfGFpXHjfd9hd1W4EDiw+HlOLH/P1tczXNS0UNT5bx++spKCV2HS+IX29yZ12Wbp+Y= 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: Expose minimum DAMON core symbols for supporting use of basic functionality from loadable modules. Followup commits will add sample loadable modules that use the exported symbols. Signed-off-by: SeongJae Park --- mm/damon/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index f91715a58dc7..8a5c3e905738 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -111,6 +111,7 @@ int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id) mutex_unlock(&damon_ops_lock); return err; } +EXPORT_SYMBOL(damon_select_ops); /* * Construct a damon_region struct @@ -343,6 +344,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern, return scheme; } +EXPORT_SYMBOL(damon_new_scheme); static void damos_set_next_apply_sis(struct damos *s, struct damon_ctx *ctx) { @@ -380,6 +382,7 @@ void damon_destroy_scheme(struct damos *s) damon_del_scheme(s); damon_free_scheme(s); } +EXPORT_SYMBOL(damon_destroy_scheme); /* * Construct a damon_target struct @@ -401,11 +404,13 @@ struct damon_target *damon_new_target(void) return t; } +EXPORT_SYMBOL(damon_new_target); void damon_add_target(struct damon_ctx *ctx, struct damon_target *t) { list_add_tail(&t->list, &ctx->adaptive_targets); } +EXPORT_SYMBOL(damon_add_target); bool damon_targets_empty(struct damon_ctx *ctx) { @@ -464,6 +469,7 @@ struct damon_ctx *damon_new_ctx(void) return ctx; } +EXPORT_SYMBOL(damon_new_ctx); static void damon_destroy_targets(struct damon_ctx *ctx) { @@ -489,6 +495,7 @@ void damon_destroy_ctx(struct damon_ctx *ctx) kfree(ctx); } +EXPORT_SYMBOL(damon_destroy_ctx); static unsigned int damon_age_for_new_attrs(unsigned int age, struct damon_attrs *old_attrs, struct damon_attrs *new_attrs) @@ -616,6 +623,7 @@ void damon_set_schemes(struct damon_ctx *ctx, struct damos **schemes, for (i = 0; i < nr_schemes; i++) damon_add_scheme(ctx, schemes[i]); } +EXPORT_SYMBOL(damon_set_schemes); /** * damon_nr_running_ctxs() - Return number of currently running contexts. @@ -719,6 +727,7 @@ int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive) return err; } +EXPORT_SYMBOL(damon_start); /* * __damon_stop() - Stops monitoring of a given context. @@ -762,6 +771,7 @@ int damon_stop(struct damon_ctx **ctxs, int nr_ctxs) } return err; } +EXPORT_SYMBOL(damon_stop); /* * Reset the aggregated monitoring results ('nr_accesses' of each region). From patchwork Tue Dec 5 02:28:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13479312 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 E5573C4167B for ; Tue, 5 Dec 2023 02:29:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 957066B0083; Mon, 4 Dec 2023 21:29:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88BEA6B0087; Mon, 4 Dec 2023 21:29:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C7056B0088; Mon, 4 Dec 2023 21:29:13 -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 4C8126B0083 for ; Mon, 4 Dec 2023 21:29:13 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2560F1404E5 for ; Tue, 5 Dec 2023 02:29:13 +0000 (UTC) X-FDA: 81531182586.24.434EAEA Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id C5E5F4000B for ; Tue, 5 Dec 2023 02:29:10 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BOwMnIXZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 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=1701743351; 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=IwYULYvPao66nYRi+bI6jWlFfhnrXGS+KvGsljmfapM=; b=k9Y9+QUwS7qnTnHCkY4zNBjivEbOy6FUYtybzsIBWFJPCmwqw+OWtj2Xo/09joV42JnFHE jGRFnRJGNvZ80ahyPqSIu23U8Z0gIfSTKDq7C7VUIMU6aOw+k/urzGT/wT9eZ5Oc0DyMVe XRiSjMUWRhGzC69xGBwNTVyWzBBlHic= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BOwMnIXZ; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf11.hostedemail.com: domain of sj@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701743351; a=rsa-sha256; cv=none; b=nyWocNpbJO/vA94k1dpSpT5hc2brmpUz7p3/XVHaUKT6g5j2D5hCF0pXJfZ5eoBD+ShehJ MxgjaVoT4KUcxyDTglNAq9s2YOS+ezc9Uc2vOnkQ/Tn6Axko7xYVBf77x3MfG0woYgjSMv X5FK2NSkovVT8brLHXEL6phOFlwoFBU= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id BAEDACE1309; Tue, 5 Dec 2023 02:29:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D7EEC433C7; Tue, 5 Dec 2023 02:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701743347; bh=ZeGpXOS+wd63sq2lkChRaopNGfsPvBCMhfOksZfRY9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BOwMnIXZYJDQI1HCnzULsLA0qvMK46eLCyBuzxRAQ6Eg5fnT+Bu5C5oDT7TdjE7y5 YaJTK/X0+IlM557gdEGgjHVbmFQeG31hFfb5Xgq3bWipkdAyprSD3cg8KC4ExBtIm9 67SJizuZmmS5SZSAqzTXjHvccTBV0FMQ3Kmf5OaV4cLgHq3axODascmXu22QuKfjb+ MHja/A2oBVUWaxLthN3+mn1B184NYu0+zaQ7PKXl9ofdxY+74fph6BlZIxV7AwG2vp IKWJ1HTJtl+Up9qgi4EhVkOAeMreCh0DBnL41QsKvj/A43N/nyjM64YhDuZ4q75Zvv U4i5KBTX3I5sw== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] samples: add working set size estimation DAMON sample module Date: Tue, 5 Dec 2023 02:28:57 +0000 Message-Id: <20231205022858.1540-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231205022858.1540-1-sj@kernel.org> References: <20231205022858.1540-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C5E5F4000B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: d96rems4y9zuee7qbh8eag3da64ko4d6 X-HE-Tag: 1701743350-316423 X-HE-Meta: U2FsdGVkX19HVEe2Rvkbyiizu5Qi6dMnKnLytc4InI2sPzWHtJipcUKt6xb8D6dnMZvc4X14RfLL1xXfONYpn/pDpDx2HQ/vQoWKInGq7KClm15nonCjkfrdgf8Ur8PpZqlE4dWyOjHGWsWeTwvuwY8gj8xOkTwotq4zq5QFH06Bum0S88xXngJUSy+khigHqo4dNobe+nTKRWenKtLNM20y2Cu4eNP5UyDtTWZvw52y4K8g0lu75SelSXniHgGgUuUgoPU1Jo4sQRaH5hOLIVQaDmkP7W2IbjJ/7ZemXFy+615UhqjPbtgqBvP7jY0OS3vtpxu4j4HiZ/kgRV1PtQ64LPstDX0yVNN09g1y1e7NIjaECZDi7sWd6qxrjmqNKXBHWu7HV0CfP3kpJKDyA3v+MZeMPViVqpIH7p3N3SraSuCCKpBZNFn7do0ZArOCWqW0O4vqEacsEZHXaAY3nY/R3MBDriM8wO+q59FcgipqbO6/T8TnPAKdEuCL/TmrDNhBful1yC6iSv1hVrY5oUiELYhJHugjWDNgv9Tbw2E0HgFLBt52kmFf3vzlw+Iv/jmxBg3XxUzW6Z+DikUTaOljnGeZkGrjK+EavNRQH7Wzbmis9PQSOR95u6cqVWf9mGndEXkZC243EiOqIzNfqRqicjwJb7cQP++asGxTUI/vJfpUkOrVBTxHkaOxVdUEVEsmuH3OOkirrxtK0YEzvVBwTMcofWnNNeqVgpfQ9aXWTGZIuwuU/6l6j0a6i8MoI3U2UQbcn2wQ0V13stvOuXSgP70M8oCqGpdQKA0V90PxmuXoiCHTW6MabhO0RmbgNQfThieQj4XsUyYejtG0zuiTIG/3jVNAqCyLZjQFvL+Jee13BsouauUW6Inth3IIAehTE+xIvQpdbnPPmHLUqDcBEZxraIwJjjdKik0xQhfAqmAoA+2llRTA1NflEHhv8YGrQMsMcTtnIcwElUT RW54Gv/y P/XpdN9xPLti8efZS9fSyGqX0uM1u22cQaI9DVXuM31+PxWj4hshjHslWGZCt1qlez0kUazaQdWPTq1w54Cpu32KXcAU9LspvQ85B1wdW/cW7he59BxS50nAKYOUNdUUSxdoLisGSKyvkrj7qDwBtGXTgemXzCueh3X9PaTs3QmM5I9sjLCKlRkbJrQaMvSoY7n2cfe86r1FLQS/97x0fBA0ZJc4iut8L6wCp0dED/MkbHOibJ9iTJUXz1peaSN/bH6iWY4yGfirdSXzhCqBsVibU2x9ptHI9+hISiOUdPCgyBGo= 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 sample DAMON application kernel module, namely damon_sample_wsse. It is same to the one of the example kernel modules that presented at kernel summit 2021 with 10 minutes live coding[1] but updated for the latest DAMON interface. The sample module receives a pid of a process to monitor the access, monitors the access to the virtual address space of the process, calculate estimated working set size, and repeatedly print it on the kernel log. [1] https://linuxplumbersconf.org/event/11/contributions/984/ Signed-off-by: SeongJae Park --- MAINTAINERS | 1 + samples/Kconfig | 2 + samples/Makefile | 2 + samples/damon/Kconfig | 17 +++++++ samples/damon/Makefile | 2 + samples/damon/damon_sample_wsse.c | 85 +++++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 samples/damon/Kconfig create mode 100644 samples/damon/Makefile create mode 100644 samples/damon/damon_sample_wsse.c diff --git a/MAINTAINERS b/MAINTAINERS index d1fcae09c910..5a44258810ef 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5764,6 +5764,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..5af6bb8afb07 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -39,3 +39,5 @@ 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/ +obj-$(CONFIG_SAMPLE_DAMON_PRCL) += damon/ diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig new file mode 100644 index 000000000000..f8b9a73717f9 --- /dev/null +++ b/samples/damon/Kconfig @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "DAMON Samples" + +config SAMPLE_DAMON_WSSE + tristate "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 pid of a process, monitor access to the virtual + address space of the process, calculate the estimated working set + size of the process, and repeatedly print 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..1ace3ad4aff0 --- /dev/null +++ b/samples/damon/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_SAMPLE_DAMON_WSSE) += damon_sample_wsse.o diff --git a/samples/damon/damon_sample_wsse.c b/samples/damon/damon_sample_wsse.c new file mode 100644 index 000000000000..897e6b136a1a --- /dev/null +++ b/samples/damon/damon_sample_wsse.c @@ -0,0 +1,85 @@ +// 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 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 __init damon_sample_wsse_init(void) +{ + struct damon_target *target; + + pr_info("Hello\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_wsse_after_aggregate; + return damon_start(&ctx, 1, true); +} + +static void __exit damon_sample_wsse_exit(void) +{ + pr_info("Goodbye\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); +} + +module_init(damon_sample_wsse_init); +module_exit(damon_sample_wsse_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("SeongJae Park"); +MODULE_DESCRIPTION("DAMON sample module for working set size estimation"); From patchwork Tue Dec 5 02:28:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13479311 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 79C81C10DCE for ; Tue, 5 Dec 2023 02:29:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4AFB6B0081; Mon, 4 Dec 2023 21:29:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF9EE6B0083; Mon, 4 Dec 2023 21:29:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B74106B0087; Mon, 4 Dec 2023 21:29:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A13AD6B0083 for ; Mon, 4 Dec 2023 21:29:11 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7661BC019E for ; Tue, 5 Dec 2023 02:29:11 +0000 (UTC) X-FDA: 81531182502.05.F222AEA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf03.hostedemail.com (Postfix) with ESMTP id C9AA120002 for ; Tue, 5 Dec 2023 02:29:09 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jngeDOXK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.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=1701743349; 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=X9ug2oDHbNJiQ6+d1a5HspawVsN24THkddLE+A501iI=; b=uZIyBPjJK9MLEVvvxny9XuVuOaZ4wQtxbK+lZIi2F0hILqWZrTjYeYbguMx1Zsmsm7tKYN L+fI0WR1paTF1AGGHmDrOLaRRrH82EJPbi0dvtxkPhjhkXIqLN3H1bVVZCpiFGckvaZU4g 4MfKtoHpyw44+AZ594B3HLPFi6nf7+8= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jngeDOXK; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf03.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=1701743349; a=rsa-sha256; cv=none; b=T++jRAcgOq8D9JGWej2k96kRxJ5jsllBcbtlOwH6Iqm4W0QyaN0yAL+1PHvoHRwokUaI0n joYNemf52wjkOtGJJrWuHzzYAyjnjea5SH8QeEQU7SWPnY5E+pzL183d6+4dQPtOi+Yb/d LtzHTkZVywjMW9dViRwlDP7rUvqevHY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 146AC61477; Tue, 5 Dec 2023 02:29:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EF36C433C7; Tue, 5 Dec 2023 02:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701743348; bh=E477KEEpVfXYBLYCDBbDHRJITkivLWed5UVr6LwW/WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jngeDOXKER4A8iR1WtRk2Q+VSSXWfsEjUkLKHDo5gl9pr5B546BF+p4Ih9ogHv/gd 3j69ZEx7YNQra9zB8utvELkTvedAI3ffNHroQG1gcpuQah3zv+sddfG/nNHJn9ou6S V0w2KF3S6nz+YbsqEFzG+OzOZhS4KVVv6Kn1osxhYFIOLBAbQcEh2xNbZeBSZMHLjN rmFPkmKu5dKkqh+PyAVPcNDF0TKhEyCuWIYnRSxwIjfg2tI9e/JnNNypV5nyWeHzks t4LyV4p1qOS8rNrGRHVZ64HFNT8LC3wuXLEBuNYV8ZZfKVtkbe2iA31eO8zza3RRqJ mwHIOcSmOtT0Q== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] samples: add proactive reclamation DAMON sample module Date: Tue, 5 Dec 2023 02:28:58 +0000 Message-Id: <20231205022858.1540-4-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231205022858.1540-1-sj@kernel.org> References: <20231205022858.1540-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C9AA120002 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: nps51a6xz7nmzto7zbniuc7wpaxrsm6s X-HE-Tag: 1701743349-767408 X-HE-Meta: U2FsdGVkX19h1H7L0F9Y5G5ZLecFdqv86d8+L3wn4mJnpjzC5EKbA40/oPlYOlw+u8Fmel9hEl0zI3SnIcaw5/D5dXVi5kOaHdfFQgonlFoZdqqN8FdMLsSM6mnvRGH++wV9dvt5q8L9CxNNYAQWoBF19mV4fS7p4ifW1vEfDTzw/C7i6jxn0ZZx0yZyHF225cQHQaMg7BfHPySDhwgeKwNv0aTfikvw+r5vwBnbumIW7Ccj75mPD2GEy/0kpDT7741hZEAPe8sg0aHTLwWtjGTIgCu+qQfINbHyZeveIu8m5v3Bl58E7vqz2NicfAu6ViW/d2AHF4THADkQ8JS4+8UVkXs2OFQVxNKV10rUdh7vtdnVaHY6tQGV9KEhAds5O/cMzBpekvSLMqkJP+Fan234+B0bn4Z7xwKfeOXzDrjbCB2tteeUJ3B5/CmL2LePe8NMzJ1llTw0SQATmRYRTPcm/FtV3HQkQjtGn4KkqzpslJi5a5dfinGQZz0ibLtYtmmeE7R9QB7/1k/UeTaAUXPmSROzNQ8uut3214jHmQ/XrKhMFOTyApQUYKgDOo7zWiaBMone0V7ZOquiji33WeqwgWhXop04Z4I1xUVY+OQz4ErhQ2rSxE//wVFUI53CYOVyfym1F3xvcyix9rpVZ34XYHWP6B9XgnlfRSU9mSNWJSaAv6ix7Jds4m/S7bn6h3UYkovy7GxxSq6lFTagm1agMsGKln2KhUcsuOjJpU61K9vKo82EyYc8mOs4cxhXy23g+EfH2njJzjKs91sW35m7HOrfrYB5AV3ApIFOgK9coLmwBDGo/mbqT17bnmAeMQuzfy1eGx/TijpOBPmJWjHYC7FegVNEUmaEnup1HlgD7R6RRajXMh3Cp2ubJI59TeYDnBbyFq+3iTk0r8cn7zbdarGX/NewTHmhVYmDv04QYizpRJSBlHX58uCoiE/azpq96pmpNgtUMzv9lmv 2Jvy8iMv OCpNBNfqS6qCV1IrYVHQDVlJA+fkzn8nF5sSgA5V53STPk34kBrWBoTxAWG2nAOTwZNghTTytoRnsRCN/oDWcqICrBs2MUd7xOss9UBwCMxh9euf+vVH6lb6xsZHkbFBt5xL/B2GOWIwgnmTlCVDmJgKWoQw59rK1C4FRgI/oVs5ImXlPIg7TZa45zX2z6HiGgRbLiSwS2fUunKo6DmYPeMJ+SvBjw10NLnTTN+fL7U5ydzOyg5q9ilD/CXFIGPmh779ZoyJrUlVYCnlX+VYUivabMcIbGkP8AFvyXMdRXHSDxD8= 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 sample DAMON application kernel module, namely damon_sample_prcl. It is same to the one of the example kernel modules that presented at kernel summit 2021 with 10 minutes live coding[1] but updated for the latest DAMON interface. The sample module receives a pid of a process to monitor the access, monitors the access to the virtual address space of the process, find regions that not accessed and proactively reclaim those using DAMOS. [1] https://linuxplumbersconf.org/event/11/contributions/984/ Signed-off-by: SeongJae Park --- samples/damon/Kconfig | 13 ++++ samples/damon/Makefile | 1 + samples/damon/damon_sample_prcl.c | 102 ++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 samples/damon/damon_sample_prcl.c diff --git a/samples/damon/Kconfig b/samples/damon/Kconfig index f8b9a73717f9..459042ce5958 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 + tristate "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 pid of a process, 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 1ace3ad4aff0..509f6a619dc4 100644 --- a/samples/damon/Makefile +++ b/samples/damon/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SAMPLE_DAMON_WSSE) += damon_sample_wsse.o +obj-$(CONFIG_SAMPLE_DAMON_PRCL) += damon_sample_prcl.o diff --git a/samples/damon/damon_sample_prcl.c b/samples/damon/damon_sample_prcl.c new file mode 100644 index 000000000000..487196f18864 --- /dev/null +++ b/samples/damon/damon_sample_prcl.c @@ -0,0 +1,102 @@ +// 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 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 __init damon_sample_prcl_init(void) +{ + struct damon_target *target; + struct damos *scheme; + + pr_info("Hello\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; + + 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){}); + if (!scheme) { + damon_destroy_ctx(ctx); + return -ENOMEM; + } + damon_set_schemes(ctx, &scheme, 1); + + return damon_start(&ctx, 1, true); +} + +static void __exit damon_sample_prcl_exit(void) +{ + pr_info("Goodbye\n"); + if (ctx) { + damon_stop(&ctx, 1); + damon_destroy_ctx(ctx); + } + if (target_pidp) + put_pid(target_pidp); +} + +module_init(damon_sample_prcl_init); +module_exit(damon_sample_prcl_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("SeongJae Park"); +MODULE_DESCRIPTION("DAMON sample module for proactive reclamation");