diff options
Diffstat (limited to 'block/cfq-iosched.c')
-rw-r--r-- | block/cfq-iosched.c | 867 |
1 files changed, 282 insertions, 585 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c index 3a3aee08ec5f..d3d76136f53a 100644 --- a/block/cfq-iosched.c +++ b/block/cfq-iosched.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * Based on ideas from a previously unfinished io | 4 | * Based on ideas from a previously unfinished io |
5 | * scheduler (round robin per-process disk scheduling) and Andrea Arcangeli. | 5 | * scheduler (round robin per-process disk scheduling) and Andrea Arcangeli. |
6 | * | 6 | * |
7 | * Copyright (C) 2003 Jens Axboe <axboe@suse.de> | 7 | * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> |
8 | */ | 8 | */ |
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/blkdev.h> | 10 | #include <linux/blkdev.h> |
@@ -17,7 +17,6 @@ | |||
17 | * tunables | 17 | * tunables |
18 | */ | 18 | */ |
19 | static const int cfq_quantum = 4; /* max queue in one round of service */ | 19 | static const int cfq_quantum = 4; /* max queue in one round of service */ |
20 | static const int cfq_queued = 8; /* minimum rq allocate limit per-queue*/ | ||
21 | static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 }; | 20 | static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 }; |
22 | static const int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */ | 21 | static const int cfq_back_max = 16 * 1024; /* maximum backwards seek, in KiB */ |
23 | static const int cfq_back_penalty = 2; /* penalty of a backwards seek */ | 22 | static const int cfq_back_penalty = 2; /* penalty of a backwards seek */ |
@@ -32,8 +31,6 @@ static int cfq_slice_idle = HZ / 125; | |||
32 | 31 | ||
33 | #define CFQ_KEY_ASYNC (0) | 32 | #define CFQ_KEY_ASYNC (0) |
34 | 33 | ||
35 | static DEFINE_SPINLOCK(cfq_exit_lock); | ||
36 | |||
37 | /* | 34 | /* |
38 | * for the hash of cfqq inside the cfqd | 35 | * for the hash of cfqq inside the cfqd |
39 | */ | 36 | */ |
@@ -41,37 +38,19 @@ static DEFINE_SPINLOCK(cfq_exit_lock); | |||
41 | #define CFQ_QHASH_ENTRIES (1 << CFQ_QHASH_SHIFT) | 38 | #define CFQ_QHASH_ENTRIES (1 << CFQ_QHASH_SHIFT) |
42 | #define list_entry_qhash(entry) hlist_entry((entry), struct cfq_queue, cfq_hash) | 39 | #define list_entry_qhash(entry) hlist_entry((entry), struct cfq_queue, cfq_hash) |
43 | 40 | ||
44 | /* | ||
45 | * for the hash of crq inside the cfqq | ||
46 | */ | ||
47 | #define CFQ_MHASH_SHIFT 6 | ||
48 | #define CFQ_MHASH_BLOCK(sec) ((sec) >> 3) | ||
49 | #define CFQ_MHASH_ENTRIES (1 << CFQ_MHASH_SHIFT) | ||
50 | #define CFQ_MHASH_FN(sec) hash_long(CFQ_MHASH_BLOCK(sec), CFQ_MHASH_SHIFT) | ||
51 | #define rq_hash_key(rq) ((rq)->sector + (rq)->nr_sectors) | ||
52 | #define list_entry_hash(ptr) hlist_entry((ptr), struct cfq_rq, hash) | ||
53 | |||
54 | #define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list) | 41 | #define list_entry_cfqq(ptr) list_entry((ptr), struct cfq_queue, cfq_list) |
55 | #define list_entry_fifo(ptr) list_entry((ptr), struct request, queuelist) | ||
56 | 42 | ||
57 | #define RQ_DATA(rq) (rq)->elevator_private | 43 | #define RQ_CIC(rq) ((struct cfq_io_context*)(rq)->elevator_private) |
44 | #define RQ_CFQQ(rq) ((rq)->elevator_private2) | ||
58 | 45 | ||
59 | /* | ||
60 | * rb-tree defines | ||
61 | */ | ||
62 | #define rb_entry_crq(node) rb_entry((node), struct cfq_rq, rb_node) | ||
63 | #define rq_rb_key(rq) (rq)->sector | ||
64 | |||
65 | static kmem_cache_t *crq_pool; | ||
66 | static kmem_cache_t *cfq_pool; | 46 | static kmem_cache_t *cfq_pool; |
67 | static kmem_cache_t *cfq_ioc_pool; | 47 | static kmem_cache_t *cfq_ioc_pool; |
68 | 48 | ||
69 | static atomic_t ioc_count = ATOMIC_INIT(0); | 49 | static DEFINE_PER_CPU(unsigned long, ioc_count); |
70 | static struct completion *ioc_gone; | 50 | static struct completion *ioc_gone; |
71 | 51 | ||
72 | #define CFQ_PRIO_LISTS IOPRIO_BE_NR | 52 | #define CFQ_PRIO_LISTS IOPRIO_BE_NR |
73 | #define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE) | 53 | #define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE) |
74 | #define cfq_class_be(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_BE) | ||
75 | #define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT) | 54 | #define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT) |
76 | 55 | ||
77 | #define ASYNC (0) | 56 | #define ASYNC (0) |
@@ -103,29 +82,14 @@ struct cfq_data { | |||
103 | unsigned int busy_queues; | 82 | unsigned int busy_queues; |
104 | 83 | ||
105 | /* | 84 | /* |
106 | * non-ordered list of empty cfqq's | ||
107 | */ | ||
108 | struct list_head empty_list; | ||
109 | |||
110 | /* | ||
111 | * cfqq lookup hash | 85 | * cfqq lookup hash |
112 | */ | 86 | */ |
113 | struct hlist_head *cfq_hash; | 87 | struct hlist_head *cfq_hash; |
114 | 88 | ||
115 | /* | ||
116 | * global crq hash for all queues | ||
117 | */ | ||
118 | struct hlist_head *crq_hash; | ||
119 | |||
120 | mempool_t *crq_pool; | ||
121 | |||
122 | int rq_in_driver; | 89 | int rq_in_driver; |
123 | int hw_tag; | 90 | int hw_tag; |
124 | 91 | ||
125 | /* | 92 | /* |
126 | * schedule slice state info | ||
127 | */ | ||
128 | /* | ||
129 | * idle window management | 93 | * idle window management |
130 | */ | 94 | */ |
131 | struct timer_list idle_slice_timer; | 95 | struct timer_list idle_slice_timer; |
@@ -141,13 +105,10 @@ struct cfq_data { | |||
141 | sector_t last_sector; | 105 | sector_t last_sector; |
142 | unsigned long last_end_request; | 106 | unsigned long last_end_request; |
143 | 107 | ||
144 | unsigned int rq_starved; | ||
145 | |||
146 | /* | 108 | /* |
147 | * tunables, see top of file | 109 | * tunables, see top of file |
148 | */ | 110 | */ |
149 | unsigned int cfq_quantum; | 111 | unsigned int cfq_quantum; |
150 | unsigned int cfq_queued; | ||
151 | unsigned int cfq_fifo_expire[2]; | 112 | unsigned int cfq_fifo_expire[2]; |
152 | unsigned int cfq_back_penalty; | 113 | unsigned int cfq_back_penalty; |
153 | unsigned int cfq_back_max; | 114 | unsigned int cfq_back_max; |
@@ -170,23 +131,24 @@ struct cfq_queue { | |||
170 | struct hlist_node cfq_hash; | 131 | struct hlist_node cfq_hash; |
171 | /* hash key */ | 132 | /* hash key */ |
172 | unsigned int key; | 133 | unsigned int key; |
173 | /* on either rr or empty list of cfqd */ | 134 | /* member of the rr/busy/cur/idle cfqd list */ |
174 | struct list_head cfq_list; | 135 | struct list_head cfq_list; |
175 | /* sorted list of pending requests */ | 136 | /* sorted list of pending requests */ |
176 | struct rb_root sort_list; | 137 | struct rb_root sort_list; |
177 | /* if fifo isn't expired, next request to serve */ | 138 | /* if fifo isn't expired, next request to serve */ |
178 | struct cfq_rq *next_crq; | 139 | struct request *next_rq; |
179 | /* requests queued in sort_list */ | 140 | /* requests queued in sort_list */ |
180 | int queued[2]; | 141 | int queued[2]; |
181 | /* currently allocated requests */ | 142 | /* currently allocated requests */ |
182 | int allocated[2]; | 143 | int allocated[2]; |
144 | /* pending metadata requests */ | ||
145 | int meta_pending; | ||
183 | /* fifo list of requests in sort_list */ | 146 | /* fifo list of requests in sort_list */ |
184 | struct list_head fifo; | 147 | struct list_head fifo; |
185 | 148 | ||
186 | unsigned long slice_start; | 149 | unsigned long slice_start; |
187 | unsigned long slice_end; | 150 | unsigned long slice_end; |
188 | unsigned long slice_left; | 151 | unsigned long slice_left; |
189 | unsigned long service_last; | ||
190 | 152 | ||
191 | /* number of requests that are on the dispatch list */ | 153 | /* number of requests that are on the dispatch list */ |
192 | int on_dispatch[2]; | 154 | int on_dispatch[2]; |
@@ -199,18 +161,6 @@ struct cfq_queue { | |||
199 | unsigned int flags; | 161 | unsigned int flags; |
200 | }; | 162 | }; |
201 | 163 | ||
202 | struct cfq_rq { | ||
203 | struct rb_node rb_node; | ||
204 | sector_t rb_key; | ||
205 | struct request *request; | ||
206 | struct hlist_node hash; | ||
207 | |||
208 | struct cfq_queue *cfq_queue; | ||
209 | struct cfq_io_context *io_context; | ||
210 | |||
211 | unsigned int crq_flags; | ||
212 | }; | ||
213 | |||
214 | enum cfqq_state_flags { | 164 | enum cfqq_state_flags { |
215 | CFQ_CFQQ_FLAG_on_rr = 0, | 165 | CFQ_CFQQ_FLAG_on_rr = 0, |
216 | CFQ_CFQQ_FLAG_wait_request, | 166 | CFQ_CFQQ_FLAG_wait_request, |
@@ -220,6 +170,7 @@ enum cfqq_state_flags { | |||
220 | CFQ_CFQQ_FLAG_fifo_expire, | 170 | CFQ_CFQQ_FLAG_fifo_expire, |
221 | CFQ_CFQQ_FLAG_idle_window, | 171 | CFQ_CFQQ_FLAG_idle_window, |
222 | CFQ_CFQQ_FLAG_prio_changed, | 172 | CFQ_CFQQ_FLAG_prio_changed, |
173 | CFQ_CFQQ_FLAG_queue_new, | ||
223 | }; | 174 | }; |
224 | 175 | ||
225 | #define CFQ_CFQQ_FNS(name) \ | 176 | #define CFQ_CFQQ_FNS(name) \ |
@@ -244,70 +195,14 @@ CFQ_CFQQ_FNS(must_dispatch); | |||
244 | CFQ_CFQQ_FNS(fifo_expire); | 195 | CFQ_CFQQ_FNS(fifo_expire); |
245 | CFQ_CFQQ_FNS(idle_window); | 196 | CFQ_CFQQ_FNS(idle_window); |
246 | CFQ_CFQQ_FNS(prio_changed); | 197 | CFQ_CFQQ_FNS(prio_changed); |
198 | CFQ_CFQQ_FNS(queue_new); | ||
247 | #undef CFQ_CFQQ_FNS | 199 | #undef CFQ_CFQQ_FNS |
248 | 200 | ||
249 | enum cfq_rq_state_flags { | ||
250 | CFQ_CRQ_FLAG_is_sync = 0, | ||
251 | }; | ||
252 | |||
253 | #define CFQ_CRQ_FNS(name) \ | ||
254 | static inline void cfq_mark_crq_##name(struct cfq_rq *crq) \ | ||
255 | { \ | ||
256 | crq->crq_flags |= (1 << CFQ_CRQ_FLAG_##name); \ | ||
257 | } \ | ||
258 | static inline void cfq_clear_crq_##name(struct cfq_rq *crq) \ | ||
259 | { \ | ||
260 | crq->crq_flags &= ~(1 << CFQ_CRQ_FLAG_##name); \ | ||
261 | } \ | ||
262 | static inline int cfq_crq_##name(const struct cfq_rq *crq) \ | ||
263 | { \ | ||
264 | return (crq->crq_flags & (1 << CFQ_CRQ_FLAG_##name)) != 0; \ | ||
265 | } | ||
266 | |||
267 | CFQ_CRQ_FNS(is_sync); | ||
268 | #undef CFQ_CRQ_FNS | ||
269 | |||
270 | static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short); | 201 | static struct cfq_queue *cfq_find_cfq_hash(struct cfq_data *, unsigned int, unsigned short); |
271 | static void cfq_dispatch_insert(request_queue_t *, struct cfq_rq *); | 202 | static void cfq_dispatch_insert(request_queue_t *, struct request *); |
272 | static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk, gfp_t gfp_mask); | 203 | static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, unsigned int key, struct task_struct *tsk, gfp_t gfp_mask); |
273 | 204 | ||
274 | /* | 205 | /* |
275 | * lots of deadline iosched dupes, can be abstracted later... | ||
276 | */ | ||
277 | static inline void cfq_del_crq_hash(struct cfq_rq *crq) | ||
278 | { | ||
279 | hlist_del_init(&crq->hash); | ||
280 | } | ||
281 | |||
282 | static inline void cfq_add_crq_hash(struct cfq_data *cfqd, struct cfq_rq *crq) | ||
283 | { | ||
284 | const int hash_idx = CFQ_MHASH_FN(rq_hash_key(crq->request)); | ||
285 | |||
286 | hlist_add_head(&crq->hash, &cfqd->crq_hash[hash_idx]); | ||
287 | } | ||
288 | |||
289 | static struct request *cfq_find_rq_hash(struct cfq_data *cfqd, sector_t offset) | ||
290 | { | ||
291 | struct hlist_head *hash_list = &cfqd->crq_hash[CFQ_MHASH_FN(offset)]; | ||
292 | struct hlist_node *entry, *next; | ||
293 | |||
294 | hlist_for_each_safe(entry, next, hash_list) { | ||
295 | struct cfq_rq *crq = list_entry_hash(entry); | ||
296 | struct request *__rq = crq->request; | ||
297 | |||
298 | if (!rq_mergeable(__rq)) { | ||
299 | cfq_del_crq_hash(crq); | ||
300 | continue; | ||
301 | } | ||
302 | |||
303 | if (rq_hash_key(__rq) == offset) | ||
304 | return __rq; | ||
305 | } | ||
306 | |||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * scheduler run of queue, if there are requests pending and no one in the | 206 | * scheduler run of queue, if there are requests pending and no one in the |
312 | * driver that will restart queueing | 207 | * driver that will restart queueing |
313 | */ | 208 | */ |
@@ -333,12 +228,12 @@ static inline pid_t cfq_queue_pid(struct task_struct *task, int rw) | |||
333 | } | 228 | } |
334 | 229 | ||
335 | /* | 230 | /* |
336 | * Lifted from AS - choose which of crq1 and crq2 that is best served now. | 231 | * Lifted from AS - choose which of rq1 and rq2 that is best served now. |
337 | * We choose the request that is closest to the head right now. Distance | 232 | * We choose the request that is closest to the head right now. Distance |
338 | * behind the head is penalized and only allowed to a certain extent. | 233 | * behind the head is penalized and only allowed to a certain extent. |
339 | */ | 234 | */ |
340 | static struct cfq_rq * | 235 | static struct request * |
341 | cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2) | 236 | cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2) |
342 | { | 237 | { |
343 | sector_t last, s1, s2, d1 = 0, d2 = 0; | 238 | sector_t last, s1, s2, d1 = 0, d2 = 0; |
344 | unsigned long back_max; | 239 | unsigned long back_max; |
@@ -346,18 +241,22 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2) | |||
346 | #define CFQ_RQ2_WRAP 0x02 /* request 2 wraps */ | 241 | #define CFQ_RQ2_WRAP 0x02 /* request 2 wraps */ |
347 | unsigned wrap = 0; /* bit mask: requests behind the disk head? */ | 242 | unsigned wrap = 0; /* bit mask: requests behind the disk head? */ |
348 | 243 | ||
349 | if (crq1 == NULL || crq1 == crq2) | 244 | if (rq1 == NULL || rq1 == rq2) |
350 | return crq2; | 245 | return rq2; |
351 | if (crq2 == NULL) | 246 | if (rq2 == NULL) |
352 | return crq1; | 247 | return rq1; |
353 | 248 | ||
354 | if (cfq_crq_is_sync(crq1) && !cfq_crq_is_sync(crq2)) | 249 | if (rq_is_sync(rq1) && !rq_is_sync(rq2)) |
355 | return crq1; | 250 | return rq1; |
356 | else if (cfq_crq_is_sync(crq2) && !cfq_crq_is_sync(crq1)) | 251 | else if (rq_is_sync(rq2) && !rq_is_sync(rq1)) |
357 | return crq2; | 252 | return rq2; |
253 | if (rq_is_meta(rq1) && !rq_is_meta(rq2)) | ||
254 | return rq1; | ||
255 | else if (rq_is_meta(rq2) && !rq_is_meta(rq1)) | ||
256 | return rq2; | ||
358 | 257 | ||
359 | s1 = crq1->request->sector; | 258 | s1 = rq1->sector; |
360 | s2 = crq2->request->sector; | 259 | s2 = rq2->sector; |
361 | 260 | ||
362 | last = cfqd->last_sector; | 261 | last = cfqd->last_sector; |
363 | 262 | ||
@@ -392,23 +291,23 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2) | |||
392 | * check two variables for all permutations: --> faster! | 291 | * check two variables for all permutations: --> faster! |
393 | */ | 292 | */ |
394 | switch (wrap) { | 293 | switch (wrap) { |
395 | case 0: /* common case for CFQ: crq1 and crq2 not wrapped */ | 294 | case 0: /* common case for CFQ: rq1 and rq2 not wrapped */ |
396 | if (d1 < d2) | 295 | if (d1 < d2) |
397 | return crq1; | 296 | return rq1; |
398 | else if (d2 < d1) | 297 | else if (d2 < d1) |
399 | return crq2; | 298 | return rq2; |
400 | else { | 299 | else { |
401 | if (s1 >= s2) | 300 | if (s1 >= s2) |
402 | return crq1; | 301 | return rq1; |
403 | else | 302 | else |
404 | return crq2; | 303 | return rq2; |
405 | } | 304 | } |
406 | 305 | ||
407 | case CFQ_RQ2_WRAP: | 306 | case CFQ_RQ2_WRAP: |
408 | return crq1; | 307 | return rq1; |
409 | case CFQ_RQ1_WRAP: | 308 | case CFQ_RQ1_WRAP: |
410 | return crq2; | 309 | return rq2; |
411 | case (CFQ_RQ1_WRAP|CFQ_RQ2_WRAP): /* both crqs wrapped */ | 310 | case (CFQ_RQ1_WRAP|CFQ_RQ2_WRAP): /* both rqs wrapped */ |
412 | default: | 311 | default: |
413 | /* | 312 | /* |
414 | * Since both rqs are wrapped, | 313 | * Since both rqs are wrapped, |
@@ -417,50 +316,43 @@ cfq_choose_req(struct cfq_data *cfqd, struct cfq_rq *crq1, struct cfq_rq *crq2) | |||
417 | * since back seek takes more time than forward. | 316 | * since back seek takes more time than forward. |
418 | */ | 317 | */ |
419 | if (s1 <= s2) | 318 | if (s1 <= s2) |
420 | return crq1; | 319 | return rq1; |
421 | else | 320 | else |
422 | return crq2; | 321 | return rq2; |
423 | } | 322 | } |
424 | } | 323 | } |
425 | 324 | ||
426 | /* | 325 | /* |
427 | * would be nice to take fifo expire time into account as well | 326 | * would be nice to take fifo expire time into account as well |
428 | */ | 327 | */ |
429 | static struct cfq_rq * | 328 | static struct request * |
430 | cfq_find_next_crq(struct cfq_data *cfqd, struct cfq_queue *cfqq, | 329 | cfq_find_next_rq(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
431 | struct cfq_rq *last) | 330 | struct request *last) |
432 | { | 331 | { |
433 | struct cfq_rq *crq_next = NULL, *crq_prev = NULL; | 332 | struct rb_node *rbnext = rb_next(&last->rb_node); |
434 | struct rb_node *rbnext, *rbprev; | 333 | struct rb_node *rbprev = rb_prev(&last->rb_node); |
435 | 334 | struct request *next = NULL, *prev = NULL; | |
436 | if (!(rbnext = rb_next(&last->rb_node))) { | ||
437 | rbnext = rb_first(&cfqq->sort_list); | ||
438 | if (rbnext == &last->rb_node) | ||
439 | rbnext = NULL; | ||
440 | } | ||
441 | 335 | ||
442 | rbprev = rb_prev(&last->rb_node); | 336 | BUG_ON(RB_EMPTY_NODE(&last->rb_node)); |
443 | 337 | ||
444 | if (rbprev) | 338 | if (rbprev) |
445 | crq_prev = rb_entry_crq(rbprev); | 339 | prev = rb_entry_rq(rbprev); |
446 | if (rbnext) | ||
447 | crq_next = rb_entry_crq(rbnext); | ||
448 | |||
449 | return cfq_choose_req(cfqd, crq_next, crq_prev); | ||
450 | } | ||
451 | 340 | ||
452 | static void cfq_update_next_crq(struct cfq_rq *crq) | 341 | if (rbnext) |
453 | { | 342 | next = rb_entry_rq(rbnext); |
454 | struct cfq_queue *cfqq = crq->cfq_queue; | 343 | else { |
344 | rbnext = rb_first(&cfqq->sort_list); | ||
345 | if (rbnext && rbnext != &last->rb_node) | ||
346 | next = rb_entry_rq(rbnext); | ||
347 | } | ||
455 | 348 | ||
456 | if (cfqq->next_crq == crq) | 349 | return cfq_choose_req(cfqd, next, prev); |
457 | cfqq->next_crq = cfq_find_next_crq(cfqq->cfqd, cfqq, crq); | ||
458 | } | 350 | } |
459 | 351 | ||
460 | static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted) | 352 | static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted) |
461 | { | 353 | { |
462 | struct cfq_data *cfqd = cfqq->cfqd; | 354 | struct cfq_data *cfqd = cfqq->cfqd; |
463 | struct list_head *list, *entry; | 355 | struct list_head *list; |
464 | 356 | ||
465 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); | 357 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); |
466 | 358 | ||
@@ -485,31 +377,26 @@ static void cfq_resort_rr_list(struct cfq_queue *cfqq, int preempted) | |||
485 | } | 377 | } |
486 | 378 | ||
487 | /* | 379 | /* |
488 | * if queue was preempted, just add to front to be fair. busy_rr | 380 | * If this queue was preempted or is new (never been serviced), let |
489 | * isn't sorted, but insert at the back for fairness. | 381 | * it be added first for fairness but beind other new queues. |
382 | * Otherwise, just add to the back of the list. | ||
490 | */ | 383 | */ |
491 | if (preempted || list == &cfqd->busy_rr) { | 384 | if (preempted || cfq_cfqq_queue_new(cfqq)) { |
492 | if (preempted) | 385 | struct list_head *n = list; |
493 | list = list->prev; | 386 | struct cfq_queue *__cfqq; |
494 | 387 | ||
495 | list_add_tail(&cfqq->cfq_list, list); | 388 | while (n->next != list) { |
496 | return; | 389 | __cfqq = list_entry_cfqq(n->next); |
497 | } | 390 | if (!cfq_cfqq_queue_new(__cfqq)) |
391 | break; | ||
498 | 392 | ||
499 | /* | 393 | n = n->next; |
500 | * sort by when queue was last serviced | 394 | } |
501 | */ | ||
502 | entry = list; | ||
503 | while ((entry = entry->prev) != list) { | ||
504 | struct cfq_queue *__cfqq = list_entry_cfqq(entry); | ||
505 | 395 | ||
506 | if (!__cfqq->service_last) | 396 | list = n; |
507 | break; | ||
508 | if (time_before(__cfqq->service_last, cfqq->service_last)) | ||
509 | break; | ||
510 | } | 397 | } |
511 | 398 | ||
512 | list_add(&cfqq->cfq_list, entry); | 399 | list_add_tail(&cfqq->cfq_list, list); |
513 | } | 400 | } |
514 | 401 | ||
515 | /* | 402 | /* |
@@ -531,7 +418,7 @@ cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) | |||
531 | { | 418 | { |
532 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); | 419 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); |
533 | cfq_clear_cfqq_on_rr(cfqq); | 420 | cfq_clear_cfqq_on_rr(cfqq); |
534 | list_move(&cfqq->cfq_list, &cfqd->empty_list); | 421 | list_del_init(&cfqq->cfq_list); |
535 | 422 | ||
536 | BUG_ON(!cfqd->busy_queues); | 423 | BUG_ON(!cfqd->busy_queues); |
537 | cfqd->busy_queues--; | 424 | cfqd->busy_queues--; |
@@ -540,81 +427,43 @@ cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) | |||
540 | /* | 427 | /* |
541 | * rb tree support functions | 428 | * rb tree support functions |
542 | */ | 429 | */ |
543 | static inline void cfq_del_crq_rb(struct cfq_rq *crq) | 430 | static inline void cfq_del_rq_rb(struct request *rq) |
544 | { | 431 | { |
545 | struct cfq_queue *cfqq = crq->cfq_queue; | 432 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
546 | struct cfq_data *cfqd = cfqq->cfqd; | 433 | struct cfq_data *cfqd = cfqq->cfqd; |
547 | const int sync = cfq_crq_is_sync(crq); | 434 | const int sync = rq_is_sync(rq); |
548 | 435 | ||
549 | BUG_ON(!cfqq->queued[sync]); | 436 | BUG_ON(!cfqq->queued[sync]); |
550 | cfqq->queued[sync]--; | 437 | cfqq->queued[sync]--; |
551 | 438 | ||
552 | cfq_update_next_crq(crq); | 439 | elv_rb_del(&cfqq->sort_list, rq); |
553 | |||
554 | rb_erase(&crq->rb_node, &cfqq->sort_list); | ||
555 | 440 | ||
556 | if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) | 441 | if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) |
557 | cfq_del_cfqq_rr(cfqd, cfqq); | 442 | cfq_del_cfqq_rr(cfqd, cfqq); |
558 | } | 443 | } |
559 | 444 | ||
560 | static struct cfq_rq * | 445 | static void cfq_add_rq_rb(struct request *rq) |
561 | __cfq_add_crq_rb(struct cfq_rq *crq) | ||
562 | { | 446 | { |
563 | struct rb_node **p = &crq->cfq_queue->sort_list.rb_node; | 447 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
564 | struct rb_node *parent = NULL; | ||
565 | struct cfq_rq *__crq; | ||
566 | |||
567 | while (*p) { | ||
568 | parent = *p; | ||
569 | __crq = rb_entry_crq(parent); | ||
570 | |||
571 | if (crq->rb_key < __crq->rb_key) | ||
572 | p = &(*p)->rb_left; | ||
573 | else if (crq->rb_key > __crq->rb_key) | ||
574 | p = &(*p)->rb_right; | ||
575 | else | ||
576 | return __crq; | ||
577 | } | ||
578 | |||
579 | rb_link_node(&crq->rb_node, parent, p); | ||
580 | return NULL; | ||
581 | } | ||
582 | |||
583 | static void cfq_add_crq_rb(struct cfq_rq *crq) | ||
584 | { | ||
585 | struct cfq_queue *cfqq = crq->cfq_queue; | ||
586 | struct cfq_data *cfqd = cfqq->cfqd; | 448 | struct cfq_data *cfqd = cfqq->cfqd; |
587 | struct request *rq = crq->request; | 449 | struct request *__alias; |
588 | struct cfq_rq *__alias; | ||
589 | 450 | ||
590 | crq->rb_key = rq_rb_key(rq); | 451 | cfqq->queued[rq_is_sync(rq)]++; |
591 | cfqq->queued[cfq_crq_is_sync(crq)]++; | ||
592 | 452 | ||
593 | /* | 453 | /* |
594 | * looks a little odd, but the first insert might return an alias. | 454 | * looks a little odd, but the first insert might return an alias. |
595 | * if that happens, put the alias on the dispatch list | 455 | * if that happens, put the alias on the dispatch list |
596 | */ | 456 | */ |
597 | while ((__alias = __cfq_add_crq_rb(crq)) != NULL) | 457 | while ((__alias = elv_rb_add(&cfqq->sort_list, rq)) != NULL) |
598 | cfq_dispatch_insert(cfqd->queue, __alias); | 458 | cfq_dispatch_insert(cfqd->queue, __alias); |
599 | |||
600 | rb_insert_color(&crq->rb_node, &cfqq->sort_list); | ||
601 | |||
602 | if (!cfq_cfqq_on_rr(cfqq)) | ||
603 | cfq_add_cfqq_rr(cfqd, cfqq); | ||
604 | |||
605 | /* | ||
606 | * check if this request is a better next-serve candidate | ||
607 | */ | ||
608 | cfqq->next_crq = cfq_choose_req(cfqd, cfqq->next_crq, crq); | ||
609 | } | 459 | } |
610 | 460 | ||
611 | static inline void | 461 | static inline void |
612 | cfq_reposition_crq_rb(struct cfq_queue *cfqq, struct cfq_rq *crq) | 462 | cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq) |
613 | { | 463 | { |
614 | rb_erase(&crq->rb_node, &cfqq->sort_list); | 464 | elv_rb_del(&cfqq->sort_list, rq); |
615 | cfqq->queued[cfq_crq_is_sync(crq)]--; | 465 | cfqq->queued[rq_is_sync(rq)]--; |
616 | 466 | cfq_add_rq_rb(rq); | |
617 | cfq_add_crq_rb(crq); | ||
618 | } | 467 | } |
619 | 468 | ||
620 | static struct request * | 469 | static struct request * |
@@ -623,27 +472,14 @@ cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio) | |||
623 | struct task_struct *tsk = current; | 472 | struct task_struct *tsk = current; |
624 | pid_t key = cfq_queue_pid(tsk, bio_data_dir(bio)); | 473 | pid_t key = cfq_queue_pid(tsk, bio_data_dir(bio)); |
625 | struct cfq_queue *cfqq; | 474 | struct cfq_queue *cfqq; |
626 | struct rb_node *n; | ||
627 | sector_t sector; | ||
628 | 475 | ||
629 | cfqq = cfq_find_cfq_hash(cfqd, key, tsk->ioprio); | 476 | cfqq = cfq_find_cfq_hash(cfqd, key, tsk->ioprio); |
630 | if (!cfqq) | 477 | if (cfqq) { |
631 | goto out; | 478 | sector_t sector = bio->bi_sector + bio_sectors(bio); |
632 | |||
633 | sector = bio->bi_sector + bio_sectors(bio); | ||
634 | n = cfqq->sort_list.rb_node; | ||
635 | while (n) { | ||
636 | struct cfq_rq *crq = rb_entry_crq(n); | ||
637 | 479 | ||
638 | if (sector < crq->rb_key) | 480 | return elv_rb_find(&cfqq->sort_list, sector); |
639 | n = n->rb_left; | ||
640 | else if (sector > crq->rb_key) | ||
641 | n = n->rb_right; | ||
642 | else | ||
643 | return crq->request; | ||
644 | } | 481 | } |
645 | 482 | ||
646 | out: | ||
647 | return NULL; | 483 | return NULL; |
648 | } | 484 | } |
649 | 485 | ||
@@ -673,11 +509,18 @@ static void cfq_deactivate_request(request_queue_t *q, struct request *rq) | |||
673 | 509 | ||
674 | static void cfq_remove_request(struct request *rq) | 510 | static void cfq_remove_request(struct request *rq) |
675 | { | 511 | { |
676 | struct cfq_rq *crq = RQ_DATA(rq); | 512 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
513 | |||
514 | if (cfqq->next_rq == rq) | ||
515 | cfqq->next_rq = cfq_find_next_rq(cfqq->cfqd, cfqq, rq); | ||
677 | 516 | ||
678 | list_del_init(&rq->queuelist); | 517 | list_del_init(&rq->queuelist); |
679 | cfq_del_crq_rb(crq); | 518 | cfq_del_rq_rb(rq); |
680 | cfq_del_crq_hash(crq); | 519 | |
520 | if (rq_is_meta(rq)) { | ||
521 | WARN_ON(!cfqq->meta_pending); | ||
522 | cfqq->meta_pending--; | ||
523 | } | ||
681 | } | 524 | } |
682 | 525 | ||
683 | static int | 526 | static int |
@@ -685,39 +528,23 @@ cfq_merge(request_queue_t *q, struct request **req, struct bio *bio) | |||
685 | { | 528 | { |
686 | struct cfq_data *cfqd = q->elevator->elevator_data; | 529 | struct cfq_data *cfqd = q->elevator->elevator_data; |
687 | struct request *__rq; | 530 | struct request *__rq; |
688 | int ret; | ||
689 | |||
690 | __rq = cfq_find_rq_hash(cfqd, bio->bi_sector); | ||
691 | if (__rq && elv_rq_merge_ok(__rq, bio)) { | ||
692 | ret = ELEVATOR_BACK_MERGE; | ||
693 | goto out; | ||
694 | } | ||
695 | 531 | ||
696 | __rq = cfq_find_rq_fmerge(cfqd, bio); | 532 | __rq = cfq_find_rq_fmerge(cfqd, bio); |
697 | if (__rq && elv_rq_merge_ok(__rq, bio)) { | 533 | if (__rq && elv_rq_merge_ok(__rq, bio)) { |
698 | ret = ELEVATOR_FRONT_MERGE; | 534 | *req = __rq; |
699 | goto out; | 535 | return ELEVATOR_FRONT_MERGE; |
700 | } | 536 | } |
701 | 537 | ||
702 | return ELEVATOR_NO_MERGE; | 538 | return ELEVATOR_NO_MERGE; |
703 | out: | ||
704 | *req = __rq; | ||
705 | return ret; | ||
706 | } | 539 | } |
707 | 540 | ||
708 | static void cfq_merged_request(request_queue_t *q, struct request *req) | 541 | static void cfq_merged_request(request_queue_t *q, struct request *req, |
542 | int type) | ||
709 | { | 543 | { |
710 | struct cfq_data *cfqd = q->elevator->elevator_data; | 544 | if (type == ELEVATOR_FRONT_MERGE) { |
711 | struct cfq_rq *crq = RQ_DATA(req); | 545 | struct cfq_queue *cfqq = RQ_CFQQ(req); |
712 | |||
713 | cfq_del_crq_hash(crq); | ||
714 | cfq_add_crq_hash(cfqd, crq); | ||
715 | |||
716 | if (rq_rb_key(req) != crq->rb_key) { | ||
717 | struct cfq_queue *cfqq = crq->cfq_queue; | ||
718 | 546 | ||
719 | cfq_update_next_crq(crq); | 547 | cfq_reposition_rq_rb(cfqq, req); |
720 | cfq_reposition_crq_rb(cfqq, crq); | ||
721 | } | 548 | } |
722 | } | 549 | } |
723 | 550 | ||
@@ -725,8 +552,6 @@ static void | |||
725 | cfq_merged_requests(request_queue_t *q, struct request *rq, | 552 | cfq_merged_requests(request_queue_t *q, struct request *rq, |
726 | struct request *next) | 553 | struct request *next) |
727 | { | 554 | { |
728 | cfq_merged_request(q, rq); | ||
729 | |||
730 | /* | 555 | /* |
731 | * reposition in fifo if next is older than rq | 556 | * reposition in fifo if next is older than rq |
732 | */ | 557 | */ |
@@ -768,13 +593,12 @@ __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
768 | if (cfq_cfqq_wait_request(cfqq)) | 593 | if (cfq_cfqq_wait_request(cfqq)) |
769 | del_timer(&cfqd->idle_slice_timer); | 594 | del_timer(&cfqd->idle_slice_timer); |
770 | 595 | ||
771 | if (!preempted && !cfq_cfqq_dispatched(cfqq)) { | 596 | if (!preempted && !cfq_cfqq_dispatched(cfqq)) |
772 | cfqq->service_last = now; | ||
773 | cfq_schedule_dispatch(cfqd); | 597 | cfq_schedule_dispatch(cfqd); |
774 | } | ||
775 | 598 | ||
776 | cfq_clear_cfqq_must_dispatch(cfqq); | 599 | cfq_clear_cfqq_must_dispatch(cfqq); |
777 | cfq_clear_cfqq_wait_request(cfqq); | 600 | cfq_clear_cfqq_wait_request(cfqq); |
601 | cfq_clear_cfqq_queue_new(cfqq); | ||
778 | 602 | ||
779 | /* | 603 | /* |
780 | * store what was left of this slice, if the queue idled out | 604 | * store what was left of this slice, if the queue idled out |
@@ -868,26 +692,25 @@ static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd) | |||
868 | { | 692 | { |
869 | struct cfq_queue *cfqq = NULL; | 693 | struct cfq_queue *cfqq = NULL; |
870 | 694 | ||
871 | /* | 695 | if (!list_empty(&cfqd->cur_rr) || cfq_get_next_prio_level(cfqd) != -1) { |
872 | * if current list is non-empty, grab first entry. if it is empty, | 696 | /* |
873 | * get next prio level and grab first entry then if any are spliced | 697 | * if current list is non-empty, grab first entry. if it is |
874 | */ | 698 | * empty, get next prio level and grab first entry then if any |
875 | if (!list_empty(&cfqd->cur_rr) || cfq_get_next_prio_level(cfqd) != -1) | 699 | * are spliced |
700 | */ | ||
876 | cfqq = list_entry_cfqq(cfqd->cur_rr.next); | 701 | cfqq = list_entry_cfqq(cfqd->cur_rr.next); |
877 | 702 | } else if (!list_empty(&cfqd->busy_rr)) { | |
878 | /* | 703 | /* |
879 | * If no new queues are available, check if the busy list has some | 704 | * If no new queues are available, check if the busy list has |
880 | * before falling back to idle io. | 705 | * some before falling back to idle io. |
881 | */ | 706 | */ |
882 | if (!cfqq && !list_empty(&cfqd->busy_rr)) | ||
883 | cfqq = list_entry_cfqq(cfqd->busy_rr.next); | 707 | cfqq = list_entry_cfqq(cfqd->busy_rr.next); |
884 | 708 | } else if (!list_empty(&cfqd->idle_rr)) { | |
885 | /* | 709 | /* |
886 | * if we have idle queues and no rt or be queues had pending | 710 | * if we have idle queues and no rt or be queues had pending |
887 | * requests, either allow immediate service if the grace period | 711 | * requests, either allow immediate service if the grace period |
888 | * has passed or arm the idle grace timer | 712 | * has passed or arm the idle grace timer |
889 | */ | 713 | */ |
890 | if (!cfqq && !list_empty(&cfqd->idle_rr)) { | ||
891 | unsigned long end = cfqd->last_end_request + CFQ_IDLE_GRACE; | 714 | unsigned long end = cfqd->last_end_request + CFQ_IDLE_GRACE; |
892 | 715 | ||
893 | if (time_after_eq(jiffies, end)) | 716 | if (time_after_eq(jiffies, end)) |
@@ -942,16 +765,14 @@ static int cfq_arm_slice_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq) | |||
942 | return 1; | 765 | return 1; |
943 | } | 766 | } |
944 | 767 | ||
945 | static void cfq_dispatch_insert(request_queue_t *q, struct cfq_rq *crq) | 768 | static void cfq_dispatch_insert(request_queue_t *q, struct request *rq) |
946 | { | 769 | { |
947 | struct cfq_data *cfqd = q->elevator->elevator_data; | 770 | struct cfq_data *cfqd = q->elevator->elevator_data; |
948 | struct cfq_queue *cfqq = crq->cfq_queue; | 771 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
949 | struct request *rq; | ||
950 | 772 | ||
951 | cfqq->next_crq = cfq_find_next_crq(cfqd, cfqq, crq); | 773 | cfq_remove_request(rq); |
952 | cfq_remove_request(crq->request); | 774 | cfqq->on_dispatch[rq_is_sync(rq)]++; |
953 | cfqq->on_dispatch[cfq_crq_is_sync(crq)]++; | 775 | elv_dispatch_sort(q, rq); |
954 | elv_dispatch_sort(q, crq->request); | ||
955 | 776 | ||
956 | rq = list_entry(q->queue_head.prev, struct request, queuelist); | 777 | rq = list_entry(q->queue_head.prev, struct request, queuelist); |
957 | cfqd->last_sector = rq->sector + rq->nr_sectors; | 778 | cfqd->last_sector = rq->sector + rq->nr_sectors; |
@@ -960,24 +781,23 @@ static void cfq_dispatch_insert(request_queue_t *q, struct cfq_rq *crq) | |||
960 | /* | 781 | /* |
961 | * return expired entry, or NULL to just start from scratch in rbtree | 782 | * return expired entry, or NULL to just start from scratch in rbtree |
962 | */ | 783 | */ |
963 | static inline struct cfq_rq *cfq_check_fifo(struct cfq_queue *cfqq) | 784 | static inline struct request *cfq_check_fifo(struct cfq_queue *cfqq) |
964 | { | 785 | { |
965 | struct cfq_data *cfqd = cfqq->cfqd; | 786 | struct cfq_data *cfqd = cfqq->cfqd; |
966 | struct request *rq; | 787 | struct request *rq; |
967 | struct cfq_rq *crq; | 788 | int fifo; |
968 | 789 | ||
969 | if (cfq_cfqq_fifo_expire(cfqq)) | 790 | if (cfq_cfqq_fifo_expire(cfqq)) |
970 | return NULL; | 791 | return NULL; |
792 | if (list_empty(&cfqq->fifo)) | ||
793 | return NULL; | ||
971 | 794 | ||
972 | if (!list_empty(&cfqq->fifo)) { | 795 | fifo = cfq_cfqq_class_sync(cfqq); |
973 | int fifo = cfq_cfqq_class_sync(cfqq); | 796 | rq = rq_entry_fifo(cfqq->fifo.next); |
974 | 797 | ||
975 | crq = RQ_DATA(list_entry_fifo(cfqq->fifo.next)); | 798 | if (time_after(jiffies, rq->start_time + cfqd->cfq_fifo_expire[fifo])) { |
976 | rq = crq->request; | 799 | cfq_mark_cfqq_fifo_expire(cfqq); |
977 | if (time_after(jiffies, rq->start_time + cfqd->cfq_fifo_expire[fifo])) { | 800 | return rq; |
978 | cfq_mark_cfqq_fifo_expire(cfqq); | ||
979 | return crq; | ||
980 | } | ||
981 | } | 801 | } |
982 | 802 | ||
983 | return NULL; | 803 | return NULL; |
@@ -1063,25 +883,25 @@ __cfq_dispatch_requests(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1063 | BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list)); | 883 | BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list)); |
1064 | 884 | ||
1065 | do { | 885 | do { |
1066 | struct cfq_rq *crq; | 886 | struct request *rq; |
1067 | 887 | ||
1068 | /* | 888 | /* |
1069 | * follow expired path, else get first next available | 889 | * follow expired path, else get first next available |
1070 | */ | 890 | */ |
1071 | if ((crq = cfq_check_fifo(cfqq)) == NULL) | 891 | if ((rq = cfq_check_fifo(cfqq)) == NULL) |
1072 | crq = cfqq->next_crq; | 892 | rq = cfqq->next_rq; |
1073 | 893 | ||
1074 | /* | 894 | /* |
1075 | * finally, insert request into driver dispatch list | 895 | * finally, insert request into driver dispatch list |
1076 | */ | 896 | */ |
1077 | cfq_dispatch_insert(cfqd->queue, crq); | 897 | cfq_dispatch_insert(cfqd->queue, rq); |
1078 | 898 | ||
1079 | cfqd->dispatch_slice++; | 899 | cfqd->dispatch_slice++; |
1080 | dispatched++; | 900 | dispatched++; |
1081 | 901 | ||
1082 | if (!cfqd->active_cic) { | 902 | if (!cfqd->active_cic) { |
1083 | atomic_inc(&crq->io_context->ioc->refcount); | 903 | atomic_inc(&RQ_CIC(rq)->ioc->refcount); |
1084 | cfqd->active_cic = crq->io_context; | 904 | cfqd->active_cic = RQ_CIC(rq); |
1085 | } | 905 | } |
1086 | 906 | ||
1087 | if (RB_EMPTY_ROOT(&cfqq->sort_list)) | 907 | if (RB_EMPTY_ROOT(&cfqq->sort_list)) |
@@ -1112,13 +932,12 @@ static int | |||
1112 | cfq_forced_dispatch_cfqqs(struct list_head *list) | 932 | cfq_forced_dispatch_cfqqs(struct list_head *list) |
1113 | { | 933 | { |
1114 | struct cfq_queue *cfqq, *next; | 934 | struct cfq_queue *cfqq, *next; |
1115 | struct cfq_rq *crq; | ||
1116 | int dispatched; | 935 | int dispatched; |
1117 | 936 | ||
1118 | dispatched = 0; | 937 | dispatched = 0; |
1119 | list_for_each_entry_safe(cfqq, next, list, cfq_list) { | 938 | list_for_each_entry_safe(cfqq, next, list, cfq_list) { |
1120 | while ((crq = cfqq->next_crq)) { | 939 | while (cfqq->next_rq) { |
1121 | cfq_dispatch_insert(cfqq->cfqd->queue, crq); | 940 | cfq_dispatch_insert(cfqq->cfqd->queue, cfqq->next_rq); |
1122 | dispatched++; | 941 | dispatched++; |
1123 | } | 942 | } |
1124 | BUG_ON(!list_empty(&cfqq->fifo)); | 943 | BUG_ON(!list_empty(&cfqq->fifo)); |
@@ -1194,8 +1013,8 @@ cfq_dispatch_requests(request_queue_t *q, int force) | |||
1194 | } | 1013 | } |
1195 | 1014 | ||
1196 | /* | 1015 | /* |
1197 | * task holds one reference to the queue, dropped when task exits. each crq | 1016 | * task holds one reference to the queue, dropped when task exits. each rq |
1198 | * in-flight on this queue also holds a reference, dropped when crq is freed. | 1017 | * in-flight on this queue also holds a reference, dropped when rq is freed. |
1199 | * | 1018 | * |
1200 | * queue lock must be held here. | 1019 | * queue lock must be held here. |
1201 | */ | 1020 | */ |
@@ -1223,7 +1042,7 @@ static void cfq_put_queue(struct cfq_queue *cfqq) | |||
1223 | kmem_cache_free(cfq_pool, cfqq); | 1042 | kmem_cache_free(cfq_pool, cfqq); |
1224 | } | 1043 | } |
1225 | 1044 | ||
1226 | static inline struct cfq_queue * | 1045 | static struct cfq_queue * |
1227 | __cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned int prio, | 1046 | __cfq_find_cfq_hash(struct cfq_data *cfqd, unsigned int key, unsigned int prio, |
1228 | const int hashval) | 1047 | const int hashval) |
1229 | { | 1048 | { |
@@ -1260,62 +1079,63 @@ static void cfq_free_io_context(struct io_context *ioc) | |||
1260 | freed++; | 1079 | freed++; |
1261 | } | 1080 | } |
1262 | 1081 | ||
1263 | if (atomic_sub_and_test(freed, &ioc_count) && ioc_gone) | 1082 | elv_ioc_count_mod(ioc_count, -freed); |
1083 | |||
1084 | if (ioc_gone && !elv_ioc_count_read(ioc_count)) | ||
1264 | complete(ioc_gone); | 1085 | complete(ioc_gone); |
1265 | } | 1086 | } |
1266 | 1087 | ||
1267 | static void cfq_trim(struct io_context *ioc) | 1088 | static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
1268 | { | 1089 | { |
1269 | ioc->set_ioprio = NULL; | 1090 | if (unlikely(cfqq == cfqd->active_queue)) |
1270 | cfq_free_io_context(ioc); | 1091 | __cfq_slice_expired(cfqd, cfqq, 0); |
1092 | |||
1093 | cfq_put_queue(cfqq); | ||
1271 | } | 1094 | } |
1272 | 1095 | ||
1273 | /* | 1096 | static void __cfq_exit_single_io_context(struct cfq_data *cfqd, |
1274 | * Called with interrupts disabled | 1097 | struct cfq_io_context *cic) |
1275 | */ | ||
1276 | static void cfq_exit_single_io_context(struct cfq_io_context *cic) | ||
1277 | { | 1098 | { |
1278 | struct cfq_data *cfqd = cic->key; | 1099 | list_del_init(&cic->queue_list); |
1279 | request_queue_t *q; | 1100 | smp_wmb(); |
1280 | 1101 | cic->key = NULL; | |
1281 | if (!cfqd) | ||
1282 | return; | ||
1283 | |||
1284 | q = cfqd->queue; | ||
1285 | |||
1286 | WARN_ON(!irqs_disabled()); | ||
1287 | |||
1288 | spin_lock(q->queue_lock); | ||
1289 | 1102 | ||
1290 | if (cic->cfqq[ASYNC]) { | 1103 | if (cic->cfqq[ASYNC]) { |
1291 | if (unlikely(cic->cfqq[ASYNC] == cfqd->active_queue)) | 1104 | cfq_exit_cfqq(cfqd, cic->cfqq[ASYNC]); |
1292 | __cfq_slice_expired(cfqd, cic->cfqq[ASYNC], 0); | ||
1293 | cfq_put_queue(cic->cfqq[ASYNC]); | ||
1294 | cic->cfqq[ASYNC] = NULL; | 1105 | cic->cfqq[ASYNC] = NULL; |
1295 | } | 1106 | } |
1296 | 1107 | ||
1297 | if (cic->cfqq[SYNC]) { | 1108 | if (cic->cfqq[SYNC]) { |
1298 | if (unlikely(cic->cfqq[SYNC] == cfqd->active_queue)) | 1109 | cfq_exit_cfqq(cfqd, cic->cfqq[SYNC]); |
1299 | __cfq_slice_expired(cfqd, cic->cfqq[SYNC], 0); | ||
1300 | cfq_put_queue(cic->cfqq[SYNC]); | ||
1301 | cic->cfqq[SYNC] = NULL; | 1110 | cic->cfqq[SYNC] = NULL; |
1302 | } | 1111 | } |
1112 | } | ||
1303 | 1113 | ||
1304 | cic->key = NULL; | 1114 | |
1305 | list_del_init(&cic->queue_list); | 1115 | /* |
1306 | spin_unlock(q->queue_lock); | 1116 | * Called with interrupts disabled |
1117 | */ | ||
1118 | static void cfq_exit_single_io_context(struct cfq_io_context *cic) | ||
1119 | { | ||
1120 | struct cfq_data *cfqd = cic->key; | ||
1121 | |||
1122 | if (cfqd) { | ||
1123 | request_queue_t *q = cfqd->queue; | ||
1124 | |||
1125 | spin_lock_irq(q->queue_lock); | ||
1126 | __cfq_exit_single_io_context(cfqd, cic); | ||
1127 | spin_unlock_irq(q->queue_lock); | ||
1128 | } | ||
1307 | } | 1129 | } |
1308 | 1130 | ||
1309 | static void cfq_exit_io_context(struct io_context *ioc) | 1131 | static void cfq_exit_io_context(struct io_context *ioc) |
1310 | { | 1132 | { |
1311 | struct cfq_io_context *__cic; | 1133 | struct cfq_io_context *__cic; |
1312 | unsigned long flags; | ||
1313 | struct rb_node *n; | 1134 | struct rb_node *n; |
1314 | 1135 | ||
1315 | /* | 1136 | /* |
1316 | * put the reference this task is holding to the various queues | 1137 | * put the reference this task is holding to the various queues |
1317 | */ | 1138 | */ |
1318 | spin_lock_irqsave(&cfq_exit_lock, flags); | ||
1319 | 1139 | ||
1320 | n = rb_first(&ioc->cic_root); | 1140 | n = rb_first(&ioc->cic_root); |
1321 | while (n != NULL) { | 1141 | while (n != NULL) { |
@@ -1324,22 +1144,21 @@ static void cfq_exit_io_context(struct io_context *ioc) | |||
1324 | cfq_exit_single_io_context(__cic); | 1144 | cfq_exit_single_io_context(__cic); |
1325 | n = rb_next(n); | 1145 | n = rb_next(n); |
1326 | } | 1146 | } |
1327 | |||
1328 | spin_unlock_irqrestore(&cfq_exit_lock, flags); | ||
1329 | } | 1147 | } |
1330 | 1148 | ||
1331 | static struct cfq_io_context * | 1149 | static struct cfq_io_context * |
1332 | cfq_alloc_io_context(struct cfq_data *cfqd, gfp_t gfp_mask) | 1150 | cfq_alloc_io_context(struct cfq_data *cfqd, gfp_t gfp_mask) |
1333 | { | 1151 | { |
1334 | struct cfq_io_context *cic = kmem_cache_alloc(cfq_ioc_pool, gfp_mask); | 1152 | struct cfq_io_context *cic; |
1335 | 1153 | ||
1154 | cic = kmem_cache_alloc_node(cfq_ioc_pool, gfp_mask, cfqd->queue->node); | ||
1336 | if (cic) { | 1155 | if (cic) { |
1337 | memset(cic, 0, sizeof(*cic)); | 1156 | memset(cic, 0, sizeof(*cic)); |
1338 | cic->last_end_request = jiffies; | 1157 | cic->last_end_request = jiffies; |
1339 | INIT_LIST_HEAD(&cic->queue_list); | 1158 | INIT_LIST_HEAD(&cic->queue_list); |
1340 | cic->dtor = cfq_free_io_context; | 1159 | cic->dtor = cfq_free_io_context; |
1341 | cic->exit = cfq_exit_io_context; | 1160 | cic->exit = cfq_exit_io_context; |
1342 | atomic_inc(&ioc_count); | 1161 | elv_ioc_count_inc(ioc_count); |
1343 | } | 1162 | } |
1344 | 1163 | ||
1345 | return cic; | 1164 | return cic; |
@@ -1420,15 +1239,12 @@ static inline void changed_ioprio(struct cfq_io_context *cic) | |||
1420 | spin_unlock(cfqd->queue->queue_lock); | 1239 | spin_unlock(cfqd->queue->queue_lock); |
1421 | } | 1240 | } |
1422 | 1241 | ||
1423 | /* | 1242 | static void cfq_ioc_set_ioprio(struct io_context *ioc) |
1424 | * callback from sys_ioprio_set, irqs are disabled | ||
1425 | */ | ||
1426 | static int cfq_ioc_set_ioprio(struct io_context *ioc, unsigned int ioprio) | ||
1427 | { | 1243 | { |
1428 | struct cfq_io_context *cic; | 1244 | struct cfq_io_context *cic; |
1429 | struct rb_node *n; | 1245 | struct rb_node *n; |
1430 | 1246 | ||
1431 | spin_lock(&cfq_exit_lock); | 1247 | ioc->ioprio_changed = 0; |
1432 | 1248 | ||
1433 | n = rb_first(&ioc->cic_root); | 1249 | n = rb_first(&ioc->cic_root); |
1434 | while (n != NULL) { | 1250 | while (n != NULL) { |
@@ -1437,10 +1253,6 @@ static int cfq_ioc_set_ioprio(struct io_context *ioc, unsigned int ioprio) | |||
1437 | changed_ioprio(cic); | 1253 | changed_ioprio(cic); |
1438 | n = rb_next(n); | 1254 | n = rb_next(n); |
1439 | } | 1255 | } |
1440 | |||
1441 | spin_unlock(&cfq_exit_lock); | ||
1442 | |||
1443 | return 0; | ||
1444 | } | 1256 | } |
1445 | 1257 | ||
1446 | static struct cfq_queue * | 1258 | static struct cfq_queue * |
@@ -1460,12 +1272,18 @@ retry: | |||
1460 | cfqq = new_cfqq; | 1272 | cfqq = new_cfqq; |
1461 | new_cfqq = NULL; | 1273 | new_cfqq = NULL; |
1462 | } else if (gfp_mask & __GFP_WAIT) { | 1274 | } else if (gfp_mask & __GFP_WAIT) { |
1275 | /* | ||
1276 | * Inform the allocator of the fact that we will | ||
1277 | * just repeat this allocation if it fails, to allow | ||
1278 | * the allocator to do whatever it needs to attempt to | ||
1279 | * free memory. | ||
1280 | */ | ||
1463 | spin_unlock_irq(cfqd->queue->queue_lock); | 1281 | spin_unlock_irq(cfqd->queue->queue_lock); |
1464 | new_cfqq = kmem_cache_alloc(cfq_pool, gfp_mask); | 1282 | new_cfqq = kmem_cache_alloc_node(cfq_pool, gfp_mask|__GFP_NOFAIL, cfqd->queue->node); |
1465 | spin_lock_irq(cfqd->queue->queue_lock); | 1283 | spin_lock_irq(cfqd->queue->queue_lock); |
1466 | goto retry; | 1284 | goto retry; |
1467 | } else { | 1285 | } else { |
1468 | cfqq = kmem_cache_alloc(cfq_pool, gfp_mask); | 1286 | cfqq = kmem_cache_alloc_node(cfq_pool, gfp_mask, cfqd->queue->node); |
1469 | if (!cfqq) | 1287 | if (!cfqq) |
1470 | goto out; | 1288 | goto out; |
1471 | } | 1289 | } |
@@ -1480,13 +1298,13 @@ retry: | |||
1480 | hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); | 1298 | hlist_add_head(&cfqq->cfq_hash, &cfqd->cfq_hash[hashval]); |
1481 | atomic_set(&cfqq->ref, 0); | 1299 | atomic_set(&cfqq->ref, 0); |
1482 | cfqq->cfqd = cfqd; | 1300 | cfqq->cfqd = cfqd; |
1483 | cfqq->service_last = 0; | ||
1484 | /* | 1301 | /* |
1485 | * set ->slice_left to allow preemption for a new process | 1302 | * set ->slice_left to allow preemption for a new process |
1486 | */ | 1303 | */ |
1487 | cfqq->slice_left = 2 * cfqd->cfq_slice_idle; | 1304 | cfqq->slice_left = 2 * cfqd->cfq_slice_idle; |
1488 | cfq_mark_cfqq_idle_window(cfqq); | 1305 | cfq_mark_cfqq_idle_window(cfqq); |
1489 | cfq_mark_cfqq_prio_changed(cfqq); | 1306 | cfq_mark_cfqq_prio_changed(cfqq); |
1307 | cfq_mark_cfqq_queue_new(cfqq); | ||
1490 | cfq_init_prio_data(cfqq); | 1308 | cfq_init_prio_data(cfqq); |
1491 | } | 1309 | } |
1492 | 1310 | ||
@@ -1502,12 +1320,10 @@ out: | |||
1502 | static void | 1320 | static void |
1503 | cfq_drop_dead_cic(struct io_context *ioc, struct cfq_io_context *cic) | 1321 | cfq_drop_dead_cic(struct io_context *ioc, struct cfq_io_context *cic) |
1504 | { | 1322 | { |
1505 | spin_lock(&cfq_exit_lock); | 1323 | WARN_ON(!list_empty(&cic->queue_list)); |
1506 | rb_erase(&cic->rb_node, &ioc->cic_root); | 1324 | rb_erase(&cic->rb_node, &ioc->cic_root); |
1507 | list_del_init(&cic->queue_list); | ||
1508 | spin_unlock(&cfq_exit_lock); | ||
1509 | kmem_cache_free(cfq_ioc_pool, cic); | 1325 | kmem_cache_free(cfq_ioc_pool, cic); |
1510 | atomic_dec(&ioc_count); | 1326 | elv_ioc_count_dec(ioc_count); |
1511 | } | 1327 | } |
1512 | 1328 | ||
1513 | static struct cfq_io_context * | 1329 | static struct cfq_io_context * |
@@ -1551,7 +1367,6 @@ cfq_cic_link(struct cfq_data *cfqd, struct io_context *ioc, | |||
1551 | cic->ioc = ioc; | 1367 | cic->ioc = ioc; |
1552 | cic->key = cfqd; | 1368 | cic->key = cfqd; |
1553 | 1369 | ||
1554 | ioc->set_ioprio = cfq_ioc_set_ioprio; | ||
1555 | restart: | 1370 | restart: |
1556 | parent = NULL; | 1371 | parent = NULL; |
1557 | p = &ioc->cic_root.rb_node; | 1372 | p = &ioc->cic_root.rb_node; |
@@ -1573,11 +1388,12 @@ restart: | |||
1573 | BUG(); | 1388 | BUG(); |
1574 | } | 1389 | } |
1575 | 1390 | ||
1576 | spin_lock(&cfq_exit_lock); | ||
1577 | rb_link_node(&cic->rb_node, parent, p); | 1391 | rb_link_node(&cic->rb_node, parent, p); |
1578 | rb_insert_color(&cic->rb_node, &ioc->cic_root); | 1392 | rb_insert_color(&cic->rb_node, &ioc->cic_root); |
1393 | |||
1394 | spin_lock_irq(cfqd->queue->queue_lock); | ||
1579 | list_add(&cic->queue_list, &cfqd->cic_list); | 1395 | list_add(&cic->queue_list, &cfqd->cic_list); |
1580 | spin_unlock(&cfq_exit_lock); | 1396 | spin_unlock_irq(cfqd->queue->queue_lock); |
1581 | } | 1397 | } |
1582 | 1398 | ||
1583 | /* | 1399 | /* |
@@ -1593,7 +1409,7 @@ cfq_get_io_context(struct cfq_data *cfqd, gfp_t gfp_mask) | |||
1593 | 1409 | ||
1594 | might_sleep_if(gfp_mask & __GFP_WAIT); | 1410 | might_sleep_if(gfp_mask & __GFP_WAIT); |
1595 | 1411 | ||
1596 | ioc = get_io_context(gfp_mask); | 1412 | ioc = get_io_context(gfp_mask, cfqd->queue->node); |
1597 | if (!ioc) | 1413 | if (!ioc) |
1598 | return NULL; | 1414 | return NULL; |
1599 | 1415 | ||
@@ -1607,6 +1423,10 @@ cfq_get_io_context(struct cfq_data *cfqd, gfp_t gfp_mask) | |||
1607 | 1423 | ||
1608 | cfq_cic_link(cfqd, ioc, cic); | 1424 | cfq_cic_link(cfqd, ioc, cic); |
1609 | out: | 1425 | out: |
1426 | smp_read_barrier_depends(); | ||
1427 | if (unlikely(ioc->ioprio_changed)) | ||
1428 | cfq_ioc_set_ioprio(ioc); | ||
1429 | |||
1610 | return cic; | 1430 | return cic; |
1611 | err: | 1431 | err: |
1612 | put_io_context(ioc); | 1432 | put_io_context(ioc); |
@@ -1640,15 +1460,15 @@ cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_io_context *cic) | |||
1640 | 1460 | ||
1641 | static void | 1461 | static void |
1642 | cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic, | 1462 | cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic, |
1643 | struct cfq_rq *crq) | 1463 | struct request *rq) |
1644 | { | 1464 | { |
1645 | sector_t sdist; | 1465 | sector_t sdist; |
1646 | u64 total; | 1466 | u64 total; |
1647 | 1467 | ||
1648 | if (cic->last_request_pos < crq->request->sector) | 1468 | if (cic->last_request_pos < rq->sector) |
1649 | sdist = crq->request->sector - cic->last_request_pos; | 1469 | sdist = rq->sector - cic->last_request_pos; |
1650 | else | 1470 | else |
1651 | sdist = cic->last_request_pos - crq->request->sector; | 1471 | sdist = cic->last_request_pos - rq->sector; |
1652 | 1472 | ||
1653 | /* | 1473 | /* |
1654 | * Don't allow the seek distance to get too large from the | 1474 | * Don't allow the seek distance to get too large from the |
@@ -1699,7 +1519,7 @@ cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1699 | */ | 1519 | */ |
1700 | static int | 1520 | static int |
1701 | cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, | 1521 | cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, |
1702 | struct cfq_rq *crq) | 1522 | struct request *rq) |
1703 | { | 1523 | { |
1704 | struct cfq_queue *cfqq = cfqd->active_queue; | 1524 | struct cfq_queue *cfqq = cfqd->active_queue; |
1705 | 1525 | ||
@@ -1718,7 +1538,17 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, | |||
1718 | */ | 1538 | */ |
1719 | if (new_cfqq->slice_left < cfqd->cfq_slice_idle) | 1539 | if (new_cfqq->slice_left < cfqd->cfq_slice_idle) |
1720 | return 0; | 1540 | return 0; |
1721 | if (cfq_crq_is_sync(crq) && !cfq_cfqq_sync(cfqq)) | 1541 | /* |
1542 | * if the new request is sync, but the currently running queue is | ||
1543 | * not, let the sync request have priority. | ||
1544 | */ | ||
1545 | if (rq_is_sync(rq) && !cfq_cfqq_sync(cfqq)) | ||
1546 | return 1; | ||
1547 | /* | ||
1548 | * So both queues are sync. Let the new request get disk time if | ||
1549 | * it's a metadata request and the current queue is doing regular IO. | ||
1550 | */ | ||
1551 | if (rq_is_meta(rq) && !cfqq->meta_pending) | ||
1722 | return 1; | 1552 | return 1; |
1723 | 1553 | ||
1724 | return 0; | 1554 | return 0; |
@@ -1730,47 +1560,45 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, | |||
1730 | */ | 1560 | */ |
1731 | static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) | 1561 | static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
1732 | { | 1562 | { |
1733 | struct cfq_queue *__cfqq, *next; | 1563 | cfq_slice_expired(cfqd, 1); |
1734 | |||
1735 | list_for_each_entry_safe(__cfqq, next, &cfqd->cur_rr, cfq_list) | ||
1736 | cfq_resort_rr_list(__cfqq, 1); | ||
1737 | 1564 | ||
1738 | if (!cfqq->slice_left) | 1565 | if (!cfqq->slice_left) |
1739 | cfqq->slice_left = cfq_prio_to_slice(cfqd, cfqq) / 2; | 1566 | cfqq->slice_left = cfq_prio_to_slice(cfqd, cfqq) / 2; |
1740 | 1567 | ||
1741 | cfqq->slice_end = cfqq->slice_left + jiffies; | 1568 | /* |
1742 | cfq_slice_expired(cfqd, 1); | 1569 | * Put the new queue at the front of the of the current list, |
1743 | __cfq_set_active_queue(cfqd, cfqq); | 1570 | * so we know that it will be selected next. |
1744 | } | 1571 | */ |
1745 | 1572 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); | |
1746 | /* | 1573 | list_move(&cfqq->cfq_list, &cfqd->cur_rr); |
1747 | * should really be a ll_rw_blk.c helper | ||
1748 | */ | ||
1749 | static void cfq_start_queueing(struct cfq_data *cfqd, struct cfq_queue *cfqq) | ||
1750 | { | ||
1751 | request_queue_t *q = cfqd->queue; | ||
1752 | 1574 | ||
1753 | if (!blk_queue_plugged(q)) | 1575 | cfqq->slice_end = cfqq->slice_left + jiffies; |
1754 | q->request_fn(q); | ||
1755 | else | ||
1756 | __generic_unplug_device(q); | ||
1757 | } | 1576 | } |
1758 | 1577 | ||
1759 | /* | 1578 | /* |
1760 | * Called when a new fs request (crq) is added (to cfqq). Check if there's | 1579 | * Called when a new fs request (rq) is added (to cfqq). Check if there's |
1761 | * something we should do about it | 1580 | * something we should do about it |
1762 | */ | 1581 | */ |
1763 | static void | 1582 | static void |
1764 | cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, | 1583 | cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
1765 | struct cfq_rq *crq) | 1584 | struct request *rq) |
1766 | { | 1585 | { |
1767 | struct cfq_io_context *cic = crq->io_context; | 1586 | struct cfq_io_context *cic = RQ_CIC(rq); |
1587 | |||
1588 | if (rq_is_meta(rq)) | ||
1589 | cfqq->meta_pending++; | ||
1590 | |||
1591 | /* | ||
1592 | * check if this request is a better next-serve candidate)) { | ||
1593 | */ | ||
1594 | cfqq->next_rq = cfq_choose_req(cfqd, cfqq->next_rq, rq); | ||
1595 | BUG_ON(!cfqq->next_rq); | ||
1768 | 1596 | ||
1769 | /* | 1597 | /* |
1770 | * we never wait for an async request and we don't allow preemption | 1598 | * we never wait for an async request and we don't allow preemption |
1771 | * of an async request. so just return early | 1599 | * of an async request. so just return early |
1772 | */ | 1600 | */ |
1773 | if (!cfq_crq_is_sync(crq)) { | 1601 | if (!rq_is_sync(rq)) { |
1774 | /* | 1602 | /* |
1775 | * sync process issued an async request, if it's waiting | 1603 | * sync process issued an async request, if it's waiting |
1776 | * then expire it and kick rq handling. | 1604 | * then expire it and kick rq handling. |
@@ -1778,17 +1606,17 @@ cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1778 | if (cic == cfqd->active_cic && | 1606 | if (cic == cfqd->active_cic && |
1779 | del_timer(&cfqd->idle_slice_timer)) { | 1607 | del_timer(&cfqd->idle_slice_timer)) { |
1780 | cfq_slice_expired(cfqd, 0); | 1608 | cfq_slice_expired(cfqd, 0); |
1781 | cfq_start_queueing(cfqd, cfqq); | 1609 | blk_start_queueing(cfqd->queue); |
1782 | } | 1610 | } |
1783 | return; | 1611 | return; |
1784 | } | 1612 | } |
1785 | 1613 | ||
1786 | cfq_update_io_thinktime(cfqd, cic); | 1614 | cfq_update_io_thinktime(cfqd, cic); |
1787 | cfq_update_io_seektime(cfqd, cic, crq); | 1615 | cfq_update_io_seektime(cfqd, cic, rq); |
1788 | cfq_update_idle_window(cfqd, cfqq, cic); | 1616 | cfq_update_idle_window(cfqd, cfqq, cic); |
1789 | 1617 | ||
1790 | cic->last_queue = jiffies; | 1618 | cic->last_queue = jiffies; |
1791 | cic->last_request_pos = crq->request->sector + crq->request->nr_sectors; | 1619 | cic->last_request_pos = rq->sector + rq->nr_sectors; |
1792 | 1620 | ||
1793 | if (cfqq == cfqd->active_queue) { | 1621 | if (cfqq == cfqd->active_queue) { |
1794 | /* | 1622 | /* |
@@ -1799,9 +1627,9 @@ cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1799 | if (cfq_cfqq_wait_request(cfqq)) { | 1627 | if (cfq_cfqq_wait_request(cfqq)) { |
1800 | cfq_mark_cfqq_must_dispatch(cfqq); | 1628 | cfq_mark_cfqq_must_dispatch(cfqq); |
1801 | del_timer(&cfqd->idle_slice_timer); | 1629 | del_timer(&cfqd->idle_slice_timer); |
1802 | cfq_start_queueing(cfqd, cfqq); | 1630 | blk_start_queueing(cfqd->queue); |
1803 | } | 1631 | } |
1804 | } else if (cfq_should_preempt(cfqd, cfqq, crq)) { | 1632 | } else if (cfq_should_preempt(cfqd, cfqq, rq)) { |
1805 | /* | 1633 | /* |
1806 | * not the active queue - expire current slice if it is | 1634 | * not the active queue - expire current slice if it is |
1807 | * idle and has expired it's mean thinktime or this new queue | 1635 | * idle and has expired it's mean thinktime or this new queue |
@@ -1809,34 +1637,32 @@ cfq_crq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1809 | */ | 1637 | */ |
1810 | cfq_preempt_queue(cfqd, cfqq); | 1638 | cfq_preempt_queue(cfqd, cfqq); |
1811 | cfq_mark_cfqq_must_dispatch(cfqq); | 1639 | cfq_mark_cfqq_must_dispatch(cfqq); |
1812 | cfq_start_queueing(cfqd, cfqq); | 1640 | blk_start_queueing(cfqd->queue); |
1813 | } | 1641 | } |
1814 | } | 1642 | } |
1815 | 1643 | ||
1816 | static void cfq_insert_request(request_queue_t *q, struct request *rq) | 1644 | static void cfq_insert_request(request_queue_t *q, struct request *rq) |
1817 | { | 1645 | { |
1818 | struct cfq_data *cfqd = q->elevator->elevator_data; | 1646 | struct cfq_data *cfqd = q->elevator->elevator_data; |
1819 | struct cfq_rq *crq = RQ_DATA(rq); | 1647 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
1820 | struct cfq_queue *cfqq = crq->cfq_queue; | ||
1821 | 1648 | ||
1822 | cfq_init_prio_data(cfqq); | 1649 | cfq_init_prio_data(cfqq); |
1823 | 1650 | ||
1824 | cfq_add_crq_rb(crq); | 1651 | cfq_add_rq_rb(rq); |
1825 | 1652 | ||
1826 | list_add_tail(&rq->queuelist, &cfqq->fifo); | 1653 | if (!cfq_cfqq_on_rr(cfqq)) |
1654 | cfq_add_cfqq_rr(cfqd, cfqq); | ||
1827 | 1655 | ||
1828 | if (rq_mergeable(rq)) | 1656 | list_add_tail(&rq->queuelist, &cfqq->fifo); |
1829 | cfq_add_crq_hash(cfqd, crq); | ||
1830 | 1657 | ||
1831 | cfq_crq_enqueued(cfqd, cfqq, crq); | 1658 | cfq_rq_enqueued(cfqd, cfqq, rq); |
1832 | } | 1659 | } |
1833 | 1660 | ||
1834 | static void cfq_completed_request(request_queue_t *q, struct request *rq) | 1661 | static void cfq_completed_request(request_queue_t *q, struct request *rq) |
1835 | { | 1662 | { |
1836 | struct cfq_rq *crq = RQ_DATA(rq); | 1663 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
1837 | struct cfq_queue *cfqq = crq->cfq_queue; | ||
1838 | struct cfq_data *cfqd = cfqq->cfqd; | 1664 | struct cfq_data *cfqd = cfqq->cfqd; |
1839 | const int sync = cfq_crq_is_sync(crq); | 1665 | const int sync = rq_is_sync(rq); |
1840 | unsigned long now; | 1666 | unsigned long now; |
1841 | 1667 | ||
1842 | now = jiffies; | 1668 | now = jiffies; |
@@ -1849,15 +1675,11 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq) | |||
1849 | if (!cfq_class_idle(cfqq)) | 1675 | if (!cfq_class_idle(cfqq)) |
1850 | cfqd->last_end_request = now; | 1676 | cfqd->last_end_request = now; |
1851 | 1677 | ||
1852 | if (!cfq_cfqq_dispatched(cfqq)) { | 1678 | if (!cfq_cfqq_dispatched(cfqq) && cfq_cfqq_on_rr(cfqq)) |
1853 | if (cfq_cfqq_on_rr(cfqq)) { | 1679 | cfq_resort_rr_list(cfqq, 0); |
1854 | cfqq->service_last = now; | ||
1855 | cfq_resort_rr_list(cfqq, 0); | ||
1856 | } | ||
1857 | } | ||
1858 | 1680 | ||
1859 | if (sync) | 1681 | if (sync) |
1860 | crq->io_context->last_end_request = now; | 1682 | RQ_CIC(rq)->last_end_request = now; |
1861 | 1683 | ||
1862 | /* | 1684 | /* |
1863 | * If this is the active queue, check if it needs to be expired, | 1685 | * If this is the active queue, check if it needs to be expired, |
@@ -1873,30 +1695,6 @@ static void cfq_completed_request(request_queue_t *q, struct request *rq) | |||
1873 | } | 1695 | } |
1874 | } | 1696 | } |
1875 | 1697 | ||
1876 | static struct request * | ||
1877 | cfq_former_request(request_queue_t *q, struct request *rq) | ||
1878 | { | ||
1879 | struct cfq_rq *crq = RQ_DATA(rq); | ||
1880 | struct rb_node *rbprev = rb_prev(&crq->rb_node); | ||
1881 | |||
1882 | if (rbprev) | ||
1883 | return rb_entry_crq(rbprev)->request; | ||
1884 | |||
1885 | return NULL; | ||
1886 | } | ||
1887 | |||
1888 | static struct request * | ||
1889 | cfq_latter_request(request_queue_t *q, struct request *rq) | ||
1890 | { | ||
1891 | struct cfq_rq *crq = RQ_DATA(rq); | ||
1892 | struct rb_node *rbnext = rb_next(&crq->rb_node); | ||
1893 | |||
1894 | if (rbnext) | ||
1895 | return rb_entry_crq(rbnext)->request; | ||
1896 | |||
1897 | return NULL; | ||
1898 | } | ||
1899 | |||
1900 | /* | 1698 | /* |
1901 | * we temporarily boost lower priority queues if they are holding fs exclusive | 1699 | * we temporarily boost lower priority queues if they are holding fs exclusive |
1902 | * resources. they are boosted to normal prio (CLASS_BE/4) | 1700 | * resources. they are boosted to normal prio (CLASS_BE/4) |
@@ -1933,9 +1731,7 @@ static void cfq_prio_boost(struct cfq_queue *cfqq) | |||
1933 | cfq_resort_rr_list(cfqq, 0); | 1731 | cfq_resort_rr_list(cfqq, 0); |
1934 | } | 1732 | } |
1935 | 1733 | ||
1936 | static inline int | 1734 | static inline int __cfq_may_queue(struct cfq_queue *cfqq) |
1937 | __cfq_may_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq, | ||
1938 | struct task_struct *task, int rw) | ||
1939 | { | 1735 | { |
1940 | if ((cfq_cfqq_wait_request(cfqq) || cfq_cfqq_must_alloc(cfqq)) && | 1736 | if ((cfq_cfqq_wait_request(cfqq) || cfq_cfqq_must_alloc(cfqq)) && |
1941 | !cfq_cfqq_must_alloc_slice(cfqq)) { | 1737 | !cfq_cfqq_must_alloc_slice(cfqq)) { |
@@ -1946,7 +1742,7 @@ __cfq_may_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq, | |||
1946 | return ELV_MQUEUE_MAY; | 1742 | return ELV_MQUEUE_MAY; |
1947 | } | 1743 | } |
1948 | 1744 | ||
1949 | static int cfq_may_queue(request_queue_t *q, int rw, struct bio *bio) | 1745 | static int cfq_may_queue(request_queue_t *q, int rw) |
1950 | { | 1746 | { |
1951 | struct cfq_data *cfqd = q->elevator->elevator_data; | 1747 | struct cfq_data *cfqd = q->elevator->elevator_data; |
1952 | struct task_struct *tsk = current; | 1748 | struct task_struct *tsk = current; |
@@ -1963,48 +1759,30 @@ static int cfq_may_queue(request_queue_t *q, int rw, struct bio *bio) | |||
1963 | cfq_init_prio_data(cfqq); | 1759 | cfq_init_prio_data(cfqq); |
1964 | cfq_prio_boost(cfqq); | 1760 | cfq_prio_boost(cfqq); |
1965 | 1761 | ||
1966 | return __cfq_may_queue(cfqd, cfqq, tsk, rw); | 1762 | return __cfq_may_queue(cfqq); |
1967 | } | 1763 | } |
1968 | 1764 | ||
1969 | return ELV_MQUEUE_MAY; | 1765 | return ELV_MQUEUE_MAY; |
1970 | } | 1766 | } |
1971 | 1767 | ||
1972 | static void cfq_check_waiters(request_queue_t *q, struct cfq_queue *cfqq) | ||
1973 | { | ||
1974 | struct cfq_data *cfqd = q->elevator->elevator_data; | ||
1975 | |||
1976 | if (unlikely(cfqd->rq_starved)) { | ||
1977 | struct request_list *rl = &q->rq; | ||
1978 | |||
1979 | smp_mb(); | ||
1980 | if (waitqueue_active(&rl->wait[READ])) | ||
1981 | wake_up(&rl->wait[READ]); | ||
1982 | if (waitqueue_active(&rl->wait[WRITE])) | ||
1983 | wake_up(&rl->wait[WRITE]); | ||
1984 | } | ||
1985 | } | ||
1986 | |||
1987 | /* | 1768 | /* |
1988 | * queue lock held here | 1769 | * queue lock held here |
1989 | */ | 1770 | */ |
1990 | static void cfq_put_request(request_queue_t *q, struct request *rq) | 1771 | static void cfq_put_request(request_queue_t *q, struct request *rq) |
1991 | { | 1772 | { |
1992 | struct cfq_data *cfqd = q->elevator->elevator_data; | 1773 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
1993 | struct cfq_rq *crq = RQ_DATA(rq); | ||
1994 | 1774 | ||
1995 | if (crq) { | 1775 | if (cfqq) { |
1996 | struct cfq_queue *cfqq = crq->cfq_queue; | ||
1997 | const int rw = rq_data_dir(rq); | 1776 | const int rw = rq_data_dir(rq); |
1998 | 1777 | ||
1999 | BUG_ON(!cfqq->allocated[rw]); | 1778 | BUG_ON(!cfqq->allocated[rw]); |
2000 | cfqq->allocated[rw]--; | 1779 | cfqq->allocated[rw]--; |
2001 | 1780 | ||
2002 | put_io_context(crq->io_context->ioc); | 1781 | put_io_context(RQ_CIC(rq)->ioc); |
2003 | 1782 | ||
2004 | mempool_free(crq, cfqd->crq_pool); | ||
2005 | rq->elevator_private = NULL; | 1783 | rq->elevator_private = NULL; |
1784 | rq->elevator_private2 = NULL; | ||
2006 | 1785 | ||
2007 | cfq_check_waiters(q, cfqq); | ||
2008 | cfq_put_queue(cfqq); | 1786 | cfq_put_queue(cfqq); |
2009 | } | 1787 | } |
2010 | } | 1788 | } |
@@ -2013,8 +1791,7 @@ static void cfq_put_request(request_queue_t *q, struct request *rq) | |||
2013 | * Allocate cfq data structures associated with this request. | 1791 | * Allocate cfq data structures associated with this request. |
2014 | */ | 1792 | */ |
2015 | static int | 1793 | static int |
2016 | cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio, | 1794 | cfq_set_request(request_queue_t *q, struct request *rq, gfp_t gfp_mask) |
2017 | gfp_t gfp_mask) | ||
2018 | { | 1795 | { |
2019 | struct cfq_data *cfqd = q->elevator->elevator_data; | 1796 | struct cfq_data *cfqd = q->elevator->elevator_data; |
2020 | struct task_struct *tsk = current; | 1797 | struct task_struct *tsk = current; |
@@ -2022,7 +1799,6 @@ cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio, | |||
2022 | const int rw = rq_data_dir(rq); | 1799 | const int rw = rq_data_dir(rq); |
2023 | pid_t key = cfq_queue_pid(tsk, rw); | 1800 | pid_t key = cfq_queue_pid(tsk, rw); |
2024 | struct cfq_queue *cfqq; | 1801 | struct cfq_queue *cfqq; |
2025 | struct cfq_rq *crq; | ||
2026 | unsigned long flags; | 1802 | unsigned long flags; |
2027 | int is_sync = key != CFQ_KEY_ASYNC; | 1803 | int is_sync = key != CFQ_KEY_ASYNC; |
2028 | 1804 | ||
@@ -2046,42 +1822,18 @@ cfq_set_request(request_queue_t *q, struct request *rq, struct bio *bio, | |||
2046 | 1822 | ||
2047 | cfqq->allocated[rw]++; | 1823 | cfqq->allocated[rw]++; |
2048 | cfq_clear_cfqq_must_alloc(cfqq); | 1824 | cfq_clear_cfqq_must_alloc(cfqq); |
2049 | cfqd->rq_starved = 0; | ||
2050 | atomic_inc(&cfqq->ref); | 1825 | atomic_inc(&cfqq->ref); |
2051 | spin_unlock_irqrestore(q->queue_lock, flags); | ||
2052 | 1826 | ||
2053 | crq = mempool_alloc(cfqd->crq_pool, gfp_mask); | 1827 | spin_unlock_irqrestore(q->queue_lock, flags); |
2054 | if (crq) { | ||
2055 | RB_CLEAR_NODE(&crq->rb_node); | ||
2056 | crq->rb_key = 0; | ||
2057 | crq->request = rq; | ||
2058 | INIT_HLIST_NODE(&crq->hash); | ||
2059 | crq->cfq_queue = cfqq; | ||
2060 | crq->io_context = cic; | ||
2061 | |||
2062 | if (is_sync) | ||
2063 | cfq_mark_crq_is_sync(crq); | ||
2064 | else | ||
2065 | cfq_clear_crq_is_sync(crq); | ||
2066 | 1828 | ||
2067 | rq->elevator_private = crq; | 1829 | rq->elevator_private = cic; |
2068 | return 0; | 1830 | rq->elevator_private2 = cfqq; |
2069 | } | 1831 | return 0; |
2070 | 1832 | ||
2071 | spin_lock_irqsave(q->queue_lock, flags); | ||
2072 | cfqq->allocated[rw]--; | ||
2073 | if (!(cfqq->allocated[0] + cfqq->allocated[1])) | ||
2074 | cfq_mark_cfqq_must_alloc(cfqq); | ||
2075 | cfq_put_queue(cfqq); | ||
2076 | queue_fail: | 1833 | queue_fail: |
2077 | if (cic) | 1834 | if (cic) |
2078 | put_io_context(cic->ioc); | 1835 | put_io_context(cic->ioc); |
2079 | /* | 1836 | |
2080 | * mark us rq allocation starved. we need to kickstart the process | ||
2081 | * ourselves if there are no pending requests that can do it for us. | ||
2082 | * that would be an extremely rare OOM situation | ||
2083 | */ | ||
2084 | cfqd->rq_starved = 1; | ||
2085 | cfq_schedule_dispatch(cfqd); | 1837 | cfq_schedule_dispatch(cfqd); |
2086 | spin_unlock_irqrestore(q->queue_lock, flags); | 1838 | spin_unlock_irqrestore(q->queue_lock, flags); |
2087 | return 1; | 1839 | return 1; |
@@ -2090,27 +1842,10 @@ queue_fail: | |||
2090 | static void cfq_kick_queue(void *data) | 1842 | static void cfq_kick_queue(void *data) |
2091 | { | 1843 | { |
2092 | request_queue_t *q = data; | 1844 | request_queue_t *q = data; |
2093 | struct cfq_data *cfqd = q->elevator->elevator_data; | ||
2094 | unsigned long flags; | 1845 | unsigned long flags; |
2095 | 1846 | ||
2096 | spin_lock_irqsave(q->queue_lock, flags); | 1847 | spin_lock_irqsave(q->queue_lock, flags); |
2097 | 1848 | blk_start_queueing(q); | |
2098 | if (cfqd->rq_starved) { | ||
2099 | struct request_list *rl = &q->rq; | ||
2100 | |||
2101 | /* | ||
2102 | * we aren't guaranteed to get a request after this, but we | ||
2103 | * have to be opportunistic | ||
2104 | */ | ||
2105 | smp_mb(); | ||
2106 | if (waitqueue_active(&rl->wait[READ])) | ||
2107 | wake_up(&rl->wait[READ]); | ||
2108 | if (waitqueue_active(&rl->wait[WRITE])) | ||
2109 | wake_up(&rl->wait[WRITE]); | ||
2110 | } | ||
2111 | |||
2112 | blk_remove_plug(q); | ||
2113 | q->request_fn(q); | ||
2114 | spin_unlock_irqrestore(q->queue_lock, flags); | 1849 | spin_unlock_irqrestore(q->queue_lock, flags); |
2115 | } | 1850 | } |
2116 | 1851 | ||
@@ -2193,7 +1928,6 @@ static void cfq_exit_queue(elevator_t *e) | |||
2193 | 1928 | ||
2194 | cfq_shutdown_timer_wq(cfqd); | 1929 | cfq_shutdown_timer_wq(cfqd); |
2195 | 1930 | ||
2196 | spin_lock(&cfq_exit_lock); | ||
2197 | spin_lock_irq(q->queue_lock); | 1931 | spin_lock_irq(q->queue_lock); |
2198 | 1932 | ||
2199 | if (cfqd->active_queue) | 1933 | if (cfqd->active_queue) |
@@ -2203,25 +1937,14 @@ static void cfq_exit_queue(elevator_t *e) | |||
2203 | struct cfq_io_context *cic = list_entry(cfqd->cic_list.next, | 1937 | struct cfq_io_context *cic = list_entry(cfqd->cic_list.next, |
2204 | struct cfq_io_context, | 1938 | struct cfq_io_context, |
2205 | queue_list); | 1939 | queue_list); |
2206 | if (cic->cfqq[ASYNC]) { | 1940 | |
2207 | cfq_put_queue(cic->cfqq[ASYNC]); | 1941 | __cfq_exit_single_io_context(cfqd, cic); |
2208 | cic->cfqq[ASYNC] = NULL; | ||
2209 | } | ||
2210 | if (cic->cfqq[SYNC]) { | ||
2211 | cfq_put_queue(cic->cfqq[SYNC]); | ||
2212 | cic->cfqq[SYNC] = NULL; | ||
2213 | } | ||
2214 | cic->key = NULL; | ||
2215 | list_del_init(&cic->queue_list); | ||
2216 | } | 1942 | } |
2217 | 1943 | ||
2218 | spin_unlock_irq(q->queue_lock); | 1944 | spin_unlock_irq(q->queue_lock); |
2219 | spin_unlock(&cfq_exit_lock); | ||
2220 | 1945 | ||
2221 | cfq_shutdown_timer_wq(cfqd); | 1946 | cfq_shutdown_timer_wq(cfqd); |
2222 | 1947 | ||
2223 | mempool_destroy(cfqd->crq_pool); | ||
2224 | kfree(cfqd->crq_hash); | ||
2225 | kfree(cfqd->cfq_hash); | 1948 | kfree(cfqd->cfq_hash); |
2226 | kfree(cfqd); | 1949 | kfree(cfqd); |
2227 | } | 1950 | } |
@@ -2231,7 +1954,7 @@ static void *cfq_init_queue(request_queue_t *q, elevator_t *e) | |||
2231 | struct cfq_data *cfqd; | 1954 | struct cfq_data *cfqd; |
2232 | int i; | 1955 | int i; |
2233 | 1956 | ||
2234 | cfqd = kmalloc(sizeof(*cfqd), GFP_KERNEL); | 1957 | cfqd = kmalloc_node(sizeof(*cfqd), GFP_KERNEL, q->node); |
2235 | if (!cfqd) | 1958 | if (!cfqd) |
2236 | return NULL; | 1959 | return NULL; |
2237 | 1960 | ||
@@ -2243,23 +1966,12 @@ static void *cfq_init_queue(request_queue_t *q, elevator_t *e) | |||
2243 | INIT_LIST_HEAD(&cfqd->busy_rr); | 1966 | INIT_LIST_HEAD(&cfqd->busy_rr); |
2244 | INIT_LIST_HEAD(&cfqd->cur_rr); | 1967 | INIT_LIST_HEAD(&cfqd->cur_rr); |
2245 | INIT_LIST_HEAD(&cfqd->idle_rr); | 1968 | INIT_LIST_HEAD(&cfqd->idle_rr); |
2246 | INIT_LIST_HEAD(&cfqd->empty_list); | ||
2247 | INIT_LIST_HEAD(&cfqd->cic_list); | 1969 | INIT_LIST_HEAD(&cfqd->cic_list); |
2248 | 1970 | ||
2249 | cfqd->crq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_MHASH_ENTRIES, GFP_KERNEL); | 1971 | cfqd->cfq_hash = kmalloc_node(sizeof(struct hlist_head) * CFQ_QHASH_ENTRIES, GFP_KERNEL, q->node); |
2250 | if (!cfqd->crq_hash) | ||
2251 | goto out_crqhash; | ||
2252 | |||
2253 | cfqd->cfq_hash = kmalloc(sizeof(struct hlist_head) * CFQ_QHASH_ENTRIES, GFP_KERNEL); | ||
2254 | if (!cfqd->cfq_hash) | 1972 | if (!cfqd->cfq_hash) |
2255 | goto out_cfqhash; | 1973 | goto out_free; |
2256 | |||
2257 | cfqd->crq_pool = mempool_create_slab_pool(BLKDEV_MIN_RQ, crq_pool); | ||
2258 | if (!cfqd->crq_pool) | ||
2259 | goto out_crqpool; | ||
2260 | 1974 | ||
2261 | for (i = 0; i < CFQ_MHASH_ENTRIES; i++) | ||
2262 | INIT_HLIST_HEAD(&cfqd->crq_hash[i]); | ||
2263 | for (i = 0; i < CFQ_QHASH_ENTRIES; i++) | 1975 | for (i = 0; i < CFQ_QHASH_ENTRIES; i++) |
2264 | INIT_HLIST_HEAD(&cfqd->cfq_hash[i]); | 1976 | INIT_HLIST_HEAD(&cfqd->cfq_hash[i]); |
2265 | 1977 | ||
@@ -2275,7 +1987,6 @@ static void *cfq_init_queue(request_queue_t *q, elevator_t *e) | |||
2275 | 1987 | ||
2276 | INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q); | 1988 | INIT_WORK(&cfqd->unplug_work, cfq_kick_queue, q); |
2277 | 1989 | ||
2278 | cfqd->cfq_queued = cfq_queued; | ||
2279 | cfqd->cfq_quantum = cfq_quantum; | 1990 | cfqd->cfq_quantum = cfq_quantum; |
2280 | cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0]; | 1991 | cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0]; |
2281 | cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1]; | 1992 | cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1]; |
@@ -2287,19 +1998,13 @@ static void *cfq_init_queue(request_queue_t *q, elevator_t *e) | |||
2287 | cfqd->cfq_slice_idle = cfq_slice_idle; | 1998 | cfqd->cfq_slice_idle = cfq_slice_idle; |
2288 | 1999 | ||
2289 | return cfqd; | 2000 | return cfqd; |
2290 | out_crqpool: | 2001 | out_free: |
2291 | kfree(cfqd->cfq_hash); | ||
2292 | out_cfqhash: | ||
2293 | kfree(cfqd->crq_hash); | ||
2294 | out_crqhash: | ||
2295 | kfree(cfqd); | 2002 | kfree(cfqd); |
2296 | return NULL; | 2003 | return NULL; |
2297 | } | 2004 | } |
2298 | 2005 | ||
2299 | static void cfq_slab_kill(void) | 2006 | static void cfq_slab_kill(void) |
2300 | { | 2007 | { |
2301 | if (crq_pool) | ||
2302 | kmem_cache_destroy(crq_pool); | ||
2303 | if (cfq_pool) | 2008 | if (cfq_pool) |
2304 | kmem_cache_destroy(cfq_pool); | 2009 | kmem_cache_destroy(cfq_pool); |
2305 | if (cfq_ioc_pool) | 2010 | if (cfq_ioc_pool) |
@@ -2308,11 +2013,6 @@ static void cfq_slab_kill(void) | |||
2308 | 2013 | ||
2309 | static int __init cfq_slab_setup(void) | 2014 | static int __init cfq_slab_setup(void) |
2310 | { | 2015 | { |
2311 | crq_pool = kmem_cache_create("crq_pool", sizeof(struct cfq_rq), 0, 0, | ||
2312 | NULL, NULL); | ||
2313 | if (!crq_pool) | ||
2314 | goto fail; | ||
2315 | |||
2316 | cfq_pool = kmem_cache_create("cfq_pool", sizeof(struct cfq_queue), 0, 0, | 2016 | cfq_pool = kmem_cache_create("cfq_pool", sizeof(struct cfq_queue), 0, 0, |
2317 | NULL, NULL); | 2017 | NULL, NULL); |
2318 | if (!cfq_pool) | 2018 | if (!cfq_pool) |
@@ -2358,7 +2058,6 @@ static ssize_t __FUNC(elevator_t *e, char *page) \ | |||
2358 | return cfq_var_show(__data, (page)); \ | 2058 | return cfq_var_show(__data, (page)); \ |
2359 | } | 2059 | } |
2360 | SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0); | 2060 | SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0); |
2361 | SHOW_FUNCTION(cfq_queued_show, cfqd->cfq_queued, 0); | ||
2362 | SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1); | 2061 | SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1); |
2363 | SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1); | 2062 | SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1); |
2364 | SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0); | 2063 | SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0); |
@@ -2386,7 +2085,6 @@ static ssize_t __FUNC(elevator_t *e, const char *page, size_t count) \ | |||
2386 | return ret; \ | 2085 | return ret; \ |
2387 | } | 2086 | } |
2388 | STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0); | 2087 | STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0); |
2389 | STORE_FUNCTION(cfq_queued_store, &cfqd->cfq_queued, 1, UINT_MAX, 0); | ||
2390 | STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1); | 2088 | STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, UINT_MAX, 1); |
2391 | STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1); | 2089 | STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, UINT_MAX, 1); |
2392 | STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0); | 2090 | STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0); |
@@ -2402,7 +2100,6 @@ STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, UINT_MAX, | |||
2402 | 2100 | ||
2403 | static struct elv_fs_entry cfq_attrs[] = { | 2101 | static struct elv_fs_entry cfq_attrs[] = { |
2404 | CFQ_ATTR(quantum), | 2102 | CFQ_ATTR(quantum), |
2405 | CFQ_ATTR(queued), | ||
2406 | CFQ_ATTR(fifo_expire_sync), | 2103 | CFQ_ATTR(fifo_expire_sync), |
2407 | CFQ_ATTR(fifo_expire_async), | 2104 | CFQ_ATTR(fifo_expire_async), |
2408 | CFQ_ATTR(back_seek_max), | 2105 | CFQ_ATTR(back_seek_max), |
@@ -2425,14 +2122,14 @@ static struct elevator_type iosched_cfq = { | |||
2425 | .elevator_deactivate_req_fn = cfq_deactivate_request, | 2122 | .elevator_deactivate_req_fn = cfq_deactivate_request, |
2426 | .elevator_queue_empty_fn = cfq_queue_empty, | 2123 | .elevator_queue_empty_fn = cfq_queue_empty, |
2427 | .elevator_completed_req_fn = cfq_completed_request, | 2124 | .elevator_completed_req_fn = cfq_completed_request, |
2428 | .elevator_former_req_fn = cfq_former_request, | 2125 | .elevator_former_req_fn = elv_rb_former_request, |
2429 | .elevator_latter_req_fn = cfq_latter_request, | 2126 | .elevator_latter_req_fn = elv_rb_latter_request, |
2430 | .elevator_set_req_fn = cfq_set_request, | 2127 | .elevator_set_req_fn = cfq_set_request, |
2431 | .elevator_put_req_fn = cfq_put_request, | 2128 | .elevator_put_req_fn = cfq_put_request, |
2432 | .elevator_may_queue_fn = cfq_may_queue, | 2129 | .elevator_may_queue_fn = cfq_may_queue, |
2433 | .elevator_init_fn = cfq_init_queue, | 2130 | .elevator_init_fn = cfq_init_queue, |
2434 | .elevator_exit_fn = cfq_exit_queue, | 2131 | .elevator_exit_fn = cfq_exit_queue, |
2435 | .trim = cfq_trim, | 2132 | .trim = cfq_free_io_context, |
2436 | }, | 2133 | }, |
2437 | .elevator_attrs = cfq_attrs, | 2134 | .elevator_attrs = cfq_attrs, |
2438 | .elevator_name = "cfq", | 2135 | .elevator_name = "cfq", |
@@ -2463,12 +2160,12 @@ static int __init cfq_init(void) | |||
2463 | 2160 | ||
2464 | static void __exit cfq_exit(void) | 2161 | static void __exit cfq_exit(void) |
2465 | { | 2162 | { |
2466 | DECLARE_COMPLETION(all_gone); | 2163 | DECLARE_COMPLETION_ONSTACK(all_gone); |
2467 | elv_unregister(&iosched_cfq); | 2164 | elv_unregister(&iosched_cfq); |
2468 | ioc_gone = &all_gone; | 2165 | ioc_gone = &all_gone; |
2469 | /* ioc_gone's update must be visible before reading ioc_count */ | 2166 | /* ioc_gone's update must be visible before reading ioc_count */ |
2470 | smp_wmb(); | 2167 | smp_wmb(); |
2471 | if (atomic_read(&ioc_count)) | 2168 | if (elv_ioc_count_read(ioc_count)) |
2472 | wait_for_completion(ioc_gone); | 2169 | wait_for_completion(ioc_gone); |
2473 | synchronize_rcu(); | 2170 | synchronize_rcu(); |
2474 | cfq_slab_kill(); | 2171 | cfq_slab_kill(); |