aboutsummaryrefslogtreecommitdiffstats
path: root/block/cfq-iosched.c
diff options
context:
space:
mode:
Diffstat (limited to 'block/cfq-iosched.c')
-rw-r--r--block/cfq-iosched.c103
1 files changed, 88 insertions, 15 deletions
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index eb4086f7dfef..f65c6f01c475 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -30,6 +30,7 @@ static const int cfq_slice_sync = HZ / 10;
30static int cfq_slice_async = HZ / 25; 30static int cfq_slice_async = HZ / 25;
31static const int cfq_slice_async_rq = 2; 31static const int cfq_slice_async_rq = 2;
32static int cfq_slice_idle = HZ / 125; 32static int cfq_slice_idle = HZ / 125;
33static int cfq_group_idle = HZ / 125;
33static const int cfq_target_latency = HZ * 3/10; /* 300 ms */ 34static const int cfq_target_latency = HZ * 3/10; /* 300 ms */
34static const int cfq_hist_divisor = 4; 35static const int cfq_hist_divisor = 4;
35 36
@@ -147,6 +148,8 @@ struct cfq_queue {
147 struct cfq_queue *new_cfqq; 148 struct cfq_queue *new_cfqq;
148 struct cfq_group *cfqg; 149 struct cfq_group *cfqg;
149 struct cfq_group *orig_cfqg; 150 struct cfq_group *orig_cfqg;
151 /* Number of sectors dispatched from queue in single dispatch round */
152 unsigned long nr_sectors;
150}; 153};
151 154
152/* 155/*
@@ -198,6 +201,8 @@ struct cfq_group {
198 struct hlist_node cfqd_node; 201 struct hlist_node cfqd_node;
199 atomic_t ref; 202 atomic_t ref;
200#endif 203#endif
204 /* number of requests that are on the dispatch list or inside driver */
205 int dispatched;
201}; 206};
202 207
203/* 208/*
@@ -271,6 +276,7 @@ struct cfq_data {
271 unsigned int cfq_slice[2]; 276 unsigned int cfq_slice[2];
272 unsigned int cfq_slice_async_rq; 277 unsigned int cfq_slice_async_rq;
273 unsigned int cfq_slice_idle; 278 unsigned int cfq_slice_idle;
279 unsigned int cfq_group_idle;
274 unsigned int cfq_latency; 280 unsigned int cfq_latency;
275 unsigned int cfq_group_isolation; 281 unsigned int cfq_group_isolation;
276 282
@@ -378,6 +384,21 @@ CFQ_CFQQ_FNS(wait_busy);
378 &cfqg->service_trees[i][j]: NULL) \ 384 &cfqg->service_trees[i][j]: NULL) \
379 385
380 386
387static inline bool iops_mode(struct cfq_data *cfqd)
388{
389 /*
390 * If we are not idling on queues and it is a NCQ drive, parallel
391 * execution of requests is on and measuring time is not possible
392 * in most of the cases until and unless we drive shallower queue
393 * depths and that becomes a performance bottleneck. In such cases
394 * switch to start providing fairness in terms of number of IOs.
395 */
396 if (!cfqd->cfq_slice_idle && cfqd->hw_tag)
397 return true;
398 else
399 return false;
400}
401
381static inline enum wl_prio_t cfqq_prio(struct cfq_queue *cfqq) 402static inline enum wl_prio_t cfqq_prio(struct cfq_queue *cfqq)
382{ 403{
383 if (cfq_class_idle(cfqq)) 404 if (cfq_class_idle(cfqq))
@@ -906,7 +927,6 @@ static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq)
906 slice_used = cfqq->allocated_slice; 927 slice_used = cfqq->allocated_slice;
907 } 928 }
908 929
909 cfq_log_cfqq(cfqq->cfqd, cfqq, "sl_used=%u", slice_used);
910 return slice_used; 930 return slice_used;
911} 931}
912 932
@@ -914,19 +934,21 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
914 struct cfq_queue *cfqq) 934 struct cfq_queue *cfqq)
915{ 935{
916 struct cfq_rb_root *st = &cfqd->grp_service_tree; 936 struct cfq_rb_root *st = &cfqd->grp_service_tree;
917 unsigned int used_sl, charge_sl; 937 unsigned int used_sl, charge;
918 int nr_sync = cfqg->nr_cfqq - cfqg_busy_async_queues(cfqd, cfqg) 938 int nr_sync = cfqg->nr_cfqq - cfqg_busy_async_queues(cfqd, cfqg)
919 - cfqg->service_tree_idle.count; 939 - cfqg->service_tree_idle.count;
920 940
921 BUG_ON(nr_sync < 0); 941 BUG_ON(nr_sync < 0);
922 used_sl = charge_sl = cfq_cfqq_slice_usage(cfqq); 942 used_sl = charge = cfq_cfqq_slice_usage(cfqq);
923 943
924 if (!cfq_cfqq_sync(cfqq) && !nr_sync) 944 if (iops_mode(cfqd))
925 charge_sl = cfqq->allocated_slice; 945 charge = cfqq->slice_dispatch;
946 else if (!cfq_cfqq_sync(cfqq) && !nr_sync)
947 charge = cfqq->allocated_slice;
926 948
927 /* Can't update vdisktime while group is on service tree */ 949 /* Can't update vdisktime while group is on service tree */
928 cfq_rb_erase(&cfqg->rb_node, st); 950 cfq_rb_erase(&cfqg->rb_node, st);
929 cfqg->vdisktime += cfq_scale_slice(charge_sl, cfqg); 951 cfqg->vdisktime += cfq_scale_slice(charge, cfqg);
930 __cfq_group_service_tree_add(st, cfqg); 952 __cfq_group_service_tree_add(st, cfqg);
931 953
932 /* This group is being expired. Save the context */ 954 /* This group is being expired. Save the context */
@@ -940,6 +962,9 @@ static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg,
940 962
941 cfq_log_cfqg(cfqd, cfqg, "served: vt=%llu min_vt=%llu", cfqg->vdisktime, 963 cfq_log_cfqg(cfqd, cfqg, "served: vt=%llu min_vt=%llu", cfqg->vdisktime,
942 st->min_vdisktime); 964 st->min_vdisktime);
965 cfq_log_cfqq(cfqq->cfqd, cfqq, "sl_used=%u disp=%u charge=%u iops=%u"
966 " sect=%u", used_sl, cfqq->slice_dispatch, charge,
967 iops_mode(cfqd), cfqq->nr_sectors);
943 cfq_blkiocg_update_timeslice_used(&cfqg->blkg, used_sl); 968 cfq_blkiocg_update_timeslice_used(&cfqg->blkg, used_sl);
944 cfq_blkiocg_set_start_empty_time(&cfqg->blkg); 969 cfq_blkiocg_set_start_empty_time(&cfqg->blkg);
945} 970}
@@ -1587,6 +1612,7 @@ static void __cfq_set_active_queue(struct cfq_data *cfqd,
1587 cfqq->allocated_slice = 0; 1612 cfqq->allocated_slice = 0;
1588 cfqq->slice_end = 0; 1613 cfqq->slice_end = 0;
1589 cfqq->slice_dispatch = 0; 1614 cfqq->slice_dispatch = 0;
1615 cfqq->nr_sectors = 0;
1590 1616
1591 cfq_clear_cfqq_wait_request(cfqq); 1617 cfq_clear_cfqq_wait_request(cfqq);
1592 cfq_clear_cfqq_must_dispatch(cfqq); 1618 cfq_clear_cfqq_must_dispatch(cfqq);
@@ -1839,6 +1865,9 @@ static bool cfq_should_idle(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1839 BUG_ON(!service_tree); 1865 BUG_ON(!service_tree);
1840 BUG_ON(!service_tree->count); 1866 BUG_ON(!service_tree->count);
1841 1867
1868 if (!cfqd->cfq_slice_idle)
1869 return false;
1870
1842 /* We never do for idle class queues. */ 1871 /* We never do for idle class queues. */
1843 if (prio == IDLE_WORKLOAD) 1872 if (prio == IDLE_WORKLOAD)
1844 return false; 1873 return false;
@@ -1863,7 +1892,7 @@ static void cfq_arm_slice_timer(struct cfq_data *cfqd)
1863{ 1892{
1864 struct cfq_queue *cfqq = cfqd->active_queue; 1893 struct cfq_queue *cfqq = cfqd->active_queue;
1865 struct cfq_io_context *cic; 1894 struct cfq_io_context *cic;
1866 unsigned long sl; 1895 unsigned long sl, group_idle = 0;
1867 1896
1868 /* 1897 /*
1869 * SSD device without seek penalty, disable idling. But only do so 1898 * SSD device without seek penalty, disable idling. But only do so
@@ -1879,8 +1908,13 @@ static void cfq_arm_slice_timer(struct cfq_data *cfqd)
1879 /* 1908 /*
1880 * idle is disabled, either manually or by past process history 1909 * idle is disabled, either manually or by past process history
1881 */ 1910 */
1882 if (!cfqd->cfq_slice_idle || !cfq_should_idle(cfqd, cfqq)) 1911 if (!cfq_should_idle(cfqd, cfqq)) {
1883 return; 1912 /* no queue idling. Check for group idling */
1913 if (cfqd->cfq_group_idle)
1914 group_idle = cfqd->cfq_group_idle;
1915 else
1916 return;
1917 }
1884 1918
1885 /* 1919 /*
1886 * still active requests from this queue, don't idle 1920 * still active requests from this queue, don't idle
@@ -1907,13 +1941,21 @@ static void cfq_arm_slice_timer(struct cfq_data *cfqd)
1907 return; 1941 return;
1908 } 1942 }
1909 1943
1944 /* There are other queues in the group, don't do group idle */
1945 if (group_idle && cfqq->cfqg->nr_cfqq > 1)
1946 return;
1947
1910 cfq_mark_cfqq_wait_request(cfqq); 1948 cfq_mark_cfqq_wait_request(cfqq);
1911 1949
1912 sl = cfqd->cfq_slice_idle; 1950 if (group_idle)
1951 sl = cfqd->cfq_group_idle;
1952 else
1953 sl = cfqd->cfq_slice_idle;
1913 1954
1914 mod_timer(&cfqd->idle_slice_timer, jiffies + sl); 1955 mod_timer(&cfqd->idle_slice_timer, jiffies + sl);
1915 cfq_blkiocg_update_set_idle_time_stats(&cfqq->cfqg->blkg); 1956 cfq_blkiocg_update_set_idle_time_stats(&cfqq->cfqg->blkg);
1916 cfq_log_cfqq(cfqd, cfqq, "arm_idle: %lu", sl); 1957 cfq_log_cfqq(cfqd, cfqq, "arm_idle: %lu group_idle: %d", sl,
1958 group_idle ? 1 : 0);
1917} 1959}
1918 1960
1919/* 1961/*
@@ -1929,9 +1971,11 @@ static void cfq_dispatch_insert(struct request_queue *q, struct request *rq)
1929 cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq); 1971 cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq);
1930 cfq_remove_request(rq); 1972 cfq_remove_request(rq);
1931 cfqq->dispatched++; 1973 cfqq->dispatched++;
1974 (RQ_CFQG(rq))->dispatched++;
1932 elv_dispatch_sort(q, rq); 1975 elv_dispatch_sort(q, rq);
1933 1976
1934 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++; 1977 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++;
1978 cfqq->nr_sectors += blk_rq_sectors(rq);
1935 cfq_blkiocg_update_dispatch_stats(&cfqq->cfqg->blkg, blk_rq_bytes(rq), 1979 cfq_blkiocg_update_dispatch_stats(&cfqq->cfqg->blkg, blk_rq_bytes(rq),
1936 rq_data_dir(rq), rq_is_sync(rq)); 1980 rq_data_dir(rq), rq_is_sync(rq));
1937} 1981}
@@ -2198,7 +2242,7 @@ static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
2198 cfqq = NULL; 2242 cfqq = NULL;
2199 goto keep_queue; 2243 goto keep_queue;
2200 } else 2244 } else
2201 goto expire; 2245 goto check_group_idle;
2202 } 2246 }
2203 2247
2204 /* 2248 /*
@@ -2226,8 +2270,23 @@ static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd)
2226 * flight or is idling for a new request, allow either of these 2270 * flight or is idling for a new request, allow either of these
2227 * conditions to happen (or time out) before selecting a new queue. 2271 * conditions to happen (or time out) before selecting a new queue.
2228 */ 2272 */
2229 if (timer_pending(&cfqd->idle_slice_timer) || 2273 if (timer_pending(&cfqd->idle_slice_timer)) {
2230 (cfqq->dispatched && cfq_should_idle(cfqd, cfqq))) { 2274 cfqq = NULL;
2275 goto keep_queue;
2276 }
2277
2278 if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
2279 cfqq = NULL;
2280 goto keep_queue;
2281 }
2282
2283 /*
2284 * If group idle is enabled and there are requests dispatched from
2285 * this group, wait for requests to complete.
2286 */
2287check_group_idle:
2288 if (cfqd->cfq_group_idle && cfqq->cfqg->nr_cfqq == 1
2289 && cfqq->cfqg->dispatched) {
2231 cfqq = NULL; 2290 cfqq = NULL;
2232 goto keep_queue; 2291 goto keep_queue;
2233 } 2292 }
@@ -3375,6 +3434,7 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
3375 WARN_ON(!cfqq->dispatched); 3434 WARN_ON(!cfqq->dispatched);
3376 cfqd->rq_in_driver--; 3435 cfqd->rq_in_driver--;
3377 cfqq->dispatched--; 3436 cfqq->dispatched--;
3437 (RQ_CFQG(rq))->dispatched--;
3378 cfq_blkiocg_update_completion_stats(&cfqq->cfqg->blkg, 3438 cfq_blkiocg_update_completion_stats(&cfqq->cfqg->blkg,
3379 rq_start_time_ns(rq), rq_io_start_time_ns(rq), 3439 rq_start_time_ns(rq), rq_io_start_time_ns(rq),
3380 rq_data_dir(rq), rq_is_sync(rq)); 3440 rq_data_dir(rq), rq_is_sync(rq));
@@ -3404,7 +3464,10 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
3404 * the queue. 3464 * the queue.
3405 */ 3465 */
3406 if (cfq_should_wait_busy(cfqd, cfqq)) { 3466 if (cfq_should_wait_busy(cfqd, cfqq)) {
3407 cfqq->slice_end = jiffies + cfqd->cfq_slice_idle; 3467 unsigned long extend_sl = cfqd->cfq_slice_idle;
3468 if (!cfqd->cfq_slice_idle)
3469 extend_sl = cfqd->cfq_group_idle;
3470 cfqq->slice_end = jiffies + extend_sl;
3408 cfq_mark_cfqq_wait_busy(cfqq); 3471 cfq_mark_cfqq_wait_busy(cfqq);
3409 cfq_log_cfqq(cfqd, cfqq, "will busy wait"); 3472 cfq_log_cfqq(cfqd, cfqq, "will busy wait");
3410 } 3473 }
@@ -3850,6 +3913,7 @@ static void *cfq_init_queue(struct request_queue *q)
3850 cfqd->cfq_slice[1] = cfq_slice_sync; 3913 cfqd->cfq_slice[1] = cfq_slice_sync;
3851 cfqd->cfq_slice_async_rq = cfq_slice_async_rq; 3914 cfqd->cfq_slice_async_rq = cfq_slice_async_rq;
3852 cfqd->cfq_slice_idle = cfq_slice_idle; 3915 cfqd->cfq_slice_idle = cfq_slice_idle;
3916 cfqd->cfq_group_idle = cfq_group_idle;
3853 cfqd->cfq_latency = 1; 3917 cfqd->cfq_latency = 1;
3854 cfqd->cfq_group_isolation = 0; 3918 cfqd->cfq_group_isolation = 0;
3855 cfqd->hw_tag = -1; 3919 cfqd->hw_tag = -1;
@@ -3922,6 +3986,7 @@ SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1);
3922SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0); 3986SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0);
3923SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0); 3987SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0);
3924SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1); 3988SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1);
3989SHOW_FUNCTION(cfq_group_idle_show, cfqd->cfq_group_idle, 1);
3925SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1); 3990SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1);
3926SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1); 3991SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1);
3927SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0); 3992SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0);
@@ -3954,6 +4019,7 @@ STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0);
3954STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1, 4019STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1,
3955 UINT_MAX, 0); 4020 UINT_MAX, 0);
3956STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1); 4021STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1);
4022STORE_FUNCTION(cfq_group_idle_store, &cfqd->cfq_group_idle, 0, UINT_MAX, 1);
3957STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1); 4023STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1);
3958STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1); 4024STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1);
3959STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, 4025STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1,
@@ -3975,6 +4041,7 @@ static struct elv_fs_entry cfq_attrs[] = {
3975 CFQ_ATTR(slice_async), 4041 CFQ_ATTR(slice_async),
3976 CFQ_ATTR(slice_async_rq), 4042 CFQ_ATTR(slice_async_rq),
3977 CFQ_ATTR(slice_idle), 4043 CFQ_ATTR(slice_idle),
4044 CFQ_ATTR(group_idle),
3978 CFQ_ATTR(low_latency), 4045 CFQ_ATTR(low_latency),
3979 CFQ_ATTR(group_isolation), 4046 CFQ_ATTR(group_isolation),
3980 __ATTR_NULL 4047 __ATTR_NULL
@@ -4028,6 +4095,12 @@ static int __init cfq_init(void)
4028 if (!cfq_slice_idle) 4095 if (!cfq_slice_idle)
4029 cfq_slice_idle = 1; 4096 cfq_slice_idle = 1;
4030 4097
4098#ifdef CONFIG_CFQ_GROUP_IOSCHED
4099 if (!cfq_group_idle)
4100 cfq_group_idle = 1;
4101#else
4102 cfq_group_idle = 0;
4103#endif
4031 if (cfq_slab_setup()) 4104 if (cfq_slab_setup())
4032 return -ENOMEM; 4105 return -ENOMEM;
4033 4106