All of lore.kernel.org
 help / color / mirror / Atom feed
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: Thu, 13 Feb 2025 09:32:49 +0800	[thread overview]
Message-ID: <87tt8y1vem.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <20250212170645.1080771-1-joshua.hahnjy@gmail.com> (Joshua Hahn's message of "Wed, 12 Feb 2025 09:06:40 -0800")

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,
>> 
>> Thanks for your patch and sorry for late reply.
>
> Hi Ying, no worries! Thank you for taking time to review this patch.
>
>> Joshua Hahn <joshua.hahnjy@gmail.com> writes:

[snip]

>> > +
>> > +static ssize_t weighted_interleave_mode_store(struct kobject *kobj,
>> > +		struct kobj_attribute *attr, const char *buf, size_t count)
>> > +{
>> > +	uint64_t *bw;
>> > +	u8 *old_iw, *new_iw;
>> > +
>> > +	if (count == 0)
>> > +		return -EINVAL;
>> > +
>> > +	if (sysfs_streq(buf, "N") || sysfs_streq(buf, "0")) {
>> 
>> kstrtobool() can be used here.  It can deal with 'count == 0' case too.
>
> These kernel string tools are very helpful, thank you for bringing
> them to my attention : -)
>
>> > +		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.

---
Best Regards,
Huang, Ying

  reply	other threads:[~2025-02-13  1:32 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 [this message]
2025-02-14 15:45       ` Joshua Hahn
2025-02-16  0:40         ` Huang, Ying

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=87tt8y1vem.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.