mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Fix bug in mm/thrash.c function grab_swap_token()
@ 2007-05-10 12:58 Mika Kukkonen
  2007-05-10 15:26 ` Satyam Sharma
  0 siblings, 1 reply; 2+ messages in thread
From: Mika Kukkonen @ 2007-05-10 12:58 UTC (permalink / raw)
  To: akpm, ashwin.chaugule; +Cc: linux-kernel

Following bug was uncovered by compiling with '-W' flag:

  CC      mm/thrash.o
mm/thrash.c: In function ‘grab_swap_token’:
mm/thrash.c:52: warning: comparison of unsigned expression < 0 is always false

Field token_priority is unsigned, so decrementing first and the checking
is not a good plan. Attached patch (compile tested) reverses the order.

Btw, I'm not sure if likely() makes any sense in this new situation.

Signed-off-by: Mika Kukkonen <mikukkon@iki.fi>

diff --git a/mm/thrash.c b/mm/thrash.c
index 9ef9071..c4c5205 100644
--- a/mm/thrash.c
+++ b/mm/thrash.c
@@ -48,9 +48,8 @@ void grab_swap_token(void)
 		if (current_interval < current->mm->last_interval)
 			current->mm->token_priority++;
 		else {
-			current->mm->token_priority--;
-			if (unlikely(current->mm->token_priority < 0))
-				current->mm->token_priority = 0;
+			if (likely(current->mm->token_priority > 0))
+				current->mm->token_priority--;
 		}
 		/* Check if we deserve the token */
 		if (current->mm->token_priority >


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

* Re: [PATCH] Fix bug in mm/thrash.c function grab_swap_token()
  2007-05-10 12:58 [PATCH] Fix bug in mm/thrash.c function grab_swap_token() Mika Kukkonen
@ 2007-05-10 15:26 ` Satyam Sharma
  0 siblings, 0 replies; 2+ messages in thread
From: Satyam Sharma @ 2007-05-10 15:26 UTC (permalink / raw)
  To: mikukkon; +Cc: akpm, ashwin.chaugule, linux-kernel

On 5/10/07, Mika Kukkonen <mikukkon@miku.homelinux.net> wrote:
> Following bug was uncovered by compiling with '-W' flag:
>
>   CC      mm/thrash.o
> mm/thrash.c: In function 'grab_swap_token':
> mm/thrash.c:52: warning: comparison of unsigned expression < 0 is always false
>
> Field token_priority is unsigned, so decrementing first and the checking
> is not a good plan. Attached patch (compile tested) reverses the order.

Heh, yeah. Actually, decrementing first and then checking < 0 to clamp
to zero is _never_ a good plan. If the original author thought he was
optimizing speed that way, he was clearly mistaken.

> Btw, I'm not sure if likely() makes any sense in this new situation.

Right, if(likely(...)) without an else wouldn't make much sense ...

> Signed-off-by: Mika Kukkonen <mikukkon@iki.fi>
>
> diff --git a/mm/thrash.c b/mm/thrash.c
> index 9ef9071..c4c5205 100644
> --- a/mm/thrash.c
> +++ b/mm/thrash.c
> @@ -48,9 +48,8 @@ void grab_swap_token(void)
>                 if (current_interval < current->mm->last_interval)
>                         current->mm->token_priority++;
>                 else {
> -                       current->mm->token_priority--;
> -                       if (unlikely(current->mm->token_priority < 0))
> -                               current->mm->token_priority = 0;
> +                       if (likely(current->mm->token_priority > 0))
> +                               current->mm->token_priority--;
>                 }
>                 /* Check if we deserve the token */
>                 if (current->mm->token_priority >
>

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

end of thread, other threads:[~2007-05-10 15:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-10 12:58 [PATCH] Fix bug in mm/thrash.c function grab_swap_token() Mika Kukkonen
2007-05-10 15:26 ` Satyam Sharma

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®