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 five DAMON fixes that cherry-pick failed [1-5] and turned out to really need to be picked. Note that seven patches [6-12] 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]
[3] https://lore.kernel.org/[email protected]
[4] https://lore.kernel.org/[email protected]
[5] https://lore.kernel.org/[email protected]
Patches that also cherry-pick failed but deliverately ignored.
[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]
[10] https://lore.kernel.org/[email protected]
[11] https://lore.kernel.org/[email protected]
[12] https://lore.kernel.org/[email protected]
SJ Park (5):
mm/damon/core: skip applying scheme if region split for quota fails mm/damon/paddr: respect folio end for DAMOS actions except STAT mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total mm/damon/core: filter out damos address filter-split failed region mm/damon/core: remove unreachable damos charge_{target,addr}_from
mm/damon/core.c | 59 ++++++++++++++++++++++++++++++------- mm/damon/paddr.c | 6 ++-- mm/damon/tests/core-kunit.h | 11 +++---- 3 files changed, 58 insertions(+), 18 deletions(-)
base-commit: 76e5c9c4cde792b3376e382e973c8ce7b978496a
Signature · 1 line
2.47.3
SJ Park
maintainerRFC PATCH 1/5 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.12.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
@@ -1266,7 +1266,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)
@@ -1470,7 +1470,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 ;
@@ -1861,15 +1862,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;
@@ -1879,6 +1882,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 */
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.12.y 1/5] 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/core: inaccurate tried stats on split failure in damos_apply_scheme() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/damon/core: inaccurate tried stats on split failure in damos_apply_scheme()
--
commit fe019f891ca813eff979dfc83e95ba297bc45135
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 code on allocation failure and skips applying the DAMOS scheme in damos_apply_scheme() when splitting a region to fit the remaining size quota fails.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
mm/damon/core.c static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, · line 1477
Quoted 10 lines
mm/damon/core.c +2
-1@@ -1470,7 +1470,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 ;
[Severity: Low]
Should this return instead of jumping to update_stat when damon_split_region_at() fails?
At this point sz holds the non-zero aligned remaining quota, and update_stat calls damos_update_stat(s, sz, sz_applied), which increments s->stat.nr_tried and adds sz to s->stat.sz_tried even though scheme application and filter evaluation were skipped. Because quota->charged_sz is not updated on this error path, persistent allocation failures across subsequent regions larger than the remaining quota will repeatedly add the remaining quota sz to s->stat.sz_tried and increment s->stat.nr_tried.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [RFC PATCH 6.12.y 1/5] mm/damon/core: skip applying scheme if region split for quota fails
Quoted 42 lines · On Sat, 07 Nov 2026 21:52:35 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low]mm/damon/core: inaccurate tried stats on split failure indamos_apply_scheme()
--commit
fe019f891ca813eff979dfc83e95ba297bc45135
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 code on allocation failure and skips applying the DAMOS scheme indamos_apply_scheme()when splitting a region to fit the remaining size quota fails.Quoted 4 lines
mm/damon/core.c +0
-0[ ... ]
mm/damon/core.c static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, · line 1477
Quoted 10 lines
mm/damon/core.c +2
-1@@ -1470,7 +1470,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 ;[Severity: Low]
Should this return instead of jumping toupdate_statwhendamon_split_region_at()fails?
Quoted 7 lines
At this point sz holds the non-zero aligned remaining quota, and
update_statcallsdamos_update_stat(s, sz, sz_applied), which incrementss->stat.nr_triedand adds sz tos->stat.sz_triedeven though scheme application and filter evaluation were skipped. Becausequota->charged_szis not updated on this error path, persistent allocation failures across subsequent regions larger than the remaining quota will repeatedly add the remaining quota sz tos->stat.sz_triedand increments->stat.nr_tried.
No blocker. The user impact is minor and constrained. Also same issue exists in the mainline. If we want to fix this, we should work on the mainline first.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerRFC PATCH 2/5 mm/damon/paddr: respect folio end for DAMOS actions except STAT
In reply to SJ ParkA 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.
--- mm/damon/paddr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/damon/paddr.c +3 -3
@@ -273,7 +273,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s)else list_add (&folio->lru, &folio_list); put_folio: - addr +=folio_size (folio); + addr =PFN_PHYS (folio_pfn (folio)) +folio_size (folio);folio_put (folio); }if (install_young_filter)
@@ -306,7 +306,7 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(folio_deactivate (folio); applied +=folio_nr_pages (folio); put_folio: - addr +=folio_size (folio); + addr =PFN_PHYS (folio_pfn (folio)) +folio_size (folio);folio_put (folio); }return applied *PAGE_SIZE ;
@@ -483,7 +483,7 @@ static unsigned long damon_pa_migrate(struct damon_region *r, struct damos *s) folio_is_file_lru(folio));list_add (&folio->lru, &folio_list); put_folio: - addr +=folio_size (folio); + addr =PFN_PHYS (folio_pfn (folio)) +folio_size (folio);folio_put (folio); } applied =damon_pa_migrate_pages (&folio_list, s->target_nid);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.12.y 2/5] mm/damon/paddr: respect folio end for DAMOS actions except STAT
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
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.
Quoted 7 lines
The issue was discovered [1] by Sashiko.
Fixes 3a06696305e7 ("mm/damon/ops: have damon_get_folio return folio even for tail pages")Signed-off-by SJ Park <[email protected]>Signed-off-by Andrew Morton <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerRFC PATCH 3/5 mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
In reply to SJ ParkWhen 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. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.
The user impact of the issue is not big, because the issue impacts only the first 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. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Check last_psi_total initialization and skip the tuning round when it is not initialized. For this, initialize last_psi_total with U64_MAX in the goal creation and the goal commit time. U64_MAX means the field is not initialized. The tuning round shows the value and adjusts it to guarantee the current quota is maintained for the round, and last_psi_total is correctly initialized on the next round.
Before this change, committing a new PSI goal on an existing PSI goal with goal-only DAMON sysfs command (commit_schemes_quota_goals) just worked. After this change, the tuning round right after the commit will be unnecessarily skipped, because last_psi_total is unconditionally marked as not initialized in the damos_commit_quota_goal_union(). This is an intended tradeoff for simplicity. Skipping just one round of tuning is no problem. Meanwhile it makes both the code and the behavior simple to understand.
Also update the quota goal commit unit test for changed last_psi_total setup behavior.
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
mm/damon/core.c +10 -2
@@ -324,6 +324,8 @@ struct damos_quota_goal *damos_new_quota_goal(return NULL ; goal->metric = metric; goal->target_value = target_value; +if (metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) + goal->last_psi_total =U64_MAX ;INIT_LIST_HEAD (&goal->list);return goal; }
@@ -705,7 +707,8 @@ static void damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ +else if (dst->metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) + dst->last_psi_total =U64_MAX ; }/**
@@ -1608,7 +1611,12 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)break ;case DAMOS_QUOTA_SOME_MEM_PSI_US : now_psi_total =damos_get_some_mem_psi_total (); - goal->current_value = now_psi_total - goal->last_psi_total; +/* uninitialized last_psi_total; make no effect this round */ +if (goal->last_psi_total ==U64_MAX ) + goal->current_value = goal->target_value; +else + goal->current_value = now_psi_total - + goal->last_psi_total; goal->last_psi_total = now_psi_total;break ;default :
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.12.y 3/5] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.The user impact of the issue is not big, because the issue impacts only the first 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. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Quoted 6 lines
[ ... ]Cc David Gow <[email protected]>Cc Quanmin Yan <[email protected]>Cc <[email protected]> # 6.9.x(cherry picked from commit 29c6084658af41b5b1fefd873d26d441830ced34)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Sasha Levin
maintainerRe: [RFC PATCH 6.12.y 3/5] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
In reply to SJ ParkQuoted 3 lines
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total.
Patches 1, 2, 4 and 5 are queued for 6.12.
This one doesn't apply: 610c4438fb66 ("mm/damon/core: error damos_commit_quota_goal() for zero target_value") is queued for 6.12 and made damos_commit_quota_goal() return int, so the return 0; has to be kept. Please rebase it on the queue and resend.
Signature · 2 lines
Thanks, Sasha
SJ Park
maintainerRe: [RFC PATCH 6.12.y 3/5] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
Quoted 10 lines · On Sun, 8 Nov 2026 19:34:37 -0500 Sasha Levin <[email protected]> wrote:
Quoted 3 lines
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total.Patches 1, 2, 4 and 5 are queued for 6.12.
This one doesn't apply:
610c4438fb66("mm/damon/core: errordamos_commit_quota_goal()for zerotarget_value") is queued for 6.12 and madedamos_commit_quota_goal()return int, so thereturn 0;has to be kept. Please rebase it on the queue and resend.
Thank you, Sasha. I just rebased and posted [1] this one as another thread.
[1] https://lore.kernel.org/[email protected]
Thanks,
SJ
[...]
SJ Park
maintainerRFC PATCH 4/5 mm/damon/core: filter out damos address filter-split failed region
In reply to SJ ParkWhen 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.
--- mm/damon/core.c | 13 +++++++++---- mm/damon/tests/core-kunit.h | 11 ++++++----- 2 files changed, 15 insertions(+), 9 deletions(-)
mm/damon/core.c +9 -4
@@ -1372,13 +1372,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) {
@@ -1404,12 +1405,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 :
@@ -1423,9 +1425,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;
mm/damon/tests/core-kunit.h +6 -5
@@ -527,6 +527,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); f->addr_range = (struct damon_addr_range ){
@@ -537,25 +538,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 );
@@ -570,7 +571,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 );
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.12.y 4/5] mm/damon/core: filter out damos address filter-split failed region
Sashiko has reviewed this patch and found no issues.
Quoted 19 lines
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.
Quoted 8 lines
Fixes ab9bda001b68 ("mm/damon/core: introduce address range type damos filter")Signed-off-by SJ Park <[email protected]>Signed-off-by Andrew Morton <[email protected]>Cc <[email protected]> # 6.6.x(cherry picked from commit bbeec2d8324d7aac438bb12dd2d22b184e0a8d43)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerRFC PATCH 5/5 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
@@ -1686,6 +1686,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 damos_adjust_quota (struct damon_ctx *c,struct damos *s) {struct damos_quota *quota = &s->quota;
@@ -1714,6 +1734,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 ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH 6.12.y 5/5] 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: dangling charge_target_from ABA reuse in damos_adjust_quota() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mm/damon/core: dangling charge_target_from ABA reuse in damos_adjust_quota()
--
commit 6429d6d07b9e92711137f889d5332896002d4342
Author: SJ Park <[email protected]>
mm/damon/core: remove unreachable damos charge_{target,addr}_from
This commit adds damos_fix_stale_charge_pointers() to damos_adjust_quota() to clear quota->charge_target_from and quota->charge_addr_from if the target was removed or has no regions left after a runtime parameter commit.
Quoted 32 lines
mm/damon/core.c +20
-0@@ -1686,6 +1686,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 damos_adjust_quota (struct damon_ctx *c,struct damos *s) {struct damos_quota *quota = &s->quota;
mm/damon/core.c static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) · line 1740
Quoted 7 lines
mm/damon/core.c +2
-0@@ -1714,6 +1734,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 ;
[Severity: Medium]
Can damos_fix_stale_charge_pointers() match a different target if quota->charge_target_from is left dangling until damos_adjust_quota() runs?
When damon_commit_targets() removes a target via damon_destroy_target(), it frees dst_target without clearing quota->charge_target_from, and damon_commit_ctx() then calls damon_set_attrs() -> damos_set_next_apply_sis(), deferring damos_adjust_quota() to a later interval. If a newly committed target reuses the freed slab address before then (or if damon_commit_target() overwrites dst_target in place with a different target), t == quota->charge_target_from matches the new target and leaves the stale charge_target_from and charge_addr_from in place whenever damon_nr_regions(t) > 0, causing damos_skip_charged_region() to skip targets and regions up to the old address.
Clearing charge_target_from and charge_addr_from directly in damon_commit_targets() when a target is destroyed or updated would avoid comparing a dangling pointer later.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
SJ Park
maintainerRe: [RFC PATCH 6.12.y 5/5] mm/damon/core: remove unreachable damos charge_{target,addr}_from
Quoted 73 lines · On Sat, 07 Nov 2026 21:58:17 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium]mm/damon/core: danglingcharge_target_fromABA reuse indamos_adjust_quota()
--commit
6429d6d07b9e92711137f889d5332896002d4342
Author: SJ Park <[email protected]>
mm/damon/core: remove unreachable damos charge_{target,addr}_fromThis commit adds
damos_fix_stale_charge_pointers()todamos_adjust_quota()to clearquota->charge_target_fromandquota->charge_addr_fromif the target was removed or has no regions left after a runtime parameter commit.Quoted 32 lines
mm/damon/core.c +20
-0@@ -1686,6 +1686,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 damos_adjust_quota (struct damon_ctx *c,struct damos *s) {struct damos_quota *quota = &s->quota;mm/damon/core.c static void damos_adjust_quota(struct damon_ctx *c, struct damos *s) · line 1740
Quoted 7 lines
mm/damon/core.c +2
-0@@ -1714,6 +1734,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 ;[Severity: Medium]
Candamos_fix_stale_charge_pointers()match a different target ifquota->charge_target_fromis left dangling untildamos_adjust_quota()runs?When
damon_commit_targets()removes a target viadamon_destroy_target(), it freesdst_targetwithout clearingquota->charge_target_from, anddamon_commit_ctx()then callsdamon_set_attrs()->damos_set_next_apply_sis(), deferringdamos_adjust_quota()to a later interval. If a newly committed target reuses the freed slab address before then (or ifdamon_commit_target()overwritesdst_targetin place with a different target), t ==quota->charge_target_frommatches the new target and leaves the stalecharge_target_fromandcharge_addr_fromin place wheneverdamon_nr_regions(t)> 0, causingdamos_skip_charged_region()to skip targets and regions up to the old address.
Quoted 3 lines
Clearing
charge_target_fromandcharge_addr_fromdirectly indamon_commit_targets()when a target is destroyed or updated would avoid comparing a dangling pointer later.
Good finding, but this is not a blocker of this patch. Occasionally starting quota charging from unexpected target is no real problem for real DAMOS usages.
Quoted 4 lines
Signature · 2 lines
-- Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Thanks,
SJ