From: Joshua Hahn Date: Mon, 2 Jun 2025 16:23:40 +0000 (-0700) Subject: mm/mempolicy: skip unnecessary synchronize_rcu() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ec8a6e30e9c4ad06ea5e94536623c59c4ae2400;p=thirdparty%2Fkernel%2Flinux.git mm/mempolicy: skip unnecessary synchronize_rcu() 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. Link: https://lkml.kernel.org/r/20250602162345.2595696-2-joshua.hahnjy@gmail.com Signed-off-by: Joshua Hahn Suggested-by: David Hildenbrand Reviewed-by: Huang Ying Cc: Alistair Popple Cc: Byungchul Park Cc: Gregory Price Cc: "Huang, Ying" Cc: kernel test robot Cc: Mathew Brost Cc: Rakie Kim Cc: Zi Yan Signed-off-by: Andrew Morton --- diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3b1dfd08338bd..b0619d0020c93 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 =