[MIPS] Use ARRAY_SIZE macro when appropriate
[sfrench/cifs-2.6.git] / block / cfq-iosched.c
index e9019ed39b7352a5416aa38a9a15623be744293d..07b706243772e46fe2434248bf0e4fba938fca0a 100644 (file)
@@ -43,8 +43,8 @@ static int cfq_slice_idle = HZ / 125;
 #define RQ_CIC(rq)             ((struct cfq_io_context*)(rq)->elevator_private)
 #define RQ_CFQQ(rq)            ((rq)->elevator_private2)
 
-static kmem_cache_t *cfq_pool;
-static kmem_cache_t *cfq_ioc_pool;
+static struct kmem_cache *cfq_pool;
+static struct kmem_cache *cfq_ioc_pool;
 
 static DEFINE_PER_CPU(unsigned long, ioc_count);
 static struct completion *ioc_gone;
@@ -219,9 +219,12 @@ static int cfq_queue_empty(request_queue_t *q)
        return !cfqd->busy_queues;
 }
 
-static inline pid_t cfq_queue_pid(struct task_struct *task, int rw)
+static inline pid_t cfq_queue_pid(struct task_struct *task, int rw, int is_sync)
 {
-       if (rw == READ || rw == WRITE_SYNC)
+       /*
+        * Use the per-process queue, for read requests and syncronous writes
+        */
+       if (!(rw & REQ_RW) || is_sync)
                return task->pid;
 
        return CFQ_KEY_ASYNC;
@@ -473,7 +476,7 @@ static struct request *
 cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio)
 {
        struct task_struct *tsk = current;
-       pid_t key = cfq_queue_pid(tsk, bio_data_dir(bio));
+       pid_t key = cfq_queue_pid(tsk, bio_data_dir(bio), bio_sync(bio));
        struct cfq_queue *cfqq;
 
        cfqq = cfq_find_cfq_hash(cfqd, key, tsk->ioprio);
@@ -565,6 +568,33 @@ 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;
+
+       /*
+        * Disallow merge of a sync bio into an async request.
+        */
+       if ((bio_data_dir(bio) == READ || bio_sync(bio)) && !rq_is_sync(rq))
+               return 0;
+
+       /*
+        * Lookup the cfqq that this bio will be queued with. Allow
+        * merge only if rq is queued there.
+        */
+       key = cfq_queue_pid(current, rw, bio_sync(bio));
+       cfqq = cfq_find_cfq_hash(cfqd, key, current->ioprio);
+
+       if (cfqq == RQ_CFQQ(rq))
+               return 1;
+
+       return 0;
+}
+
 static inline void
 __cfq_set_active_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
 {
@@ -1748,6 +1778,9 @@ static int cfq_may_queue(request_queue_t *q, int rw)
        struct cfq_data *cfqd = q->elevator->elevator_data;
        struct task_struct *tsk = current;
        struct cfq_queue *cfqq;
+       unsigned int key;
+
+       key = cfq_queue_pid(tsk, rw, rw & REQ_RW_SYNC);
 
        /*
         * don't force setup of a queue from here, as a call to may_queue
@@ -1755,7 +1788,7 @@ static int cfq_may_queue(request_queue_t *q, int rw)
         * so just lookup a possibly existing queue, or return 'may queue'
         * if that fails
         */
-       cfqq = cfq_find_cfq_hash(cfqd, cfq_queue_pid(tsk, rw), tsk->ioprio);
+       cfqq = cfq_find_cfq_hash(cfqd, key, tsk->ioprio);
        if (cfqq) {
                cfq_init_prio_data(cfqq);
                cfq_prio_boost(cfqq);
@@ -1798,10 +1831,10 @@ cfq_set_request(request_queue_t *q, struct request *rq, gfp_t gfp_mask)
        struct task_struct *tsk = current;
        struct cfq_io_context *cic;
        const int rw = rq_data_dir(rq);
-       pid_t key = cfq_queue_pid(tsk, rw);
+       const int is_sync = rq_is_sync(rq);
+       pid_t key = cfq_queue_pid(tsk, rw, is_sync);
        struct cfq_queue *cfqq;
        unsigned long flags;
-       int is_sync = key != CFQ_KEY_ASYNC;
 
        might_sleep_if(gfp_mask & __GFP_WAIT);
 
@@ -1840,9 +1873,11 @@ queue_fail:
        return 1;
 }
 
-static void cfq_kick_queue(void *data)
+static void cfq_kick_queue(struct work_struct *work)
 {
-       request_queue_t *q = data;
+       struct cfq_data *cfqd =
+               container_of(work, struct cfq_data, unplug_work);
+       request_queue_t *q = cfqd->queue;
        unsigned long flags;
 
        spin_lock_irqsave(q->queue_lock, flags);
@@ -1986,7 +2021,7 @@ static void *cfq_init_queue(request_queue_t *q)
        cfqd->idle_class_timer.function = cfq_idle_class_timer;
        cfqd->idle_class_timer.data = (unsigned long) cfqd;
 
-       INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q);
+       INIT_WORK(&cfqd->unplug_work, cfq_kick_queue);
 
        cfqd->cfq_quantum = cfq_quantum;
        cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0];
@@ -2117,6 +2152,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,