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: 167497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp412793vqb; Mon, 20 Nov 2023 21:36:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQyJORF5cOfFC8Hu1lW+gc4z4vL5abyBZVpfcZxVWOhIAesjV5+2PzG73KEHUX96fs908E X-Received: by 2002:a17:90b:3ec1:b0:274:6839:6a8c with SMTP id rm1-20020a17090b3ec100b0027468396a8cmr7980733pjb.6.1700545017242; Mon, 20 Nov 2023 21:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700545017; cv=none; d=google.com; s=arc-20160816; b=wOYpz5T+xNJQQwwBo9xTMOrpPRFAKqutAsASkFYh3AppKnlWmXIRABdCow1/fwLhFr hYnK+4ZSs3bE6uM/7pBT95LLi4xJ0Lr62jpXRQ63nkaasV6gu6Vz2t01V5wbtuWmFGsq UYBWIg1epXD7ntPI4S0bsOnwysXwinQLkuVXLaFLIHLgTa05fyFi/3MW6xSqBLv5TedA bMEKsWcsjB7YmRTZojOfnfUpJFNF5ollNSGbc7ajLgLAw5+VmE/XxkZOpkGdtR4/7sIZ q3/HEKxpCmr2UcxsZUlRaUr+VgiGeFMS3ShkQHcdLlh8pDePtkRcmc3tasso2cBhfEh5 M7Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=zHc+VPOxJyhOPtgpDz53Zq9ECmvdOs0WU0qM61Fu+EY=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=yGwmVFZ6ehvnItSk7iRBLYCyqQkUYCcRlS2IsXR/ERLkSJncFEJeGaRVdUDkQfA3Ve f808IrhIuRZCxsTzZCf6GxFnPVEkrh3A8ZwmQZDgOgX8nqfyYiQ0nR5TqE22XyLsYEuU qXmkhqueyTkYAh6ZW4Q6qRHN9FQOyoaQJIrH+M+Kzdi2kvTqJMYehi7LhxBOcGt5NIzu ZSZGwOwrSbmk4W7LD5VsVNW7VAOUf/qGbr7LpntsFioEGdRcD+m/tfct/D7NuATp1FZ2 lMVJnqmv12AuFM23nEKxfemBUrnflojwnI1Ag8fJQwRkeKiT22WLAicxelhokIRWkVX7 rUPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=RuE6wR8s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id a1-20020a17090a8c0100b0027d11201a11si11977338pjo.170.2023.11.20.21.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 21:36:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=RuE6wR8s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5CD138040813; Mon, 20 Nov 2023 21:36:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233463AbjKUFgs (ORCPT + 99 others); Tue, 21 Nov 2023 00:36:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233397AbjKUFg0 (ORCPT ); Tue, 21 Nov 2023 00:36:26 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67EF9D79 for ; Mon, 20 Nov 2023 21:36:16 -0800 (PST) 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 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 21:36:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783150691750371062 X-GMAIL-MSGID: 1783150691750371062 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: 167498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp412952vqb; Mon, 20 Nov 2023 21:37:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFkDxYzluphKVN2DIvMp4hgHeSEuNE80goDI+dJGG2xSHhTgBD/4axJkc/4U9Hd9FBp2a34 X-Received: by 2002:a17:902:9309:b0:1cc:7077:c87c with SMTP id bc9-20020a170902930900b001cc7077c87cmr9836738plb.14.1700545041810; Mon, 20 Nov 2023 21:37:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700545041; cv=none; d=google.com; s=arc-20160816; b=SN6sJpRROoshM2dlya9hCWxfw7DYwTp1TQR68ie9mItHT6z+mDrI6Do+tXeDY86yoC anyBFcC951p/alj/m39RoBh1d6Koem6/6OFdoiw6fabp1NVhWyZ280vBUOAZRYgj9hXP k7BQmAFwzMX2XzP+dncBeMBkOATsn8Nxo1IrUtS63rgl81Z7UFYzp3KRNawNUdJ2o8lY jNNEUkqCu+gjO94FPemmmoQppRuUFQvefyPZIPc2TTffX2UCufS6/CUY1b3uYixjbS+/ jpdWqIm90buk4M6WZCb67s6tPzbTIE2m4i6Z+2dJMWQy4qFZ7JmxPsbj3h+fiD67npM7 yycg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=/p2sVdLQRi0+2irFQAkSbYC491HU/Jb2PPY7wkQyEsk=; fh=vqNpWvtrgKyqgLywmXrl7l1d0QUXOIwW93A3X4awQbI=; b=j3DuIgZvyucgj2W768VFyUvetJM4/sqcW42ImO6Qbh3xWdIAQQ3TjhVvA5GZtc7dp/ QQh5N8FJg+nZF5w/R5/4sNAoP6xq4ZuJeTm9OWGMv0xqS6rzJjPNnlvKPHk2TiurRP1s WPtuvBi1OCl2f/z4m+yRrG/QeZbo83K9GSkmUwnCsw7QA135s49lHVGE5uwk2e+nHle1 VlkNp9PVQwH/P6kM4Dzez7ggQpQDbFCjNBpfF1+BlvJwgG1OPIJvN8S9y70SsqJYxPlU /V/jsd+OqiOHwGzd3ayIh1wOH7B7X5n3yGKD8Jbt5WRjKDMjARN5R1J4DVVWzcVQpFDj rQeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XRqUqenp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j10-20020a17090276ca00b001c9d7d70d7bsi9305459plt.4.2023.11.20.21.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 21:37:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=XRqUqenp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5FABD804080B; Mon, 20 Nov 2023 21:37:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbjKUFgx (ORCPT + 99 others); Tue, 21 Nov 2023 00:36:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233471AbjKUFg2 (ORCPT ); Tue, 21 Nov 2023 00:36:28 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07832D7B for ; Mon, 20 Nov 2023 21:36:17 -0800 (PST) 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 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 20 Nov 2023 21:37:18 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783150717694145710 X-GMAIL-MSGID: 1783150717694145710 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");