]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/mempolicy: skip unnecessary synchronize_rcu()
authorJoshua Hahn <joshua.hahnjy@gmail.com>
Mon, 2 Jun 2025 16:23:40 +0000 (09:23 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 10 Jul 2025 05:42:02 +0000 (22:42 -0700)
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 <joshua.hahnjy@gmail.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Huang Ying <ying.huang@linux.alibaba.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: kernel test robot <lkp@intel.com>
Cc: Mathew Brost <matthew.brost@intel.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mempolicy.c

index 3b1dfd08338bd322c6d71fff8dd0715d3a0006ba..b0619d0020c93af7b240c8170a636cd3871fdd00 100644 (file)
@@ -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 =