From: David Hildenbrand <david@redhat.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: gourry@gourry.net, akpm@linux-foundation.org,
harry.yoo@oracle.com, ying.huang@linux.alibaba.com,
honggyu.kim@sk.com, yunjeong.mun@sk.com,
gregkh@linuxfoundation.org, rakie.kim@sk.com, rafael@kernel.org,
lenb@kernel.org, dan.j.williams@intel.com,
Jonathan.Cameron@huawei.com, dave.jiang@intel.com,
horen.chuang@linux.dev, hannes@cmpxchg.org, osalvador@suse.de,
linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-mm@kvack.org, kernel-team@meta.com
Subject: Re: [PATCH v9] mm/mempolicy: Weighted Interleave Auto-tuning
Date: Wed, 21 May 2025 17:40:07 +0200 [thread overview]
Message-ID: <6ce8f663-2bcc-43a0-bbd8-71fc36005e86@redhat.com> (raw)
In-Reply-To: <20250521153730.2196701-1-joshua.hahnjy@gmail.com>
On 21.05.25 17:37, Joshua Hahn wrote:
> On Wed, 21 May 2025 15:04:00 +0200 David Hildenbrand <david@redhat.com> wrote:
>
>> On 20.05.25 16:12, Joshua Hahn wrote:
>
> [...snip...]
>
>> [...]
>>
>>> -static void iw_table_free(void)
>>> +static void wi_state_free(void)
>>> {
>>> - u8 *old;
>>> + struct weighted_interleave_state *old_wi_state;
>>>
>>> - mutex_lock(&iw_table_lock);
>>> - old = rcu_dereference_protected(iw_table,
>>> - lockdep_is_held(&iw_table_lock));
>>> - rcu_assign_pointer(iw_table, NULL);
>>> - mutex_unlock(&iw_table_lock);
>>> + mutex_lock(&wi_state_lock);
>>> +
>>> + old_wi_state = rcu_dereference_protected(wi_state,
>>> + lockdep_is_held(&wi_state_lock));
>>> + if (!old_wi_state) {
>>> + mutex_unlock(&wi_state_lock);
>>> + goto out;
>>> + }
>>>
>>> + rcu_assign_pointer(wi_state, NULL);
>>> + mutex_unlock(&wi_state_lock);
>>
>> Just one nit: if written as:
>>
>> ...
>> rcu_assign_pointer(wi_state, NULL);
>> mutex_unlock(&wi_state_lock);
>>
>> old_wi_state = ...
>> if (old_wi_state) {
>> synchronize_rcu();
>> kfree(old_wi_state);
>> }
>> kfree(&wi_group->wi_kobj);
>>
>> You can easily avoid the goto.
>
> Ah I see, thank you for the suggestion!
> I think we would have to move the "old_wi_state = ..." to be inside
> the lock and before the rcu_assign_pointer since wi_state will be
> NULL at that point if we do not, but other than that, I think this
> is a great optimization over the version I have : -)
>
> I will send in a fix patch for this later as a cleanup patch, if
> that sounds good with you!
Sure, you can do a cleanup on top.
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-05-21 15:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 14:12 [PATCH v9] mm/mempolicy: Weighted Interleave Auto-tuning Joshua Hahn
2025-05-20 17:53 ` Andrew Morton
2025-05-20 18:11 ` Joshua Hahn
2025-05-20 18:37 ` Andrew Morton
2025-05-20 19:00 ` Joshua Hahn
2025-05-21 13:04 ` David Hildenbrand
2025-05-21 15:37 ` Joshua Hahn
2025-05-21 15:40 ` David Hildenbrand [this message]
2025-05-21 13:38 ` Oscar Salvador
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=6ce8f663-2bcc-43a0-bbd8-71fc36005e86@redhat.com \
--to=david@redhat.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=harry.yoo@oracle.com \
--cc=honggyu.kim@sk.com \
--cc=horen.chuang@linux.dev \
--cc=joshua.hahnjy@gmail.com \
--cc=kernel-team@meta.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osalvador@suse.de \
--cc=rafael@kernel.org \
--cc=rakie.kim@sk.com \
--cc=ying.huang@linux.alibaba.com \
--cc=yunjeong.mun@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox