* [PATCH 6.6.y 0/3] mm/damon: porting fixes that cherry-pick failed on 2026-11-07
@ 2026-11-08 20:14 SJ Park
2026-11-08 20:14 ` [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: SJ Park @ 2026-11-08 20:14 UTC (permalink / raw)
To: stable; +Cc: SJ Park, Andrew Morton, Usama Arif, damon, linux-kernel, linux-mm
Manually port three DAMON fixes that cherry-pick failed [1-3] and turned
out to really need to be picked. Note that seven patches [4-10] that
also failed in the same day were having wrong Cc:stable@ tags, so
ignored.
Patches that this series is porting.
[1] https://lore.kernel.org/20261107053211-failed-6.6-90c2fa6adfed@kernel.org
[2] https://lore.kernel.org/20261107053907-failed-6.6-bbeec2d8324d@kernel.org
[3] https://lore.kernel.org/20261107053915-failed-6.6-5695abc4e742@kernel.org
Patches that also cherry-pick failed but deliverately ignored.
[4] https://lore.kernel.org/20261107053348-failed-6.6-6f276422aded@kernel.org
[5] https://lore.kernel.org/20261107053350-failed-6.6-cec08aad3def@kernel.org
[6] https://lore.kernel.org/20261107053353-failed-6.6-409d2ab6d982@kernel.org
[7] https://lore.kernel.org/20261107053355-failed-6.6-1bfb9384ae0e@kernel.org
[8] https://lore.kernel.org/20261107053357-failed-6.6-a1c7fdaf1657@kernel.org
[9] https://lore.kernel.org/20261107053400-failed-6.6-1d2397b2c414@kernel.org
[10] https://lore.kernel.org/20261107053402-failed-6.6-1c3352282063@kernel.org
Changes from RFC
- RFC: https://lore.kernel.org/20261107222202.331476-1-sj@kernel.org
- None.
SJ Park (3):
mm/damon/core: skip applying scheme if region split for quota fails
mm/damon/core: filter out damos address filter-split failed region
mm/damon/core: remove unreachable damos charge_{target,addr}_from
mm/damon/core-test.h | 11 +++++-----
mm/damon/core.c | 48 ++++++++++++++++++++++++++++++++++++--------
2 files changed, 46 insertions(+), 13 deletions(-)
base-commit: 9990534f18e75bebba6b6a557012d1253980de9e
--
2.47.3
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails 2026-11-08 20:14 [PATCH 6.6.y 0/3] mm/damon: porting fixes that cherry-pick failed on 2026-11-07 SJ Park @ 2026-11-08 20:14 ` SJ Park 2026-11-08 20:23 ` sashiko-bot 2026-11-08 20:14 ` [PATCH 6.6.y 2/3] mm/damon/core: filter out damos address filter-split failed region SJ Park 2026-11-08 20:14 ` [PATCH 6.6.y 3/3] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park 2 siblings, 1 reply; 6+ messages in thread From: SJ Park @ 2026-11-08 20:14 UTC (permalink / raw) To: stable; +Cc: SJ Park, Andrew Morton, Usama Arif, damon, linux-kernel, linux-mm Patch series "mm/damon: fix DAMOS bugs in core, paddr and vaddr". Fix misc bugs of DAMOS. Patch 1 makes DAMOS less stress memory allocator under extreme situation. Patches 2 and 3 fix wrong folios walking in DAMON_PADDR. Patches 4 and 5 fix wrong folios walking in DAMON_VADDR. Patches 6-8 handle extreme and unlikely memory situations that can cause divide by zero and underflow. All bugs are discovered by Sashiko. This patch (of 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. 6.6.y porting notes. Modify damon_split_region_at() to return failures. It is a part of commit c60874860762 ("mm/damon/core: handle region split failure in apply_min_nr_regions()"). Without it, build fails. Link: https://lore.kernel.org/20260901131850.98037-1-sj@kernel.org Link: https://lore.kernel.org/20260901131850.98037-2-sj@kernel.org Link: https://lore.kernel.org/20260718171523.87547-1-sj@kernel.org [1] Fixes: 2b8a248d5873 ("mm/damon/schemes: implement size quota for schemes application speed control") Signed-off-by: SJ Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Usama Arif <usamaarif642@gmail.com> Cc: <stable@vger.kernel.org> # 5.16.x (cherry picked from commit 90c2fa6adfed7abe0935506a43cdff3a05c1fff0) Signed-off-by: SJ Park <sj@kernel.org> --- mm/damon/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index b5b6d00d7a3b5..9d4a78deaa06a 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -828,7 +828,7 @@ static void kdamond_reset_aggregated(struct damon_ctx *c) } } -static void damon_split_region_at(struct damon_target *t, +static int damon_split_region_at(struct damon_target *t, struct damon_region *r, unsigned long sz_r); static bool __damos_valid_target(struct damon_region *r, struct damos *s) @@ -1004,7 +1004,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, DAMON_MIN_REGION); 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_filter_out(c, t, r, s)) return; @@ -1266,15 +1267,17 @@ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold, * * r the region to be split * sz_r size of the first sub-region that will be made + * + * Return: 0 on success, negative error code otherwise. */ -static void damon_split_region_at(struct damon_target *t, +static int damon_split_region_at(struct damon_target *t, struct damon_region *r, unsigned long sz_r) { struct damon_region *new; new = damon_new_region(r->ar.start + sz_r, r->ar.end); if (!new) - return; + return -ENOMEM; r->ar.end = new->ar.start; @@ -1283,6 +1286,7 @@ static void damon_split_region_at(struct damon_target *t, new->nr_accesses = r->nr_accesses; damon_insert_region(new, r, damon_next_region(r), t); + return 0; } /* Split every region in the given target into 'nr_subs' regions */ -- 2.47.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails 2026-11-08 20:14 ` [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails SJ Park @ 2026-11-08 20:23 ` sashiko-bot 2026-11-08 20:25 ` SJ Park 0 siblings, 1 reply; 6+ messages in thread From: sashiko-bot @ 2026-11-08 20:23 UTC (permalink / raw) To: SJ Park; +Cc: Andrew Morton, Usama Arif, damon, linux-mm Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm/damon: false tried stats on split failure in damos_apply_scheme() -- commit 17459070b1916b2d77f607f0fb7f0f9158e6224f Author: SJ Park <sj@kernel.org> mm/damon/core: skip applying scheme if region split for quota fails This commit updates damon_split_region_at() to return an error code on allocation failure and skips applying the DAMOS scheme in damos_apply_scheme() if splitting a region to fit within the size quota fails. Link: https://lore.kernel.org/20260901131850.98037-1-sj@kernel.org Link: https://lore.kernel.org/20260901131850.98037-2-sj@kernel.org Link: https://lore.kernel.org/20260718171523.87547-1-sj@kernel.org [1] > diff --git a/mm/damon/core.c b/mm/damon/core.c > index b5b6d00d7a3b5..9d4a78deaa06a 100644 > --- a/mm/damon/core.c > +++ b/mm/damon/core.c [ ... ] > @@ -1004,7 +1004,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, > DAMON_MIN_REGION); > if (!sz) > goto update_stat; > - damon_split_region_at(t, r, sz); > + if (damon_split_region_at(t, r, sz)) > + goto update_stat; [Severity: Medium] Does jumping to update_stat here falsely inflate s->stat.nr_tried and s->stat.sz_tried when damon_split_region_at() fails? At this point sz is the non-zero remaining quota size, and damos_update_stat(s, sz, sz_applied) unconditionally increments s->stat.nr_tried and adds sz to s->stat.sz_tried even though damos_filter_out() and c->ops.apply_scheme() were skipped. Because quota->charged_sz is not updated on split failure, every subsequent matching region in the walk that exceeds the remaining quota and fails to split will also add sz to s->stat.sz_tried again. Returning early here, as damos_filter_out() does just below, would avoid counting skipped regions as tried. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261108201456.116824-1-sj@kernel.org?part=1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails 2026-11-08 20:23 ` sashiko-bot @ 2026-11-08 20:25 ` SJ Park 0 siblings, 0 replies; 6+ messages in thread From: SJ Park @ 2026-11-08 20:25 UTC (permalink / raw) To: sashiko-bot; +Cc: SJ Park, Andrew Morton, Usama Arif, damon, linux-mm On Sun, 08 Nov 2026 20:23:37 +0000 sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [Medium] mm/damon: false tried stats on split failure in > damos_apply_scheme() > -- > > commit 17459070b1916b2d77f607f0fb7f0f9158e6224f > Author: SJ Park <sj@kernel.org> > > mm/damon/core: skip applying scheme if region split for quota fails > > This commit updates damon_split_region_at() to return an error code on > allocation failure and skips applying the DAMOS scheme in > damos_apply_scheme() if splitting a region to fit within the size quota > fails. > > Link: https://lore.kernel.org/20260901131850.98037-1-sj@kernel.org > Link: https://lore.kernel.org/20260901131850.98037-2-sj@kernel.org > Link: https://lore.kernel.org/20260718171523.87547-1-sj@kernel.org [1] > > > diff --git a/mm/damon/core.c b/mm/damon/core.c > > index b5b6d00d7a3b5..9d4a78deaa06a 100644 > > --- a/mm/damon/core.c > > +++ b/mm/damon/core.c > > [ ... ] > > > @@ -1004,7 +1004,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, > > DAMON_MIN_REGION); > > if (!sz) > > goto update_stat; > > - damon_split_region_at(t, r, sz); > > + if (damon_split_region_at(t, r, sz)) > > + goto update_stat; > > [Severity: Medium] > Does jumping to update_stat here falsely inflate s->stat.nr_tried and > s->stat.sz_tried when damon_split_region_at() fails? > > At this point sz is the non-zero remaining quota size, and > damos_update_stat(s, sz, sz_applied) unconditionally increments > s->stat.nr_tried and adds sz to s->stat.sz_tried even though > damos_filter_out() and c->ops.apply_scheme() were skipped. Because > quota->charged_sz is not updated on split failure, every subsequent > matching region in the walk that exceeds the remaining quota and fails to > split will also add sz to s->stat.sz_tried again. Returning early here, as > damos_filter_out() does just below, would avoid counting skipped regions as > tried. Trivial user impact. The same behavior exists in the mainline. No blocker for this patch. > > -- > Sashiko AI review · https://sashiko.dev/#/patchset/20261108201456.116824-1-sj@kernel.org?part=1 > Thanks, SJ ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 6.6.y 2/3] mm/damon/core: filter out damos address filter-split failed region 2026-11-08 20:14 [PATCH 6.6.y 0/3] mm/damon: porting fixes that cherry-pick failed on 2026-11-07 SJ Park 2026-11-08 20:14 ` [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails SJ Park @ 2026-11-08 20:14 ` SJ Park 2026-11-08 20:14 ` [PATCH 6.6.y 3/3] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park 2 siblings, 0 replies; 6+ messages in thread From: SJ Park @ 2026-11-08 20:14 UTC (permalink / raw) To: stable; +Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm When an address type DAMOS filter is configured, DAMOS tries to split the region for the filter range, and apply DAMOS action to the filter-in region. The split operation (damon_split_region_at()) could fail from allocation failure under extreme memory pressure. In the case, DAMOS action could be applied more or less than expected, ignoring the address filter. The issue only rarely happens under extreme memory pressure. No crash or leak happens. Occasionally not applying the action to a few regions shouldn't be a real problem. But applying the action to a region that the user has excluded via address filter could be a surprise depending on the use case. It is only theoretical. No such real case is found yet. Filter out the entire region if the split is failed. Update damos_filter_match() signature to receive the error from split. Also update kunit tests for the updated signature. The issue was discovered [1] by sashiko. Link: https://lore.kernel.org/20261020004119.106690-1-sj@kernel.org Link: https://lore.kernel.org/20260801203121.117449-1-sj@kernel.org [1] Fixes: ab9bda001b68 ("mm/damon/core: introduce address range type damos filter") Signed-off-by: SJ Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: <stable@vger.kernel.org> # 6.6.x (cherry picked from commit bbeec2d8324d7aac438bb12dd2d22b184e0a8d43) Signed-off-by: SJ Park <sj@kernel.org> --- mm/damon/core-test.h | 11 ++++++----- mm/damon/core.c | 13 +++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index dd91b0eea61ff..1988b7dd29e96 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -461,6 +461,7 @@ static void damos_test_filter_out(struct kunit *test) struct damon_target *t; struct damon_region *r, *r2; struct damos_filter *f; + int err; f = damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true); if (!f) @@ -482,25 +483,25 @@ static void damos_test_filter_out(struct kunit *test) damon_add_region(r, t); /* region in the range */ - KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f, &err)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); /* region before the range */ r->ar.start = DAMON_MIN_REGION * 1; r->ar.end = DAMON_MIN_REGION * 2; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f, &err)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); /* region after the range */ r->ar.start = DAMON_MIN_REGION * 6; r->ar.end = DAMON_MIN_REGION * 8; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f, &err)); KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); /* region started before the range */ r->ar.start = DAMON_MIN_REGION * 1; r->ar.end = DAMON_MIN_REGION * 4; - KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f, &err)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2); @@ -515,7 +516,7 @@ static void damos_test_filter_out(struct kunit *test) /* region started in the range */ r->ar.start = DAMON_MIN_REGION * 2; r->ar.end = DAMON_MIN_REGION * 8; - KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f, &err)); /* filter should have split the region */ KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2); KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6); diff --git a/mm/damon/core.c b/mm/damon/core.c index 9d4a78deaa06a..99e934a6d1ce9 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -930,13 +930,14 @@ static void damos_update_stat(struct damos *s, } static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, - struct damon_region *r, struct damos_filter *filter) + struct damon_region *r, struct damos_filter *filter, int *err) { bool matched = false; struct damon_target *ti; int target_idx = 0; unsigned long start, end; + *err = 0; switch (filter->type) { case DAMOS_FILTER_TYPE_TARGET: damon_for_each_target(ti, ctx) { @@ -962,12 +963,13 @@ static bool __damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, } /* start before the range and overlap */ if (r->ar.start < start) { - damon_split_region_at(t, r, start - r->ar.start); + *err = damon_split_region_at(t, r, + start - r->ar.start); matched = false; break; } /* start inside the range */ - damon_split_region_at(t, r, end - r->ar.start); + *err = damon_split_region_at(t, r, end - r->ar.start); matched = true; break; default: @@ -981,9 +983,12 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *s) { struct damos_filter *filter; + bool matching; + int err; damos_for_each_filter(filter, s) { - if (__damos_filter_out(ctx, t, r, filter)) + matching = __damos_filter_out(ctx, t, r, filter, &err); + if (matching || err) return true; } return false; -- 2.47.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 6.6.y 3/3] mm/damon/core: remove unreachable damos charge_{target,addr}_from 2026-11-08 20:14 [PATCH 6.6.y 0/3] mm/damon: porting fixes that cherry-pick failed on 2026-11-07 SJ Park 2026-11-08 20:14 ` [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails SJ Park 2026-11-08 20:14 ` [PATCH 6.6.y 2/3] mm/damon/core: filter out damos address filter-split failed region SJ Park @ 2026-11-08 20:14 ` SJ Park 2 siblings, 0 replies; 6+ messages in thread From: SJ Park @ 2026-11-08 20:14 UTC (permalink / raw) To: stable; +Cc: SJ Park, Andrew Morton, damon, linux-kernel, linux-mm damos_quota->charge_{target,addr}_from saves the target and region the scheme's quota limit is reached. damos_skip_charged_region() skips the target and regions before the point. The target that was assigned to charge_target_from could be dynamically removed from the context by the runtime parameters update (aka commit) feature. In this case, damos_skip_charged_region() cannot find if the point is passed or not, so the scheme is effectively disabled. Similarly, the user could also remove all the regions of the target using the runtime parameters update feature. It would be uncommon to do that, but it is a supported feature. Because the skip pointer detection logic (damos_skip_charged_region()) works for each region of targets, this result in the logic is entirely skipped and the scheme is effectively disabled again. The user impact is that the DAMOS scheme could suddenly stop working under certain uses of the runtime parameters update feature. It could surprise users. No crash or leak happens though. Users could also simply work around by re-installing the scheme. Catch the corner cases in damos_adjust_quota() and reset the pointers. Link: https://lore.kernel.org/20261020023958.108276-1-sj@kernel.org Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update") Signed-off-by: SJ Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Closes: https://sashiko.dev/#/bug/linux-cd0c55fc-0cc8-45d8-9637-3334811c49b8 Cc: <stable@vger.kernel.org> # 5.19.x (cherry picked from commit 5695abc4e742b947f586bfb6a080a80ad9957e5d) Signed-off-by: SJ Park <sj@kernel.org> --- mm/damon/core.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index 99e934a6d1ce9..61d45d40fc1d3 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -1088,6 +1088,27 @@ static void damos_set_effective_quota(struct damos_quota *quota) quota->esz = esz; } + +static void damos_fix_stale_charge_pointers(struct damon_ctx *c, + struct damos *s) +{ + struct damos_quota *quota; + struct damon_target *t; + + quota = &s->quota; + if (!quota->charge_target_from) + return; + damon_for_each_target(t, c) { + if (t == quota->charge_target_from) { + if (damon_nr_regions(t) > 0) + return; + break; + } + } + quota->charge_target_from = NULL; + quota->charge_addr_from = 0; +} + static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) { struct damos_quota *quota = &s->quota; @@ -1115,6 +1136,8 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) damos_set_effective_quota(quota); } + damos_fix_stale_charge_pointers(c, s); + if (!c->ops.get_scheme_score) return; -- 2.47.3 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-08 20:25 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08 20:14 [PATCH 6.6.y 0/3] mm/damon: porting fixes that cherry-pick failed on 2026-11-07 SJ Park
2026-11-08 20:14 ` [PATCH 6.6.y 1/3] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
2026-11-08 20:23 ` sashiko-bot
2026-11-08 20:25 ` SJ Park
2026-11-08 20:14 ` [PATCH 6.6.y 2/3] mm/damon/core: filter out damos address filter-split failed region SJ Park
2026-11-08 20:14 ` [PATCH 6.6.y 3/3] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox