mm/damon/vaddr: preserve migration weights above UINT_MAX
Subsystems (2)
PATCH 1/1 mm/damon/vaddr: preserve migration weights above UINT_MAX
DAMOS migration accepts an unsigned int weight for each destination, but sums the weights into an unsigned int. If the total wraps to zero, no folio is migrated. Other wrapped totals select the wrong node.
Sum weights into a u64 once per migration walk. Keep the existing 32-bit divisor path for totals up to UINT_MAX and use a 64-bit remainder for larger totals. Add KUnit coverage for the actual summing path and for destination selection at the overflow boundary.
--- mm/damon/tests/vaddr-kunit.h | 35 +++++++++++++++++++ mm/damon/vaddr.c | 65 +++++++++++++++++++++++------------- 2 files changed, 77 insertions(+), 23 deletions(-)
mm/damon/tests/vaddr-kunit.h +35 -0
@@ -266,12 +266,47 @@ static void damon_test_apply_three_regions4(struct kunit *test) new_three_regions, expected, ARRAY_SIZE(expected)); } +static void damon_test_migrate_dests_idx (struct kunit *test) +{ +unsigned int weights[] = {UINT_MAX ,1 }; +struct damos_migrate_dests dests = { + .weight_arr = weights, + .nr_dests =ARRAY_SIZE (weights), + }; +u64 total =damos_va_migrate_weight_total (&dests); + +KUNIT_EXPECT_EQ (test, total, (u64 )UINT_MAX +1 ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests,0 , total),0 ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests, +UINT_MAX , total),1 ); + + weights[1 ] =2 ; + total =damos_va_migrate_weight_total (&dests); +KUNIT_EXPECT_EQ (test, total, (u64 )UINT_MAX +2 ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests, +UINT_MAX , total),1 ); + + weights[0 ] =0 ; + weights[1 ] =0 ; + total =damos_va_migrate_weight_total (&dests); +KUNIT_EXPECT_EQ (test, total,0ULL ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests,0 , total),-1 ); + + weights[0 ] =1 ; + weights[1 ] =3 ; + total =damos_va_migrate_weight_total (&dests); +KUNIT_EXPECT_EQ (test, total,4ULL ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests,1 , total),1 ); +KUNIT_EXPECT_EQ (test,damos_va_migrate_dests_idx (&dests,4 , total),0 ); +} +static struct kunit_case damon_test_cases[] = {KUNIT_CASE (damon_test_three_regions_in_vmas),KUNIT_CASE (damon_test_apply_three_regions1),KUNIT_CASE (damon_test_apply_three_regions2),KUNIT_CASE (damon_test_apply_three_regions3),KUNIT_CASE (damon_test_apply_three_regions4), +KUNIT_CASE (damon_test_migrate_dests_idx), {}, };
mm/damon/vaddr.c +42 -23
127 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 11 lines
DAMOS migration accepts an unsigned int weight for each destination, but sums the weights into an unsigned int. If the total wraps to zero, no folio is migrated. Other wrapped totals select the wrong node.
Sum weights into a u64 once per migration walk. Keep the existing 32-bit divisor path for totals up to
UINT_MAXand use a 64-bit remainder for larger totals. Add KUnit coverage for the actual summing path and for destination selection at the overflow boundary.Fixes 19c1dc15c859 ("mm/damon/vaddr: use damos->migrate_dests in migrate_{hot,cold}")Signed-off-by Daemyung Kang <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi Daemyung,
Quoted 3 lines · On Tue, 27 Oct 2026 12:54:31 +0900 Daemyung Kang wrote:
Sum weights into a u64 once per migration walk. Keep the existing 32-bit divisor path for totals up to
UINT_MAXand use a 64-bit remainder for larger totals.
Tested locally. Looks good to me :)
Tested in an x86_64 QEMU guest; both the buggy and corrected behavior were verified.
Thanks,
Aveline Noir
SJ Park
maintainerHello Daemyung,
Quoted 3 lines · On Tue, 27 Oct 2026 12:54:31 +0900 Daemyung Kang <[email protected]> wrote:
DAMOS migration accepts an unsigned int weight for each destination, but sums the weights into an unsigned int. If the total wraps to zero, no folio is migrated. Other wrapped totals select the wrong node.
Thank you for finding the issue.
But, is it realistic to have the weight_total overflow? Have you found the issue on real usage? Or, theoretical?
Quoted 5 lines
Sum weights into a u64 once per migration walk. Keep the existing 32-bit divisor path for totals up to
UINT_MAXand use a 64-bit remainder for larger totals. Add KUnit coverage for the actual summing path and for destination selection at the overflow boundary.
Do we really need to support that user inputs? Unless we have a very real use case that require such huge weight values, I'd prefer not.
How about just clearly notify users those are invalid parameters? We could do so by adding weight_total overflow check to the central parameters validation
path: damos_commit_dests().
Quoted 2 lines
Fixes 19c1dc15c859 ("mm/damon/vaddr: use damos->migrate_dests in migrate_{hot,cold}")
Should we Cc: stable?
Thanks,
SJ
[...]
Hi, SJ.
Thanks for your reply.
1. I found this by code inspection, not from a real-world bug report. I consider it a correctness issue for valid inputs.
2. I would prefer a u64 total over rejecting those inputs, since the interface does not document a limit on the sum of weights.
3. Given the lack of a reported real-world impact, I do not think Cc:
stable is needed.
Thanks.
Daemyung
2026년 10월 27일 (화) 오후 10:54, SJ Park <[email protected]>님이 작성:
Quoted 37 lines
Hello Daemyung,
Quoted 3 lines · On Tue, 27 Oct 2026 12:54:31 +0900 Daemyung Kang <[email protected]> wrote:
DAMOS migration accepts an unsigned int weight for each destination, but sums the weights into an unsigned int. If the total wraps to zero, no folio is migrated. Other wrapped totals select the wrong node.
Thank you for finding the issue.
But, is it realistic to have the
weight_totaloverflow? Have you found the issue on real usage? Or, theoretical?Quoted 5 lines
Sum weights into a u64 once per migration walk. Keep the existing 32-bit divisor path for totals up to
UINT_MAXand use a 64-bit remainder for larger totals. Add KUnit coverage for the actual summing path and for destination selection at the overflow boundary.Do we really need to support that user inputs? Unless we have a very real use case that require such huge weight values, I'd prefer not.
How about just clearly notify users those are invalid parameters? We could do so by adding
weight_totaloverflow check to the central parameters validation
path:damos_commit_dests().Quoted 2 lines
Fixes 19c1dc15c859 ("mm/damon/vaddr: use damos->migrate_dests in migrate_{hot,cold}")Should we Cc: stable?
Thanks,
SJ[...]
SJ Park
maintainerApparently Bijan's micron email is no more working. I added Bijan's gmail to Cc list.
Quoted 3 lines · On Wed, 28 Oct 2026 08:57:06 +0900 CharSyam <[email protected]> wrote:
Hi, SJ.
Thanks for your reply.
You're welcome!
Quoted 3 lines
1. I found this by code inspection, not from a real-world bug report. I consider it a correctness issue for valid inputs.
Thank you for clarifying.
Quoted 2 lines
2. I would prefer a u64 total over rejecting those inputs, since the interface does not document a limit on the sum of weights.
But I doubt the value of documenting it. I wonder if real users will find the behavior at all. I think it would be not too late to consider documenting it after we get an issue report from a real world user.
Even just keeping the current behavior looks not really bad to me, as long as it is easy to test and only shoot the foot of users who didn't run test for their weird inputs. We can revisit after a real issue report is delivered.
What do you think?
Quoted 2 lines
3. Given the lack of a reported real-world impact, I do not think Cc:
stable is needed.
Makes sense, I agree.
Please avoid top-posting [1] from the next time.
[1] https://subspace.kernel.org/etiquette.html#do-not-top-post-when-replying
Thanks,
SJ
[...]
Hi, SJ
Quoted 5 lines
Even just keeping the current behavior looks not really bad to me, as long as it is easy to test and only shoot the foot of users who didn't run test for their weird inputs. We can revisit after a real issue report is delivered.
What do you think?
I agree. This is a correctness issue, but I am not aware of any
real-world impact,
so I do not think it needs to be fixed now. We can revisit it if a user reports a problem.
Quoted 1 line
Please avoid top-posting [1] from the next time.
Sorry about that. I will reply inline from now on.
Thanks,
Daemyung
SJ Park
maintainerQuoted 6 lines · On Wed, 28 Oct 2026 23:44:28 +0900 CharSyam <[email protected]> wrote:
Hi, SJ
Quoted 4 lines
Even just keeping the current behavior looks not really bad to me, as long as it is easy to test and only shoot the foot of users who didn't run test for their weird inputs. We can revisit after a real issue report is delivered.
Quoted 6 lines
Quoted 1 line
What do you think?
I agree. This is a correctness issue, but I am not aware of any
real-world impact,
so I do not think it needs to be fixed now. We can revisit it if a user reports a problem.
I agree, let's do so. I will consider adding the input validity check with low priority, since it might help us getting a real issue report sooner.
Quoted 4 lines
Quoted 2 lines
Please avoid top-posting [1] from the next time.
Sorry about that. I will reply inline from now on.
No worries!
Thanks,
SJ
[...]