Re: [RFC PATCH v2 2/2] mm/damon/paddr: Allow multiple migrate targets
From: Bijan Tabatabai
Date: Mon Jun 23 2025 - 10:27:37 EST
On Sat, Jun 21, 2025 at 1:11 PM SeongJae Park <sj@xxxxxxxxxx> wrote:
>
> On Sat, 21 Jun 2025 11:02:15 -0700 SeongJae Park <sj@xxxxxxxxxx> wrote:
>
> [...]
> > I'd hence suggest to implement and use a simple weights handling mechanism
> > here. It could be roud-robin way, like weighted interleaving, or probabilistic
> > way, using damon_rand().
> >
> > The round-robin way may be simpler in my opinion. For example,
> >
> > unsigned int damos_pa_nid_to_migrate(struct damos_migrate_dest *dest)
> > {
> > static unsigned int nr_migrated = 0;
> > unsigned int total_weight = 0;
> > unsigned int weights_to_ignore;
> > size_t i;
> >
> > for (i = 0; i < dest->nr_dests; i++)
> > total_weight += dest->weight_arr[i];
> > weights_to_ignore = nr_migrate++ % total_weight;
>
> Actually, probabilistic way may be not that complicated. Maybe we could to
> below here.
>
> return damon_rand(0, total_weight) >= weight_to_ignore;
>
> > total_weight = 0;
> > for (i = 0; i < dest->nr_dests; i++) {
> > total_weight += dest->weight_arr[i];
> > if (total_weight >= weights_to_ignore)
> > return dest->node_id_arr[i];
> > }
> > WARN_ON_ONCE(1, "I don't know what I did wrong");
> > return 0;
> > }
>
> But damon_rand() might be more expensive than the roud-robin way, and arguably
> roud-robin way is what usrs who familiar with weighted interleaving may easily
> expect and even prefer? I have no preferrence here.
I think my comments about the round-robin approach also apply here,
but all things equal, I generally prefer being deterministic over
being probabilistic when possible.
Bijan
[...]