aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/blk-cgroup.c14
-rw-r--r--block/blk-cgroup.h3
-rw-r--r--block/blk-core.c45
-rw-r--r--block/blk-ioc.c2
-rw-r--r--block/blk-merge.c8
-rw-r--r--block/blk-settings.c131
-rw-r--r--block/blk-sysfs.c11
-rw-r--r--block/cfq-iosched.c192
-rw-r--r--block/elevator.c11
9 files changed, 161 insertions, 256 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index e7dbbaf5fb3e..c85d74cae200 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -23,20 +23,6 @@ static LIST_HEAD(blkio_list);
23struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT }; 23struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
24EXPORT_SYMBOL_GPL(blkio_root_cgroup); 24EXPORT_SYMBOL_GPL(blkio_root_cgroup);
25 25
26bool blkiocg_css_tryget(struct blkio_cgroup *blkcg)
27{
28 if (!css_tryget(&blkcg->css))
29 return false;
30 return true;
31}
32EXPORT_SYMBOL_GPL(blkiocg_css_tryget);
33
34void blkiocg_css_put(struct blkio_cgroup *blkcg)
35{
36 css_put(&blkcg->css);
37}
38EXPORT_SYMBOL_GPL(blkiocg_css_put);
39
40struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup) 26struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
41{ 27{
42 return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id), 28 return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
index 4d316df863b4..84bf745fa775 100644
--- a/block/blk-cgroup.h
+++ b/block/blk-cgroup.h
@@ -43,9 +43,6 @@ struct blkio_group {
43 unsigned long sectors; 43 unsigned long sectors;
44}; 44};
45 45
46extern bool blkiocg_css_tryget(struct blkio_cgroup *blkcg);
47extern void blkiocg_css_put(struct blkio_cgroup *blkcg);
48
49typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg); 46typedef void (blkio_unlink_group_fn) (void *key, struct blkio_group *blkg);
50typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg, 47typedef void (blkio_update_group_weight_fn) (struct blkio_group *blkg,
51 unsigned int weight); 48 unsigned int weight);
diff --git a/block/blk-core.c b/block/blk-core.c
index 718897e6d37f..9fe174dc74d1 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1147,7 +1147,7 @@ void init_request_from_bio(struct request *req, struct bio *bio)
1147 */ 1147 */
1148static inline bool queue_should_plug(struct request_queue *q) 1148static inline bool queue_should_plug(struct request_queue *q)
1149{ 1149{
1150 return !(blk_queue_nonrot(q) && blk_queue_queuing(q)); 1150 return !(blk_queue_nonrot(q) && blk_queue_tagged(q));
1151} 1151}
1152 1152
1153static int __make_request(struct request_queue *q, struct bio *bio) 1153static int __make_request(struct request_queue *q, struct bio *bio)
@@ -1490,9 +1490,9 @@ end_io:
1490/* 1490/*
1491 * We only want one ->make_request_fn to be active at a time, 1491 * We only want one ->make_request_fn to be active at a time,
1492 * else stack usage with stacked devices could be a problem. 1492 * else stack usage with stacked devices could be a problem.
1493 * So use current->bio_{list,tail} to keep a list of requests 1493 * So use current->bio_list to keep a list of requests
1494 * submited by a make_request_fn function. 1494 * submited by a make_request_fn function.
1495 * current->bio_tail is also used as a flag to say if 1495 * current->bio_list is also used as a flag to say if
1496 * generic_make_request is currently active in this task or not. 1496 * generic_make_request is currently active in this task or not.
1497 * If it is NULL, then no make_request is active. If it is non-NULL, 1497 * If it is NULL, then no make_request is active. If it is non-NULL,
1498 * then a make_request is active, and new requests should be added 1498 * then a make_request is active, and new requests should be added
@@ -1500,11 +1500,11 @@ end_io:
1500 */ 1500 */
1501void generic_make_request(struct bio *bio) 1501void generic_make_request(struct bio *bio)
1502{ 1502{
1503 if (current->bio_tail) { 1503 struct bio_list bio_list_on_stack;
1504
1505 if (current->bio_list) {
1504 /* make_request is active */ 1506 /* make_request is active */
1505 *(current->bio_tail) = bio; 1507 bio_list_add(current->bio_list, bio);
1506 bio->bi_next = NULL;
1507 current->bio_tail = &bio->bi_next;
1508 return; 1508 return;
1509 } 1509 }
1510 /* following loop may be a bit non-obvious, and so deserves some 1510 /* following loop may be a bit non-obvious, and so deserves some
@@ -1512,30 +1512,27 @@ void generic_make_request(struct bio *bio)
1512 * Before entering the loop, bio->bi_next is NULL (as all callers 1512 * Before entering the loop, bio->bi_next is NULL (as all callers
1513 * ensure that) so we have a list with a single bio. 1513 * ensure that) so we have a list with a single bio.
1514 * We pretend that we have just taken it off a longer list, so 1514 * We pretend that we have just taken it off a longer list, so
1515 * we assign bio_list to the next (which is NULL) and bio_tail 1515 * we assign bio_list to a pointer to the bio_list_on_stack,
1516 * to &bio_list, thus initialising the bio_list of new bios to be 1516 * thus initialising the bio_list of new bios to be
1517 * added. __generic_make_request may indeed add some more bios 1517 * added. __generic_make_request may indeed add some more bios
1518 * through a recursive call to generic_make_request. If it 1518 * through a recursive call to generic_make_request. If it
1519 * did, we find a non-NULL value in bio_list and re-enter the loop 1519 * did, we find a non-NULL value in bio_list and re-enter the loop
1520 * from the top. In this case we really did just take the bio 1520 * from the top. In this case we really did just take the bio
1521 * of the top of the list (no pretending) and so fixup bio_list and 1521 * of the top of the list (no pretending) and so remove it from
1522 * bio_tail or bi_next, and call into __generic_make_request again. 1522 * bio_list, and call into __generic_make_request again.
1523 * 1523 *
1524 * The loop was structured like this to make only one call to 1524 * The loop was structured like this to make only one call to
1525 * __generic_make_request (which is important as it is large and 1525 * __generic_make_request (which is important as it is large and
1526 * inlined) and to keep the structure simple. 1526 * inlined) and to keep the structure simple.
1527 */ 1527 */
1528 BUG_ON(bio->bi_next); 1528 BUG_ON(bio->bi_next);
1529 bio_list_init(&bio_list_on_stack);
1530 current->bio_list = &bio_list_on_stack;
1529 do { 1531 do {
1530 current->bio_list = bio->bi_next;
1531 if (bio->bi_next == NULL)
1532 current->bio_tail = &current->bio_list;
1533 else
1534 bio->bi_next = NULL;
1535 __generic_make_request(bio); 1532 __generic_make_request(bio);
1536 bio = current->bio_list; 1533 bio = bio_list_pop(current->bio_list);
1537 } while (bio); 1534 } while (bio);
1538 current->bio_tail = NULL; /* deactivate */ 1535 current->bio_list = NULL; /* deactivate */
1539} 1536}
1540EXPORT_SYMBOL(generic_make_request); 1537EXPORT_SYMBOL(generic_make_request);
1541 1538
@@ -1617,8 +1614,7 @@ int blk_rq_check_limits(struct request_queue *q, struct request *rq)
1617 * limitation. 1614 * limitation.
1618 */ 1615 */
1619 blk_recalc_rq_segments(rq); 1616 blk_recalc_rq_segments(rq);
1620 if (rq->nr_phys_segments > queue_max_phys_segments(q) || 1617 if (rq->nr_phys_segments > queue_max_segments(q)) {
1621 rq->nr_phys_segments > queue_max_hw_segments(q)) {
1622 printk(KERN_ERR "%s: over max segments limit.\n", __func__); 1618 printk(KERN_ERR "%s: over max segments limit.\n", __func__);
1623 return -EIO; 1619 return -EIO;
1624 } 1620 }
@@ -1859,15 +1855,8 @@ void blk_dequeue_request(struct request *rq)
1859 * and to it is freed is accounted as io that is in progress at 1855 * and to it is freed is accounted as io that is in progress at
1860 * the driver side. 1856 * the driver side.
1861 */ 1857 */
1862 if (blk_account_rq(rq)) { 1858 if (blk_account_rq(rq))
1863 q->in_flight[rq_is_sync(rq)]++; 1859 q->in_flight[rq_is_sync(rq)]++;
1864 /*
1865 * Mark this device as supporting hardware queuing, if
1866 * we have more IOs in flight than 4.
1867 */
1868 if (!blk_queue_queuing(q) && queue_in_flight(q) > 4)
1869 set_bit(QUEUE_FLAG_CQ, &q->queue_flags);
1870 }
1871} 1860}
1872 1861
1873/** 1862/**
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index 98e6bf61b0ac..3f65c8aadb2f 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -91,7 +91,7 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
91 spin_lock_init(&ret->lock); 91 spin_lock_init(&ret->lock);
92 ret->ioprio_changed = 0; 92 ret->ioprio_changed = 0;
93 ret->ioprio = 0; 93 ret->ioprio = 0;
94 ret->last_waited = jiffies; /* doesn't matter... */ 94 ret->last_waited = 0; /* doesn't matter... */
95 ret->nr_batch_requests = 0; /* because this is 0 */ 95 ret->nr_batch_requests = 0; /* because this is 0 */
96 INIT_RADIX_TREE(&ret->radix_root, GFP_ATOMIC | __GFP_HIGH); 96 INIT_RADIX_TREE(&ret->radix_root, GFP_ATOMIC | __GFP_HIGH);
97 INIT_HLIST_HEAD(&ret->cic_list); 97 INIT_HLIST_HEAD(&ret->cic_list);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 99cb5cf1f447..5e7dc9973458 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -206,8 +206,7 @@ static inline int ll_new_hw_segment(struct request_queue *q,
206{ 206{
207 int nr_phys_segs = bio_phys_segments(q, bio); 207 int nr_phys_segs = bio_phys_segments(q, bio);
208 208
209 if (req->nr_phys_segments + nr_phys_segs > queue_max_hw_segments(q) || 209 if (req->nr_phys_segments + nr_phys_segs > queue_max_segments(q)) {
210 req->nr_phys_segments + nr_phys_segs > queue_max_phys_segments(q)) {
211 req->cmd_flags |= REQ_NOMERGE; 210 req->cmd_flags |= REQ_NOMERGE;
212 if (req == q->last_merge) 211 if (req == q->last_merge)
213 q->last_merge = NULL; 212 q->last_merge = NULL;
@@ -300,10 +299,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
300 total_phys_segments--; 299 total_phys_segments--;
301 } 300 }
302 301
303 if (total_phys_segments > queue_max_phys_segments(q)) 302 if (total_phys_segments > queue_max_segments(q))
304 return 0;
305
306 if (total_phys_segments > queue_max_hw_segments(q))
307 return 0; 303 return 0;
308 304
309 /* Merge is OK... */ 305 /* Merge is OK... */
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 5eeb9e0d256e..31e7a9375c13 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -91,10 +91,9 @@ EXPORT_SYMBOL_GPL(blk_queue_lld_busy);
91 */ 91 */
92void blk_set_default_limits(struct queue_limits *lim) 92void blk_set_default_limits(struct queue_limits *lim)
93{ 93{
94 lim->max_phys_segments = MAX_PHYS_SEGMENTS; 94 lim->max_segments = BLK_MAX_SEGMENTS;
95 lim->max_hw_segments = MAX_HW_SEGMENTS;
96 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK; 95 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
97 lim->max_segment_size = MAX_SEGMENT_SIZE; 96 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
98 lim->max_sectors = BLK_DEF_MAX_SECTORS; 97 lim->max_sectors = BLK_DEF_MAX_SECTORS;
99 lim->max_hw_sectors = INT_MAX; 98 lim->max_hw_sectors = INT_MAX;
100 lim->max_discard_sectors = 0; 99 lim->max_discard_sectors = 0;
@@ -154,7 +153,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
154 q->unplug_timer.data = (unsigned long)q; 153 q->unplug_timer.data = (unsigned long)q;
155 154
156 blk_set_default_limits(&q->limits); 155 blk_set_default_limits(&q->limits);
157 blk_queue_max_sectors(q, SAFE_MAX_SECTORS); 156 blk_queue_max_hw_sectors(q, BLK_SAFE_MAX_SECTORS);
158 157
159 /* 158 /*
160 * If the caller didn't supply a lock, fall back to our embedded 159 * If the caller didn't supply a lock, fall back to our embedded
@@ -210,37 +209,32 @@ void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
210EXPORT_SYMBOL(blk_queue_bounce_limit); 209EXPORT_SYMBOL(blk_queue_bounce_limit);
211 210
212/** 211/**
213 * blk_queue_max_sectors - set max sectors for a request for this queue 212 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
214 * @q: the request queue for the device 213 * @q: the request queue for the device
215 * @max_sectors: max sectors in the usual 512b unit 214 * @max_hw_sectors: max hardware sectors in the usual 512b unit
216 * 215 *
217 * Description: 216 * Description:
218 * Enables a low level driver to set an upper limit on the size of 217 * Enables a low level driver to set a hard upper limit,
219 * received requests. 218 * max_hw_sectors, on the size of requests. max_hw_sectors is set by
219 * the device driver based upon the combined capabilities of I/O
220 * controller and storage device.
221 *
222 * max_sectors is a soft limit imposed by the block layer for
223 * filesystem type requests. This value can be overridden on a
224 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
225 * The soft limit can not exceed max_hw_sectors.
220 **/ 226 **/
221void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors) 227void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
222{ 228{
223 if ((max_sectors << 9) < PAGE_CACHE_SIZE) { 229 if ((max_hw_sectors << 9) < PAGE_CACHE_SIZE) {
224 max_sectors = 1 << (PAGE_CACHE_SHIFT - 9); 230 max_hw_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
225 printk(KERN_INFO "%s: set to minimum %d\n", 231 printk(KERN_INFO "%s: set to minimum %d\n",
226 __func__, max_sectors); 232 __func__, max_hw_sectors);
227 } 233 }
228 234
229 if (BLK_DEF_MAX_SECTORS > max_sectors) 235 q->limits.max_hw_sectors = max_hw_sectors;
230 q->limits.max_hw_sectors = q->limits.max_sectors = max_sectors; 236 q->limits.max_sectors = min_t(unsigned int, max_hw_sectors,
231 else { 237 BLK_DEF_MAX_SECTORS);
232 q->limits.max_sectors = BLK_DEF_MAX_SECTORS;
233 q->limits.max_hw_sectors = max_sectors;
234 }
235}
236EXPORT_SYMBOL(blk_queue_max_sectors);
237
238void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors)
239{
240 if (BLK_DEF_MAX_SECTORS > max_sectors)
241 q->limits.max_hw_sectors = BLK_DEF_MAX_SECTORS;
242 else
243 q->limits.max_hw_sectors = max_sectors;
244} 238}
245EXPORT_SYMBOL(blk_queue_max_hw_sectors); 239EXPORT_SYMBOL(blk_queue_max_hw_sectors);
246 240
@@ -257,17 +251,15 @@ void blk_queue_max_discard_sectors(struct request_queue *q,
257EXPORT_SYMBOL(blk_queue_max_discard_sectors); 251EXPORT_SYMBOL(blk_queue_max_discard_sectors);
258 252
259/** 253/**
260 * blk_queue_max_phys_segments - set max phys segments for a request for this queue 254 * blk_queue_max_segments - set max hw segments for a request for this queue
261 * @q: the request queue for the device 255 * @q: the request queue for the device
262 * @max_segments: max number of segments 256 * @max_segments: max number of segments
263 * 257 *
264 * Description: 258 * Description:
265 * Enables a low level driver to set an upper limit on the number of 259 * Enables a low level driver to set an upper limit on the number of
266 * physical data segments in a request. This would be the largest sized 260 * hw data segments in a request.
267 * scatter list the driver could handle.
268 **/ 261 **/
269void blk_queue_max_phys_segments(struct request_queue *q, 262void blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
270 unsigned short max_segments)
271{ 263{
272 if (!max_segments) { 264 if (!max_segments) {
273 max_segments = 1; 265 max_segments = 1;
@@ -275,33 +267,9 @@ void blk_queue_max_phys_segments(struct request_queue *q,
275 __func__, max_segments); 267 __func__, max_segments);
276 } 268 }
277 269
278 q->limits.max_phys_segments = max_segments; 270 q->limits.max_segments = max_segments;
279} 271}
280EXPORT_SYMBOL(blk_queue_max_phys_segments); 272EXPORT_SYMBOL(blk_queue_max_segments);
281
282/**
283 * blk_queue_max_hw_segments - set max hw segments for a request for this queue
284 * @q: the request queue for the device
285 * @max_segments: max number of segments
286 *
287 * Description:
288 * Enables a low level driver to set an upper limit on the number of
289 * hw data segments in a request. This would be the largest number of
290 * address/length pairs the host adapter can actually give at once
291 * to the device.
292 **/
293void blk_queue_max_hw_segments(struct request_queue *q,
294 unsigned short max_segments)
295{
296 if (!max_segments) {
297 max_segments = 1;
298 printk(KERN_INFO "%s: set to minimum %d\n",
299 __func__, max_segments);
300 }
301
302 q->limits.max_hw_segments = max_segments;
303}
304EXPORT_SYMBOL(blk_queue_max_hw_segments);
305 273
306/** 274/**
307 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg 275 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
@@ -507,7 +475,7 @@ static unsigned int lcm(unsigned int a, unsigned int b)
507 * blk_stack_limits - adjust queue_limits for stacked devices 475 * blk_stack_limits - adjust queue_limits for stacked devices
508 * @t: the stacking driver limits (top device) 476 * @t: the stacking driver limits (top device)
509 * @b: the underlying queue limits (bottom, component device) 477 * @b: the underlying queue limits (bottom, component device)
510 * @offset: offset to beginning of data within component device 478 * @start: first data sector within component device
511 * 479 *
512 * Description: 480 * Description:
513 * This function is used by stacking drivers like MD and DM to ensure 481 * This function is used by stacking drivers like MD and DM to ensure
@@ -525,10 +493,9 @@ static unsigned int lcm(unsigned int a, unsigned int b)
525 * the alignment_offset is undefined. 493 * the alignment_offset is undefined.
526 */ 494 */
527int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, 495int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
528 sector_t offset) 496 sector_t start)
529{ 497{
530 sector_t alignment; 498 unsigned int top, bottom, alignment, ret = 0;
531 unsigned int top, bottom, ret = 0;
532 499
533 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); 500 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
534 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); 501 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
@@ -537,18 +504,14 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
537 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, 504 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
538 b->seg_boundary_mask); 505 b->seg_boundary_mask);
539 506
540 t->max_phys_segments = min_not_zero(t->max_phys_segments, 507 t->max_segments = min_not_zero(t->max_segments, b->max_segments);
541 b->max_phys_segments);
542
543 t->max_hw_segments = min_not_zero(t->max_hw_segments,
544 b->max_hw_segments);
545 508
546 t->max_segment_size = min_not_zero(t->max_segment_size, 509 t->max_segment_size = min_not_zero(t->max_segment_size,
547 b->max_segment_size); 510 b->max_segment_size);
548 511
549 t->misaligned |= b->misaligned; 512 t->misaligned |= b->misaligned;
550 513
551 alignment = queue_limit_alignment_offset(b, offset); 514 alignment = queue_limit_alignment_offset(b, start);
552 515
553 /* Bottom device has different alignment. Check that it is 516 /* Bottom device has different alignment. Check that it is
554 * compatible with the current top alignment. 517 * compatible with the current top alignment.
@@ -611,11 +574,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
611 574
612 /* Discard alignment and granularity */ 575 /* Discard alignment and granularity */
613 if (b->discard_granularity) { 576 if (b->discard_granularity) {
614 unsigned int granularity = b->discard_granularity; 577 alignment = queue_limit_discard_alignment(b, start);
615 offset &= granularity - 1;
616
617 alignment = (granularity + b->discard_alignment - offset)
618 & (granularity - 1);
619 578
620 if (t->discard_granularity != 0 && 579 if (t->discard_granularity != 0 &&
621 t->discard_alignment != alignment) { 580 t->discard_alignment != alignment) {
@@ -657,7 +616,7 @@ int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
657 616
658 start += get_start_sect(bdev); 617 start += get_start_sect(bdev);
659 618
660 return blk_stack_limits(t, &bq->limits, start << 9); 619 return blk_stack_limits(t, &bq->limits, start);
661} 620}
662EXPORT_SYMBOL(bdev_stack_limits); 621EXPORT_SYMBOL(bdev_stack_limits);
663 622
@@ -668,9 +627,8 @@ EXPORT_SYMBOL(bdev_stack_limits);
668 * @offset: offset to beginning of data within component device 627 * @offset: offset to beginning of data within component device
669 * 628 *
670 * Description: 629 * Description:
671 * Merges the limits for two queues. Returns 0 if alignment 630 * Merges the limits for a top level gendisk and a bottom level
672 * didn't change. Returns -1 if adding the bottom device caused 631 * block_device.
673 * misalignment.
674 */ 632 */
675void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, 633void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
676 sector_t offset) 634 sector_t offset)
@@ -678,9 +636,7 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
678 struct request_queue *t = disk->queue; 636 struct request_queue *t = disk->queue;
679 struct request_queue *b = bdev_get_queue(bdev); 637 struct request_queue *b = bdev_get_queue(bdev);
680 638
681 offset += get_start_sect(bdev) << 9; 639 if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
682
683 if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
684 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE]; 640 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
685 641
686 disk_name(disk, 0, top); 642 disk_name(disk, 0, top);
@@ -752,22 +708,19 @@ EXPORT_SYMBOL(blk_queue_update_dma_pad);
752 * does is adjust the queue so that the buf is always appended 708 * does is adjust the queue so that the buf is always appended
753 * silently to the scatterlist. 709 * silently to the scatterlist.
754 * 710 *
755 * Note: This routine adjusts max_hw_segments to make room for 711 * Note: This routine adjusts max_hw_segments to make room for appending
756 * appending the drain buffer. If you call 712 * the drain buffer. If you call blk_queue_max_segments() after calling
757 * blk_queue_max_hw_segments() or blk_queue_max_phys_segments() after 713 * this routine, you must set the limit to one fewer than your device
758 * calling this routine, you must set the limit to one fewer than your 714 * can support otherwise there won't be room for the drain buffer.
759 * device can support otherwise there won't be room for the drain
760 * buffer.
761 */ 715 */
762int blk_queue_dma_drain(struct request_queue *q, 716int blk_queue_dma_drain(struct request_queue *q,
763 dma_drain_needed_fn *dma_drain_needed, 717 dma_drain_needed_fn *dma_drain_needed,
764 void *buf, unsigned int size) 718 void *buf, unsigned int size)
765{ 719{
766 if (queue_max_hw_segments(q) < 2 || queue_max_phys_segments(q) < 2) 720 if (queue_max_segments(q) < 2)
767 return -EINVAL; 721 return -EINVAL;
768 /* make room for appending the drain */ 722 /* make room for appending the drain */
769 blk_queue_max_hw_segments(q, queue_max_hw_segments(q) - 1); 723 blk_queue_max_segments(q, queue_max_segments(q) - 1);
770 blk_queue_max_phys_segments(q, queue_max_phys_segments(q) - 1);
771 q->dma_drain_needed = dma_drain_needed; 724 q->dma_drain_needed = dma_drain_needed;
772 q->dma_drain_buffer = buf; 725 q->dma_drain_buffer = buf;
773 q->dma_drain_size = size; 726 q->dma_drain_size = size;
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 8606c9543fdd..e85442415db3 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -189,7 +189,8 @@ static ssize_t queue_nonrot_store(struct request_queue *q, const char *page,
189 189
190static ssize_t queue_nomerges_show(struct request_queue *q, char *page) 190static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
191{ 191{
192 return queue_var_show(blk_queue_nomerges(q), page); 192 return queue_var_show((blk_queue_nomerges(q) << 1) |
193 blk_queue_noxmerges(q), page);
193} 194}
194 195
195static ssize_t queue_nomerges_store(struct request_queue *q, const char *page, 196static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
@@ -199,10 +200,12 @@ static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
199 ssize_t ret = queue_var_store(&nm, page, count); 200 ssize_t ret = queue_var_store(&nm, page, count);
200 201
201 spin_lock_irq(q->queue_lock); 202 spin_lock_irq(q->queue_lock);
202 if (nm) 203 queue_flag_clear(QUEUE_FLAG_NOMERGES, q);
204 queue_flag_clear(QUEUE_FLAG_NOXMERGES, q);
205 if (nm == 2)
203 queue_flag_set(QUEUE_FLAG_NOMERGES, q); 206 queue_flag_set(QUEUE_FLAG_NOMERGES, q);
204 else 207 else if (nm)
205 queue_flag_clear(QUEUE_FLAG_NOMERGES, q); 208 queue_flag_set(QUEUE_FLAG_NOXMERGES, q);
206 spin_unlock_irq(q->queue_lock); 209 spin_unlock_irq(q->queue_lock);
207 210
208 return ret; 211 return ret;
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index 17b768d0d42f..dee9d9378fee 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -19,7 +19,7 @@
19 * tunables 19 * tunables
20 */ 20 */
21/* max queue in one round of service */ 21/* max queue in one round of service */
22static const int cfq_quantum = 4; 22static const int cfq_quantum = 8;
23static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 }; 23static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 };
24/* maximum backwards seek, in KiB */ 24/* maximum backwards seek, in KiB */
25static const int cfq_back_max = 16 * 1024; 25static const int cfq_back_max = 16 * 1024;
@@ -42,16 +42,14 @@ static const int cfq_hist_divisor = 4;
42 */ 42 */
43#define CFQ_MIN_TT (2) 43#define CFQ_MIN_TT (2)
44 44
45/*
46 * Allow merged cfqqs to perform this amount of seeky I/O before
47 * deciding to break the queues up again.
48 */
49#define CFQQ_COOP_TOUT (HZ)
50
51#define CFQ_SLICE_SCALE (5) 45#define CFQ_SLICE_SCALE (5)
52#define CFQ_HW_QUEUE_MIN (5) 46#define CFQ_HW_QUEUE_MIN (5)
53#define CFQ_SERVICE_SHIFT 12 47#define CFQ_SERVICE_SHIFT 12
54 48
49#define CFQQ_SEEK_THR (sector_t)(8 * 100)
50#define CFQQ_SECT_THR_NONROT (sector_t)(2 * 32)
51#define CFQQ_SEEKY(cfqq) (hweight32(cfqq->seek_history) > 32/8)
52
55#define RQ_CIC(rq) \ 53#define RQ_CIC(rq) \
56 ((struct cfq_io_context *) (rq)->elevator_private) 54 ((struct cfq_io_context *) (rq)->elevator_private)
57#define RQ_CFQQ(rq) (struct cfq_queue *) ((rq)->elevator_private2) 55#define RQ_CFQQ(rq) (struct cfq_queue *) ((rq)->elevator_private2)
@@ -80,11 +78,12 @@ struct cfq_rb_root {
80 struct rb_root rb; 78 struct rb_root rb;
81 struct rb_node *left; 79 struct rb_node *left;
82 unsigned count; 80 unsigned count;
81 unsigned total_weight;
83 u64 min_vdisktime; 82 u64 min_vdisktime;
84 struct rb_node *active; 83 struct rb_node *active;
85 unsigned total_weight;
86}; 84};
87#define CFQ_RB_ROOT (struct cfq_rb_root) { RB_ROOT, NULL, 0, 0, } 85#define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, .left = NULL, \
86 .count = 0, .min_vdisktime = 0, }
88 87
89/* 88/*
90 * Per process-grouping structure 89 * Per process-grouping structure
@@ -118,11 +117,11 @@ struct cfq_queue {
118 /* time when queue got scheduled in to dispatch first request. */ 117 /* time when queue got scheduled in to dispatch first request. */
119 unsigned long dispatch_start; 118 unsigned long dispatch_start;
120 unsigned int allocated_slice; 119 unsigned int allocated_slice;
120 unsigned int slice_dispatch;
121 /* time when first request from queue completed and slice started. */ 121 /* time when first request from queue completed and slice started. */
122 unsigned long slice_start; 122 unsigned long slice_start;
123 unsigned long slice_end; 123 unsigned long slice_end;
124 long slice_resid; 124 long slice_resid;
125 unsigned int slice_dispatch;
126 125
127 /* pending metadata requests */ 126 /* pending metadata requests */
128 int meta_pending; 127 int meta_pending;
@@ -133,14 +132,11 @@ struct cfq_queue {
133 unsigned short ioprio, org_ioprio; 132 unsigned short ioprio, org_ioprio;
134 unsigned short ioprio_class, org_ioprio_class; 133 unsigned short ioprio_class, org_ioprio_class;
135 134
136 unsigned int seek_samples;
137 u64 seek_total;
138 sector_t seek_mean;
139 sector_t last_request_pos;
140 unsigned long seeky_start;
141
142 pid_t pid; 135 pid_t pid;
143 136
137 u32 seek_history;
138 sector_t last_request_pos;
139
144 struct cfq_rb_root *service_tree; 140 struct cfq_rb_root *service_tree;
145 struct cfq_queue *new_cfqq; 141 struct cfq_queue *new_cfqq;
146 struct cfq_group *cfqg; 142 struct cfq_group *cfqg;
@@ -227,8 +223,8 @@ struct cfq_data {
227 223
228 unsigned int busy_queues; 224 unsigned int busy_queues;
229 225
230 int rq_in_driver[2]; 226 int rq_in_driver;
231 int sync_flight; 227 int rq_in_flight[2];
232 228
233 /* 229 /*
234 * queue-depth detection 230 * queue-depth detection
@@ -314,6 +310,7 @@ enum cfqq_state_flags {
314 CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */ 310 CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */
315 CFQ_CFQQ_FLAG_sync, /* synchronous queue */ 311 CFQ_CFQQ_FLAG_sync, /* synchronous queue */
316 CFQ_CFQQ_FLAG_coop, /* cfqq is shared */ 312 CFQ_CFQQ_FLAG_coop, /* cfqq is shared */
313 CFQ_CFQQ_FLAG_split_coop, /* shared cfqq will be splitted */
317 CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */ 314 CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */
318 CFQ_CFQQ_FLAG_wait_busy, /* Waiting for next request */ 315 CFQ_CFQQ_FLAG_wait_busy, /* Waiting for next request */
319}; 316};
@@ -342,6 +339,7 @@ CFQ_CFQQ_FNS(prio_changed);
342CFQ_CFQQ_FNS(slice_new); 339CFQ_CFQQ_FNS(slice_new);
343CFQ_CFQQ_FNS(sync); 340CFQ_CFQQ_FNS(sync);
344CFQ_CFQQ_FNS(coop); 341CFQ_CFQQ_FNS(coop);
342CFQ_CFQQ_FNS(split_coop);
345CFQ_CFQQ_FNS(deep); 343CFQ_CFQQ_FNS(deep);
346CFQ_CFQQ_FNS(wait_busy); 344CFQ_CFQQ_FNS(wait_busy);
347#undef CFQ_CFQQ_FNS 345#undef CFQ_CFQQ_FNS
@@ -419,11 +417,6 @@ static struct cfq_queue *cfq_get_queue(struct cfq_data *, bool,
419static struct cfq_io_context *cfq_cic_lookup(struct cfq_data *, 417static struct cfq_io_context *cfq_cic_lookup(struct cfq_data *,
420 struct io_context *); 418 struct io_context *);
421 419
422static inline int rq_in_driver(struct cfq_data *cfqd)
423{
424 return cfqd->rq_in_driver[0] + cfqd->rq_in_driver[1];
425}
426
427static inline struct cfq_queue *cic_to_cfqq(struct cfq_io_context *cic, 420static inline struct cfq_queue *cic_to_cfqq(struct cfq_io_context *cic,
428 bool is_sync) 421 bool is_sync)
429{ 422{
@@ -953,10 +946,6 @@ cfq_find_alloc_cfqg(struct cfq_data *cfqd, struct cgroup *cgroup, int create)
953 struct backing_dev_info *bdi = &cfqd->queue->backing_dev_info; 946 struct backing_dev_info *bdi = &cfqd->queue->backing_dev_info;
954 unsigned int major, minor; 947 unsigned int major, minor;
955 948
956 /* Do we need to take this reference */
957 if (!blkiocg_css_tryget(blkcg))
958 return NULL;;
959
960 cfqg = cfqg_of_blkg(blkiocg_lookup_group(blkcg, key)); 949 cfqg = cfqg_of_blkg(blkiocg_lookup_group(blkcg, key));
961 if (cfqg || !create) 950 if (cfqg || !create)
962 goto done; 951 goto done;
@@ -987,7 +976,6 @@ cfq_find_alloc_cfqg(struct cfq_data *cfqd, struct cgroup *cgroup, int create)
987 hlist_add_head(&cfqg->cfqd_node, &cfqd->cfqg_list); 976 hlist_add_head(&cfqg->cfqd_node, &cfqd->cfqg_list);
988 977
989done: 978done:
990 blkiocg_css_put(blkcg);
991 return cfqg; 979 return cfqg;
992} 980}
993 981
@@ -1422,9 +1410,9 @@ static void cfq_activate_request(struct request_queue *q, struct request *rq)
1422{ 1410{
1423 struct cfq_data *cfqd = q->elevator->elevator_data; 1411 struct cfq_data *cfqd = q->elevator->elevator_data;
1424 1412
1425 cfqd->rq_in_driver[rq_is_sync(rq)]++; 1413 cfqd->rq_in_driver++;
1426 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d", 1414 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
1427 rq_in_driver(cfqd)); 1415 cfqd->rq_in_driver);
1428 1416
1429 cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); 1417 cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq);
1430} 1418}
@@ -1432,12 +1420,11 @@ static void cfq_activate_request(struct request_queue *q, struct request *rq)
1432static void cfq_deactivate_request(struct request_queue *q, struct request *rq) 1420static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
1433{ 1421{
1434 struct cfq_data *cfqd = q->elevator->elevator_data; 1422 struct cfq_data *cfqd = q->elevator->elevator_data;
1435 const int sync = rq_is_sync(rq);
1436 1423
1437 WARN_ON(!cfqd->rq_in_driver[sync]); 1424 WARN_ON(!cfqd->rq_in_driver);
1438 cfqd->rq_in_driver[sync]--; 1425 cfqd->rq_in_driver--;
1439 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d", 1426 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d",
1440 rq_in_driver(cfqd)); 1427 cfqd->rq_in_driver);
1441} 1428}
1442 1429
1443static void cfq_remove_request(struct request *rq) 1430static void cfq_remove_request(struct request *rq)
@@ -1566,6 +1553,15 @@ __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1566 cfq_clear_cfqq_wait_busy(cfqq); 1553 cfq_clear_cfqq_wait_busy(cfqq);
1567 1554
1568 /* 1555 /*
1556 * If this cfqq is shared between multiple processes, check to
1557 * make sure that those processes are still issuing I/Os within
1558 * the mean seek distance. If not, it may be time to break the
1559 * queues apart again.
1560 */
1561 if (cfq_cfqq_coop(cfqq) && CFQQ_SEEKY(cfqq))
1562 cfq_mark_cfqq_split_coop(cfqq);
1563
1564 /*
1569 * store what was left of this slice, if the queue idled/timed out 1565 * store what was left of this slice, if the queue idled/timed out
1570 */ 1566 */
1571 if (timed_out && !cfq_cfqq_slice_new(cfqq)) { 1567 if (timed_out && !cfq_cfqq_slice_new(cfqq)) {
@@ -1663,22 +1659,10 @@ static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
1663 return cfqd->last_position - blk_rq_pos(rq); 1659 return cfqd->last_position - blk_rq_pos(rq);
1664} 1660}
1665 1661
1666#define CFQQ_SEEK_THR 8 * 1024
1667#define CFQQ_SEEKY(cfqq) ((cfqq)->seek_mean > CFQQ_SEEK_THR)
1668
1669static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq, 1662static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1670 struct request *rq, bool for_preempt) 1663 struct request *rq, bool for_preempt)
1671{ 1664{
1672 sector_t sdist = cfqq->seek_mean; 1665 return cfq_dist_from_last(cfqd, rq) <= CFQQ_SEEK_THR;
1673
1674 if (!sample_valid(cfqq->seek_samples))
1675 sdist = CFQQ_SEEK_THR;
1676
1677 /* if seek_mean is big, using it as close criteria is meaningless */
1678 if (sdist > CFQQ_SEEK_THR && !for_preempt)
1679 sdist = CFQQ_SEEK_THR;
1680
1681 return cfq_dist_from_last(cfqd, rq) <= sdist;
1682} 1666}
1683 1667
1684static struct cfq_queue *cfqq_close(struct cfq_data *cfqd, 1668static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
@@ -1874,8 +1858,7 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)
1874 cfqq->dispatched++; 1858 cfqq->dispatched++;
1875 elv_dispatch_sort(q, rq); 1859 elv_dispatch_sort(q, rq);
1876 1860
1877 if (cfq_cfqq_sync(cfqq)) 1861 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++;
1878 cfqd->sync_flight++;
1879 cfqq->nr_sectors += blk_rq_sectors(rq); 1862 cfqq->nr_sectors += blk_rq_sectors(rq);
1880} 1863}
1881 1864
@@ -2215,6 +2198,19 @@ static int cfq_forced_dispatch(struct cfq_data *cfqd)
2215 return dispatched; 2198 return dispatched;
2216} 2199}
2217 2200
2201static inline bool cfq_slice_used_soon(struct cfq_data *cfqd,
2202 struct cfq_queue *cfqq)
2203{
2204 /* the queue hasn't finished any request, can't estimate */
2205 if (cfq_cfqq_slice_new(cfqq))
2206 return 1;
2207 if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched,
2208 cfqq->slice_end))
2209 return 1;
2210
2211 return 0;
2212}
2213
2218static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq) 2214static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2219{ 2215{
2220 unsigned int max_dispatch; 2216 unsigned int max_dispatch;
@@ -2222,16 +2218,16 @@ static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2222 /* 2218 /*
2223 * Drain async requests before we start sync IO 2219 * Drain async requests before we start sync IO
2224 */ 2220 */
2225 if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_driver[BLK_RW_ASYNC]) 2221 if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_flight[BLK_RW_ASYNC])
2226 return false; 2222 return false;
2227 2223
2228 /* 2224 /*
2229 * If this is an async queue and we have sync IO in flight, let it wait 2225 * If this is an async queue and we have sync IO in flight, let it wait
2230 */ 2226 */
2231 if (cfqd->sync_flight && !cfq_cfqq_sync(cfqq)) 2227 if (cfqd->rq_in_flight[BLK_RW_SYNC] && !cfq_cfqq_sync(cfqq))
2232 return false; 2228 return false;
2233 2229
2234 max_dispatch = cfqd->cfq_quantum; 2230 max_dispatch = max_t(unsigned int, cfqd->cfq_quantum / 2, 1);
2235 if (cfq_class_idle(cfqq)) 2231 if (cfq_class_idle(cfqq))
2236 max_dispatch = 1; 2232 max_dispatch = 1;
2237 2233
@@ -2248,13 +2244,22 @@ static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2248 /* 2244 /*
2249 * We have other queues, don't allow more IO from this one 2245 * We have other queues, don't allow more IO from this one
2250 */ 2246 */
2251 if (cfqd->busy_queues > 1) 2247 if (cfqd->busy_queues > 1 && cfq_slice_used_soon(cfqd, cfqq))
2252 return false; 2248 return false;
2253 2249
2254 /* 2250 /*
2255 * Sole queue user, no limit 2251 * Sole queue user, no limit
2256 */ 2252 */
2257 max_dispatch = -1; 2253 if (cfqd->busy_queues == 1)
2254 max_dispatch = -1;
2255 else
2256 /*
2257 * Normally we start throttling cfqq when cfq_quantum/2
2258 * requests have been dispatched. But we can drive
2259 * deeper queue depths at the beginning of slice
2260 * subjected to upper limit of cfq_quantum.
2261 * */
2262 max_dispatch = cfqd->cfq_quantum;
2258 } 2263 }
2259 2264
2260 /* 2265 /*
@@ -2976,43 +2981,20 @@ static void
2976cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq, 2981cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
2977 struct request *rq) 2982 struct request *rq)
2978{ 2983{
2979 sector_t sdist; 2984 sector_t sdist = 0;
2980 u64 total; 2985 sector_t n_sec = blk_rq_sectors(rq);
2981 2986 if (cfqq->last_request_pos) {
2982 if (!cfqq->last_request_pos) 2987 if (cfqq->last_request_pos < blk_rq_pos(rq))
2983 sdist = 0; 2988 sdist = blk_rq_pos(rq) - cfqq->last_request_pos;
2984 else if (cfqq->last_request_pos < blk_rq_pos(rq)) 2989 else
2985 sdist = blk_rq_pos(rq) - cfqq->last_request_pos; 2990 sdist = cfqq->last_request_pos - blk_rq_pos(rq);
2986 else 2991 }
2987 sdist = cfqq->last_request_pos - blk_rq_pos(rq);
2988 2992
2989 /* 2993 cfqq->seek_history <<= 1;
2990 * Don't allow the seek distance to get too large from the 2994 if (blk_queue_nonrot(cfqd->queue))
2991 * odd fragment, pagein, etc 2995 cfqq->seek_history |= (n_sec < CFQQ_SECT_THR_NONROT);
2992 */
2993 if (cfqq->seek_samples <= 60) /* second&third seek */
2994 sdist = min(sdist, (cfqq->seek_mean * 4) + 2*1024*1024);
2995 else 2996 else
2996 sdist = min(sdist, (cfqq->seek_mean * 4) + 2*1024*64); 2997 cfqq->seek_history |= (sdist > CFQQ_SEEK_THR);
2997
2998 cfqq->seek_samples = (7*cfqq->seek_samples + 256) / 8;
2999 cfqq->seek_total = (7*cfqq->seek_total + (u64)256*sdist) / 8;
3000 total = cfqq->seek_total + (cfqq->seek_samples/2);
3001 do_div(total, cfqq->seek_samples);
3002 cfqq->seek_mean = (sector_t)total;
3003
3004 /*
3005 * If this cfqq is shared between multiple processes, check to
3006 * make sure that those processes are still issuing I/Os within
3007 * the mean seek distance. If not, it may be time to break the
3008 * queues apart again.
3009 */
3010 if (cfq_cfqq_coop(cfqq)) {
3011 if (CFQQ_SEEKY(cfqq) && !cfqq->seeky_start)
3012 cfqq->seeky_start = jiffies;
3013 else if (!CFQQ_SEEKY(cfqq))
3014 cfqq->seeky_start = 0;
3015 }
3016} 2998}
3017 2999
3018/* 3000/*
@@ -3037,8 +3019,7 @@ cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
3037 cfq_mark_cfqq_deep(cfqq); 3019 cfq_mark_cfqq_deep(cfqq);
3038 3020
3039 if (!atomic_read(&cic->ioc->nr_tasks) || !cfqd->cfq_slice_idle || 3021 if (!atomic_read(&cic->ioc->nr_tasks) || !cfqd->cfq_slice_idle ||
3040 (!cfq_cfqq_deep(cfqq) && sample_valid(cfqq->seek_samples) 3022 (!cfq_cfqq_deep(cfqq) && CFQQ_SEEKY(cfqq)))
3041 && CFQQ_SEEKY(cfqq)))
3042 enable_idle = 0; 3023 enable_idle = 0;
3043 else if (sample_valid(cic->ttime_samples)) { 3024 else if (sample_valid(cic->ttime_samples)) {
3044 if (cic->ttime_mean > cfqd->cfq_slice_idle) 3025 if (cic->ttime_mean > cfqd->cfq_slice_idle)
@@ -3224,14 +3205,14 @@ static void cfq_update_hw_tag(struct cfq_data *cfqd)
3224{ 3205{
3225 struct cfq_queue *cfqq = cfqd->active_queue; 3206 struct cfq_queue *cfqq = cfqd->active_queue;
3226 3207
3227 if (rq_in_driver(cfqd) > cfqd->hw_tag_est_depth) 3208 if (cfqd->rq_in_driver > cfqd->hw_tag_est_depth)
3228 cfqd->hw_tag_est_depth = rq_in_driver(cfqd); 3209 cfqd->hw_tag_est_depth = cfqd->rq_in_driver;
3229 3210
3230 if (cfqd->hw_tag == 1) 3211 if (cfqd->hw_tag == 1)
3231 return; 3212 return;
3232 3213
3233 if (cfqd->rq_queued <= CFQ_HW_QUEUE_MIN && 3214 if (cfqd->rq_queued <= CFQ_HW_QUEUE_MIN &&
3234 rq_in_driver(cfqd) <= CFQ_HW_QUEUE_MIN) 3215 cfqd->rq_in_driver <= CFQ_HW_QUEUE_MIN)
3235 return; 3216 return;
3236 3217
3237 /* 3218 /*
@@ -3241,7 +3222,7 @@ static void cfq_update_hw_tag(struct cfq_data *cfqd)
3241 */ 3222 */
3242 if (cfqq && cfq_cfqq_idle_window(cfqq) && 3223 if (cfqq && cfq_cfqq_idle_window(cfqq) &&
3243 cfqq->dispatched + cfqq->queued[0] + cfqq->queued[1] < 3224 cfqq->dispatched + cfqq->queued[0] + cfqq->queued[1] <
3244 CFQ_HW_QUEUE_MIN && rq_in_driver(cfqd) < CFQ_HW_QUEUE_MIN) 3225 CFQ_HW_QUEUE_MIN && cfqd->rq_in_driver < CFQ_HW_QUEUE_MIN)
3245 return; 3226 return;
3246 3227
3247 if (cfqd->hw_tag_samples++ < 50) 3228 if (cfqd->hw_tag_samples++ < 50)
@@ -3294,13 +3275,12 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
3294 3275
3295 cfq_update_hw_tag(cfqd); 3276 cfq_update_hw_tag(cfqd);
3296 3277
3297 WARN_ON(!cfqd->rq_in_driver[sync]); 3278 WARN_ON(!cfqd->rq_in_driver);
3298 WARN_ON(!cfqq->dispatched); 3279 WARN_ON(!cfqq->dispatched);
3299 cfqd->rq_in_driver[sync]--; 3280 cfqd->rq_in_driver--;
3300 cfqq->dispatched--; 3281 cfqq->dispatched--;
3301 3282
3302 if (cfq_cfqq_sync(cfqq)) 3283 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--;
3303 cfqd->sync_flight--;
3304 3284
3305 if (sync) { 3285 if (sync) {
3306 RQ_CIC(rq)->last_end_request = now; 3286 RQ_CIC(rq)->last_end_request = now;
@@ -3354,7 +3334,7 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
3354 } 3334 }
3355 } 3335 }
3356 3336
3357 if (!rq_in_driver(cfqd)) 3337 if (!cfqd->rq_in_driver)
3358 cfq_schedule_dispatch(cfqd); 3338 cfq_schedule_dispatch(cfqd);
3359} 3339}
3360 3340
@@ -3453,14 +3433,6 @@ cfq_merge_cfqqs(struct cfq_data *cfqd, struct cfq_io_context *cic,
3453 return cic_to_cfqq(cic, 1); 3433 return cic_to_cfqq(cic, 1);
3454} 3434}
3455 3435
3456static int should_split_cfqq(struct cfq_queue *cfqq)
3457{
3458 if (cfqq->seeky_start &&
3459 time_after(jiffies, cfqq->seeky_start + CFQQ_COOP_TOUT))
3460 return 1;
3461 return 0;
3462}
3463
3464/* 3436/*
3465 * Returns NULL if a new cfqq should be allocated, or the old cfqq if this 3437 * Returns NULL if a new cfqq should be allocated, or the old cfqq if this
3466 * was the last process referring to said cfqq. 3438 * was the last process referring to said cfqq.
@@ -3469,9 +3441,9 @@ static struct cfq_queue *
3469split_cfqq(struct cfq_io_context *cic, struct cfq_queue *cfqq) 3441split_cfqq(struct cfq_io_context *cic, struct cfq_queue *cfqq)
3470{ 3442{
3471 if (cfqq_process_refs(cfqq) == 1) { 3443 if (cfqq_process_refs(cfqq) == 1) {
3472 cfqq->seeky_start = 0;
3473 cfqq->pid = current->pid; 3444 cfqq->pid = current->pid;
3474 cfq_clear_cfqq_coop(cfqq); 3445 cfq_clear_cfqq_coop(cfqq);
3446 cfq_clear_cfqq_split_coop(cfqq);
3475 return cfqq; 3447 return cfqq;
3476 } 3448 }
3477 3449
@@ -3510,7 +3482,7 @@ new_queue:
3510 /* 3482 /*
3511 * If the queue was seeky for too long, break it apart. 3483 * If the queue was seeky for too long, break it apart.
3512 */ 3484 */
3513 if (cfq_cfqq_coop(cfqq) && should_split_cfqq(cfqq)) { 3485 if (cfq_cfqq_coop(cfqq) && cfq_cfqq_split_coop(cfqq)) {
3514 cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq"); 3486 cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq");
3515 cfqq = split_cfqq(cic, cfqq); 3487 cfqq = split_cfqq(cic, cfqq);
3516 if (!cfqq) 3488 if (!cfqq)
diff --git a/block/elevator.c b/block/elevator.c
index 9ad5ccc4c5ee..ee3a883840f2 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -474,6 +474,15 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
474 int ret; 474 int ret;
475 475
476 /* 476 /*
477 * Levels of merges:
478 * nomerges: No merges at all attempted
479 * noxmerges: Only simple one-hit cache try
480 * merges: All merge tries attempted
481 */
482 if (blk_queue_nomerges(q))
483 return ELEVATOR_NO_MERGE;
484
485 /*
477 * First try one-hit cache. 486 * First try one-hit cache.
478 */ 487 */
479 if (q->last_merge) { 488 if (q->last_merge) {
@@ -484,7 +493,7 @@ int elv_merge(struct request_queue *q, struct request **req, struct bio *bio)
484 } 493 }
485 } 494 }
486 495
487 if (blk_queue_nomerges(q)) 496 if (blk_queue_noxmerges(q))
488 return ELEVATOR_NO_MERGE; 497 return ELEVATOR_NO_MERGE;
489 498
490 /* 499 /*