From nobody Sun Feb 8 01:30:56 2026 Received: from mail-dy1-f195.google.com (mail-dy1-f195.google.com [74.125.82.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F150367F46 for ; Thu, 29 Jan 2026 21:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769723904; cv=none; b=Rcrar8X78FWvRoJ1wJ6EnD/Ivq4emAvsxXMyNwwaQFy2DiCWsVKyyv4Kw8KjeWtP51oWLsG+EEPIx37l6wDQgXMmrhZ6L8G3ajaMUJCcDaeH827Wf3rgf4P2nchWSr5vaysK0vuYkl7YHGKZXtTCa7mOZf9HLOKFIsrGxq2AskA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769723904; c=relaxed/simple; bh=Lz87npd8Ymj4dgzZ8guZFLbK7FQeXfTehjSY3ldIw48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UKgjMe6xzh7KCkr9KuBc9txRVYwPOubavvof5oCWgNzw+rncwSPEdv/jh8vgXCWX6rdXXcMi+79S08vwaGWIKzPu5n6827qmf6l0WFhnli3Xa1GmFlTLpr8cpXEnSm0/6YnSK+vhcycD72M5/E3Ej9zLKZ9FBQXRa0Zm1+WE2rk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bp0qT+ak; arc=none smtp.client-ip=74.125.82.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bp0qT+ak" Received: by mail-dy1-f195.google.com with SMTP id 5a478bee46e88-2b720bb90d0so1565102eec.0 for ; Thu, 29 Jan 2026 13:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769723902; x=1770328702; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0za+mTabqTtCcABlRwV4DBkxWsk326LNSJGiU0z1JGs=; b=bp0qT+ak9ggjTSkgp8Jx848Fkj4cRlVNy5tNIMFmBmUhIeiBjzk/uBTjcj7W4tJp6x Hiss37TRpQHA6RpF/3+c2km77qef9KRCezf8CJtNJpEUdjuKumqOFOeQkXu4xEkzHJAW E75bisoEpmDPHRFCqeOopMYcZaTeKWGJ94rq2pSoQFEkzpJFaI8SVMds3WzfjXiEoQBp mfCzWiwL377CSv6cltJ/NZtMRXL5y+I9DFuO1qdazAcRrFjvOARAmc1M1l+fauSq0tTX thAh/4Ciygz9zjBJg4RdCgT6OS0hrHSEu/1l2yTbBxmTZWPO4wRUVwNwEd1Ttxi7tVZR W1kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769723902; x=1770328702; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=0za+mTabqTtCcABlRwV4DBkxWsk326LNSJGiU0z1JGs=; b=RBB7/lJEL3A+g8m5mhr7ekA3UmslQUR3EEsi13/sRGo3tEjngZauJUVg8pI9npTLIp Ch5SQYwCFhWlxGueFJ+k6Q3nW7Dglfw457dZ0/I0F1j+GfSILlFKG8Jur+2d6I9Zlf10 e7AFPzBR1OwqZkwR+S76ES3+l7FeLAgVtIWVjY1zjjBwXKNZ8RL30WKLe10he3pJv+jS X8ZVDwgAzOKPk00VnXWf6mBP6fYBHYx4B63L57IhcCIBSTcHZaI4CImmqVcAJJ13rMgX EqJHMW5xC6tftrKkTOOmZ3Scko6zcgdHbNMSZLcZQbzx9Bp229tuQqh7vqaPJF1lz5As vNQQ== X-Forwarded-Encrypted: i=1; AJvYcCVUmXJjMQ1qnnJQA/qbwsWv5R4JG3KrKvAYu76DKOrArRCKwdkMdGGPNVsOg3DHT2D0CVaXDfdiJpIA3fY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/juuGsDqiyjD7W6zPmyNY3TFhRfNf7nNppkjt1mE1gCE1bjer 8XqoyGViRKolXrT7fgGcqBdwBZz+aZrW0QGVf/B/GtMhUpcypqTMFxo= X-Gm-Gg: AZuq6aLhQvCjVbAi+nCJFZBizPeZ+4HOy97PyFPln4UFQCZpRnmvjmBZNqSaH6WnsSB MN4irs5SFbGRZ5iMf9UTLoMki8qVdR3eml9lwK8GU+RYl3u6jjF4km3FaC2nroE7juzHcGfUV8u xRmEMb0fMX4X0u2mLaTneXa0+VExuUxsXyBuc/2kh84Xo7MyVxBDWfO7sjqvnJGR5xinSTfkwvf RBPNGV8ZV5u5tgOCFL+D0stSQs46r33WITvBSwIqm7L7yCD2gjJyXCu/MdFzb2AEtaDi0UVcfZT f2/zBgiO/a9tqM1Xyio1aN2WogBoT4X50qDyupgBasDNf+RT0hUKbeHDbWT5so2SAQgjbbHb241 jM2iuupwpH/gHpl2Z2liabnFiIzxaznJDP/pYwpexhvoJfNDsoSAxvbKUDUqvcABsCUYvFgy46T dc6oTdc1yGIw== X-Received: by 2002:a05:7300:bc05:b0:2ae:4f61:892e with SMTP id 5a478bee46e88-2b7c8903199mr438341eec.36.1769723902104; Thu, 29 Jan 2026 13:58:22 -0800 (PST) Received: from localhost ([137.201.204.52]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b7a16ec51csm8713746eec.10.2026.01.29.13.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jan 2026 13:58:21 -0800 (PST) From: Ravi Jonnalagadda To: sj@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: akpm@linux-foundation.org, corbet@lwn.net, bijan311@gmail.com, ajayjoshi@micron.com, honggyu.kim@sk.com, yunjeong.mun@sk.com, Ravi Jonnalagadda Subject: [PATCH 2/3] mm/damon/core: implement NODE_TARGET_MEM_BP metric calculation Date: Thu, 29 Jan 2026 13:58:13 -0800 Message-ID: <20260129215814.1618-3-ravis.opensrc@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260129215814.1618-1-ravis.opensrc@gmail.com> References: <20260129215814.1618-1-ravis.opensrc@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add damos_get_node_target_mem_bp() function that calculates the ratio of scheme-eligible memory on a specific NUMA node to the total node capacity, expressed in basis points (bp, 1/10000). The function iterates through all regions that match the scheme's access pattern criteria (checked via __damos_valid_target) and counts how many pages from those regions reside on the specified node. This enables quota auto-tuning based on the actual distribution of hot/cold pages across NUMA nodes. To support this new metric which requires access to both the DAMON context and scheme: - Update damos_set_quota_goal_current_value() signature - Update damos_quota_score() to pass ctx and scheme through - Update damos_set_effective_quota() and its callers This metric is particularly useful for heterogeneous memory systems (e.g., DRAM + CXL) where controlling the distribution of hot pages across nodes can optimize memory bandwidth utilization. Suggested-by: SeongJae Park Signed-off-by: Ravi Jonnalagadda --- mm/damon/core.c | 66 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 84f80a20f233..1482c97828e8 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -2119,8 +2120,52 @@ static unsigned long damos_get_node_memcg_used_bp( } #endif =20 +static unsigned long damos_get_node_target_mem_bp( + struct damon_ctx *ctx, struct damos *scheme, + struct damos_quota_goal *goal) +{ + int nid =3D goal->nid; + unsigned long node_capacity, scheme_node_bytes =3D 0; + unsigned long addr_unit =3D ctx->addr_unit; + struct damon_target *t; + struct damon_region *r; + unsigned long start_pfn, end_pfn, pfn; + + /* Only supported for physical address space monitoring */ + if (ctx->ops.id !=3D DAMON_OPS_PADDR) + return 0; + + if (nid < 0 || nid >=3D MAX_NUMNODES || !node_online(nid)) + return 0; + + node_capacity =3D NODE_DATA(nid)->node_spanned_pages << PAGE_SHIFT; + if (!node_capacity) + return 0; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) { + if (!__damos_valid_target(r, scheme)) + continue; + + start_pfn =3D (phys_addr_t)r->ar.start * + addr_unit >> PAGE_SHIFT; + end_pfn =3D (phys_addr_t)r->ar.end * + addr_unit >> PAGE_SHIFT; + + for (pfn =3D start_pfn; pfn < end_pfn; pfn++) { + if (pfn_valid(pfn) && + page_to_nid(pfn_to_page(pfn)) =3D=3D nid) + scheme_node_bytes +=3D PAGE_SIZE; + } + } + } + + return mult_frac(scheme_node_bytes, 10000, node_capacity); +} =20 -static void damos_set_quota_goal_current_value(struct damos_quota_goal *go= al) +static void damos_set_quota_goal_current_value( + struct damon_ctx *ctx, struct damos *scheme, + struct damos_quota_goal *goal) { u64 now_psi_total; =20 @@ -2141,19 +2186,25 @@ static void damos_set_quota_goal_current_value(stru= ct damos_quota_goal *goal) case DAMOS_QUOTA_NODE_MEMCG_FREE_BP: goal->current_value =3D damos_get_node_memcg_used_bp(goal); break; + case DAMOS_QUOTA_NODE_TARGET_MEM_BP: + goal->current_value =3D damos_get_node_target_mem_bp( + ctx, scheme, goal); + break; default: break; } } =20 /* Return the highest score since it makes schemes least aggressive */ -static unsigned long damos_quota_score(struct damos_quota *quota) +static unsigned long damos_quota_score( + struct damon_ctx *ctx, struct damos *scheme, + struct damos_quota *quota) { struct damos_quota_goal *goal; unsigned long highest_score =3D 0; =20 damos_for_each_quota_goal(goal, quota) { - damos_set_quota_goal_current_value(goal); + damos_set_quota_goal_current_value(ctx, scheme, goal); highest_score =3D max(highest_score, goal->current_value * 10000 / goal->target_value); @@ -2165,7 +2216,8 @@ static unsigned long damos_quota_score(struct damos_q= uota *quota) /* * Called only if quota->ms, or quota->sz are set, or quota->goals is not = empty */ -static void damos_set_effective_quota(struct damos_quota *quota) +static void damos_set_effective_quota(struct damon_ctx *ctx, + struct damos *scheme, struct damos_quota *quota) { unsigned long throughput; unsigned long esz =3D ULONG_MAX; @@ -2176,7 +2228,7 @@ static void damos_set_effective_quota(struct damos_qu= ota *quota) } =20 if (!list_empty("a->goals)) { - unsigned long score =3D damos_quota_score(quota); + unsigned long score =3D damos_quota_score(ctx, scheme, quota); =20 quota->esz_bp =3D damon_feed_loop_next_input( max(quota->esz_bp, 10000UL), @@ -2227,7 +2279,7 @@ static void damos_adjust_quota(struct damon_ctx *c, s= truct damos *s) /* First charge window */ if (!quota->total_charged_sz && !quota->charged_from) { quota->charged_from =3D jiffies; - damos_set_effective_quota(quota); + damos_set_effective_quota(c, s, quota); } =20 /* New charge window starts */ @@ -2240,7 +2292,7 @@ static void damos_adjust_quota(struct damon_ctx *c, s= truct damos *s) quota->charged_sz =3D 0; if (trace_damos_esz_enabled()) cached_esz =3D quota->esz; - damos_set_effective_quota(quota); + damos_set_effective_quota(c, s, quota); if (trace_damos_esz_enabled() && quota->esz !=3D cached_esz) damos_trace_esz(c, s, quota); } --=20 2.43.0