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: 173673 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3173022vqy; Mon, 4 Dec 2023 18:30:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5bsTGpJUK6VzIbXnePu/OmNO09OC73MW5lOIm2EDz2wKB+gMavFPGZJXXpsrMGrd7yO6g X-Received: by 2002:a17:903:5d0:b0:1d0:700b:3f77 with SMTP id kf16-20020a17090305d000b001d0700b3f77mr748567plb.49.1701743404325; Mon, 04 Dec 2023 18:30:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743404; cv=none; d=google.com; s=arc-20160816; b=SqSxNaES4zUHOfM7GNH7V0Conl0vgDsvh7KVg4fFlhZ1rpdhW6SDtri4YgqZUIkaca hRiJijx2ZeqMTk1XoBNydnhOc/cZn8PhuFUKAYwIS3Q8ezKu2rUrl+HR7BBqw1mHADm4 tN9eTFYpHL/DR2Pr5J6E/WWrTzjCQC5f6IEcwDXFzQj7uFY1+rmL3d5dhNaLalLpfLSP jiYn7rTE6q/H+1n/H+iXl89D+sOhWoI2JzyVLfKxR/2dX/rkq7re+o1QDDyAnWUc5ff1 i2ST8+ieGEAke9ZdJ5ruw/iuPaGgCiRqHAFj/Wxs6fzPqXXwNSFWa8WsReFdwJtGiU2R fRcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RbnZDQn17mlTBLITgMkCXl6q3Gb9LyY0eTRhgOneHZA=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=hirFrSZVrxyLeEx6aOXxoBxtpiirJopZZeVAJgdmGZVK0oyIJGKHUotm3bZ+XPS2Xw 3XsBRp5sE7uCO0Df0GfFs8cGe2ZwocfOJ1Eo8AvdGQ6uwKq2RS671PoLk4VdhRds093P BR18xMXIO0V+kXTr6yh7Z+Shm1hXDveQgSoc4s0rWH4EiRTOGFF5hLc5IHreO25lWRQf UYyZ3aOoVZG6LglXOjeFYXn/9HssdfJQxYSXYmBbR0Y2iBwpfP+CFuURnTLTwrat909T fFdfAF17cU7PtLxC3N5UGVu8vBpGjXCuJrBU7/4BxpBUcRTbTKWx+pxXtiZY45QlbD6N 9C2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J6aY+O82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id p22-20020a170902b09600b001d00ff4bf6csi8506816plr.466.2023.12.04.18.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:30:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J6aY+O82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 754D280781E9; Mon, 4 Dec 2023 18:30:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346426AbjLEC3y (ORCPT + 99 others); Mon, 4 Dec 2023 21:29:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344107AbjLEC3l (ORCPT ); Mon, 4 Dec 2023 21:29:41 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F820124 for ; Mon, 4 Dec 2023 18:29:05 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:30:03 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784407292049438513 X-GMAIL-MSGID: 1784407292049438513 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: 173674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3173407vqy; Mon, 4 Dec 2023 18:30:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZbWsMM3/aV0nSUozQv2iAx+EMyETCfMboh3wcO8YGAdBTjDDvIDEHN8BBbBZrJnrDrdqW X-Received: by 2002:a17:90b:1b41:b0:285:bc41:2a07 with SMTP id nv1-20020a17090b1b4100b00285bc412a07mr449326pjb.25.1701743454847; Mon, 04 Dec 2023 18:30:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743454; cv=none; d=google.com; s=arc-20160816; b=iosb4C8JekeSOV4C883A9VU8idTlmnby9hz+JJC8lZXxdqecfijUrcGGGlSFtBUtw9 h78Iiq8bomKNrnGm1Kjx7wqdSa0iyghK1ToMSaq888vRL6PF7/7IXLLflLG50bz/VrT0 7A/75BnWqhttMGW27Pk5g6Z3LBOH8Q1yIZl2NS9dGBgQE8EyfCD6rEdwp4/nyPoh0+jW 879J9982IRqcOamYf3yrMjUiTIpVrzWc4oEAtn6O2EvxXjW0O9OEPJYBwyX32XlzgKyc 95qLHhTBFC+WPlYVxoCa6ydgLxxw33PV78CLa4mzBv9jB63yoytHxHU53HPOMHQdeFRT Eb1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IwYULYvPao66nYRi+bI6jWlFfhnrXGS+KvGsljmfapM=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=rH9V6wKugfv2L9i7VtYQ0QNFlKYSGCVyDpgjCv8AmFo2ezmMOgeROjQI/ttZekmda4 nIw5gOi4KcdQHiS38Nbs4Ys2KeSiv2bKhfzRmrQryB7dYZfv50vmDoJEIyYmz1sS/7rf 6SrQqZeXCgDG6hZmXLsm2yy2dYJS2ZYxG9/3fUIZQR1vpaiSs/vgzYu+lQHMr42FCzhx 1E/cvoLQI5ATxkzd4r1r1g2L/UWpllWOdqZpX65efU0Nn2wEOtWqfFqWELj39mW2NFxn HuM/sCXU76ZOD/mccmACtuuUYSRw/IS2kmET/FFIHdC96dOwX13zjsu2hooneZbRgHa1 +9QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BOwMnIXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id qb11-20020a17090b280b00b002839db82641si1836832pjb.85.2023.12.04.18.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:30:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BOwMnIXZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 80E42809356E; Mon, 4 Dec 2023 18:30:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346426AbjLEC37 (ORCPT + 99 others); Mon, 4 Dec 2023 21:29:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346419AbjLEC3m (ORCPT ); Mon, 4 Dec 2023 21:29:42 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54C2C127 for ; Mon, 4 Dec 2023 18:29:07 -0800 (PST) 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-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 lipwig.vger.email 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 (lipwig.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:30:25 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784407345245083226 X-GMAIL-MSGID: 1784407345245083226 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: 173684 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3175696vqy; Mon, 4 Dec 2023 18:38:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFhOFFj7FsCvIxYuvlcuCL2fSLLAHlbJ/qI1OjBLM8VDvPLzilZAddXv/eaDmuTAKufUt9 X-Received: by 2002:a54:4e93:0:b0:3b8:b879:e4b2 with SMTP id c19-20020a544e93000000b003b8b879e4b2mr3359310oiy.15.1701743902617; Mon, 04 Dec 2023 18:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701743902; cv=none; d=google.com; s=arc-20160816; b=aZij1IVh8uRscHtaK4SiAUOEhjdSq9o3rcYdtd43D3mOOfC3jkQPyfNEfYYEt+xFXU JF/tPnmuGsTw93/ix8hv7MpWyyS7WduDrv5AsuSz6gP9zfeTwEOlt+u/QlmBhBkYYOIK Typ4EfTJDcR4LIdirXjWdUw8yMQtdDg9ifjcuZAyLKS6wWpJqPLIlIgxCHaMHXhkZsoh F3UfSGege/zRN9sPh+P1qWxmaejQCOnKBibrEVpiq/DFRjpuUE7QHyfMoFfI1hcAo4Ke rmHFmAXK/QKlYKbjpbXtgPrhYv3KREi6jDR/XbSpD3wtrxd8whJmFsOwB5SzXHEWe8Zt fNvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=X9ug2oDHbNJiQ6+d1a5HspawVsN24THkddLE+A501iI=; fh=BzdeVYqZhG5iuwuKJRNLP969rvCput73lx0iwx2zu7A=; b=BUK0/u1hlPqaC+fMk5hxR7IJQsbV2yXgAByQkqXwhS26FtMSImuXC5zAwdBLdWahZ3 F8vXRX71FWd9mbnHr7N5MG/ie3FbPQbitpbZtCIfXhA0wOooFlkieaKcVc+NBHb1neEx v5rcZX0cy6Yv2rm01Y7MdOdEWOZ6a0pyrI2W4SNBu8dtQfU38cQf/qC+Jttj7ZEfHMRv AK3LKD+jyR/MIaSNOFztXSUGIXx0+3Ywkjq1AKQ7H8yi4ucrR0/PUWtWW9QuJa0kleRl u87nQdeufrbCxbkUdgBUIlaCkUo4uRZeTKYzRA5fgkZ9Mu95tHJZNPfQHHHJ/yDvPx3v OswA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jngeDOXK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f7-20020a631f07000000b005c2135c5018si3815334pgf.571.2023.12.04.18.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 18:38:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jngeDOXK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 742A18045943; Mon, 4 Dec 2023 18:38:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346397AbjLECiL (ORCPT + 99 others); Mon, 4 Dec 2023 21:38:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346389AbjLECiI (ORCPT ); Mon, 4 Dec 2023 21:38:08 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1621F184 for ; Mon, 4 Dec 2023 18:29:09 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 04 Dec 2023 18:38:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784407814344072040 X-GMAIL-MSGID: 1784407814344072040 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");