From patchwork Tue Dec 10 21:50:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13902111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE0A0E77182 for ; Tue, 10 Dec 2024 21:50:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9200B6B0275; Tue, 10 Dec 2024 16:50:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 881D78D0013; Tue, 10 Dec 2024 16:50:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 723F86B027A; Tue, 10 Dec 2024 16:50:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 566D86B0275 for ; Tue, 10 Dec 2024 16:50:42 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 15457160B91 for ; Tue, 10 Dec 2024 21:50:42 +0000 (UTC) X-FDA: 82880393316.01.1C0CAA4 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf19.hostedemail.com (Postfix) with ESMTP id C16E31A0011 for ; Tue, 10 Dec 2024 21:50:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EmMRqjDE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733867430; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=erE1a+6ZDJtWpOYrLI3UZndddOJa2v/uUKQM7Slf8PA=; b=5QYEXVRQe4Hfk4DdXV/QmcmKN64fIRGejEhk1nmLN6+OaLSR1LaakosmqK30JCTpuQGQyg jmsM3cVGyMlWaGOB68acNQUkKWhfpcafz4eMlUmGUzIetUtgTUDGuDtiWMeArM+PcfoFmU PijKi+p7regNv8VP2/hEZqlfuIbJZ68= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733867430; a=rsa-sha256; cv=none; b=c1fouQ9ojbo98B3z08hdnVOirvNJ3UyOg0Mqb+yY7WvvVH2WiyKz6332tT+AN5fVNcatKy Bk7XcNIHVD0CDELXNCj5y79rzuEm7/zGN0GR8Ck1QTLdL9Nbve9yRJnXoS04TD2KIVff7N 8lxp2O6am+bLLRwng/xbZVYhMee+obM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=EmMRqjDE; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 8B807A419DF; Tue, 10 Dec 2024 21:48:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74FDFC4CEDF; Tue, 10 Dec 2024 21:50:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733867439; bh=WhKbvDPjbuIBA/Td7/ebEpkfZLrMJgwOSAMpKKqqUME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EmMRqjDEmysTyaTfmY/VxeGmtYNZm7cToJf/5OuUA/BWeBb5Wcre05Ccqb5qdayLZ 7F93iFBLS8q4pebZnd/TYpcySoLYarrtciHg4Hge3+ZALTkxtye8utueT89EXUmQed OjrhDQ4wm84CWa1Ew1Cx3L7FsYZ+QwTVgFGZlpHikj5RITpsTDj4fU0UJp+NEtTUJl N+mOlxI9BbGqSpB+c1dJJmuHPjcdhvfJfe8qcT0Ihx73vIc6wk//JUEaMt7K43Zahf ixcOYKt7CNRTpQwjuhbbl8+XHlgtOna/Kdv2pT36zEQgvfyMmvcBDycQaSbaPc2/ny uc/F7vl7pyvFg== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 3/5] samples/damon/wsse: implement working set size estimation and logging Date: Tue, 10 Dec 2024 13:50:28 -0800 Message-Id: <20241210215030.85675-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241210215030.85675-1-sj@kernel.org> References: <20241210215030.85675-1-sj@kernel.org> MIME-Version: 1.0 X-Stat-Signature: kcqf5xsrjzt93n9xz4jx6e7aztbbzji4 X-Rspamd-Queue-Id: C16E31A0011 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1733867416-73139 X-HE-Meta: U2FsdGVkX1+NE2Bsan4Ip/BIk1ceWhjBcRJDNwChJQ51AmhZEfNZTWHBAMQ5e/atORfNN446TpXregXbYBkQj/voSdJZmE7bM+quF5TNWZV3+XbMzXLfQuZLH9hVFPan5tXFm69LFHiZqJ4MFcbu/CCspFDzhW7eOAv0DXvOCbCZCoiTM+D/NoKYyjUeqjK4YSlHuhG1R+Q4ZuWu20TlJWWDhGxTsiJfJPTma9n2gq1qsYPvFdxnmkfs81mmgJTk+zl5JOd9Fz8oTtoBRzC7mTpo3hXaQviWBaNBWsWpG6aP2SUEEPwdsdk3QqLesV01mV41XBvGkZ64m/PudTOd1VCHYuZDyy+Lq+OrXhQ3DwwDUkPW13tjaWhMuPlgB/nIryoniVperwQ6rH+z24dplby0ixVgQJvAW9e2LJLO6iUsNkr/qAOs4Dv1d6m27MisTZ1MQUh0X7PXEpzbChxfM3rv9V9mHKXL1t6m8cfM3e2ChhBIiDyy7mPohg70sXWXM2ntFnv6B8HyhyUh9g8xS26+gUA9pOMMbEVxcDn8tgW2x7zCXoKOgrrwkfo84zU8NGylO8T56/aOtkdJFHfmisNq015NvbRwRHB060RwdAwGjxX3d6kC35lxxjPnnkhBhJUMF5OTuNY2gWXia2CN9x1Z1aRfq3UhuBYEcvKY6Exz8+sNYLldPDNQBjLBlDngWSJDRGeaIX8J11iFyBZrKF9JzHK4DDAnKJI5r7tp7ewEupiX5BQDzDFJh3m6miho1EZpW85LrcqGsasTVZRcYgWyPtSlOrdGDqhrSWTSwCAt10Ct1f4/OHo8XhMCPrh3lQV4c8Lspzw+oGRS8jbcIInA7FrFBHbY0kNRmXaiJqvFa5GPA77/HczmW85eQ+KOwz5kGHYoEz3ukxCIGgq06/gmv96ILrEX+pQlHAzyRK8RwnDqAWxdK7kmG6JhS47Ojxe/fc0WbDbA0DXYk9C t/jIsJgp iP7EXTtiOPqhMmPWEPQ6XnK97BpwfdBLP9tjNzCj32HKUia1I5TdhXLX8+MZr76hAfG9e8W/NshEUZpV+40+bY+pxM5+RRyKz4X+/993uhQU3Ht9hXa9tVic4B67m940dOYOAulTt1O5hDrvVnpyL5kBsZB6cagJuzl3osyqPbJFq3Wjj88CyIn9oxXCDSLjmyVTNxqO2qTQ63QkVrVE01Uu7P5cp+r/zd2MlbpgLmdmkPww= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Implement the DAMON-based working set size estimation logic. The logic iterates memory regions in DAMON-generated access pattern snapshot for every aggregation interval and get the total sum of the size of any region having one or higher 'nr_accesses' count. That is, it assumes any region having one or higher 'nr_accesses' to be a part of the working set. The estimated value is reported to the user by printing it to the kernel log. Signed-off-by: SeongJae Park --- samples/damon/wsse.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c index 2ba0c91baad9..11be25803274 100644 --- a/samples/damon/wsse.c +++ b/samples/damon/wsse.c @@ -30,6 +30,23 @@ MODULE_PARM_DESC(enable, "Enable or disable DAMON_SAMPLE_WSSE"); static struct damon_ctx *ctx; static struct pid *target_pidp; +static int damon_sample_wsse_after_aggregate(struct damon_ctx *c) +{ + struct damon_target *t; + + damon_for_each_target(t, c) { + struct damon_region *r; + unsigned long wss = 0; + + damon_for_each_region(r, t) { + if (r->nr_accesses > 0) + wss += r->ar.end - r->ar.start; + } + pr_info("wss: %lu\n", wss); + } + return 0; +} + static int damon_sample_wsse_start(void) { struct damon_target *target; @@ -57,6 +74,7 @@ static int damon_sample_wsse_start(void) } target->pid = target_pidp; + ctx->callback.after_aggregation = damon_sample_wsse_after_aggregate; return damon_start(&ctx, 1, true); }