diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2006-12-20 11:04:12 +0100 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2006-12-20 11:04:12 +0100 |
commit | da775265021b61d5eb81df155e36cb0810f6df53 (patch) | |
tree | f7b28991b281a8c581bd3ab0bb470e158ae2206f /block/cfq-iosched.c | |
parent | 8e5cfc45e7527eb5c8a9a22d56a7b9227e7c0913 (diff) | |
download | linux-da775265021b61d5eb81df155e36cb0810f6df53.tar.bz2 |
[PATCH] cfq-iosched: don't allow sync merges across queues
Currently we allow any merge, even if the io originates from different
processes. This can cause really bad starvation and unfairness, if those
ios happen to be synchronous (reads or direct writes).
So add a allow_merge hook to the io scheduler ops, so an io scheduler can
help decide whether a bio/process combination may be merged with an
existing request.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'block/cfq-iosched.c')
-rw-r--r-- | block/cfq-iosched.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 533a2938ffd6..9fc5eafa6c0e 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c @@ -568,6 +568,38 @@ cfq_merged_requests(request_queue_t *q, struct request *rq, cfq_remove_request(next); } +static int cfq_allow_merge(request_queue_t *q, struct request *rq, + struct bio *bio) +{ + struct cfq_data *cfqd = q->elevator->elevator_data; + const int rw = bio_data_dir(bio); + struct cfq_queue *cfqq; + pid_t key; + + /* + * If bio is async or a write, always allow merge + */ + if (!bio_sync(bio) || rw == WRITE) + return 1; + + /* + * bio is sync. if request is not, disallow. + */ + if (!rq_is_sync(rq)) + return 0; + + /* + * Ok, both bio and request are sync. Allow merge if they are + * from the same queue. + */ + key = cfq_queue_pid(current, rw, 1); + cfqq = cfq_find_cfq_hash(cfqd, key, current->ioprio); + if (cfqq != RQ_CFQQ(rq)) + return 0; + + return 1; +} + static inline void __cfq_set_active_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) { @@ -2125,6 +2157,7 @@ static struct elevator_type iosched_cfq = { .elevator_merge_fn = cfq_merge, .elevator_merged_fn = cfq_merged_request, .elevator_merge_req_fn = cfq_merged_requests, + .elevator_allow_merge_fn = cfq_allow_merge, .elevator_dispatch_fn = cfq_dispatch_requests, .elevator_add_req_fn = cfq_insert_request, .elevator_activate_req_fn = cfq_activate_request, |