[patch] Re: elevator algorithm bug in ll_rw_blk.c

MOLNAR Ingo (mingo@chiara.csoma.elte.hu)
Thu, 12 Nov 1998 03:39:28 +0100 (CET)


On Wed, 11 Nov 1998, Philip Gladstone wrote:

> Ah. All this induced me to stare at the code. It turns out that
> there *is* a bug.
>
> It turns out that a new request which is added which should go
> at the end of the current elevator pass (once we have a new
> pass being built) currently goes to the end of the second pass.
>
> I.e. if you have a queue: 10 20 5 and you insert 25, then
> you should get 10 20 25 5 and not 10 20 5 25 as currently.

nicely spotted ... unless i'm missing something, this was probably one of
the oldest Linux bugs :) the attached patch fixes it. (it's against
2.1.127, and it's tested with heavy IO load)

-- mingo

--- linux/drivers/block/ll_rw_blk.c.orig2 Thu Nov 12 03:46:18 1998
+++ linux/drivers/block/ll_rw_blk.c Thu Nov 12 04:42:15 1998
@@ -362,10 +362,16 @@
goto out;
}
for ( ; tmp->next ; tmp = tmp->next) {
- if ((IN_ORDER(tmp,req) ||
- !IN_ORDER(tmp,tmp->next)) &&
- IN_ORDER(req,tmp->next))
- break;
+ const int after_current = IN_ORDER(tmp,req);
+ const int before_next = IN_ORDER(req,tmp->next);
+
+ if (!IN_ORDER(tmp,tmp->next)) {
+ if (after_current || before_next)
+ break;
+ } else {
+ if (after_current && before_next)
+ break;
+ }
}
req->next = tmp->next;
tmp->next = req;

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/