From nobody Sat Sep 26 12:26:28 2026 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 A331B32A3E5; Tue, 1 Sep 2026 13:13:35 +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=1788268416; cv=none; b=Kf+aq63iFov8pJPm6frFt6bYeqL9ZrX4+056OzFPDKR4xgkhQ51H7GP716hMznAnQXoT9pj7HUiCkehT+yi6MfWocjLS7BA0aKoESEUqn9xiKUL8iwSa5KW5p1Ek1BRXFQwq3DTPG8oFwiM9u+3R/hg2kWvvdCL5pbcmz+s1IL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268416; c=relaxed/simple; bh=35/yin/QF8t3Kqfg+UAOrsmVX85pqU2Iyl2wuXO5t+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nnYVlEccAO1Aj/EnEovq79oBT3jX8yHMA2rvBf26LEWQjJprn7zBwVF6/McbyAGvkaM2BVg92XmTdW6v6lY7nU9wYsiiC7No0tCCI638+5cUNuSulFJSCnJMDsVfFptQ6vSuuiOKEgLQ76xGl3dGJFmhLCVHI5dc6aAYmI5ma5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VmCJP86o; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VmCJP86o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 266FF1F00A3E; Tue, 1 Sep 2026 13:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268415; bh=7ZB1yfEGzN5K33ID0e3bcOFkHhvifJ8hhhrNtAvrugg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VmCJP86oeHn76JzQLhDmTScTgW+IQItKLl9s/BVtCWN6+31Zv3FKqrjnmL/GHP6Y0 7NyPgN784/d/zfr6IaXQ1Q7G6hghehkfC5yVy/ucrAlz22jveR89bO60RfJ81n7roT 5QYT8W1WRaCLjfJAeCdOt0aEdfS1E1ctnkyf1uNNbeP6ibbaHWJKcARxSDDMqq2zlU wKCmnJuNfkB/JOmC7LlU9MTTu13WvDmPXIyh/6mciXcvapOcaeAv9U/2jVHTwBFVtL 0oPMdpW3BGL9Fs1d+ZzPsipWp/kjLfHZrHrHA26yrV3TuY7WenMcHdKe0LS6x17Lnf lA0opfQpWCzfA== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, Usama Arif , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/7] mm/damon/paddr: respect folio end for DAMOS_STAT Date: Tue, 1 Sep 2026 06:13:18 -0700 Message-ID: <20260901131326.97615-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" The function for applying DAMOS_STAT in DAMON physical address space operation set (paddr), namely damon_pa_stat(), applies DAMOS filters to folios of the given region. For that, it gets folios of addresses in the region. It starts from the region start address and advances the address by the size of the folio of the address until it goes out of the region. If the start address is in the middle of a large folio, and if the next folios are small, some of the next folios could be skipped. Fix the issue by advancing the address to exactly the start address of the next folio. The user impact is that the DAMOS_STAT-based page level monitoring results become inaccurate. Since the page level monitoring is supposed to provide relatively high precision, this is definitely a problem. It is arguably not critical since it is only monitoring quality degradation. Fixes: bdbe1d7bc325 ("mm/damon/paddr: increment pa_stat damon address range= by folio size") Cc: # 6.14.x Signed-off-by: SJ Park --- mm/damon/paddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 5c6c3a597fd0b..2ab7b3842701e 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -379,7 +379,7 @@ static unsigned long damon_pa_stat(struct damon_region = *r, =20 if (!damos_pa_filter_out(s, folio)) *sz_filter_passed +=3D folio_size(folio) / addr_unit; - addr +=3D folio_size(folio); + addr =3D PFN_PHYS(folio_pfn(folio)) + folio_size(folio); folio_put(folio); } s->last_applied =3D folio; --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 2615F3E7621; Tue, 1 Sep 2026 13:13:36 +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=1788268417; cv=none; b=GDU6HvB0/qrFjM93UMIwcmnK5X2VDuqvdAjHivBjSg/oT05FKe+bBvFQ+xWHTLP+ZdxUpZONUOKIx9w/RGCACLQqbw4LkfHK7189cOLopNGq/80r38T0SnuIiucp/zlJi3YMnA7dsBAib+MnRkqWwkcKwqJtdvb4QXpbp9jokLE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268417; c=relaxed/simple; bh=3tuXFYxnY5whCfMb9BBfKAgRQ7zxuSBaL+SQQ8TayGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DWuVDCUN24nh61HXPfEgf+MiTNfRf5tE8bSngNfBszPNdxutdiEYBAOWBUXAGfSjuF1DOY6cS2UDHp0GaenMDFvcLbFECVSVTHb3P3Hfvnf9Zjebx8SZmWy8Nizr5OhovmZcTg0tJ3SgC6H9JUKF8AezM3QrD1YKlwwvkru9aMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MpeJKmrK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MpeJKmrK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F9E71F00A3F; Tue, 1 Sep 2026 13:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268415; bh=l4DJBfV8Ln2wiu4MTHaklCvhtPpo+9nKnYvuVasq3nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MpeJKmrK9iHVcoS550Knf/Mlx3E0FIKosfejJKu6aHXOgY8rXc69/9aUaYT6efHrh 318yLkiCl+yee/KmUKnyfNEhOXMrlAqQqVtymWWhNQsV3d+Cjqry887CtY6hOzaIt7 QaAyDFo1SdZRMTt81syDLPKzwjjQXP1PN0tqFIDd21PZ9Y3IEjycwwxJPYwtPA3r+f XD7VzjFO2gS24GALcmEwiUy3AkyUxwl2II0b7NhFjwGRh89maVLHrSnvxKd1KV+C0x +I8DT3ansh/JMHAJ0niHX4xbLfGfrsQjh5wWlAQen97xpHuCuButa+KiEztUyVpqNN R4UfKFv61ey1A== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, Usama Arif , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/7] mm/damon/paddr: respect folio end for DAMOS actions except STAT Date: Tue, 1 Sep 2026 06:13:19 -0700 Message-ID: <20260901131326.97615-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" A few functions for applying DAMOS actions including pageout, lru_[de]prio and migrate_{hot,cold} in DAMON physical address space operation set (paddr) collect folios of the given region by getting the folios of region-internal addresses. Then, those functions apply the action to the collected folios at once. The collection starts from the region start address and advances the address by the size of the folio of the address until it goes out of the region. If the start address is in the middle of a large folio, and if the next folios are small, some of the next folios could be skipped. Fix the issue by advancing the address to exactly the start address of the next folio. The user impact is that DAMOS action is applied to less than expected amount of memory. Given the best effort nature of DAMON, it is no big problem, but it is clearly a bug that is better to be fixed. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260517234112.89245-1-sj@kernel.org Fixes: 3a06696305e7 ("mm/damon/ops: have damon_get_folio return folio even = for tail pages") Cc: # 6.15.x Signed-off-by: SJ Park --- mm/damon/paddr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index 2ab7b3842701e..9ddd1ec8202b7 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -264,7 +264,7 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, else list_add(&folio->lru, &folio_list); put_folio: - addr +=3D folio_size(folio); + addr =3D PFN_PHYS(folio_pfn(folio)) + folio_size(folio); folio_put(folio); } if (install_young_filter) @@ -302,7 +302,7 @@ static inline unsigned long damon_pa_de_activate( folio_deactivate(folio); applied +=3D folio_nr_pages(folio); put_folio: - addr +=3D folio_size(folio); + addr =3D PFN_PHYS(folio_pfn(folio)) + folio_size(folio); folio_put(folio); } s->last_applied =3D folio; @@ -350,7 +350,7 @@ static unsigned long damon_pa_migrate(struct damon_regi= on *r, folio_is_file_lru(folio)); list_add(&folio->lru, &folio_list); put_folio: - addr +=3D folio_size(folio); + addr =3D PFN_PHYS(folio_pfn(folio)) + folio_size(folio); folio_put(folio); } applied =3D damon_migrate_pages(&folio_list, s->target_nid); --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 A309C440647; Tue, 1 Sep 2026 13:13:36 +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=1788268418; cv=none; b=Z7Vn44OM25PQjlsjvP5zJZkLcWIFuHHQjs/eOhhecG/SWRGFv/LTGsomlVMiaC0pQde4M5s7TTKPjbAudn6+mejFqyGcyTf71pZ1mgtACzmr4y7ZUpLrBypCnAdcI7crOVtwFZiSYBQMYf2zQUf2NaQi+N0E7RD2fQiiWCtzvBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268418; c=relaxed/simple; bh=5AGJ58CxaHUHnA7OwFTsM+2rMQoeaY6UpbD7qoJcoXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVAXtAk35TTK0E/wVk8MxJaXquLISTFMF7zd3fGWuNxFXgOV/OhGqVytb4CknJogEytcEHDyn5LZkEPWba9wwie/0VclN56fGvfwV9RPxnSje8xDRiwRYfDwKCt8aAao5p/1ELpwwKH8JfsWGVtE8Brlr0k0IXA4DlbUwQ6PbNc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O4pt0221; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O4pt0221" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA72F1F00ACA; Tue, 1 Sep 2026 13:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268416; bh=nSTjwnDV8A+NiGPVQu+FC6bukzN4Edj/bjp5VqLzRxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=O4pt02213qlx6vaOUorj4+qScp9QUGMdKg0r2z7Ig1+cTKFLdGATxgOPJmG+0ausZ 9k7uxgUAbpuj1hA2+pe7xKB9/ya+XvAms303tM+x4cVqEKT8XVnbEGYCgBYdl2+8zR NT4u3lOIHDm+eDIXGl9A22qGzY1KWJL8UXKa4WK2fIuKlN+Yeo7mIbBMhLdrw+Zc0O e6Lr/ANyMNKg3RHSWVhgEJm1RZQOapI3KuQ2uAKfzH5n+ZTA1DzzdPDLsFHuYvUEp1 lJj2cwxm2pQr9wtVpR0Pgx63/x8BcbQBW0qufPtI437MoV+XatD9W9DN9mBIlcQpgM vrGgioAlPAYVA== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, Yueyang Pan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/7] mm/damon/vaddr: respect folio end for DAMOS_STAT Date: Tue, 1 Sep 2026 06:13:20 -0700 Message-ID: <20260901131326.97615-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" For applying DAMOS_STAT action to a region, DAMON virtual address space operation set (vaddr) calls walk_page_range[_vma]() for the region. The pmd walk entry function, namely damon_va_stat_pmd_entry(), applies DAMOS filters to folios of addresses of the region in the pmd. It starts from the walking address and advances the address by the size of the folio of the address until it goes out of the pmd or the region. Let's suppose it is for the first pmd of the region, and the region start address is in the middle of a large folio. Also, the next folios are small. Then, some of the next folios could be skipped. Fix the issue by advancing the address to exactly the start address of the next folio. The user impact is that the DAMOS_STAT-based page level monitoring results become inaccurate. Since the page level monitoring is supposed to provide relatively high precision, this is definitely a problem. It is arguably not critical since it is only monitoring quality degradation. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260514015053.149396-1-sj@kernel.org Fixes: 63f39737d1e3 ("mm/damon/vaddr: support stat-purpose DAMOS filters") Cc: # 6.18.x Signed-off-by: SJ Park --- mm/damon/vaddr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 0648400b2d65b..4b0b5edf67952 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -831,6 +831,8 @@ static int damos_va_stat_pmd_entry(pmd_t *pmd, unsigned= long addr, return 0; =20 for (; addr < next; pte +=3D nr, addr +=3D nr * PAGE_SIZE) { + unsigned long page_idx; + nr =3D 1; ptent =3D ptep_get(pte); =20 @@ -844,7 +846,8 @@ static int damos_va_stat_pmd_entry(pmd_t *pmd, unsigned= long addr, =20 if (!damos_va_filter_out(s, folio, vma, addr, pte, NULL)) *sz_filter_passed +=3D folio_size(folio); - nr =3D folio_nr_pages(folio); + page_idx =3D folio_page_idx(folio, pte_page(ptent)); + nr =3D folio_nr_pages(folio) - page_idx; s->last_applied =3D folio; } pte_unmap_unlock(start_pte, ptl); --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 D5830471CFA; Tue, 1 Sep 2026 13:13:36 +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=1788268418; cv=none; b=TkhJ7mlu3wCyAqsQgzA3B4BbJH7iwozfNn/qthvvxfpSNf/8fjwYPOUCAir3rkIpgj+Ndx7D46Atwh8BcF+4MakQ0lFO2owu14Qae1+CFaKLaO13aRgf1QSxLFdXstLLEef4z0fNBHkT/jE08gEHGGqlh/vY2NNNQBgnXqvMUHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268418; c=relaxed/simple; bh=6Z73CbNxQYTOYNM3TzN9z5SgCwrzw1We6fTUP5ae8l4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cku5qms2pNPL/RA2Ylefzt6yr8yj69vA+Rxi0YmCazOD3CBfusZxnnDerlFmqrzqS2MVnj53eCAsvumh9a/MTbQd5U95Dsi6Srlc02tLgGG5WmD1dr2j2kEYs90uEx44FoNodbtA9cfwuTJLgF3dtADgOGanr8BFXllL+2ql890= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ISTQmw/t; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ISTQmw/t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4214C1F00ACF; Tue, 1 Sep 2026 13:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268416; bh=SLM/iGuOERBTFxu8mql/4ATf4p59p9Me6R2GTZoj17M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ISTQmw/tUeMfyZ3j7y/xmVcZvSz9sEmicVRl4nMGFsu7JgnYWmcRD3cjGplj+RFqY SzwbDlUHp6D1uLMc83RycO9ukSm8WfNVpxN5ZR4g/Qj0jolcRgchArdIZgHo4Ya+CE SGbm3kkrMr47kVdPwXvEB6ZOam9MjOYIFwzvnRuXmiiTMIkCTc7yVaTOkt9Z4E3/9w VAqiW4+X1sgdJZpSX4JQlmQJpbZtKrRqJtnD1QwWnBIvlOjUdPWcg/R9AYdyB3xFZ8 Rz0q3MXNzD7+Eh/UKSoInw/8jEwCQAHMxf5cpOD+ppNaeoVW0YqbENlWi2gqdAXmja E5TLxQo48RZtA== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/7] mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD} Date: Tue, 1 Sep 2026 06:13:21 -0700 Message-ID: <20260901131326.97615-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" For applying DAMOS_MIGRATE_{HOT,COLD} actions to a region, DAMON virtual address space operation set (vaddr) calls walk_page_range[_vma]() for the region. The pmd walk entry function, namely damon_va_migrate_pmd_entry(), collects folios of addresses of the region in the pmd. It starts from the walking address and advances the address by the size of the folio of the address until it goes out of the pmd or the region. Let's suppose it is for the first pmd of the region, and the region start address is in the middle of a large folio. Also, the next folios are small. Then, some of the next folios could be skipped. Fix the issue by advancing the address to exactly the start address of the next folio. The user impact is that DAMOS action is applied to less than expected amount of memory. Given the best effort nature of DAMON, it is no big problem, but it is clearly a bug that is better to be fixed. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260514015053.149396-1-sj@kernel.org Fixes: 09efc56a3b1c ("mm/damon/vaddr: consistently use only pmd_entry for d= amos_migrate") Cc: # 6.19.x Signed-off-by: SJ Park --- mm/damon/vaddr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c index 4b0b5edf67952..c8c32b2ae0402 100644 --- a/mm/damon/vaddr.c +++ b/mm/damon/vaddr.c @@ -669,6 +669,8 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsig= ned long addr, return 0; =20 for (; addr < next; pte +=3D nr, addr +=3D nr * PAGE_SIZE) { + unsigned long page_idx; + nr =3D 1; ptent =3D ptep_get(pte); =20 @@ -681,7 +683,8 @@ static int damos_va_migrate_pmd_entry(pmd_t *pmd, unsig= ned long addr, continue; damos_va_migrate_dests_add(folio, walk->vma, addr, dests, migration_lists); - nr =3D folio_nr_pages(folio); + page_idx =3D folio_page_idx(folio, pte_page(ptent)); + nr =3D folio_nr_pages(folio) - page_idx; } pte_unmap_unlock(start_pte, ptl); return 0; --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 3AB784756C0; Tue, 1 Sep 2026 13:13:37 +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=1788268419; cv=none; b=oqzwHLNrRcKsBXLn8e7h9M3MsGw6nLgPaA8DID/5lr4UlHr8Ku9UWJpb3TYXGsfRxPYKt7zNdHViQBNJJn+SMGxHpeI3mkd7jMEg0GJeFt6SWpNeO6b+rCcrvhnB/+83UZDjkrGBQxqDCjbPMAjeFkUhIAEUAWqkdaYq4UYfRag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268419; c=relaxed/simple; bh=tzAcE6SEgWB3A7dvKIyT7G341pe6G1l97zdd278rH/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hN3CTYuXiQtAxdK+75Fn0vEpSTg6bAsYPytHJFdCorzxBJr9L9Hg8bC80r/d6IKsc3cqrD/FczlETLonQp5KZ7ql7EMmVCVKQjZe0JKX5u0AbMxK0K7mRanCgcXW9uy8soygxblrXeYHZ2oJl37spzLI9RYZbrRfIIEp110KSvI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BuII0p++; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BuII0p++" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D331F000E9; Tue, 1 Sep 2026 13:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268416; bh=YLJtgrH/eA5cfD1d64StUX4ou+TBBQRag4ZJY9MXlY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BuII0p++NSivesuV41kQLUZ8NvVu65lJ1q0Po85tU2T2wrCHHnSCAip4Mc7mNtJ8U mSu+1g/nC+ZndK2iZqieVTsVDOIysZt3y48irQsnaeHM04LP35H5p3XbD17eecxuoJ e8JzG78Btt/C6QsIAMOjflxrNSpcuYr8bgnGwcGFyM4XSprpMtQZN8Nvyylhak30nC u/NtYZ2ALhqH9V89sXl72O1jaIehbk9AZHp8YPKR4Tq9vm0ZjhxpwOkmBLmYnV53q/ CgdNTDi6YbwVVNH2Ydqww6DAt3MVJX9BudXurVUvWcR2atT5G1mo0Lx/7/jMO9aMfK QfOGNe97ZAlfw== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/7] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp() Date: Tue, 1 Sep 2026 06:13:22 -0700 Message-ID: <20260901131326.97615-6-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" In an extreme and unlikely situation, si_meminfo_node() might let the caller show zero total ram. That could cause a divide by zero in damon_get_node_mem_bp(). It could also show free memory larger than the total memory. This could cause underflow and make DAMOS temporarily make unexpected behavior. Thanks to safety guards in the auto-tuning feedback loop, that should not be a real problem, though. Fix the problems by respectively returning 100% and 0% for used and free memory queries in the corner cases. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260328133216.9697-1-sj@kernel.org Fixes: 0e1c773b501f ("mm/damon/core: introduce damos quota goal metrics for= memory node utilization") Cc: # 6.16.x Signed-off-by: SJ Park --- mm/damon/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index a6fdb3068262d..ad3657d356fbc 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2807,6 +2807,13 @@ static __kernel_ulong_t damos_get_node_mem_bp( } =20 si_meminfo_node(&i, goal->nid); + if (!i.totalram || i.totalram < i.freeram) { + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEM_USED_BP) + return 10000; + else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */ + return 0; + } + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEM_USED_BP) numerator =3D i.totalram - i.freeram; else /* DAMOS_QUOTA_NODE_MEM_FREE_BP */ --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 5691B4756C5; Tue, 1 Sep 2026 13:13:37 +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=1788268418; cv=none; b=HxgdzaVDe8n5GhgsucNCX9Ip+UrnKCTp0xkI4QoJi4Ycif4tPtExoALxX8jFJb5GAgM9weRJPleFANhLosGSvztle5pGIZh2qM3kt/3cpnLZ8/mEiFY1ApkPjw8m73MWzdp7VsqbHVBm/PGL2ieuxj8+MDkt4wL3aLoOE8WIHb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268418; c=relaxed/simple; bh=lZqnF/fq0s75WPlK1Ldiv9o028oS83xr/Lv60UdZAxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FZ75xTi9vZ3lcStaNwiPc+7E4Sc+yYN/lmjxVgEOux5inZYdiZHkyJoI2oM8Y3rYiAzaL4t7auXZ7zlJ2tFcRPdewHMKTV+w/weE+NgomJHpVoialSVegZt/IMotSAuppFR6kRhyGQWWbRduXRoNy/Rr5so7ibMuarw/FnLVWu0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e7aBuYx/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e7aBuYx/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8A4F1F00A3D; Tue, 1 Sep 2026 13:13:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268417; bh=/E3Oie88We+VUNBoQinHbEvxciAXpLnuOmC5tKc4/XE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e7aBuYx/zoaNFKLfyEi3UwnDYq4cH2lGtZXVK8S2AnTXEpjIkTxPvQPvbnSKGBfCE n+3ROEh/GlRyDbtHcq8cp9T2dv9o+stRSkAbb9/rXv1D02xuuuaRI3FjNcDA63olqM +f9pWQPDebd/5u3QrrvNqgVNHMvS/aGO+8a6Bnt6f5wBvuFy3QoKbraB8D/HcNnQMd uE3raa2cOTxCpXZDsVTb90cy+Wqql3A8KH42Q1xeIFfoIGLwnubw/p37bcVoUiMKf0 hbcuRernukzJBG6qSveIbRz9sujbYxISeQMTsBRVr1JQPkhXSGrVH+DWGztzhJ/Ozn umezALzzlzjwA== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 6/7] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() Date: Tue, 1 Sep 2026 06:13:23 -0700 Message-ID: <20260901131326.97615-7-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" In extreme unlikely situations, total memory might be zero. In less extreme but still very unlikely situations, lruvec_page_state() calls might let the caller show used memory larger than total memory. In the two cases, damos_get_node_memcg_used_bp() could cause division by zero, or return underflowed value, respectively. Handle the cases by respectively returning 100% and 0% for used and free memory queries in the corner cases. This issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260329154813.47382-1-sj@kernel.org Fixes: b74a120bcf50 ("mm/damon/core: implement DAMOS_QUOTA_NODE_MEMCG_USED_= BP") Cc: # 6.19.x Signed-off-by: SJ Park --- mm/damon/core.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index ad3657d356fbc..3060edf5e4fa6 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2854,6 +2854,12 @@ static unsigned long damos_get_node_memcg_used_bp( mem_cgroup_put(memcg); =20 si_meminfo_node(&i, goal->nid); + if (!i.totalram || i.totalram < used_pages) { + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEMCG_USED_BP) + return 10000; + else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ + return 0; + } if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEMCG_USED_BP) numerator =3D used_pages; else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ --=20 2.47.3 From nobody Sat Sep 26 12:26:28 2026 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 BDA88476044; Tue, 1 Sep 2026 13:13:37 +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=1788268419; cv=none; b=eV/8aPGMf5fCXM0xL6JJG1zuoJEfql24usVFxsSDOTPS9MIRpPbNvYUaHenlUGRRU1CW8lFf2D81FGZqFFo1lHeX5lH1yhcX4Qv7s6ejerqnfdBG6Dheo0p0EqEb9OGhNv36WMK69nNA4H6z8PDeesflN5YbFPtratyEET5nAJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788268419; c=relaxed/simple; bh=GXr/1jJ0ZcG+tvVvUf9OAFx0ZgFUmAAa9q7CIMr6dbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QHrZIR6eR73az0FNZC3w84TfXt0r1799RhJiFZoOLJEXml0pBsWV1utXpPjsEYyqZ6Kygryr5D4hur6nr23HGrm8WRXKqD7h4jvqsfHZi6wglGq5qFrIob487zEVZKgBCo1EmuXpsFhNEuSssSUfrC6c8VYF4NPw2H41okm463o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jhxcEplR; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jhxcEplR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49CFE1F00A3E; Tue, 1 Sep 2026 13:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788268417; bh=VvO9nu/pvwrT8AJnGanMkEVbhfeAa8vp4BSGaiM1GXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jhxcEplR7ISywxsedbUTqGQu7PZiqFsRqLmJ3SUop1iqYrPGKpKqoT674IWzD2tpu vBKhSLCyTbHm0V6fYoTATWVQveKAq2w5X64m/0MQNtP+IiYN93BqNWV2ViAhcMtX1/ tqIZdRCnsYz43Xci1FCQr67kw4uCSYAx7jYvLx1WYB3dpyKaQ4+Un1lTsNMSWrmB6W dC8vgFFYVStw3iHBO6BUnogGZQuhtMB3gXe30XaprI60pLphYo6I3Ivlp4/LbIiE1+ ibEu3mqQ3WKSz2Cp3lcPTVpM5FnaQu8gT7ZIy2gGykqp8hwfyfGbLKjMaiUtZF0Czp G8fV0gNgBz3nA== From: SJ Park To: Andrew Morton Cc: SJ Park , stable@vger.kernel.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 7/7] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() Date: Tue, 1 Sep 2026 06:13:24 -0700 Message-ID: <20260901131326.97615-8-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260901131326.97615-1-sj@kernel.org> References: <20260901131326.97615-1-sj@kernel.org> 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" damos_get_in_active_mem_bp() uses the sum of the active and inactive memory amount as a denominator. In an extreme and unlikely environment, active and inactive memory might be zero. In this case, hence, it results in a divide by zero problem. Avoid it by changing the denominator to one if it is zero, before it is being used. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260721034756.147011-1-sj@kernel.org Fixes: 4835e2871321 ("mm/damon/core: introduce [in]active memory ratio damo= s quota goal metric") Cc: # 7.0.x Signed-off-by: SJ Park --- mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 3060edf5e4fa6..0df785e72438f 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -3006,7 +3006,7 @@ static unsigned int damos_get_in_active_mem_bp(bool a= ctive_ratio) global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); inactive =3D global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) + global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); - total =3D active + inactive; + total =3D max(active + inactive, 1); if (active_ratio) return mult_frac(active, 10000, total); return mult_frac(inactive, 10000, total); --=20 2.47.3