From: "Huang, Ying" <ying.huang@linux.alibaba.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: gourry@gourry.net, hyeonggon.yoo@sk.com, honggyu.kim@sk.com,
akpm@linux-foundation.org, rafael@kernel.org, lenb@kernel.org,
gregkh@linuxfoundation.org, rakie.kim@sk.com,
dan.j.williams@intel.com, Jonathan.Cameron@huawei.com,
dave.jiang@intel.com, horen.chuang@linux.dev,
hannes@cmpxchg.org, linux-kernel@vger.org,
linux-acpi@vger.kernel.org, linux-mm@kvack.org,
kernel-team@meta.com
Subject: Re: [PATCH v5] mm/mempolicy: Weighted Interleave Auto-tuning
Date: Sun, 16 Feb 2025 08:40:23 +0800 [thread overview]
Message-ID: <87wmdq3eo8.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <20250214154557.329912-1-joshua.hahnjy@gmail.com> (Joshua Hahn's message of "Fri, 14 Feb 2025 07:45:48 -0800")
Joshua Hahn <joshua.hahnjy@gmail.com> writes:
> On Thu, 13 Feb 2025 09:32:49 +0800 "Huang, Ying" <ying.huang@linux.alibaba.com> wrote:
>
>> Joshua Hahn <joshua.hahnjy@gmail.com> writes:
>>
>> > On Wed, 12 Feb 2025 10:49:32 +0800 "Huang, Ying" <ying.huang@linux.alibaba.com> wrote:
>> >
>> >> Hi, Joshua,
>> >>
>
> [...snip...]
>
>> >> > + weighted_interleave_auto = false;
>> >> > + return count;
>> >> > + } else if (!sysfs_streq(buf, "Y") && !sysfs_streq(buf, "1")) {
>> >> > + return -EINVAL;
>> >> > + }
>> >> > +
>> >> > + new_iw = kcalloc(nr_node_ids, sizeof(u8), GFP_KERNEL);
>> >> > + if (!new_iw)
>> >> > + return -ENOMEM;
>> >> > +
>> >> > + mutex_lock(&iw_table_lock);
>> >> > + bw = node_bw_table;
>> >> > +
>> >> > + if (!bw) {
>> >> > + mutex_unlock(&iw_table_lock);
>> >> > + kfree(new_iw);
>> >> > + return -ENODEV;
>> >> > + }
>> >> > +
>> >> > + old_iw = rcu_dereference_protected(iw_table,
>> >> > + lockdep_is_held(&iw_table_lock));
>> >> > +
>> >> > + reduce_interleave_weights(bw, new_iw);
>> >> > + rcu_assign_pointer(iw_table, new_iw);
>> >> > + mutex_unlock(&iw_table_lock);
>> >> > +
>> >> > + synchronize_rcu();
>> >> > + kfree(old_iw);
>> >> > +
>> >> > + weighted_interleave_auto = true;
>> >>
>> >> Why assign weighted_interleave_auto after synchronize_rcu()? To reduce
>> >> the race window, it's better to change weighted_interleave_auto and
>> >> iw_table together? Is it better to put them into a data structure and
>> >> change them together always?
>> >>
>> >> struct weighted_interleave_state {
>> >> bool weighted_interleave_auto;
>> >> u8 iw_table[0]
>> >> };
>> >
>> > I see, I think your explanation makes sense. For the first question,
>> > I think your point makes sense, so I will move the updating to be
>> > inside the rcu section.
>> >
>> > As for the combined data structure, I think that this makes sense,
>> > but I have a few thoughts. First, there are some times when we don't
>> > update both of them, like moving from auto --> manual, and whenever
>> > we just update iw_table, we don't need to update the weighted_interleave
>> > auto field. I also have a concern that this might make the code a bit
>> > harder to read, but that is just my humble opinion.
>>
>> I think the overhead is relatively small. With that, we can avoid the
>> inconsistency between weighted_interleave_auto and iw_table[].
>> struct_size() or struct_size_t() family helpers can be used to manage
>> the flexible array at the end of the struct.
>
> That sounds good to me. I don't have any strong opinions about this
> change, so I am happy to combine them into a struct. I just want to
> make sure I am understanding your perspective correctly: what is the
> incosistency between weighted_interleave_auto and iw_table[]?
> If I move the weighted_interleave_auto = true statement inside the
> rcu section, will the inconsistency still be there?
Because weighted_interleave_auto and iw_table are 2 variables, you may
read new weighted_interleave_auto and old iw_table or vice versa. If
we put them into one struct and write/read the pointer to the struct
with rcu_assign_pointer() / rcu_dereference(), we can avoid this.
> Just want to make sure so that I am not missing anything important!
>
> Thank you again for your great feedback. I hope you have a happy Friday!
Thanks!
---
Best Regards,
Huang, Ying
prev parent reply other threads:[~2025-02-16 0:40 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-07 20:13 [PATCH v5] mm/mempolicy: Weighted Interleave Auto-tuning Joshua Hahn
2025-02-08 2:20 ` Andrew Morton
2025-02-08 5:06 ` Joshua Hahn
2025-02-12 0:17 ` Andrew Morton
2025-02-12 15:26 ` Joshua Hahn
2025-02-10 5:36 ` Gregory Price
2025-02-11 0:39 ` Andrew Morton
2025-02-11 2:14 ` Gregory Price
2025-02-08 6:51 ` Oscar Salvador
2025-02-12 15:18 ` Joshua Hahn
2025-02-12 2:49 ` Huang, Ying
2025-02-12 17:06 ` Joshua Hahn
2025-02-13 1:32 ` Huang, Ying
2025-02-14 15:45 ` Joshua Hahn
2025-02-16 0:40 ` Huang, Ying [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmdq3eo8.fsf@DESKTOP-5N7EMDA \
--to=ying.huang@linux.alibaba.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=gourry@gourry.net \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=honggyu.kim@sk.com \
--cc=horen.chuang@linux.dev \
--cc=hyeonggon.yoo@sk.com \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.org \
--cc=linux-mm@kvack.org \
--cc=rafael@kernel.org \
--cc=rakie.kim@sk.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.