From nobody Sun Feb 8 21:12:34 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (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 703A121348 for ; Mon, 20 Oct 2025 13:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760966231; cv=none; b=d6L+nWkJEQFHhl38gi4ZxMTnvZyMYedoCplHDYDG7ARsCPdwJywtGH3EAjfXs1ebfR02uCOYIF9Eys0HHucEfoxvyOioHu9d0naYfcq4LLkSo/wxQ202dPdc2ZeGsz+T3+UXYQ4mzA0XrCuH93Ko5+KEYzkMYrPoiitG/rFqflQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760966231; c=relaxed/simple; bh=um27Lp0znARwhHkb8Ctg3AnoZVmq3g3HCnQMHHg3qIo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FrMUFkIuf0dFiVjNDsFVZF5gs9OpyhM7ouJWqslvJa5PQGfCQ9tJZ3x5hkyLqQySkdpcu4/tYAp5Vs7wa1w9Mt5DsemtAKgTn4QyRZQJK8jKF0LWNKnn+9USRfYpOs78g5M099wK0JSIVrsRS9y0tzB4BJ0LKqfA6O5zcVbXBV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=0VsxutGC; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="0VsxutGC" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=tGywFmiSziGA+dzPphRNfH4Y/ZZUvdraDxQ2WUrBU/0=; b=0VsxutGCqGQW4jtqWjaZUUbbFGZPhdE86CgBoCtRq/pzPgRj5wzqb070klI1+qzeMNamfY5D0 s9J0SVX8Z8abFKU3zzzvke6TPPU3ylbZUpRsrJjbXoFbtorrlu/iyvM3pWBlRf31pfc6f1uIKg4 IzSe2duFzv0A+5Xn6dQoRRk= Received: from mail.maildlp.com (unknown [172.19.162.112]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4cqwtb1pl5zLlVc; Mon, 20 Oct 2025 21:16:39 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id B27751400CB; Mon, 20 Oct 2025 21:17:02 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 20 Oct 2025 21:17:02 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 1/2] mm/damon: add a min_sz_region parameter to damon_set_region_biggest_system_ram_default() Date: Mon, 20 Oct 2025 21:01:24 +0800 Message-ID: <20251020130125.2875164-2-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251020130125.2875164-1-yanquanmin1@huawei.com> References: <20251020130125.2875164-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" In DAMON_LRU_SORT, damon_set_regions() will apply DAMON_MIN_REGION as the core address alignment, and the monitoring target address ranges would be aligned on DAMON_MIN_REGION * addr_unit. When users 1) set addr_unit to a value larger than 1, and 2) set the monitoring target address range as not aligned on DAMON_MIN_REGION * addr_unit, it will cause DAMON_LRU_SORT to operate on unexpectedly large physical address ranges. For example, if the user sets the monitoring target address range to [4, 8) and addr_unit as 1024, the aimed monitoring target address range is [4 KiB, 8 KiB). Assuming DAMON_MIN_REGION is 4096, so resulting target address range will be [0, 4096) in the DAMON core layer address system, and [0, 4 MiB) in the physical address space, which is an unexpected range. To fix the issue, add a min_sz_region parameter to damon_set_region_biggest_system_ram_default() and use it when calling damon_set_regions(), replacing the direct use of DAMON_MIN_REGION. Fixes: 2e0fe9245d6b ("mm/damon/lru_sort: support addr_unit for DAMON_LRU_SO= RT") Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- include/linux/damon.h | 3 ++- mm/damon/core.c | 6 ++++-- mm/damon/lru_sort.c | 3 ++- mm/damon/reclaim.c | 3 ++- mm/damon/stat.c | 3 ++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/include/linux/damon.h b/include/linux/damon.h index cae8c613c5fc..1ce75a20febf 100644 --- a/include/linux/damon.h +++ b/include/linux/damon.h @@ -947,7 +947,8 @@ int damon_call(struct damon_ctx *ctx, struct damon_call= _control *control); int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control); =20 int damon_set_region_biggest_system_ram_default(struct damon_target *t, - unsigned long *start, unsigned long *end); + unsigned long *start, unsigned long *end, + unsigned long min_sz_region); =20 #endif /* CONFIG_DAMON */ =20 diff --git a/mm/damon/core.c b/mm/damon/core.c index 109b050c795a..dbe48e43682b 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2770,6 +2770,7 @@ static bool damon_find_biggest_system_ram(unsigned lo= ng *start, * @t: The monitoring target to set the region. * @start: The pointer to the start address of the region. * @end: The pointer to the end address of the region. + * @min_sz_region: Minimum region size. * * This function sets the region of @t as requested by @start and @end. I= f the * values of @start and @end are zero, however, this function finds the bi= ggest @@ -2780,7 +2781,8 @@ static bool damon_find_biggest_system_ram(unsigned lo= ng *start, * Return: 0 on success, negative error code otherwise. */ int damon_set_region_biggest_system_ram_default(struct damon_target *t, - unsigned long *start, unsigned long *end) + unsigned long *start, unsigned long *end, + unsigned long min_sz_region) { struct damon_addr_range addr_range; =20 @@ -2793,7 +2795,7 @@ int damon_set_region_biggest_system_ram_default(struc= t damon_target *t, =20 addr_range.start =3D *start; addr_range.end =3D *end; - return damon_set_regions(t, &addr_range, 1, DAMON_MIN_REGION); + return damon_set_regions(t, &addr_range, 1, min_sz_region); } =20 /* diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index 42b9a656f9de..49b4bc294f4e 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -242,7 +242,8 @@ static int damon_lru_sort_apply_parameters(void) =20 err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, - &monitor_region_end); + &monitor_region_end, + param_ctx->min_sz_region); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 7ba3d0f9a19a..e30811cafe90 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -250,7 +250,8 @@ static int damon_reclaim_apply_parameters(void) =20 err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, - &monitor_region_end); + &monitor_region_end, + DAMON_MIN_REGION); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); diff --git a/mm/damon/stat.c b/mm/damon/stat.c index d8010968bbed..6c4503d2aee3 100644 --- a/mm/damon/stat.c +++ b/mm/damon/stat.c @@ -187,7 +187,8 @@ static struct damon_ctx *damon_stat_build_ctx(void) if (!target) goto free_out; damon_add_target(ctx, target); - if (damon_set_region_biggest_system_ram_default(target, &start, &end)) + if (damon_set_region_biggest_system_ram_default(target, &start, &end, + ctx->min_sz_region)) goto free_out; return ctx; free_out: --=20 2.43.0 From nobody Sun Feb 8 21:12:34 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 E53A72FDC20 for ; Mon, 20 Oct 2025 13:17:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760966233; cv=none; b=gpaphRQUl9kukz3+RYYzpsflCkW3teZI16NprB31WDzgWpCUOGLf2Z3Ca9gXio7QuHx6ptGccLezuJ+f4DRLXZ5NllaTweBsf7kqviJbZp+npghPl3LKCTmDV4OwBoW0ink1CSCqP7P4yz+YSBxh+CmXL61rHhEyVXRqVBqowRA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760966233; c=relaxed/simple; bh=72/eKEewF1yLnofGStpeC9RG258u5h/4R3ySthE2qHI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZEU/HFW8dw3hGcSmVOQsEq+geVESPskjXcAM3iB76F74f/IFNw7f65bxST1V0ClXJk2YETxwRBHPfl0kl9oD5W9YcDiCu1+WbLwgK2ciznvEveBd5EovoFAvyh7GytCyYjWMssR2udlI73iqNFlnALaMacOSvKECNVz+cwjzLSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=g5VLyWi4; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="g5VLyWi4" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=+hzZWxSIYi+JVfYnlDNwIrYbUMB0DxpyA9gkTSqNtlA=; b=g5VLyWi4O3Y2K82/N8WkX2UDJiZzoqRrDR//Q0iFzgGbzZgbzTwvVJMK3qwqrUOoygL+6+O2v 9urAr0RbXO4rpJavMpmvC+3IDBpAlVjfNd27zafHeGB+sy2nRUvpyeIaqRnVuV1pktTmbljmF4J oKKv/7Eug7rrK8tUO/gXiNk= Received: from mail.maildlp.com (unknown [172.19.88.105]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4cqwtb2lHtz1prQ0; Mon, 20 Oct 2025 21:16:39 +0800 (CST) Received: from dggpemf200018.china.huawei.com (unknown [7.185.36.31]) by mail.maildlp.com (Postfix) with ESMTPS id 3DE621402DA; Mon, 20 Oct 2025 21:17:03 +0800 (CST) Received: from huawei.com (10.50.85.135) by dggpemf200018.china.huawei.com (7.185.36.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 20 Oct 2025 21:17:02 +0800 From: Quanmin Yan To: CC: , , , , , , Subject: [PATCH v2 2/2] mm/damon/reclaim: use min_sz_region for core address alignment when setting regions Date: Mon, 20 Oct 2025 21:01:25 +0800 Message-ID: <20251020130125.2875164-3-yanquanmin1@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251020130125.2875164-1-yanquanmin1@huawei.com> References: <20251020130125.2875164-1-yanquanmin1@huawei.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 X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf200018.china.huawei.com (7.185.36.31) Content-Type: text/plain; charset="utf-8" When setting regions in DAMON_RECLAIM, DAMON_MIN_REGION will be applied as the core address alignment, and the monitoring target address ranges would be aligned on DAMON_MIN_REGION * addr_unit. When users 1) set addr_unit to a value larger than 1, and 2) set the monitoring target address range as not aligned on DAMON_MIN_REGION * addr_unit, it will cause DAMON_RECLAIM to operate on unexpectedly large physical address ranges. For example, if the user sets the monitoring target address range to [4, 8) and addr_unit as 1024, the aimed monitoring target address range is [4 KiB, 8 KiB). Assuming DAMON_MIN_REGION is 4096, so resulting target address range will be [0, 4096) in the DAMON core layer address system, and [0, 4 MiB) in the physical address space, which is an unexpected range. To fix the issue, use min_sz_region for core address alignment when setting regions. Fixes: 7db551fcfb2a ("mm/damon/reclaim: support addr_unit for DAMON_RECLAIM= ") Signed-off-by: Quanmin Yan Reviewed-by: SeongJae Park --- mm/damon/reclaim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index e30811cafe90..36a582e09eae 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -251,7 +251,7 @@ static int damon_reclaim_apply_parameters(void) err =3D damon_set_region_biggest_system_ram_default(param_target, &monitor_region_start, &monitor_region_end, - DAMON_MIN_REGION); + param_ctx->min_sz_region); if (err) goto out; err =3D damon_commit_ctx(ctx, param_ctx); --=20 2.43.0