From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796310841; b=sY2R1Yoid3c9THcQkV+/MVAC78LHDtwhLh4AV8UPfOqVi8cVSrUOSonCr7e13JL18++F LpOjQYaBnKhcJ+cCjyNuKInwxJcPbe6tHsLmfIe36ZSibzWU5KwpTysV6WgAEq3HZ5vA/ Eg6JKnCWf74L9KUcKB1Nxb6lt2oI1SCOnGgePoRzG7nPgDody1Dube30V9poAQmbFT8HR Kp6kN7XtvbAKiIYV7QVc+O8VCseo25/7+EhAaFXZEnWYrh1ImlGzP7YVTq+NRYA62cojq VpSoeKE7hS1+ix0Dn9WvOkmpf4kplBlSOqONnC+1Iz8zkFABzHoXcW8rAs7l6/2uMvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310841; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=+rzBAV+nzFWvvtQcZ85/JGAuq/UiHFLxPLBgLSWW7M0=; b=VAKIPyuyDzBavvHMlwttQYNKtIiuCo4xe0zQshsgjMNTHGlK3QdgM33W7IcDaaYON8g/ 6Mh5OOQkJC30iKT1VCraHhg0Dxsi6n6mm4a5mFVrX3HlZNk5TFBNx5OYwlHW+so2dzbiv BYzeTMH9lGb0y9Ya5JrD1sR3+MSE8VSFPTr9LI0yKGAuvCbQzlMoMvo9t3+Rphsw3jO8R 4q83IVlOBFEwny5k0GRN7EDf3NBNqckSEp0pyopmeZCHKpuLpfYHBS5TxJ019DWNwfYij GQiwr7G0DA2knJJf1YgToGRydUntq5HbLE13IdfjG7vwX57Bpwd5O3gHSWZpoV3HJuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R3vQxHMf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6844606A32D for ; Thu, 3 Dec 2026 15:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R3vQxHMf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33E6E1F0089C; Thu, 3 Dec 2026 15:14:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796310841; bh=+rzBAV+nzFWvvtQcZ85/JGAuq/UiHFLxPLBgLSWW7M0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=R3vQxHMfvWYv0PLoNz/dlsI9WtXUDYBAbTDLWt1kiGodRpkYmp9WszgSDgGnpU9YB 51LFUX64HnC8zEo7lSgXiId4h/FZ5SUv8D7u9yxDUNkz8uPDCGMBj5Frc/+GMABF6d r8DIIrUJhSjWXaD8B6uhjiWU62y+o8sHzJ2FGgYli3CAY55FHRrPaMg4ZASfE6RGSN F+lRNd0BaNBsrSpU7js2GATA4GfGlnsByjY6KI+XhsVwbcCDp/F5AGsmHxkIcmvLT3 Uhpg+v+vShF6hXwbhS+ESYVicBgiQ1ZzVJTYZ+HisNyBNB5NQuoRys9R64n41kuGwq hvyd+BIPBhzpw== From: SJ Park To: Andrew Morton Cc: SJ Park , damon@lists.linux.dev, linux-mm@kvack.org Subject: [PATCH 2/2] mm/damon/ops-common: use probe hits weighted sum in damon_hot_score() Date: Thu, 3 Dec 2026 07:13:51 -0800 Message-ID: <20261203151352.731319-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261203151352.731319-1-sj@kernel.org> References: <20261203151352.731319-1-sj@kernel.org> X-Mailing-List: damon@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit DAMOS finds memory that is eligible to apply the action, using DAMOS core filters and target access pattern. If the total amount of the eligible memory is larger than DAMOS quota, DAMOS selects memory to apply the action based on their relative hotness and the action type. For migrate_hot action, hotter regions are selected. For migrate_cold action, colder regions are selected. The hotness is calculated using the age and the access frequency. The frequency is counted by the traditional access monitoring and saved in damon_region->nr_accesses. When DAMON is configured with data attribute probes and probe weights, it runs in attributes-only monitoring mode. In the mode, the traditional access monitoring is skipped and therefore the access frequency counter is not updated. If the mode is enabled at runtime, the counter would have a stale value for the remaining aggregation interval. Though the counter will eventually be reset after the aggregation interval. Assuming the counter values are zero for the above mentioned reason, the prioritization logic will show all regions as having zero access frequency. For actions that prefer hot regions such as migrate_hot, regions of shorter age will be prioritized. For actions that prefer cold regions such as migrate_cold and pageout, regions of longer age will be prioritized. No real access frequency or the attributes monitoring results are considered. It is only chaotic and useless. It could be even more chaotic if the counters have stale values. In the attribute-only mode, probe hits weighted sum plays the role that is similar to that of the traditional access frequency. The adaptive region adjustment logic uses it in the attributes only mode. Do the same for the DAMOS quota region prioritization purpose hotness calculation. Replace the access frequency with the probe hits weighted sum for the hotness calculation in the mode. Signed-off-by: SJ Park --- mm/damon/ops-common.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c index 38720794c9fc..adbdba6dc6da 100644 --- a/mm/damon/ops-common.c +++ b/mm/damon/ops-common.c @@ -165,6 +165,25 @@ void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm, #define DAMON_MAX_SUBSCORE (100) #define DAMON_MAX_AGE_IN_LOG (32) +static int damon_freq_subscore(struct damon_ctx *c, + struct damon_region *r) +{ + unsigned int num, denom, samples_per_aggr; + struct damon_probe *p; + + samples_per_aggr = damon_nr_samples_per_aggr(&c->attrs); + if (damon_has_probe_weights(c)) { + num = damon_probe_hits_wsum(r, false, true, c); + denom = 0; + damon_for_each_probe(p, c) + denom += samples_per_aggr * p->weight; + } else { + num = damon_nr_accesses_mvsum(r, c); + denom = samples_per_aggr; + } + return mult_frac(num, DAMON_MAX_SUBSCORE, denom); +} + int damon_hot_score(struct damon_ctx *c, struct damon_region *r, struct damos *s) { @@ -175,9 +194,7 @@ int damon_hot_score(struct damon_ctx *c, struct damon_region *r, unsigned int age_weight = s->quota.weight_age; int hotness; - freq_subscore = mult_frac(damon_nr_accesses_mvsum(r, c), - DAMON_MAX_SUBSCORE, - damon_nr_samples_per_aggr(&c->attrs)); + freq_subscore = damon_freq_subscore(c, r); age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval, USEC_PER_SEC); -- 2.47.3