Skip to content

Commit c6d68c1

Browse files
compudjIngo Molnar
authored andcommitted
sched/membarrier: Skip IPIs when mm->mm_users == 1
If there is only a single mm_user for the mm, the private expedited membarrier command can skip the IPIs, because only a single thread is using the mm. Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Eric W. Biederman <[email protected]> Cc: Kirill Tkhai <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Russell King - ARM Linux admin <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 19a4ff5 commit c6d68c1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kernel/sched/membarrier.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,21 @@ static int membarrier_private_expedited(int flags)
145145
int cpu;
146146
bool fallback = false;
147147
cpumask_var_t tmpmask;
148+
struct mm_struct *mm = current->mm;
148149

149150
if (flags & MEMBARRIER_FLAG_SYNC_CORE) {
150151
if (!IS_ENABLED(CONFIG_ARCH_HAS_MEMBARRIER_SYNC_CORE))
151152
return -EINVAL;
152-
if (!(atomic_read(&current->mm->membarrier_state) &
153+
if (!(atomic_read(&mm->membarrier_state) &
153154
MEMBARRIER_STATE_PRIVATE_EXPEDITED_SYNC_CORE_READY))
154155
return -EPERM;
155156
} else {
156-
if (!(atomic_read(&current->mm->membarrier_state) &
157+
if (!(atomic_read(&mm->membarrier_state) &
157158
MEMBARRIER_STATE_PRIVATE_EXPEDITED_READY))
158159
return -EPERM;
159160
}
160161

161-
if (num_online_cpus() == 1)
162+
if (atomic_read(&mm->mm_users) == 1 || num_online_cpus() == 1)
162163
return 0;
163164

164165
/*
@@ -194,7 +195,7 @@ static int membarrier_private_expedited(int flags)
194195
continue;
195196
rcu_read_lock();
196197
p = rcu_dereference(cpu_rq(cpu)->curr);
197-
if (p && p->mm == current->mm) {
198+
if (p && p->mm == mm) {
198199
if (!fallback)
199200
__cpumask_set_cpu(cpu, tmpmask);
200201
else

0 commit comments

Comments
 (0)