From mboxrd@z Thu Jan 1 00:00:00 1970 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 A027CC5AD49 for ; Mon, 26 May 2025 21:09:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B5FE6B0085; Mon, 26 May 2025 17:09:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87BD26B0088; Mon, 26 May 2025 17:09:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 76B086B0089; Mon, 26 May 2025 17:09:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 573386B0085 for ; Mon, 26 May 2025 17:09:46 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F38D080E8C for ; Mon, 26 May 2025 21:09:45 +0000 (UTC) X-FDA: 83486300730.11.2725C12 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf04.hostedemail.com (Postfix) with ESMTP id 6A23740003 for ; Mon, 26 May 2025 21:09:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JysvVqgK; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.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=1748293784; 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=RZTMP5NJ3BmzeJN849gXiIqrpKmTktqWgD8AM6zP7ug=; b=UMgciJ/eFeSsSwFjelT3yyZG/ucoWGJxHgTSevs6cm0QE5ZQcnHp0TTZXXanPyYwYgLJPI MWycr+TBSGq2T5tw9h22HCPgFlDxJwJUTfKhixnoPs0kW9Hspj1+PdHwqY9pTvAn4EP0Qh 37HitFy3R+8gJA3BC5A69jb5s0wAn3o= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JysvVqgK; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of sj@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1748293784; a=rsa-sha256; cv=none; b=bfKVwEsfl/p5JoglpWVkhbNs6SD6o6e/iEM0eFYkQJWYvV925nlUYj/9snYSzOcIVHz4Wu 83Vdqn+m5SKijVqFboNfZ5Fmsbpm//bqhzJJiiAIKWII1KJYVm6bnkFaaLJPnIk+0pcKRa yb+taq6lpxBa25uLPES7w9LzxKhHMIg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 9E546A4AFE0; Mon, 26 May 2025 21:09:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 204C1C4CEEF; Mon, 26 May 2025 21:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1748293783; bh=47rhffbSXH0eMjS6yxQtcQiXlFtplaL38A+e/fJH57s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JysvVqgKl1cSEUbpzQJvGMcJMc82ffvmnMzhG51C8hwnvpLqAcv7kXa9a0EfDCZaP XVdgBBH0+abyb0PybGslT8R/OLrdpoCZc7MlObWupcQbhAx3S7jv2vABNtkkptak0l sXuZzU7KWjvRqLzwzPn66XdNh46EXNgneBpnRnOMc7mCLmLlOTL0EWK2SDlG6EdP2o 7+/w4eWZ4F5XWdJwXw1TGDqbDkHm4EsHkR1VqfWDh13C+xDkuadGZEwOEWbuUzfhFE DyXXos0VUzOXvur+A/xut9CCcT7Qv1wSwruOKGOd7sHx+Fr2Y2eCrm3Hz20YKyfS/s p7P5v7wN/yYWQ== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, kernel-team@meta.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm/damon/stat: calculate and expose estimated memory bandwidth Date: Mon, 26 May 2025 14:09:34 -0700 Message-Id: <20250526210936.2744-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250526210936.2744-1-sj@kernel.org> References: <20250526210936.2744-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6A23740003 X-Stat-Signature: muce5znr5s5tf6e85aikfgytqa1ad8tr X-Rspam-User: X-HE-Tag: 1748293784-422851 X-HE-Meta: U2FsdGVkX18XffT2VUrYIwvVQhpuNVhsbVdRrPRm4eaZtS4Kr2x+/vgqS++n65PVX4UxCejl5d0+IVoJazfq7RDW7zLrSgTD5kWYlYMci3lq1y9III7RvjcB9WekUp2bsNyrA48Uc7OaMjz/WIFKIjztTHjoJ+vuDCEFS2myFJq42r40gmgwZCNS5tgnEipLWQ+zXH3x14GIFFpqLbqlSWLtIsG7X9GWMd4Ls+VNtkgR4Oq9pc+GRUODvxGQ+MUmSbrhvKDsNxXWcLONBfKWQkA9Ts+6cQSGqYzTIXSegwb9icba0uDRAs8SiYIdsanVFWtdRZ3EsMVTXj+8v0AcpYEb3plw4Fn2KscYq/CtA5W4AacmOGVNyVLCdUQh5RIVpwBAfB6JMUT9SadLXpbAD2A2myDHNeGaTAq1+0jZ5LzY3NEnvhC35TMT7j10r/aDviXoQ0JsbDQw9MpC/+fQy8IGWAkqvXa2pn+M6hjoL80sJypoDxTAoWyAd4cqGR8xBUEEsx/Ex2WPM0+KGcB8D2o6ZoS211JnDyau/bt9kmOqHoa5Hm/+tIAy5V1iHsoCm/EdzGdlAKzOtVLKHdX1p6pwElmtAhUnR3z6bk/TEz+0ixDyGhkL2MDaleKaCSbnfOrCDq7pkS6dz8QDPvKVWYfHYZxuw/5P/yEugzPMLFh7Oi0apWl7W9afeyrAn0vLL8vVaUCa7zt8eyJIYVeS0yyNEgSR2xTpEh+Y2GBnH6nP/tZTJGz9855O/fAXvEULAn5pJ/1hexlEy05/cjQKprYaTe4cqjpYsCbiIC1GvXOYT9mKjor+BUa7Y8Tl+BYPKrmb5OyVl4ws212ypP0G6pWh/DnvU1m+TdmiEpYrS9vzsCnMYkKcqVL5xkXiU3qnJYJ8oOH6Aokfd2UQQ1nFay2RFFxvz51nnKhRQ9rmI3CIUhcqWOxPBggT08W/ekqQud9JRTXZ/LIWs4AZOVb zxhZoj3o 78mv15/6gMWVXazk9cLmUBHMoQ7A6rU8jF7U6rXNMpYMCYCF+Z0lbw/6jI4qNkvxvVm5iKigFwPetP58JsrAhBBYPXDvtSORDL6kv2iIYhV1l8J6VzGqYaxQgf+AkvbBv0a25XDXI/DXN/0fwHsGppOB+HS7iYn7KzokxGmoi2YGG+18znsMAg2rnYiKRa9hamzDIzWBpVCn1oAMbMWtfycC7tSfeM6SVwNdXHHfhvmsE5Wg= 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: The raw form of DAMON's monitoring results captures many details of the information. However, not every bit of the information is always required for understanding practical access patterns. Especially on real world production systems of high scale time and size, the raw form is difficult to be aggregated and compared. Convert the raw monitoring results into a single number metric, namely estimated memory bandwidth and expose it to users as a read-only DAMON_STAT parameter. The metric represents access intensiveness (hotness) of the system. It can easily be aggregated and compared for high level understanding of the access pattern on large systems. Signed-off-by: SeongJae Park --- mm/damon/stat.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/mm/damon/stat.c b/mm/damon/stat.c index 852848ce844e..f9ae44db265b 100644 --- a/mm/damon/stat.c +++ b/mm/damon/stat.c @@ -28,8 +28,42 @@ static bool enabled __read_mostly = CONFIG_DAMON_STAT_ENABLED_DEFAULT; module_param_cb(enabled, &enabled_param_ops, &enabled, 0600); MODULE_PARM_DESC(enabled, "Enable of disable DAMON_STAT"); +static unsigned long estimated_memory_bandwidth __read_mostly; +module_param(estimated_memory_bandwidth, ulong, 0400); +MODULE_PARM_DESC(estimated_memory_bandwidth, + "Estimated memory bandwidth usage in bytes per second"); + static struct damon_ctx *damon_stat_context; +static void damon_stat_set_estimated_memory_bandwidth(struct damon_ctx *c) +{ + struct damon_target *t; + struct damon_region *r; + unsigned long access_bytes = 0; + + damon_for_each_target(t, c) { + damon_for_each_region(r, t) + access_bytes += (r->ar.end - r->ar.start) * + r->nr_accesses; + } + estimated_memory_bandwidth = access_bytes * USEC_PER_MSEC * + MSEC_PER_SEC / c->attrs.aggr_interval; +} + +static int damon_stat_after_aggregation(struct damon_ctx *c) +{ + static unsigned long last_refresh_jiffies; + + /* avoid unnecessarily frequent stat update */ + if (time_before_eq(jiffies, last_refresh_jiffies + + msecs_to_jiffies(5 * MSEC_PER_SEC))) + return 0; + last_refresh_jiffies = jiffies; + + damon_stat_set_estimated_memory_bandwidth(c); + return 0; +} + static struct damon_ctx *damon_stat_build_ctx(void) { struct damon_ctx *ctx; @@ -75,6 +109,7 @@ static struct damon_ctx *damon_stat_build_ctx(void) damon_add_target(ctx, target); if (damon_set_region_biggest_system_ram_default(target, &start, &end)) goto free_out; + ctx->callback.after_aggregation = damon_stat_after_aggregation; return ctx; free_out: damon_destroy_ctx(ctx); -- 2.39.5