mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] sched: there is no need to call switch_mm_irqs_off when sched between two user thread.
@ 2022-05-31 11:56 Ming Wang
  2022-05-31 14:46 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Wang @ 2022-05-31 11:56 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel

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.

Signed-off-by: Ming Wang <wangming01@loongson.cn>
---
 kernel/sched/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 696c649..9d7f6fb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -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(). */
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] sched: there is no need to call switch_mm_irqs_off when sched between two user thread.
  2022-05-31 11:56 [PATCH v1] sched: there is no need to call switch_mm_irqs_off when sched between two user thread Ming Wang
@ 2022-05-31 14:46 ` Peter Zijlstra
  2022-06-01  6:45   ` Ming Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2022-05-31 14:46 UTC (permalink / raw)
  To: Ming Wang
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel

On Tue, May 31, 2022 at 07:56:41PM +0800, Ming Wang wrote:
> 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.
> 
> Signed-off-by: Ming Wang <wangming01@loongson.cn>
> ---
>  kernel/sched/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 696c649..9d7f6fb 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -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).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] sched: there is no need to call switch_mm_irqs_off when sched between two user thread.
  2022-05-31 14:46 ` Peter Zijlstra
@ 2022-06-01  6:45   ` Ming Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Ming Wang @ 2022-06-01  6:45 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Ingo Molnar, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Steven Rostedt, Ben Segall, Mel Gorman,
	Daniel Bristot de Oliveira, Valentin Schneider, linux-kernel


On 2022/5/31 下午10:46, Peter Zijlstra wrote:
> On Tue, May 31, 2022 at 07:56:41PM +0800, Ming Wang wrote:
>> 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.
>>
>> Signed-off-by: Ming Wang <wangming01@loongson.cn>
>> ---
>>   kernel/sched/core.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 696c649..9d7f6fb 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-01  6:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 11:56 [PATCH v1] sched: there is no need to call switch_mm_irqs_off when sched between two user thread Ming Wang
2022-05-31 14:46 ` Peter Zijlstra
2022-06-01  6:45   ` Ming Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®