diff options
| author | Joshua Hahn <joshua.hahnjy@gmail.com> | 2025-06-02 09:23:40 -0700 | 
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2025-07-09 22:42:02 -0700 | 
| commit | 1ec8a6e30e9c4ad06ea5e94536623c59c4ae2400 (patch) | |
| tree | e0517ccb2f8938ed77d418d4426b1e6b7d970cb6 /mm/mempolicy.c | |
| parent | 1e6b17b4237dacb02e9cfeaed35d889bbc9e8a84 (diff) | |
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 <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>
Diffstat (limited to 'mm/mempolicy.c')
| -rw-r--r-- | mm/mempolicy.c | 13 | 
1 files 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 = | 
