From patchwork Tue Nov 21 05:36:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13462504 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 81075C61D93 for ; Tue, 21 Nov 2023 05:36:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CC586B03D5; Tue, 21 Nov 2023 00:36:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17D5D6B03D7; Tue, 21 Nov 2023 00:36:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06C766B03D8; Tue, 21 Nov 2023 00:36:19 -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 EB57C6B03D5 for ; Tue, 21 Nov 2023 00:36:18 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C4BFA1201BE for ; Tue, 21 Nov 2023 05:36:18 +0000 (UTC) X-FDA: 81480850836.02.C652929 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 36C6D120015 for ; Tue, 21 Nov 2023 05:36:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RuE6wR8s; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1700544977; 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=zHc+VPOxJyhOPtgpDz53Zq9ECmvdOs0WU0qM61Fu+EY=; b=j+MkftTlpwQZV88RHoqVp8sB9vlgiResljbV4Z+1xVmk2vzv0fYyppCpRc8CLln79BeZZ+ xsGlLNqwq42VLWbUFGDaFzOF5UA8cd+YIKhRWwVKmr6L/9J5/ikYOzwrt6LaqqOsPYFg7u ASLkMVKDQMWAXUiWQhLZ7loaaR7En3M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=RuE6wR8s; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.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=1700544977; a=rsa-sha256; cv=none; b=JQhbsnqeEU7dZD+b11t5Wiqmj8bSdPiGiYLf3AKq8SdWUmU9srrMw+1kS62bn/yYGtYzkF oQU+xT6ljTtP3qaHTtPfGc1wzLdzZsyYgXQR2uOOYjDoBdh+JoSmaAeEIllYoVfs2G0gVN IN/Og5FRL70la12Ldztc9wtolAp3aws= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 514BA61699; Tue, 21 Nov 2023 05:36:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B6E5C433CA; Tue, 21 Nov 2023 05:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700544976; bh=NQFkESlGtOo/Z9kTwMOTiB8dRtXYj2d4RmPD6fS+g6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RuE6wR8s0cxItHT3S4v7846HvTe8lzcB2GDG2usS3By8VthmMpudVeqd8U8fNOrH6 om/JguB2ZLBLI0bLl3U0NAX7CceryPzzMnPfR9xGRaLfqRcFNiwfDwT6pIaxcK9SV2 /gtAtDGnJLSTZWk4xkjlCYg3LX7ai4cL0RyKBkq+yp0G0UxgmQX4v/PETr61S7jvDV 4nMxnm3stGHrnb5XnaXTX5vUlk6CkAFUrSa3qGPDhGNIbTnPrtfGYVcfJaIZJWZOYF cME8q3NrmRl3KKcqTti1PJTJ0zNtx7K3SPeH9JonPLtlYq4UYPPx/AVKO6uoc1hiFc X13VXI4G9j19Q== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/2] mm/damon/core: export symbols for supporting loadable modules Date: Tue, 21 Nov 2023 05:36:02 +0000 Message-Id: <20231121053604.60798-2-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121053604.60798-1-sj@kernel.org> References: <20231121053604.60798-1-sj@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: tyxcka6tg9pho76wfsmf7z74fcwfk76e X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 36C6D120015 X-HE-Tag: 1700544977-943771 X-HE-Meta: U2FsdGVkX1+Jc/hi/+MKmaIHSZnzvc6IvPvXKBgTruH2ZEDE54kd8oA28wamkvHKm5e78Momeaw6ZvCZGOWgO1KE7ZG+rIVvidi1ESJkFpmQRe5TTO3Errh4gHLYYrELxIi1EXyxK8HuuAivSFbOf5wsyQESSfT36V1L1yGTuo6g4FF6jv1bmV8IENzTCFtLLdwKj5KLnzF7n4VaHrSZT67pcW52xuq34YnaSAoVplyOhYSeT7sTrLU7jF9279xaz6NaptNCpkKj18PCHLoQmQGsIWkDMj4kEqHspncN93c23E1NB0jWROPJSCd7Yy3s0mHGmJiIRLKYKyk/Qj6nGPeEoOSFPuWiMH7sCpoC+VwCSPRhha24Ut3+r9xMbSde3pnZgqL90kX5EXKNXnvmtUpm60RMuGZPo+/K5fANgSDTTJfXLhV6lAwSo+rYBGwiSAv9BNJ6Tcjrt+HoD8k6vxkmlvdMT+ERn8a2aP7JqmGuNXNlJ/eBhd5xkbKIw1/zZlSmgQbf+S4txavOWYdk2FF8vXXPfNHCYqyaChGJmsZ+0L9qpHOlGYQ1KBVUs7r8xpUZ5AjXkW6vWDdazYyADOGLuRJ+bxHeAfeT9354wIeVrHGFIV7JBOMjWP+yUM0pgikqZemPQDTNZRdsuDDR/hhqr3ESpmgfejiy+NFgZYHjdUYpu9vLlfq3kn3b0fZZRBNFJdqyQK0zdaK7jcrZOhDK/pnHEyu8A1TJlgaz/pd8TlhVBWa3w0PU4IE2F8nskZ4NZC7+kZmgyPfhWU/yDcGLK9vWybU8v28liaaWn/7ogeW9WVl36jf1lC2PZAJcCbh1OZzOlXmHfzPps/W6btaVM4R5KSpTFkJtxPMM9QinjLsNuFAFbI+E+QY7O+UJR3+caNsd6IRc/oY+cXXjNiPuckZexZcrY6KkBH3QNS7thnySfQZkvOTGz1Wb/Fzjsl1kr+sB7HjITFy+4EM 66UJGsbd 7/gnqRFbWBwlOZt58p43imxD60emxMR4RzDxJ3Ffrs7l4lLXSUjPtt3wEMfdjlFoqRXORi5wfm/c7dhIxMOIccOmTudd/X3WEvdOt79odR2DP3oyWObUwA00uBBKkT6vRniBKLrRbB28fAUMOyGts4Ps8xfdOWeuMjYz3DdwjGPyHJM6nZz6+FHOBRkL717hx97Pmrn/FPkxSV2oERAKLOZees3TbhoOyraXsQiAn8j5QtiE= 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 DAMON core symbols for supporting minimum functionality from loadable modules. 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 c080a16f6bdd..8ab8c902b9e2 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 @@ -353,6 +354,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) { @@ -390,6 +392,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 @@ -411,11 +414,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) { @@ -493,6 +498,7 @@ struct damon_ctx *damon_new_ctx(void) return ctx; } +EXPORT_SYMBOL(damon_new_ctx); static void damon_destroy_targets(struct damon_ctx *ctx) { @@ -518,6 +524,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) @@ -645,6 +652,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. @@ -748,6 +756,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. @@ -791,6 +800,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 Nov 21 05:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13462506 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 64BEBC54FB9 for ; Tue, 21 Nov 2023 05:36:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEC646B03D8; Tue, 21 Nov 2023 00:36:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9D356B03DC; Tue, 21 Nov 2023 00:36:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D65656B03DE; Tue, 21 Nov 2023 00:36:22 -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 C40476B03D8 for ; Tue, 21 Nov 2023 00:36:22 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9B48B140774 for ; Tue, 21 Nov 2023 05:36:22 +0000 (UTC) X-FDA: 81480851004.10.FD7052A Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 5264240004 for ; Tue, 21 Nov 2023 05:36:19 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XRqUqenp; spf=pass (imf11.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=1700544981; a=rsa-sha256; cv=none; b=xy9UTI8qTdGa3t8R4z5jHoHh+m1BimTeMBgKvMwREfIu4dpURbk+CiYyVTJ2NV/ZQf2+uB otcEuIUgCwZNzSKsYKbiqwv6s69uu9upTZFD38l4GlbxICAN4lYrL89uRt238iZLT/T7o6 9P+4ieL0mi/21YuvvtntinkijX8QFjU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=XRqUqenp; spf=pass (imf11.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=1700544981; 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=/p2sVdLQRi0+2irFQAkSbYC491HU/Jb2PPY7wkQyEsk=; b=VNgTpBh78UGAURWoEBFBRdo4pQyuCaUl9dBtRM4nsbNdfFLTc9B3V7XeXnyjF4W1IEO9x5 5o6ATGQ9KxcjEV1XCZMxn/eJ+6iGdLtyPLwFcINCMX/HUY1hYPxFRlFlFqxgADXJUEBE3m 0/5AqisJCdK6Gce0OXd+3tOLNKFP2us= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 61453CE1A15; Tue, 21 Nov 2023 05:36:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35AFDC433CC; Tue, 21 Nov 2023 05:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700544976; bh=xeB5Q/0nCB1T8mGIogEvXwiHT5yYGJPGjYRZafQD3vs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XRqUqenpLitbMJv0BlMtg1ANbPQdVT7r8XE2BBmQvFEbs0CRkYq0X8FWuePv05Ssh zZMUKayZf5fuJpRq0xuuw+UDavlWbGYYMIlttP9kxAKic+0yazEGZwtIQC4U+gcS0T l8oA8ZFf+XFQGdlpPlkzZqZNJIT5+9eTLr9C1tKglZZTvjAgKWvxZX+8ntE2TjPc/b bUb3wn7Hp4IsOKdHMZ+Vd3LjLC8DARb0mZj3k0ZRWcSKzukE+8NWFlsuF8ohrLovPc OpMI+7hDqmDnMN9hAznF+p2jw/uQ+VdkUt4CCfUkcSlTQvS7xblyFDBVM9WX6OEQwK jkVNLt1do6gUA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/2] samples: add DAMON sample kernel modules Date: Tue, 21 Nov 2023 05:36:03 +0000 Message-Id: <20231121053604.60798-3-sj@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231121053604.60798-1-sj@kernel.org> References: <20231121053604.60798-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5264240004 X-Stat-Signature: cokhsrerzcygmk5zk5c6psj9opccogyf X-Rspam-User: X-HE-Tag: 1700544979-454280 X-HE-Meta: U2FsdGVkX1+ZUpW71tcYXw6+w2Y+2Fe0g3UvpyiXZfgGe/TzCGPgClhvFXO5aKNy1+QmqPnOHDugWo1pGFAAFXvZjemd9dIDCzEEIuqm8MNXvLzeBTt2LOQoYxmDpjFDXOQjhavyTfnxLrPTEVf7MmN/eB3J5A0FwwGw5mRA+o19hD5RpSOw7LPv6XJaFbkwN2R8EgRzGCmcG6093/FDcV3Yq8S6qq6PFzFps1bqUhoRV4ag+3rRvbtmzmXnDHIagIs0+nuxmbua70hq0zZxgRu44KlFXr+8hky5xDiJE64rolUL95yMXMxjrgGwa79bY9JbBAZWzg/15fb9WpM+NzUYtNbYb/iQppEvnKalnid+oO4Bu7t5G1j47CTQotzcgw8pV9DQz8w5/Eoe9axy1PpqSYc856+NLed/K+6AHTUUAOZvj2evQ/el7Pi/EhMkwaRUsOZBEF1ApCITgQKFQ08oi2pdM1myiXspDWHZNOf6SuZkh89oIYAnuF0fnovxIhkeyUNFT/o/G3yQxO++YYyQ9ax5AQuE0/mlnj4qjdm76QboO6clLHrUvDEaY6NEvy+57r3FKm9c74R+bVesDGh82DGK7UgcKtacg4P+d6BvH877w2hxCnXjuM1biamRemtiLZgsp2+bc5zrQYRqvUB9BMzKRWBBtcCjbJqjaOLIAj9iQAYPAqmD9Xkvl1R314p8MleSOUqGv5Q/07hEzOCRF1YTlxNgdpgIM5/2OGemDTjquT1GCqpwsChcCdyUsJPuiR3vvgMfkinPpR3HG9CRvWtZyQ6ugphpNzNwmQmNh6rPFu4eqzaRGYMfWd6rlwW5y74yemIKebRWMKm0ppwh0cVSCgeQh2ASdUOSgV5ihTcOx/2Od0Ue0p7PjlN6f9C2KvmsybXxchbgKf8oqhWd+ujxUgpcbEncBWtFtEAWMNIUTzMPDaDEWs0hI5CTnPM9QyrY+eaXzQltCR/ dOVxtL+L KsDE7KDw6uPWsBup78qd6pLtiilPlvS83AAw+73uksVlbcud0BQUfcYwZJIGQJubpSSKl82FGd+ujF9rnZu3QtOHtJiDkldpF8gEa/TW+M6Inp+Ipem/m4HAP+vqioOVenetwb0xXKdqmQQfoxBfb1eKdhDrRUe/UdTvU34H/ZlcUY8Qb3esPLHrS1Npl7hRBSMdmK7tNDRwiwrD3/xqJXpA3SGv7S7ihkO/DIBXcGTROBxA/hRS5vZgkqH/MfK5IXUnY0iesSfBe2G7ANk+pYWHJX9TrRRVoGOjuFGnLrDlL1sM= 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 sample DAMON application kernel modules that same to the example kernel modules that presented at kernel summit 2021 with 10 minutes live coding[1] but updated for the latest DAMON interface. Specifically, add two sample modules, namely damon_sample_wsse and damon_sample_prcl. 'damon_sample_wsse' 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. 'damon_sample_prcl' is similar to 'damon_sample_wsse', but find regions that not accessed and proactively reclaim those using DAMOS. [1] https://linuxplumbersconf.org/event/11/contributions/984/ Signed-off-by: SeongJae Park --- MAINTAINERS | 1 + samples/Kconfig | 2 + samples/Makefile | 2 + samples/damon/Kconfig | 30 ++++++++++ samples/damon/Makefile | 3 + samples/damon/damon_sample_prcl.c | 98 +++++++++++++++++++++++++++++++ samples/damon/damon_sample_wsse.c | 80 +++++++++++++++++++++++++ 7 files changed, 216 insertions(+) create mode 100644 samples/damon/Kconfig create mode 100644 samples/damon/Makefile create mode 100644 samples/damon/damon_sample_prcl.c create mode 100644 samples/damon/damon_sample_wsse.c diff --git a/MAINTAINERS b/MAINTAINERS index 6eedc85a013b..3ee99307229a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5781,6 +5781,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 b0ddf5f36738..1e3f1b33b3d8 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -287,6 +287,8 @@ config SAMPLE_KMEMLEAK source "samples/rust/Kconfig" +source "samples/damon/Kconfig" + endif # SAMPLES config HAVE_SAMPLE_FTRACE_DIRECT diff --git a/samples/Makefile b/samples/Makefile index 0a551c2b33f4..ae863e7c5250 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -38,3 +38,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..459042ce5958 --- /dev/null +++ b/samples/damon/Kconfig @@ -0,0 +1,30 @@ +# 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. + +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 new file mode 100644 index 000000000000..df102e8c2b7b --- /dev/null +++ b/samples/damon/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +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..962b3309e490 --- /dev/null +++ b/samples/damon/damon_sample_prcl.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0 + +#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"); diff --git a/samples/damon/damon_sample_wsse.c b/samples/damon/damon_sample_wsse.c new file mode 100644 index 000000000000..7bfbd2bf56aa --- /dev/null +++ b/samples/damon/damon_sample_wsse.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 + +#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");