sched: there is no need to call switch_mm_irqs_off when sched between two user thread.
PATCH 1/1 sched: there is no need to call switch_mm_irqs_off when sched between two user thread.
When condition (prev->active_mm == next->mm && !prev->mm) is met, the situation is as follows:
user thread -> user thread
There is not need switch_mm when sched between two user thread. Because they share the mm_struct. This can provide better performance when testing UnixBench.
--- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/sched/core.c +2 -1
@@ -5099,7 +5099,8 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)* case 'prev->active_mm == next->mm' through * finish_task_switch()'s mmdrop(). */ -switch_mm_irqs_off (prev->active_mm, next->mm, next); +if ((prev->active_mm != next->mm) || (!prev->mm)) +switch_mm_irqs_off (prev->active_mm, next->mm, next);if (!prev->mm) {// from kernel /* will mmdrop() in finish_task_switch(). */
Signature · 1 line
1.8.3.1
Peter Zijlstra
maintainerQuoted 19 lines · Ming Wang
When condition (
prev->active_mm==next->mm&& !prev->mm) is met, the situation is as follows:user thread -> user thread
There is not need
switch_mmwhen sched between two user thread. Because they share themm_struct. This can provide better performance when testing UnixBench.Signed-off-by Ming Wang <[email protected]>--- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/sched/core.c +0
-0
kernel/sched/core.c asmlinkage __visible void schedule_tail(struct task_struct *prev) · line 5103
Quoted 6 lines
kernel/sched/core.c +2
-1@@ -5099,7 +5099,8 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)* case 'prev->active_mm == next->mm' through * finish_task_switch()'s mmdrop(). */ -switch_mm_irqs_off (prev->active_mm, next->mm, next); +if ((prev->active_mm != next->mm) || (!prev->mm)) +switch_mm_irqs_off (prev->active_mm, next->mm, next);
I think this needs to be inside switch_mm(). Architectures are free to play silly games with what the current active mm is (and iirc x86 actually does this).
Quoted 15 lines · Peter Zijlstra
Quoted 14 lines · Ming Wang
When condition (
prev->active_mm==next->mm&& !prev->mm) is met, the situation is as follows:user thread -> user thread
There is not need
switch_mmwhen sched between two user thread. Because they share themm_struct. This can provide better performance when testing UnixBench.Signed-off-by Ming Wang <[email protected]>--- kernel/sched/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
kernel/sched/core.c asmlinkage __visible void schedule_tail(struct task_struct *prev) · line 5103
Quoted 11 lines
kernel/sched/core.c +2
-1@@ -5099,7 +5099,8 @@ asmlinkage __visible void schedule_tail(struct task_struct *prev)* case 'prev->active_mm == next->mm' through * finish_task_switch()'s mmdrop(). */ -switch_mm_irqs_off (prev->active_mm, next->mm, next); +if ((prev->active_mm != next->mm) || (!prev->mm)) +switch_mm_irqs_off (prev->active_mm, next->mm, next);I think this needs to be inside
switch_mm(). Architectures are free to play silly games with what the current active mm is (and iirc x86 actually does this).
ok, thanks! And I will do it in architecture code.