From nobody Sun Feb 8 11:43:25 2026 Received: from mail-yw1-f193.google.com (mail-yw1-f193.google.com [209.85.128.193]) (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 B31B9395DA9 for ; Fri, 23 Jan 2026 04:57:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769144272; cv=none; b=E1Hhh7MqWasVtEqaIfMLrSwWK+AOJ7bfnZPuyDTxeSdAU+GZ1LS29SBq43nVYL+BVNJQb2MThKE1jd5rCQwF+LyeIgx51TDTuXw/DT9zEp9sDE7PJfNYZ6DG+/UqBMVs/64xO4nUkACBvtj624KyW6Nqch4f1Jp5BiRhvyVutXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769144272; c=relaxed/simple; bh=LPrYTrwnUWZ7ytHBL5nCDH6LuVnTbfijgy57EHaTEFE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G5I5Q0cJQbGod/C7WesZ6BYVjX3Pf1Ky+7RKSAUyD15lp5yoSvAB+yQvm9OLS0IR99/UViyFbDv1gd1oLM1yAG6LT43Lp6rnyKXjah2xS1l8FPxUJH5f+k0iDVEgFm9U3prOiDOKiv9/W8wNqa9KXhwJNtnLhukVn3FGzrHgObA= 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=J687YmJ6; arc=none smtp.client-ip=209.85.128.193 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="J687YmJ6" Received: by mail-yw1-f193.google.com with SMTP id 00721157ae682-79427f739b0so19106517b3.3 for ; Thu, 22 Jan 2026 20:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769144264; x=1769749064; 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=K0i7a7403YgQyMlpi7E1tGdpNbWRUN7COl/lkLxdLS4=; b=J687YmJ6+mAWFyfu1hh12msny+kJzcEuUoiKoWfs8fOmOhmFjKnlEd7iWfGsDW5GMq yzZTuNF1bmp7nQ3wFaFLwewEjwYLhla+3zqbpkUU6DDenZ6mJV7CD5y+/YDySHpzs5Qu ghOoq6WgTA0RllUzPJsjgqfANAj+aBvue3JfaCRsilIHbnEf2tP/HvhSrNJ4kqdHzKnM 6TQiSzuVCy33rOwXOUQGIuEmjWsW2upi5rPyXM2Vqod1OOFyxf+B2BGgioy3db8+xB/v Y+dZWkOnMgiCyrvzuuEQuczgMfyQHWao6To2XEK7bpLjMPONB2Gg76ULKEBf4tjYlnrp QFzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769144264; x=1769749064; 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=K0i7a7403YgQyMlpi7E1tGdpNbWRUN7COl/lkLxdLS4=; b=Ruc7Axa7rS0DviW7zYWetlT1dD0PiwS++nK0BnDJTk4jOn6/B22cZ9wyxGL49TJGxN SPJODMz+o58aH1NDrbDfQ/a/zmDGcMbvQjOEIbwAWko18SMbjgOJlnYFbYGYf9h7ZT+6 lBTkESTKF43q2Eu05zRQxd8m30fpJEDv6O2l41y8eHjBUIAweJBTedhjgEqLjf0y3s8j b1kCxym2AwGzdpsE/CJNMB0zzGwPGuHsTS2i4QCW1cxuws5xOyh91Mgdi/zvcVnTROeg zd5vbrr7fBNoHRTqqUiFeArghvMB6RdTDa1ttYWmaPbRdJYXAiASUk/cpUKr7rwr3bOZ rLbw== X-Forwarded-Encrypted: i=1; AJvYcCVMVNUEvfP2Fpvd8GopSQNzHDlMbmLEcqTxDVgE95w3oLEh1GZRX5OJQ9Ftk7Hdiw0zhCbzJxVrJixnlE4=@vger.kernel.org X-Gm-Message-State: AOJu0YzVzXVO7o1EXCbzS6JvmaD3SSjRFmqwCyzd1D7OUTTwnqtnNu3Y 8RKCuaO6sEFjJVT7La0V5+syAZ2Mhxee2BJTmDsbR1ZZ7yrGQHfHUaexjToAJO0= X-Gm-Gg: AZuq6aJ3WwfO4XXBxYURcAeloEEinDnDvgntRF+fPErJhcBlBjVoeRJkt3CKCiZeo3S VyLrRmAVSdxZnMaLnnuHHVHLoGpNrShtbkWWczcDhzSDq7CTfCzjBlEuIENRRDJ89tGhibNp130 2aZxYUXrWDFCPHBVwPabwKt8lerAINkKSNgeP7/8WapnLl9USAwU/J4QmXBpN3zKvYX+2tezRkt DFexm0DNhYLz+39GJO8CJ6DLJanPC0sSZ5wA63DwvJKjD4yZltOHoQEWbpAJSR6cnT8xI+yYRwQ 8vFbSLzSh3mudXF2yR7374b0yhb2gslcXJ9rPj72PR7W/RZbGelkosWdN78N7A1/986Qk/9IJbK KP9EHNl6fnJmkg6Rd0AyDGMOjoUnbGW5a4P+QGAnO4Tua8h2hjcAe8lQBCBR2HQLOqPYSzbfS9i aZcaBonhHZIWCrlCJLgj6zWh2YzAjpDbpM1mxlw+cICeXSSCraVpD0c0iBs7LRlQ== X-Received: by 2002:a05:690c:ed6:b0:787:b5ac:68e4 with SMTP id 00721157ae682-79440b4d2cbmr136867b3.48.1769144264173; Thu, 22 Jan 2026 20:57:44 -0800 (PST) Received: from localhost (23-116-43-216.lightspeed.sntcca.sbcglobal.net. [23.116.43.216]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7943af14163sm6332217b3.7.2026.01.22.20.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jan 2026 20:57:43 -0800 (PST) From: Ravi Jonnalagadda To: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: sj@kernel.org, akpm@linux-foundation.org, corbet@lwn.net, bijan311@gmail.com, ajayjoshi@micron.com, Ravi Jonnalagadda Subject: [RFC PATCH 2/5] mm/damon: add get_goal_metric() op and PA provider Date: Thu, 22 Jan 2026 20:57:25 -0800 Message-ID: <20260123045733.6954-3-ravis.opensrc@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260123045733.6954-1-ravis.opensrc@gmail.com> References: <20260123045733.6954-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" Introduce an optional damon_operations callback `get_goal_metric()` that lets ops providers compute goal metrics requiring address-space knowledge. Provide a PA implementation that handles DAMOS_QUOTA_NODE_SYS_BP by iterating the monitored PFN regions and attributing bytes to the goal's nid. Core remains generic and asks ops only when needed. Signed-off-by: Ravi Jonnalagadda --- include/linux/damon.h | 3 +++ mm/damon/paddr.c | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/linux/damon.h b/include/linux/damon.h index ec5ed1a217fc..67233898c27c 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -649,6 +649,9 @@ struct damon_operations { bool (*target_valid)(struct damon_target *t); void (*cleanup_target)(struct damon_target *t); void (*cleanup)(struct damon_ctx *context); + unsigned long (*get_goal_metric)(struct damon_ctx *ctx, + struct damos *scheme, + const struct damos_quota_goal *goal); }; =20 /* diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 07a8aead439e..30e4e5663dcb 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include =20 #include "../internal.h" #include "ops-common.h" @@ -148,6 +150,48 @@ static bool damon_pa_invalid_damos_folio(struct folio = *folio, struct damos *s) return false; } =20 +/* System total RAM in bytes (denominator for bp computation) */ +static unsigned long damon_pa_totalram_bytes(void) +{ + return (unsigned long)totalram_pages() << PAGE_SHIFT; +} + +/* + * Compute node-scoped system bp for PA contexts: + * bp =3D (bytes attributed to goal->nid across monitored PA regions) / + * (system total bytes) * 10000 + */ +static unsigned long damon_pa_get_node_sys_bp(struct damon_ctx *ctx, + struct damos *scheme, + const struct damos_quota_goal *goal) +{ + int nid =3D goal ? goal->nid : -1; + unsigned long node_bytes =3D 0; + unsigned long total_bytes =3D damon_pa_totalram_bytes(); + struct damon_target *t; + struct damon_region *r; + + if (nid < 0 || !total_bytes) + return 0; + + damon_for_each_target(t, ctx) { + damon_for_each_region(r, t) { + unsigned long start_pfn =3D r->ar.start >> PAGE_SHIFT; + unsigned long end_pfn =3D r->ar.end >> PAGE_SHIFT; + unsigned long pfn; + + for (pfn =3D start_pfn; pfn < end_pfn; pfn++) { + if (!pfn_valid(pfn)) + continue; + if (page_to_nid(pfn_to_page(pfn)) =3D=3D nid) + node_bytes +=3D PAGE_SIZE; + } + } + } + + return div64_u64((u64)node_bytes * 10000ULL, total_bytes); +} + static unsigned long damon_pa_pageout(struct damon_region *r, unsigned long addr_unit, struct damos *s, unsigned long *sz_filter_passed) @@ -344,6 +388,19 @@ static unsigned long damon_pa_apply_scheme(struct damo= n_ctx *ctx, return 0; } =20 +/* Generic goal-metric provider for PA */ +static unsigned long damon_pa_get_goal_metric(struct damon_ctx *ctx, + struct damos *scheme, + const struct damos_quota_goal *goal) +{ + switch (goal ? goal->metric : -1) { + case DAMOS_QUOTA_NODE_SYS_BP: + return damon_pa_get_node_sys_bp(ctx, scheme, goal); + default: + return 0; + } +} + static int damon_pa_scheme_score(struct damon_ctx *context, struct damon_target *t, struct damon_region *r, struct damos *scheme) @@ -378,6 +435,7 @@ static int __init damon_pa_initcall(void) .cleanup =3D NULL, .apply_scheme =3D damon_pa_apply_scheme, .get_scheme_score =3D damon_pa_scheme_score, + .get_goal_metric =3D damon_pa_get_goal_metric, }; =20 return damon_register_ops(&ops); --=20 2.43.0