linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@linux.alibaba.com>
To: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	 Gregory Price <gourry@gourry.net>,
	 David Hildenbrand <david@redhat.com>,  Zi Yan <ziy@nvidia.com>,
	 Matthew Brost <matthew.brost@intel.com>,
	 Rakie Kim <rakie.kim@sk.com>,  Byungchul Park <byungchul@sk.com>,
	 Alistair Popple <apopple@nvidia.com>,
	 linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH 2/2] mm/mempolicy: Skip unnecessary synchronize_rcu()
Date: Tue, 03 Jun 2025 10:10:46 +0800	[thread overview]
Message-ID: <87h60xtw0p.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <20250602162345.2595696-2-joshua.hahnjy@gmail.com> (Joshua Hahn's message of "Mon, 2 Jun 2025 09:23:40 -0700")

Joshua Hahn <joshua.hahnjy@gmail.com> writes:

> By unconditionally setting wi_state to NULL and conditionally calling
> synchronize_rcu(), we can save an unncessary call when there is no
> old_wi_state.

Per my understanding, in the original code, if !old_wi_state, we will
return immediately instead of calling synchronize_rcu() too.  Or I miss
something?

The patch itself is a nice cleanup with reduced line number.  Feel free
to add my

Reviewed-by: Huang Ying <ying.huang@linux.alibaba.com>

in the future version.

> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Joshua Hahn <joshua.hahnjy@gmail.com>
> ---
>  mm/mempolicy.c | 13 +++++--------
>  1 file changed, 5 insertions(+), 8 deletions(-)
>
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 3b1dfd08338b..b0619d0020c9 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -3703,18 +3703,15 @@ static void wi_state_free(void)
>  	struct weighted_interleave_state *old_wi_state;
>  
>  	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);
> -		return;
> -	}
> -
>  	rcu_assign_pointer(wi_state, NULL);
>  	mutex_unlock(&wi_state_lock);
> -	synchronize_rcu();
> -	kfree(old_wi_state);
> +
> +	if (old_wi_state) {
> +		synchronize_rcu();
> +		kfree(old_wi_state);
> +	}
>  }
>  
>  static struct kobj_attribute wi_auto_attr =

---
Best Regards,
Huang, Ying


  reply	other threads:[~2025-06-03  2:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-02 16:23 [PATCH 1/2] mm/mempolicy: Fix incorrect freeing of wi_kobj Joshua Hahn
2025-06-02 16:23 ` [PATCH 2/2] mm/mempolicy: Skip unnecessary synchronize_rcu() Joshua Hahn
2025-06-03  2:10   ` Huang, Ying [this message]
2025-06-03 14:31     ` Joshua Hahn
2025-06-02 16:53 ` [PATCH 1/2] mm/mempolicy: Fix incorrect freeing of wi_kobj Joshua Hahn

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=87h60xtw0p.fsf@DESKTOP-5N7EMDA \
    --to=ying.huang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=david@redhat.com \
    --cc=gourry@gourry.net \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.brost@intel.com \
    --cc=rakie.kim@sk.com \
    --cc=ziy@nvidia.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