From nobody Sat Aug 1 21:31:00 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 B88D0242D72; Sat, 1 Aug 2026 17:36:04 +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=1785605765; cv=none; b=kAYmSIUVm2b9L/nBlEAIgFjfSm++NbVENfKUmCvt5k/TxrN2QILJLtjJlh15VzzpAjF204Czu+wmTt164VT/e8NqQCqtjXFKd8yTZ3lqQ/ghBZf/T6NBv1d5uiwJhH48fK25ATuXse8yPhTh1pr3sBAAD6jxfl+hLXEmPfN+NfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605765; c=relaxed/simple; bh=c8YnLYM9gCkCamNMX4Ifu9ihjCO2crXUFIBol3Mz1aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngI7vgUpFj7hT5ou1y5H94/C5GKextklz/TzufsUdTJUZfM+rxGBo5n+TVkZpBKN5xmp8IguRuztEMdiYK//aKdyXjYS1tO9eFkUZI97rISCs26gr4Es1gSfgTjFvKK9BoJrmXaVoPo4PmJY1ynFfKkKM1kplz44qD1o23jKafE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JqZJuyL+; 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="JqZJuyL+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D2D21F00ACA; Sat, 1 Aug 2026 17:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605764; bh=ccJR9KUzvn7k6BzhoDEjN3sQrL1C2MxY/yOiNOzvC90=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JqZJuyL+6d1IhKbNi3w6gCesrHj9Klcy91QoQIT3Yfypuou1ns/P3r9cPTwoBnKIV UUBjUbqYoAyh2tbixCqhvMuXxpChVokzSU1CCrquXVF3A4jx5FYg6eN9e4cXC3Vry9 qahhEhLizN95D1WMm9bve9Lt4DCQFkCKjdjzI4uJJoR6lHTrXiHAT/Px6f6pUGUcso 7Wg9gv4kXybbp3KEgKqkIBcCzvCiCeD4WocPdrWGwWrjPhapXPzQcEEwrzoqKIXcKr YIsG53J1BNDLdEBw3Nqekbid0SncAlf0EQmhHeMmdz0dFM8QgahAYOkCKbxIb7r3uX AQd5+b4cgEABw== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/9] mm/damon/core: skip applying scheme if region split for quota fails Date: Sat, 1 Aug 2026 10:35:44 -0700 Message-ID: <20260801173554.94710-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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_apply_scheme() splits a region and apply the action to the subregion if it is needed for not violating the quota. The split operation (damon_split_region_at()) could fail for allocation failure. In the case, the quota could be violated. From the user's perspective, DAMOS becomes more aggressive than expected under the extreme situation. Handle the failure. The user impact is not critical. The failure of damon_split_region_at() is unlikely since it is arguably too small to fail. Also DAMOS being aggressive is limited to the single region. Users can set min_nr_regions to set the maximum size of each region. If it is reasonably set, the transient overhead shouldn't be critical. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260718171523.87547-1-sj@kernel.org Fixes: 2b8a248d5873 ("mm/damon/schemes: implement size quota for schemes ap= plication speed control") Cc: # 5.16.x Signed-off-by: SJ Park --- mm/damon/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 644daf5a16560..e2900d0c984c9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2613,7 +2613,8 @@ static void damos_apply_scheme(struct damon_ctx *c, s= truct damon_target *t, c->min_region_sz); if (!sz) goto update_stat; - damon_split_region_at(t, r, sz); + if (damon_split_region_at(t, r, sz)) + goto update_stat; } if (damos_core_filter_out(c, t, r, s)) return; --=20 2.47.3 From nobody Sat Aug 1 21:31:00 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 4B4CE3B71CC; Sat, 1 Aug 2026 17:36:05 +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=1785605766; cv=none; b=OLCXvxS38R5aGvAR7eqmThxd1AiEByHBkjXzf5MoW+8Pg6t59l1CxbP2fX+Hro9Hd4zLxKuJZe62jI7bDtNUBuW9V6n26hq3flQiG/D/VDlGrGyMYBFgDppROxLqGkZSZ1N0Gf/FUOZPj0rhF32UAvvLWbu9KpaK6S2LEjkSxZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605766; c=relaxed/simple; bh=ZKIT6xnY2oY0e92eMERMwBiCQNJeROh6kYo/rMQan28=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zcqh0xZglgxDFMS8em63xo8wirA40Actn+PkBJAd9E964vblH30HToi/iZcraKPAtkuM2Q3iLEmZ5fvl/GaGDS7Pg7V+heGznDxWGJ5+xFKScNoj3LI47e+vRf8KaZhHQpQH8tbaMFAhro8Ybi6cF7Jh1QHiE/Gb+AXGqEJBZKQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LIlnGYbl; 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="LIlnGYbl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4E491F00ACF; Sat, 1 Aug 2026 17:36:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605765; bh=u3Yai1oWYsB5IJ1T8UFXb8F9ZG0QK/4CFjudJQO8wtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LIlnGYblIdAJF2L9ANrF/LWWjqlMRNw0pyblGdwP+H0Y0oNSeuaXfWqnRatJ1P8jP 3V7rmoYiqRnGONnpuCaK0KT2FVuVPlEnwCSTGHZtDwkDiP9i2efZAZorGcPskdfVvC vcTwwzppVg6859yhqMlgowY8ZzTeL6KEB8RctiOy3yxsvPExbA5AF/dEWIGObwl33v nA5qztxHlIASYkZGam7SLdh44jv8LmnGPDugdf22fRA6SSZq9fOcrGR5Gp4mWtYi+L cTDaolvHBd80EjG7lBftVS5gpN/l0YZk2v5Hnr/woUVfGnd/FWWZCVGkJvLyFvDeqf NhbnPy6Qa21lQ== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/9] mm/damon/core: initialize damos_quota_goal->last_psi_total Date: Sat, 1 Aug 2026 10:35:45 -0700 Message-ID: <20260801173554.94710-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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" When DAMOS_QUOTA_SOME_MEM_PSI_US metric damos quota goal is set, the PSI delta for the feedback loop is calculated using damos_quota_goal->last_psi_total. It is not initialized at the beginning. So the first iteration of the feedback loop uses the uninitialized value and makes an unexpected starting point quota. Initialize the value at the beginning of kdamond. The user impact would be trivial because the issue impacts only the initial iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. The issue was discovered [1] by Sashiko. [1] https://lore.kernel.org/20260718005316.89585-1-sj@kernel.org Fixes: 2dbb60f789cb ("mm/damon/core: implement PSI metric DAMOS quota goal") Cc: # 6.9.x Signed-off-by: SJ Park --- mm/damon/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index e2900d0c984c9..3bdbf4fbf7147 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -3728,6 +3728,17 @@ static int kdamond_wait_activation(struct damon_ctx = *ctx) return -EBUSY; } =20 +static void damos_init_quota_goal_last_psi(struct damos *s) +{ + struct damos_quota_goal *goal; + + damos_for_each_quota_goal(goal, &s->quota) { + if (goal->metric !=3D DAMOS_QUOTA_SOME_MEM_PSI_US) + continue; + goal->last_psi_total =3D damos_get_some_mem_psi_total(); + } +} + static void kdamond_init_ctx(struct damon_ctx *ctx) { unsigned long sample_interval =3D ctx->attrs.sample_interval ? @@ -3744,6 +3755,7 @@ static void kdamond_init_ctx(struct damon_ctx *ctx) damon_for_each_scheme(scheme, ctx) { damos_set_next_apply_sis(scheme, ctx); damos_set_filters_default_reject(scheme); + damos_init_quota_goal_last_psi(scheme); } } =20 --=20 2.47.3 From nobody Sat Aug 1 21:31:00 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 8A3643B71DF; Sat, 1 Aug 2026 17:36:05 +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=1785605766; cv=none; b=NOzqVXnyQyzLrHN1Xa/h7qtLKF2MuuoUttBsnvlwp67V3+Seam8f84DrzzjtEtsCt7iqIp1xJxAqxDhlBgSeJrp41eF5qdfONuM5cxFnL4bQJOcmZVA3uvQcA++DyQyGvc/g0HMWfZeLNTxeKJq2lKUM2DWiYh8BxgDoo3xyu5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605766; c=relaxed/simple; bh=35/yin/QF8t3Kqfg+UAOrsmVX85pqU2Iyl2wuXO5t+0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UvDfbsvIqqnEiA88O7j4un8HlozXAR9lPS573thRCEKGDWcWgcqGQyL+L+VAaR28N5di/PEKSMnYFncHIk46trKsqlRt/3tZCzGB6OsdicUYRfeYg46LBQnBGHxyqkneBq8L6hnWB2vi7cpAM5JrlUFXLxvJZ/OM3sRYa1chif8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e4PRMLtq; 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="e4PRMLtq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D4A51F00ADB; Sat, 1 Aug 2026 17:36:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605765; bh=7ZB1yfEGzN5K33ID0e3bcOFkHhvifJ8hhhrNtAvrugg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=e4PRMLtqTAjfRRZxmbsgvWw8e5lXePPUxbbTmhN0W/gAIwMdFP2qf6r4/oc/MmsOV WQWLRvTzQUmxzXrDyf+QtyI+FASDmSsCeP5EeP4O9QlBWh8QPhCXwjgmii5PZqIF8c H/gD72ItYDDgLlpeuaI7gkUal4HYI7fGs335IzK+IHJIWyC1scK7i4p/BUUl4gN7m6 +oeDBpmtrTOxWCnRUIpWE54a4LAo31ZKjGDnijQU1azkSyuFcQJi+GQZc7eAVOlI7G G2gkp/WjlkAbPyTrt7hhVgfNRGj7IemSXr+IqRmw3zoXc7vmBrLbdqzgcE2rB8ccO2 4nw3NH3ZZb5hA== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Usama Arif , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 3/9] mm/damon/paddr: respect folio end for DAMOS_STAT Date: Sat, 1 Aug 2026 10:35:46 -0700 Message-ID: <20260801173554.94710-4-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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 Aug 1 21:31:00 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 DF3683B777D; Sat, 1 Aug 2026 17:36:05 +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=1785605767; cv=none; b=O8rndji98HrN9D3Nn/vdGuyL1RmhbGePNfX5TnSilqBogNtjOs9nmcaHhV/RY1MZ0LNGWnjFYbPawUSSOmJj+sGJpN3GA1tX+DImAw0JNlQ3atf5pWg3Z8ucLjy5taAbTcaJz4ges9wcNRs88xzz7+0JCNkGX+DiEfPm/+vQ9wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605767; c=relaxed/simple; bh=3tuXFYxnY5whCfMb9BBfKAgRQ7zxuSBaL+SQQ8TayGI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I6qln1SybsAFd45M4EHL9hTu1nRKwdDSg6EPuM2Oe7lnKLscNegw5vwHjJx0fyqjnBWgccggbk4UO1RCyK8g+UHjD9zMFn0ffx4gmLNBQF+VM1VpQqGnNo9zPsnAw5oFALE54Hws3l7s0jntz5cD68F1LhTs9xBQrActgzS9hGQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kAzyu0co; 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="kAzyu0co" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DEBF1F00ADE; Sat, 1 Aug 2026 17:36:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605765; bh=l4DJBfV8Ln2wiu4MTHaklCvhtPpo+9nKnYvuVasq3nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kAzyu0cofgTIbETEzsvvZxvktgzPaOr38ohWe+pSywBKNnruYBRn80Ts4aPf2VJjs 0C+v4MzKnZoWjO1+ZtLDQp0OZduK3ZJltgJjKmPml2Be47S83ErTYXSBht/ywD5sdB 3srSC9tF7QdPk32ebtnVGojvHAsJi0L/wIuMk5hyKMu7VViWMQsjd6dJxIg4St86PV qgGsSzfHCOKtiSekrKn1XcasvSIEZ1+GqdWxHv10lzNoGdV0mjyPtCskFFAvlnRGmD pVsDF6gBalSNqIr7A+meMOum8IW/bqqjOTI5EceRtpFkZqPa65f+a4NwxjqAislL7k Zh8w7+K2PbSyQ== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Usama Arif , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 4/9] mm/damon/paddr: respect folio end for DAMOS actions except STAT Date: Sat, 1 Aug 2026 10:35:47 -0700 Message-ID: <20260801173554.94710-5-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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 Aug 1 21:31:00 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 832C93B5F5D; Sat, 1 Aug 2026 17:36:06 +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=1785605767; cv=none; b=VeswkmxhXc3jpiMOvbQEyH9R00SnYh/daW9h7ZKLo9uF9RKhjEWvLdmxIzC7kzHvhssAqMRCS6V/beymK6bT6WC2FfZyhHpBRfKRG6wkVnVfoHp1f771lbtqx7JXCkc07X3TXYtUUbpY561mQL3akJx4i0lx541hP23uDWYsvaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605767; c=relaxed/simple; bh=MjjB5G5ZYPHAN6OhRBUuLe8e8C+NqQJVFFYrSfVVLuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k5tSobJ0yAanePmhsUj6VShQD9ejjby0H70Rg0QDYDy41lBOWyVUNA0GQtW968sN/SFCa+twe1qHWUDBf72ojeEPAH/Lumgqm4yHJwIds8Ja4F2cZHVV7khPNPuUWhOUgpbT4OwsK6wn7zSbd3DDIebXWx/vc0m+pZiiTsp8Ybs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LXIkgE/P; 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="LXIkgE/P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC44B1F00ACA; Sat, 1 Aug 2026 17:36:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605766; bh=3oTPCb+uFC9gTUspvXroRLy6myVSMRGtc9G75nT2wA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LXIkgE/Phl2spAH+TaSyI40fQBmMzX+oWb52mHp0kJwWim/1mkUMIhuNY3V/tcF4T 3lrnLEjOjMIzN+DEJCrxS63rvxgnAFvnp+czaAxMnIlaBlnsVyP/s48I/+TVepo2ih xkyv+OJGUoj3WRZgbkWJE/4YcaadqkZE1OO0VSaQUliAUFiLnT9kLzXJVgr3E6yOlr CK+624jhDvtzDVMHTTEPAjynRHIBdZ8e3R+uH3ZxhjcIEOwZsMZOaLXDV9Z4485Fje L2VHQaKUn0NUwhwQT+le12y4kzL7auhIjShTi37pPhVGiVmA52INz2J2p4NYhCtGbY dWlU81TwvsVzQ== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , Yueyang Pan , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 5/9] mm/damon/vaddr: respect folio end for DAMOS_STAT Date: Sat, 1 Aug 2026 10:35:48 -0700 Message-ID: <20260801173554.94710-6-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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..035cd509f6b58 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(*pte)); + 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 Aug 1 21:31:00 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 A1C8F3B893F; Sat, 1 Aug 2026 17:36:06 +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=1785605768; cv=none; b=V/aKqwIy5jk0VTHSMbTrcbg7SgEXR+FG7pheFaqV68hKYobTzXbrVWfE+11RQORAftk9kTqbnH9yFf/4hpAMrKNyjS9CjG1Sm5EFC3Z2S/7dMkq2OXGZCEMW5z9aKApSK8R+QCHgXDzqHMw35+3a03bzU/cJsIceNiNf7lphqhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605768; c=relaxed/simple; bh=WKMBurie6Z+ycsPihLvmZk3twze0eXZmOYItbK5Vsz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qOmz/tkpcZus2XIVF8PGcT+O+4iJMqoXKlAo3NP3kyQOqAHZXy8YaDfZco19LIgvnVNyLg6BFUMdPlj6qSYTCyc33N/Ol6L/Jtu1S+88mjHR4H3n5engJkzzitd8kL1RQJwkU5L1vcQ+Ej+yLLmzYA8HOZUsSvziNiq8uiQCm5s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jYq63uts; 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="jYq63uts" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59C941F00ADF; Sat, 1 Aug 2026 17:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605766; bh=uiWMed+e4y9TXxwRAiQ3Fg56ABB5uO8dHBY+Ne9IA7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jYq63uts2BX3RT8QBWXV1P7DCrKOFcTgxo9PGxsrjQSW+hcplom+EoZzSFzf8zyDA YBfSaEi2as9OOiT8vi6D8MV/9GKLCWMM3kvoPfq+W7ffAMYGDFxY71gCPSbLDOkzI5 VqipxAaAfN2yf6IBxsVuuVlLpkCwxjA0HlYy4l7NOn+zNUEh64PO49gfnQZbfyTJNk IwZ3TYq5lpv8dYAk3/puCw4SLj3Plg4lggsOnf0Mi4n+HJpB/OKbgsWgSXQWy2iCCE 7jxncCePmxG+KBBYCeDEVblgL8GClZ6kWUS3y1RnCd0wztk45h7K3hWPYQSqsPXQYt fi5DaXe+Fi1+w== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 6/9] mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD} Date: Sat, 1 Aug 2026 10:35:49 -0700 Message-ID: <20260801173554.94710-7-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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 035cd509f6b58..aa833c2c4fa35 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(*pte)); + nr =3D folio_nr_pages(folio) - page_idx; } pte_unmap_unlock(start_pte, ptl); return 0; --=20 2.47.3 From nobody Sat Aug 1 21:31:00 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 39A5B3B774D; Sat, 1 Aug 2026 17:36:07 +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=1785605768; cv=none; b=NNMq5qE7i0UVlUkbsncONsDu1NxMAZiYNQGFNvfsf2C1wIvMGAqYofkzW+Vf2f47xQvvUTcdyS/BSnUOv5NTSxzgeRwRQKB100GRFSxdnt3sHlVhKASTbqOXL3iPy8oVlM+pVGbrDolZdbF/n6Ibf6b2Y3t5Ts4CQWYLe0YX3eE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605768; c=relaxed/simple; bh=KjoY84pOsntbTzs2pYQd5yUSWCVGO50nSKIZh/b5N2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cG229i3Gk23CPXq8vPD61e7zFn76gxIlYORQsnCzYvavAbivXZc5idUStcsrLXc5mk3xu7+ZJUvqz15cOSZZP5ME4IYqdCpexBVo5vABpdv6gAcSgEDxdfzsKI9KMAXfHhr80Tn+vT9q8pj6H0plqNT1yMx0L5plxz451mAElrc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dBhdoT/o; 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="dBhdoT/o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFDBA1F00ACF; Sat, 1 Aug 2026 17:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605766; bh=o1TLO1J6QDVVNz5r0BRdl5+1+gHGcHEvIPNqhuz3/rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dBhdoT/oGy8uRNBe84+vYOBuny3Wc3DU+omPxB8qCyOOhCnd7o9VPHfTLGSr0svTm WIVpXEAo95W2gFYNTc60Q/WrtdVkwUCPxrXFqI0aCS1pvhIFlzieCAPUArKSzS7M7E WiCSPcSHFSaorwfw1JYkCD+X/Z6b8UycD0GVzoa6YTU6LaSH+i8jYQ4BqC3u4nkN50 aVM3BZ6dyZVLl5ekBfmG8Qzr27Ok+q7YLzONrQq1/3z9fWr02hCNBH7/Bbv78Ez8kf DORcHdnxEUA7CGYp9TRVu0eCFvk35jcx2SgKzYvpD57ijKfUj4y99iyAUR1EaPkGGM LadBoeJhACBfg== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 7/9] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp() Date: Sat, 1 Aug 2026 10:35:50 -0700 Message-ID: <20260801173554.94710-8-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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(). Fix it by setting the totalram one byte in the case. 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 3bdbf4fbf7147..269865eb8fbfa 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2816,6 +2816,8 @@ static __kernel_ulong_t damos_get_node_mem_bp( } =20 si_meminfo_node(&i, goal->nid); + if (!i.totalram) + i.totalram =3D 1; 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 Aug 1 21:31:00 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 5A94F3B9952; Sat, 1 Aug 2026 17:36:07 +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=1785605768; cv=none; b=QrxSxGFWLJ4huIgQwizozeoA2qIv7IbdPOMSFrQb1X0pKVWOee5y18KbNhaTbb+GqKrkVB9+uXeGcCxCPmbHGthkw9RJ6mvHk/Oo//59Jtq2o79A4VuTemLq0qK93Dk64J8OYr9Ok3yAZc80G2J0N5rwFPFf8mlNt0eg1cosi7Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605768; c=relaxed/simple; bh=TsApn/EBuEZDdp22FMCoBKg8o3mNdte07+twbtXDt38=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ExPkJyaBvDsiibfbVQtuG3Whwv7okaVp9IfNbLvsp4tB+ZJZ8FhCZMjwCKy9vdpeRYA6Q4fa0Ljtjb2SW/WVLcYrBjdFSMnsv5cVdorFd1F3vOsvyI5/pFE1MZqhVwuzaFZrSg5bnpt1IaPGOrdS70bRDJu1Y4rFkPttsONkDnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bLT4gtqM; 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="bLT4gtqM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 132801F00ADB; Sat, 1 Aug 2026 17:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605767; bh=yKFkp73Zizuc7gexvqH7fNRh7GwZeAoSufeXbUk/pxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bLT4gtqMoalg2zLuDMjvtK/ef07qFRzpt+RM2ctRTcIZ3j9/K93AyBnxGZVuNwRng Gopobsn1Fx/WJ0+EPpcLwkzkBIyGDzjtYzBPjMV84zQg8qjWyUZm2S/h0EGdVAGM97 8+ddelOUyoG40WvlZHuHGfMa4oVq/Q7lZQjm5vDVaU6vHW1HSRoL2qKTCb8fPT2DCb 8VbgD0EaeCNFedX9ba2aXObuYY/jOAyAh0LmpwssCEGEzmr2Lr9FhrYr05xvYJFC1g QSnU8Y2im/ARKApd+jeszY1vR4bIsqgjhyWquzUzQ1/8vJpzmIjD43qOPfHm9UBe+n TGZ7L9lrbZd0A== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 8/9] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() Date: Sat, 1 Aug 2026 10:35:51 -0700 Message-ID: <20260801173554.94710-9-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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 returning 100% and 0% for the two cases, respectively. 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index 269865eb8fbfa..76764a2056f7c 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -2858,10 +2858,16 @@ static unsigned long damos_get_node_memcg_used_bp( mem_cgroup_put(memcg); =20 si_meminfo_node(&i, goal->nid); - if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEMCG_USED_BP) + if (!i.totalram) + return 10000; + if (goal->metric =3D=3D DAMOS_QUOTA_NODE_MEMCG_USED_BP) { numerator =3D used_pages; - else /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ + } else { + /* DAMOS_QUOTA_NODE_MEMCG_FREE_BP */ + if (i.totalram < used_pages) + return 0; numerator =3D i.totalram - used_pages; + } return mult_frac(numerator, 10000, i.totalram); } =20 --=20 2.47.3 From nobody Sat Aug 1 21:31:00 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 DC1F53B7767; Sat, 1 Aug 2026 17:36:07 +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=1785605769; cv=none; b=FWdbs3GbxENtVYj+WKpPZk0WFKiMIdBldhtcPGpwmDiFFSFaTdmqMoLlrweLUUuoP7XutRSa3SZxs+BHxThNxLYPs9qKqfyHiE1uw4Kom/fiBWAFvir9KjNWj0A5k7dK6v1p+O4qAIHMtqsee9hXqJlwYFInHMtCtcuNU9S9/bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785605769; c=relaxed/simple; bh=uBgSX1JL3LZIlrv1TPXSHtS7ge7Vi0spiDNd2yiDPw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tHphtrzjPveykKcE/pavFA3KRxbeRH/1urfeJLD9M0R4J6cMgwCrOGBPUGtrzaT+xx7IrZrYkA9nHuX54b6aqE0t/FohE+ya04HI50g7BgeLGNLSIoLsHk2gExoM5EX0xl9+XB4J4ILOEFKyznok4SjhigYXh7IZZ5/mhjDnWsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hS2FSll7; 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="hS2FSll7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B4581F00ADE; Sat, 1 Aug 2026 17:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785605767; bh=2lVMcowLJ38JKqepYS3zjjIyEUx+xmDnTKakKUngaTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hS2FSll79ic9yMYMFuLhwoUua4YRp9/4WIiXbfw5x6UFbIs9W48ZLxX71wW/1mjPp 4hElEN3ceCaDJwohmysCJQ8Os/yBJMkMcDr1ed/B5fNDoaLkfvTSODJXQDHLUZ68ec gJq/5SVn2fJak45Gu3sBShz/WaVDXWL15JZpIc2FUL5zEgVrPnbJExuIILUBga5MNX rubm5ausGrbA/uIV/lFwajWxVdcZEzt5htR8R4Y3Vy1v1Dv/LcTJCU1HYMhc+UbJvA ybvYjUeYMh32ArPj5pkOW8bpiM+OXlIQ0Hg/3GPKuhDWGQS26QQMwztb/ASwWAU+BV uGUP52S9y5k9g== From: SJ Park To: Cc: SJ Park , stable@vger.kernel.org, Andrew Morton , damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() Date: Sat, 1 Aug 2026 10:35:52 -0700 Message-ID: <20260801173554.94710-10-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260801173554.94710-1-sj@kernel.org> References: <20260801173554.94710-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" damon_get_intervals_adaptation_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 76764a2056f7c..4944cf2c5afae 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -3010,7 +3010,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