Skip to contentSkip to conversation

block: fix request sorting at unplug

PATCH In review Konstantin Khlebnikov 2 participants 2 messages Apr 2, 2011 – Apr 3, 2011 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: fix request sorting at unplug

Comparison function for list_sort() must be anticommutative, otherwise it is not sorting in ordinary meaning.

But fortunately list_sort() always check ((*cmp)(priv, a, b) <= 0) it not distinguish negative and zero, so comparison function can implement only less-or-equal instead of full three-way comparison.

---
 block/blk-core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block/blk-core.c +1 -1
index e0a0623..5e151d2 100644
@@ -2665,7 +2665,7 @@ static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
 	struct request *rqa = container_of(a, struct request, queuelist);
 	struct request *rqb = container_of(b, struct request, queuelist);
 
-	return !(rqa->q == rqb->q);
+	return !(rqa->q <= rqb->q);
 }
 
 static void flush_plug_list(struct blk_plug *plug)
maintainer
#1 lore raw
Quoted 6 lines · Konstantin Khlebnikov

Comparison function for list_sort() must be anticommutative, otherwise it is not sorting in ordinary meaning.

But fortunately list_sort() always check ((*cmp)(priv, a, b) <= 0) it not distinguish negative and zero, so comparison function can implement only less-or-equal instead of full three-way comparison.

Thanks, good catch! It's an optimization, so no breakage. But if you end up often having > 1 queue plugged, it's a good optimization.

Signature · 1 line
Jens Axboe