Skip to content

Commit

Permalink
cfq-iosched: limit coop preemption
Browse files Browse the repository at this point in the history
CFQ has an optimization for cooperated applications. if several
io-context have close requests, they will get boost. But the
optimization get abused. Considering thread a, b, which work on one
file. a reads sectors s, s+2, s+4, ...; b reads sectors s+1, s+3, s
+5, ... Both a and b are sequential read, so they can open idle window.
a reads a sector s and goes to idle window and wakeup b. b reads sector
s+1, since in current implementation, cfq_should_preempt() thinks a and
b are cooperators, b will preempt a. b then reads sector s+1 and goes to
idle window and wakeup a. for the same reason, a will preempt b and
reads s+2. a and b will continue the circle. The circle will be very
long, and a and b will occupy whole disk queue. Other applications will
nearly have no chance to run.

Fix this limiting coop preempt until a queue is scheduled normally
again.

Signed-off-by: Shaohua Li <[email protected]>
Acked-by: Jeff Moyer <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Shaohua Li authored and Jens Axboe committed Nov 3, 2009
1 parent e6ec4fe commit 4b27e1b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions block/cfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ enum cfqq_state_flags {
CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */
CFQ_CFQQ_FLAG_sync, /* synchronous queue */
CFQ_CFQQ_FLAG_coop, /* has done a coop jump of the queue */
CFQ_CFQQ_FLAG_coop_preempt, /* coop preempt */
};

#define CFQ_CFQQ_FNS(name) \
Expand All @@ -222,6 +223,7 @@ CFQ_CFQQ_FNS(prio_changed);
CFQ_CFQQ_FNS(slice_new);
CFQ_CFQQ_FNS(sync);
CFQ_CFQQ_FNS(coop);
CFQ_CFQQ_FNS(coop_preempt);
#undef CFQ_CFQQ_FNS

#define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
Expand Down Expand Up @@ -945,10 +947,13 @@ static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
{
if (!cfqq) {
cfqq = cfq_get_next_queue(cfqd);
if (cfqq)
if (cfqq && !cfq_cfqq_coop_preempt(cfqq))
cfq_clear_cfqq_coop(cfqq);
}

if (cfqq)
cfq_clear_cfqq_coop_preempt(cfqq);

__cfq_set_active_queue(cfqd, cfqq);
return cfqq;
}
Expand Down Expand Up @@ -2066,8 +2071,16 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
* if this request is as-good as one we would expect from the
* current cfqq, let it preempt
*/
if (cfq_rq_close(cfqd, rq))
if (cfq_rq_close(cfqd, rq) && (!cfq_cfqq_coop(new_cfqq) ||
cfqd->busy_queues == 1)) {
/*
* Mark new queue coop_preempt, so its coop flag will not be
* cleared when new queue gets scheduled at the very first time
*/
cfq_mark_cfqq_coop_preempt(new_cfqq);
cfq_mark_cfqq_coop(new_cfqq);
return true;
}

return false;
}
Expand Down

0 comments on commit 4b27e1b

Please sign in to comment.