From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E25A2F617C; Sat, 12 Sep 2026 11:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789214339; cv=none; b=LGn/qhTU5KucfCscHpCaICLaASSLElAKtLhTr+N3xUpkUo8mEiKxVGnsVvDXKUzqkNYr35DCjI7ZCDM1ZXLew6tC82BJpXLXxLfYU+e89c7ZupkrxWaiiykDLrq42NL9og2ltGqRLO72Zu9T+4fim1ZXLF/bi0/c1MjLjfNFSP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789214339; c=relaxed/simple; bh=IFy7CnI12KaFOGk0PrZ9dwvGaDDnX7zRpu0q13Onq/Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ft5TVsLhJvLi3DOnBU1SsWh3yFIbyB2sWNIxfh3Ku5PqLK5mXU5z9AZBX3ZouzjXzL1bHLKH0Nv8DRxGDjaTKASzp9e2R8ZjPtug1ozuiQTlMCbsHWHi1swxZAm7ihTMmrXudejXFqKnwLoyuH0mHFey7zJBDqNa6j8bFAmOMX4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OKYLvnR+; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OKYLvnR+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9318E1F000FF; Sat, 12 Sep 2026 11:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789214338; bh=6tI2Xhn7o4CYsUUTb4/HwkkV3zwxwz+B8lLB8DgHmeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OKYLvnR+X040uxgnCcJ6mQnmTECwvQ9CVfDFgp0Pjwvz/UV2lMbcl+N6/x+atPvkB rASXbjPakIQ+0255HAvqYfRD+Wz/WJRQiv3lNmh8X5KCS9UWBRTo7YmgwI+z91H4+Y X+WqWwEZdCp/Pg1DLmHy/lECXCT9qmYIF0280AIA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, SJ Park , Andrew Morton , Sasha Levin Subject: [PATCH 6.12 0306/1376] mm/damon/core: skip aging from repeated aggressive merging Date: Sat, 12 Sep 2026 08:45:32 +0200 Message-ID: <20260912065614.370091166@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: SJ Park [ Upstream commit 0250dbe08c730d003ef9f484da56ae09a1ea0c4c ] The number of DAMON regions could temporarily exceed the user-defined maximum number of regions limit for corner cases. For example, users could lower the limit via runtime parameters update. For such a case, kdamond_merge_regions() repeats merging regions in the case doubling the merge threshold. The repeated merge operation could update the age of regions multiple times. This corrupts the monitoring results. Fix the issue by asking the merge operation to skip aging for the corner case. The user impact is degradation of the monitoring quality. The impact should be mild, since the degradation is only temporal, and it is not common to happen in realistic setups. The issue was discovered [1,2] by Sashiko. Link: https://lore.kernel.org/20260712165432.87609-1-sj@kernel.org Link: https://lore.kernel.org/20260621203548.10718-1-sj@kernel.org [1] Link: https://lore.kernel.org/20260709145425.96247-1-sj@kernel.org [2] Fixes: 310d6c15e910 ("mm/damon/core: merge regions aggressively when max_nr_regions is unmet") Signed-off-by: SJ Park Cc: # 6.10 Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/damon/core.c | 17 +++++++++++------ mm/damon/tests/core-kunit.h | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 71264018cf2d1..8901a80c8a21f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1786,15 +1786,17 @@ static void damon_merge_two_regions(struct damon_target *t, * sz_limit size upper limit of each region */ static void damon_merge_regions_of(struct damon_target *t, unsigned int thres, - unsigned long sz_limit) + unsigned long sz_limit, bool count_age) { struct damon_region *r, *prev = NULL, *next; damon_for_each_region_safe(r, next, t) { - if (abs(r->nr_accesses - r->last_nr_accesses) > thres) - r->age = 0; - else - r->age++; + if (count_age) { + if (abs(r->nr_accesses - r->last_nr_accesses) > thres) + r->age = 0; + else + r->age++; + } if (prev && prev->ar.end == r->ar.start && abs(prev->nr_accesses - r->nr_accesses) <= thres && @@ -1828,15 +1830,18 @@ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold, struct damon_target *t; unsigned int nr_regions; unsigned int max_thres; + bool count_age = true; max_thres = c->attrs.aggr_interval / (c->attrs.sample_interval ? c->attrs.sample_interval : 1); do { nr_regions = 0; damon_for_each_target(t, c) { - damon_merge_regions_of(t, threshold, sz_limit); + damon_merge_regions_of(t, threshold, sz_limit, + count_age); nr_regions += damon_nr_regions(t); } + count_age = false; threshold = max(1, threshold * 2); } while (nr_regions > c->attrs.max_nr_regions && threshold / 2 < max_thres); diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 1039d2f793b9b..ff9f73579f7b3 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -266,7 +266,7 @@ static void damon_test_merge_regions_of(struct kunit *test) damon_add_region(r, t); } - damon_merge_regions_of(t, 9, 9999); + damon_merge_regions_of(t, 9, 9999, true); /* 0-112, 114-130, 130-156, 156-170 */ KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 5u); if (damon_nr_regions(t) != 5) -- 2.53.0