sched: core: Simplify init_sched_mm_cid()

Message ID 20230507023352.2784-1-kunyu@nfschina.com
State New
Headers
Series sched: core: Simplify init_sched_mm_cid() |

Commit Message

Li kunyu May 7, 2023, 2:33 a.m. UTC
  int mm_users variable definition move to variable usage location.

Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
 kernel/sched/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Steven Rostedt May 7, 2023, 2:04 a.m. UTC | #1
On Sun,  7 May 2023 10:33:52 +0800
Li kunyu <kunyu@nfschina.com> wrote:

> int mm_users variable definition move to variable usage location.

Why?

> 
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
>  kernel/sched/core.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index f341e2100304..a66960da3f5c 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -11910,10 +11910,9 @@ static void task_mm_cid_work(struct callback_head *work)
>  void init_sched_mm_cid(struct task_struct *t)
>  {
>  	struct mm_struct *mm = t->mm;
> -	int mm_users = 0;
>  
>  	if (mm) {
> -		mm_users = atomic_read(&mm->mm_users);
> +		int mm_users = atomic_read(&mm->mm_users);

This is not a requirement, and not everyone prefers this method.

If anything, a real cleanup would simply be to remove the "= 0" and
just have it be:

	int mm_users;

As there's no reason to initialize it to zero.

-- Steve

>  		if (mm_users == 1)
>  			mm->mm_cid_next_scan = jiffies + msecs_to_jiffies(MM_CID_SCAN_DELAY);
>  	}
  

Patch

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f341e2100304..a66960da3f5c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -11910,10 +11910,9 @@  static void task_mm_cid_work(struct callback_head *work)
 void init_sched_mm_cid(struct task_struct *t)
 {
 	struct mm_struct *mm = t->mm;
-	int mm_users = 0;
 
 	if (mm) {
-		mm_users = atomic_read(&mm->mm_users);
+		int mm_users = atomic_read(&mm->mm_users);
 		if (mm_users == 1)
 			mm->mm_cid_next_scan = jiffies + msecs_to_jiffies(MM_CID_SCAN_DELAY);
 	}