mm/damon: porting fixes that cherry-pick failed on 2026-11-07
Subsystems (3)
SJ Park
maintainercover mm/damon: porting fixes that cherry-pick failed on 2026-11-07
Manually port two DAMON fixes that cherry-pick failed [1,2] and turned out to really need to be picked. Note that seven patches [3-9] 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/[email protected]
[2] https://lore.kernel.org/[email protected]
Patches that also cherry-pick failed but deliverately ignored.
[3] https://lore.kernel.org/[email protected]
[4] https://lore.kernel.org/[email protected]
[5] https://lore.kernel.org/[email protected]
[6] https://lore.kernel.org/[email protected]
[7] https://lore.kernel.org/[email protected]
[8] https://lore.kernel.org/[email protected]
[9] https://lore.kernel.org/[email protected]
SJ Park (2):
mm/damon/core: skip applying scheme if region split for quota fails mm/damon/core: remove unreachable damos charge_{target,addr}_from
mm/damon/core.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-)
base-commit: 807b0a2cf04f7d9b6d42d23f5e63915fb80a54fd
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 1/2 mm/damon/core: skip applying scheme if region split for quota fails
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.1.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.
--- mm/damon/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
mm/damon/core.c +8 -4
@@ -718,7 +718,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)
@@ -810,7 +810,8 @@ static void damon_do_apply_schemes(struct damon_ctx *c, 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; }ktime_get_coarse_ts64 (&begin); sz_applied = c->ops.apply_scheme (c, t, r, s);
@@ -1015,15 +1016,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;
@@ -1031,6 +1034,7 @@ static void damon_split_region_at(struct damon_target *t, new->last_nr_accesses = r->last_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 */
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.1.y 1/2] mm/damon/core: skip applying scheme if region split for quota fails
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] mm/damon: inflated tried stats in damon_do_apply_schemes() on split failure --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/damon: inflated tried stats in damon_do_apply_schemes() on split failure
--
commit 2d405ecddea503227b3b4138fe63cbeb95dc50b9
Author: SJ Park <[email protected]>
mm/damon/core: skip applying scheme if region split for quota fails
This commit changes damon_split_region_at() to return an error on memory allocation failure and skips applying the DAMOS scheme in damon_do_apply_schemes() when splitting a region to fit within the size quota fails.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
mm/damon/core.c static void damon_do_apply_schemes(struct damon_ctx *c, · line 814
Quoted 7 lines
mm/damon/core.c +2
-1@@ -810,7 +810,8 @@ static void damon_do_apply_schemes(struct damon_ctx *c, 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: Low]
Does jumping to update_stat here inflate s->stat.nr_tried and s->stat.sz_tried when damon_split_region_at() fails?
Unlike the !sz path right above, sz holds the non-zero remaining quota when damon_split_region_at() is called, and update_stat unconditionally accounts it:
mm/damon/core.c:damon_do_apply_schemes() {
...
update_stat:
s->stat.nr_tried++;
s->stat.sz_tried += sz;
...
}Because c->ops.apply_scheme() is skipped and quota->charged_sz is not advanced, any subsequent matching regions in the same pass that also fail to split will repeatedly add sz to s->stat.sz_tried.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [RFC PATCH 6.1.y 1/2] mm/damon/core: skip applying scheme if region split for quota fails
Quoted 51 lines · On Sat, 07 Nov 2026 22:56:53 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/damon: inflated tried stats indamon_do_apply_schemes()on split failure
--commit
2d405ecddea503227b3b4138fe63cbeb95dc50b9
Author: SJ Park <[email protected]>
mm/damon/core: skip applying scheme if region split for quota failsThis commit changes
damon_split_region_at()to return an error on memory allocation failure and skips applying the DAMOS scheme indamon_do_apply_schemes()when splitting a region to fit within the size quota fails.Quoted 4 lines
mm/damon/core.c +0
-0[ ... ]
mm/damon/core.c static void damon_do_apply_schemes(struct damon_ctx *c, · line 814
Quoted 7 lines
mm/damon/core.c +2
-1@@ -810,7 +810,8 @@ static void damon_do_apply_schemes(struct damon_ctx *c, 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: Low]
Does jumping toupdate_stathere inflates->stat.nr_triedands->stat.sz_triedwhendamon_split_region_at()fails?Unlike the !sz path right above, sz holds the non-zero remaining quota when
damon_split_region_at()is called, andupdate_statunconditionally accounts it:mm/damon/core.c:damon_do_apply_schemes() { ... update_stat: s->stat.nr_tried++; s->stat.sz_tried += sz; ... }
Quoted 3 lines
Because
c->ops.apply_scheme()is skipped andquota->charged_szis not advanced, any subsequent matching regions in the same pass that also fail to split will repeatedly add sz tos->stat.sz_tried.
Good finding, but the user impact is trivial. Same behavior exists in the mainline, too. Hence no blocker for this patch.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerRFC PATCH 2/2 mm/damon/core: remove unreachable damos charge_{target,addr}_from
In reply to SJ Parkdamos_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.
--- mm/damon/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
mm/damon/core.c +22 -0
@@ -860,6 +860,26 @@ 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 kdamond_apply_schemes (struct damon_ctx *c) {struct damon_target *t;
@@ -890,6 +910,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)damos_set_effective_quota (quota); } +damos_fix_stale_charge_pointers (c, s); +if (!c->ops.get_scheme_score)continue ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.1.y 2/2] mm/damon/core: remove unreachable damos charge_{target,addr}_from
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mm/damon/core: stale charge_target_from ABA reuse when scheme is inactive --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mm/damon/core: stale charge_target_from ABA reuse when scheme is inactive
--
commit 853b3e89da132f2ce03750bcf6dfc1f62a70d261
Author: SJ Park <[email protected]>
mm/damon/core: remove unreachable damos charge_{target,addr}_from
This commit adds damos_fix_stale_charge_pointers() to clear quota->charge_target_from and quota->charge_addr_from when the referenced target has been removed or no longer has any regions.
Quoted 32 lines
mm/damon/core.c +20
-0@@ -860,6 +860,26 @@ 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 kdamond_apply_schemes (struct damon_ctx *c) {struct damon_target *t;
mm/damon/core.c static void kdamond_apply_schemes(struct damon_ctx *c) · line 917
Quoted 8 lines
mm/damon/core.c +2
-0@@ -890,6 +910,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)damos_set_effective_quota (quota); } +damos_fix_stale_charge_pointers (c, s); +if (!c->ops.get_scheme_score)continue ;
[Severity: Medium]
Can quota->charge_target_from match a newly allocated target due to slab address reuse if the old target was freed while the scheme was inactive?
kdamond_apply_schemes() skips inactive schemes at the !s->wmarks.activated check before reaching damos_fix_stale_charge_pointers(), and damon_sysfs_set_targets() frees removed targets via damon_destroy_target() without clearing charge_target_from. If an online commit removes the target stored in charge_target_from while the scheme is deactivated by watermarks and a later commit allocates a new target at the same address, damos_fix_stale_charge_pointers() will see t == quota->charge_target_from with regions present and leave the stale charge_target_from and charge_addr_from in place. When the scheme reactivates, damon_do_apply_schemes() will skip targets before the new target and regions up to the old charge_addr_from.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerRe: [RFC PATCH 6.1.y 2/2] mm/damon/core: remove unreachable damos charge_{target,addr}_from
Quoted 62 lines · On Sat, 07 Nov 2026 23:02:33 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium]mm/damon/core: stalecharge_target_fromABA reuse when scheme is inactive
--commit
853b3e89da132f2ce03750bcf6dfc1f62a70d261
Author: SJ Park <[email protected]>
mm/damon/core: remove unreachable damos charge_{target,addr}_fromThis commit adds
damos_fix_stale_charge_pointers()to clearquota->charge_target_fromandquota->charge_addr_fromwhen the referenced target has been removed or no longer has any regions.Quoted 32 lines
mm/damon/core.c +20
-0@@ -860,6 +860,26 @@ 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 kdamond_apply_schemes (struct damon_ctx *c) {struct damon_target *t;mm/damon/core.c static void kdamond_apply_schemes(struct damon_ctx *c) · line 917
Quoted 8 lines
mm/damon/core.c +2
-0@@ -890,6 +910,8 @@ static void kdamond_apply_schemes(struct damon_ctx *c)damos_set_effective_quota (quota); } +damos_fix_stale_charge_pointers (c, s); +if (!c->ops.get_scheme_score)continue ;[Severity: Medium]
Canquota->charge_target_frommatch a newly allocated target due to slab address reuse if the old target was freed while the scheme was inactive?
Quoted 11 lines
kdamond_apply_schemes()skips inactive schemes at the !s->wmarks.activated check before reachingdamos_fix_stale_charge_pointers(), anddamon_sysfs_set_targets()frees removed targets viadamon_destroy_target()without clearingcharge_target_from. If an online commit removes the target stored incharge_target_fromwhile the scheme is deactivated by watermarks and a later commit allocates a new target at the same address,damos_fix_stale_charge_pointers()will see t ==quota->charge_target_fromwith regions present and leave the stalecharge_target_fromandcharge_addr_fromin place. When the scheme reactivates,damon_do_apply_schemes()will skip targets before the new target and regions up to the oldcharge_addr_from.
Good finding but no real issue. Occasionally starting quota charging from an unexpected target is no real issue for DAMOS in my opinion. So, no blocker.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Thanks,
SJ