From patchwork Wed Nov 13 16:26:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13873999 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 B76C7D462D6 for ; Wed, 13 Nov 2024 16:26:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 364626B00AB; Wed, 13 Nov 2024 11:26:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2ECE36B00AC; Wed, 13 Nov 2024 11:26:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 18E046B00AD; Wed, 13 Nov 2024 11:26:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EA8CE6B00AB for ; Wed, 13 Nov 2024 11:26:34 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A339D160A7D for ; Wed, 13 Nov 2024 16:26:34 +0000 (UTC) X-FDA: 82781598648.24.ED448E2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id E1A51C0010 for ; Wed, 13 Nov 2024 16:26:13 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nN9kf5OF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.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=1731515016; 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=ZO+enpc9GWnlEjI1jOf0Kr1GZNP9yxke2vQ6rNIE7HY=; b=diR75iNDxmogN86nZyFNINBFDP0A206dT8jk5kfkR3htd+WASUZuSKA1vyY4xxi1wcOM/u Nhcdcvhy4eabWFSQx4CocpEE4Apd5PNBhoAg8NwgixszFGMM20dLkqGDitY3+WiXa5WMPC 4WSGtHwPUBrY/x9NRNtfwqNnH+1F0XI= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nN9kf5OF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.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=1731515016; a=rsa-sha256; cv=none; b=g9qAMgoSq+yu3ZEHNqw4LiIxgKyNLHFRjjeMjTOMnp8eKa75RjD1ClsD1QyAj27iZ9nYYy VIaZq0dEelF/H+BtN+3iMdxPoZdK4EKCTMMfOpxHWMliE6nhuLvVBpSVlxkWnwxNK1ZDcA 8ZTpMYt9nxyRsL0or6iUz6ahFiCkGRk= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 023905C58C0; Wed, 13 Nov 2024 16:25:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECA66C4CECD; Wed, 13 Nov 2024 16:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731515192; bh=WP1gX/xo4x64pFwAnpa4+qlhjEolC1jxzqSRjjY1A0I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nN9kf5OFlgu4dQr8kCgt11CeEmO3VjWDz9PPNEL9PiWAWkorJg3cQDh8o7rskgdSs cn+ZKCIsnVwh+8dDZO4Zbyur1MW45QSGn8txRaDsySqSV7KIMmfUKA5PWQ1Dv3NHmv +N+s+m3m/WrVUHwd5kcgs7cL+OxACk/rGNf0EmWGQOVxp0vp7tt78QGYKr46jUlIvE NOTMsBSNsx0g5Ie9rDombMvKqIbh7Nyju6A3ZegmdGTOr9s5LdvlzbdX0wltREHHny 3qbGbMDgb7mTKOD9Et9doc+jpde1E3Wt42dbzEXoOmxjsTZX2KM5B2RTwzhiT1mwTz nVlaC5Lb/NTtg== From: SeongJae Park To: Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [RFC PATCH 3/5] samples/damon/wsse: implement working set size estimation and logging Date: Wed, 13 Nov 2024 08:26:22 -0800 Message-Id: <20241113162624.48973-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241113162624.48973-1-sj@kernel.org> References: <20241113162624.48973-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E1A51C0010 X-Stat-Signature: 8j8t6iwjbya6hbng4fkdyow7sfp5wqff X-Rspam-User: X-HE-Tag: 1731515173-260291 X-HE-Meta: U2FsdGVkX1/eQv7ROGi6pv7pGxhHfV0VCfw3yqENUa2GzVJ9sCTf2c6S/n9F3ipq15RrpyzSQZerjPSYfv01gB5nE9TiPCE2Y0+JY/nFNrogDaHjFdyrm0uKR0+44TUymxDzs1OfL3ZbCk3ZDT49VvS3e2NRf65YiWbopgpPJeMFlYXJmvf7MktsDJoex3s4zfmvNBRqQuEGqjq/5Pzjwysc+90Tre6xWXfy2jz4QqJRZ0Zru4erNbxOuEmVSqOmtEM40dpfFoLYN+Uv+4cROAXnuJofeexckCQEKxkLhKUiHrufH5jFtuBDtCC0xMnFoVb5f0DB8cMCehFWo0CjeGmI1xUVeLKpavnBcTH0EjejS9AesO44vBmLUH35IQ+Lot7EFJeA1QRG6MlXDvkYQUkcmA5h1u2egv1kykhBaPIvZuY1jtuelkL081PxWXcFEVttNXykxRxhYWx6+y5wb5uR5RbMnQomDpi6766TZ8z+QWqCqRjNlyjBlIFkWAyDzhgEgWCmJ4sKJK21J1xwWZT5iOoY+KEpvOZ5nj8YdQsi4rgA6F+xzYwzjShfGwC8+R9QP0UiJ0JKot/y3PYY1u9NxmyP7ecBvYksHlemnW3eQdsPqqOA1pIE2pK9Td5lqXsjNqJZg952oY8MBwRMvC9RMeSrXswvAclHm69v7ClQpB4PVavRzEAzOLyaBiBhppJ79X8jRPLHTVIcR4bxa5d51+URaaRQtZl7QW2DhAHesB/zUHeG3OSgqLLG/m7c0cTKKwoqNXCVQ7NGFJ0sZB88oyeedWvSRvX2QGSg0CQaGPRGS4VyRH6tQDrnPi53mzEL7SgKpg+XRPBpsfXcQYEiWaTyfsIy1LgSCMatzXxvsTsFGfKc22hTLn2KO1123luPiDOj/a4enKm7DJkaL7Yy65GuNH7sdK/LIZmJDVwlh6NznVsTXU0BxRpq1suU6bsrpT9qlB4HmI8LSs+ yTfRLSPW gzRKxNML+Tsrb5bK/F7DsjBgqp/MSlPEFf5lkomu0DA6EIC6jdWN3EbZazxfeajoAIYZ8sRhx6zwe6PfECa6nvRmjv3M5Cuad4C5xEK4gfqz7Y0/T2ur0IbEBESScE/JkHNFTaomg7pUEenXaDApvtPiWm035kfSU3JPaHQmOVOipQ/Lg0nDKNUWU3MNrN40QSEYOCTlrudEw1D52ocH63/CW3H8PwGKoX+QuSJOekErkypY= 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 simply iterates memory regions in DAMON-generated access pattern snapshot for every aggregation, 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 printed 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 119ac8a2c901..a2a94c505938 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); }