Skip to content

Commit 796d511

Browse files
JeffMoyerJens Axboe
authored andcommitted
iosched: prevent aliased requests from starving other I/O
Hi, Jens, If you recall, I posted an RFC patch for this back in July of last year: http://lkml.org/lkml/2010/7/13/279 The basic problem is that a process can issue a never-ending stream of async direct I/Os to the same sector on a device, thus starving out other I/O in the system (due to the way the alias handling works in both cfq and deadline). The solution I proposed back then was to start dispatching from the fifo after a certain number of aliases had been dispatched. Vivek asked why we had to treat aliases differently at all, and I never had a good answer. So, I put together a simple patch which allows aliases to be added to the rb tree (it adds them to the right, though that doesn't matter as the order isn't guaranteed anyway). I think this is the preferred solution, as it doesn't break up time slices in CFQ or batches in deadline. I've tested it, and it does solve the starvation issue. Let me know what you think. Cheers, Jeff Signed-off-by: Jeff Moyer <jmoyer@redhat.com> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 1fa7b6a commit 796d511

4 files changed

Lines changed: 6 additions & 16 deletions

File tree

‎block/cfq-iosched.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,16 +1501,11 @@ static void cfq_add_rq_rb(struct request *rq)
15011501
{
15021502
struct cfq_queue *cfqq = RQ_CFQQ(rq);
15031503
struct cfq_data *cfqd = cfqq->cfqd;
1504-
struct request *__alias, *prev;
1504+
struct request *prev;
15051505

15061506
cfqq->queued[rq_is_sync(rq)]++;
15071507

1508-
/*
1509-
* looks a little odd, but the first insert might return an alias.
1510-
* if that happens, put the alias on the dispatch list
1511-
*/
1512-
while ((__alias = elv_rb_add(&cfqq->sort_list, rq)) != NULL)
1513-
cfq_dispatch_insert(cfqd->queue, __alias);
1508+
elv_rb_add(&cfqq->sort_list, rq);
15141509

15151510
if (!cfq_cfqq_on_rr(cfqq))
15161511
cfq_add_cfqq_rr(cfqd, cfqq);

‎block/deadline-iosched.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ static void
7777
deadline_add_rq_rb(struct deadline_data *dd, struct request *rq)
7878
{
7979
struct rb_root *root = deadline_rb_root(dd, rq);
80-
struct request *__alias;
8180

82-
while (unlikely(__alias = elv_rb_add(root, rq)))
83-
deadline_move_request(dd, __alias);
81+
elv_rb_add(root, rq);
8482
}
8583

8684
static inline void

‎block/elevator.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ static struct request *elv_rqhash_find(struct request_queue *q, sector_t offset)
353353
* RB-tree support functions for inserting/lookup/removal of requests
354354
* in a sorted RB tree.
355355
*/
356-
struct request *elv_rb_add(struct rb_root *root, struct request *rq)
356+
void elv_rb_add(struct rb_root *root, struct request *rq)
357357
{
358358
struct rb_node **p = &root->rb_node;
359359
struct rb_node *parent = NULL;
@@ -365,15 +365,12 @@ struct request *elv_rb_add(struct rb_root *root, struct request *rq)
365365

366366
if (blk_rq_pos(rq) < blk_rq_pos(__rq))
367367
p = &(*p)->rb_left;
368-
else if (blk_rq_pos(rq) > blk_rq_pos(__rq))
368+
else if (blk_rq_pos(rq) >= blk_rq_pos(__rq))
369369
p = &(*p)->rb_right;
370-
else
371-
return __rq;
372370
}
373371

374372
rb_link_node(&rq->rb_node, parent, p);
375373
rb_insert_color(&rq->rb_node, root);
376-
return NULL;
377374
}
378375
EXPORT_SYMBOL(elv_rb_add);
379376

‎include/linux/elevator.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ extern struct request *elv_rb_latter_request(struct request_queue *, struct requ
146146
/*
147147
* rb support functions.
148148
*/
149-
extern struct request *elv_rb_add(struct rb_root *, struct request *);
149+
extern void elv_rb_add(struct rb_root *, struct request *);
150150
extern void elv_rb_del(struct rb_root *, struct request *);
151151
extern struct request *elv_rb_find(struct rb_root *, sector_t);
152152

0 commit comments

Comments
 (0)