Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * CFQ, or complete fairness queueing, disk scheduler. |
| 3 | * |
| 4 | * Based on ideas from a previously unfinished io |
| 5 | * scheduler (round robin per-process disk scheduling) and Andrea Arcangeli. |
| 6 | * |
Jens Axboe | 0fe2347 | 2006-09-04 15:41:16 +0200 | [diff] [blame] | 7 | * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 10 | #include <linux/slab.h> |
Al Viro | 1cc9be6 | 2006-03-18 12:29:52 -0500 | [diff] [blame] | 11 | #include <linux/blkdev.h> |
| 12 | #include <linux/elevator.h> |
Randy Dunlap | ad5ebd2 | 2009-11-11 13:47:45 +0100 | [diff] [blame] | 13 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/rbtree.h> |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 15 | #include <linux/ioprio.h> |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 16 | #include <linux/blktrace_api.h> |
Tejun Heo | 6e736be | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 17 | #include "blk.h" |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 18 | #include "blk-cgroup.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 20 | static struct blkio_policy_type blkio_policy_cfq; |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | /* |
| 23 | * tunables |
| 24 | */ |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 25 | /* max queue in one round of service */ |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 26 | static const int cfq_quantum = 8; |
Arjan van de Ven | 6410009 | 2006-01-06 09:46:02 +0100 | [diff] [blame] | 27 | static const int cfq_fifo_expire[2] = { HZ / 4, HZ / 8 }; |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 28 | /* maximum backwards seek, in KiB */ |
| 29 | static const int cfq_back_max = 16 * 1024; |
| 30 | /* penalty of a backwards seek */ |
| 31 | static const int cfq_back_penalty = 2; |
Arjan van de Ven | 6410009 | 2006-01-06 09:46:02 +0100 | [diff] [blame] | 32 | static const int cfq_slice_sync = HZ / 10; |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 33 | static int cfq_slice_async = HZ / 25; |
Arjan van de Ven | 6410009 | 2006-01-06 09:46:02 +0100 | [diff] [blame] | 34 | static const int cfq_slice_async_rq = 2; |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 35 | static int cfq_slice_idle = HZ / 125; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 36 | static int cfq_group_idle = HZ / 125; |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 37 | static const int cfq_target_latency = HZ * 3/10; /* 300 ms */ |
| 38 | static const int cfq_hist_divisor = 4; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 39 | |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 40 | /* |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 41 | * offset from end of service tree |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 42 | */ |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 43 | #define CFQ_IDLE_DELAY (HZ / 5) |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * below this threshold, we consider thinktime immediate |
| 47 | */ |
| 48 | #define CFQ_MIN_TT (2) |
| 49 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 50 | #define CFQ_SLICE_SCALE (5) |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 51 | #define CFQ_HW_QUEUE_MIN (5) |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 52 | #define CFQ_SERVICE_SHIFT 12 |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 53 | |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 54 | #define CFQQ_SEEK_THR (sector_t)(8 * 100) |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 55 | #define CFQQ_CLOSE_THR (sector_t)(8 * 1024) |
Corrado Zoccolo | 41647e7 | 2010-02-27 19:45:40 +0100 | [diff] [blame] | 56 | #define CFQQ_SECT_THR_NONROT (sector_t)(2 * 32) |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 57 | #define CFQQ_SEEKY(cfqq) (hweight32(cfqq->seek_history) > 32/8) |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 58 | |
Tejun Heo | a612fdd | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 59 | #define RQ_CIC(rq) icq_to_cic((rq)->elv.icq) |
| 60 | #define RQ_CFQQ(rq) (struct cfq_queue *) ((rq)->elv.priv[0]) |
| 61 | #define RQ_CFQG(rq) (struct cfq_group *) ((rq)->elv.priv[1]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 63 | static struct kmem_cache *cfq_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 65 | #define CFQ_PRIO_LISTS IOPRIO_BE_NR |
| 66 | #define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 67 | #define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT) |
| 68 | |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 69 | #define sample_valid(samples) ((samples) > 80) |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 70 | #define rb_entry_cfqg(node) rb_entry((node), struct cfq_group, rb_node) |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 71 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 72 | struct cfq_ttime { |
| 73 | unsigned long last_end_request; |
| 74 | |
| 75 | unsigned long ttime_total; |
| 76 | unsigned long ttime_samples; |
| 77 | unsigned long ttime_mean; |
| 78 | }; |
| 79 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 80 | /* |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 81 | * Most of our rbtree usage is for sorting with min extraction, so |
| 82 | * if we cache the leftmost node we don't have to walk down the tree |
| 83 | * to find it. Idea borrowed from Ingo Molnars CFS scheduler. We should |
| 84 | * move this into the elevator for the rq sorting as well. |
| 85 | */ |
| 86 | struct cfq_rb_root { |
| 87 | struct rb_root rb; |
| 88 | struct rb_node *left; |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 89 | unsigned count; |
Richard Kennedy | 73e9ffd | 2010-03-01 10:50:20 +0100 | [diff] [blame] | 90 | unsigned total_weight; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 91 | u64 min_vdisktime; |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 92 | struct cfq_ttime ttime; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 93 | }; |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 94 | #define CFQ_RB_ROOT (struct cfq_rb_root) { .rb = RB_ROOT, \ |
| 95 | .ttime = {.last_end_request = jiffies,},} |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 96 | |
| 97 | /* |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 98 | * Per process-grouping structure |
| 99 | */ |
| 100 | struct cfq_queue { |
| 101 | /* reference count */ |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 102 | int ref; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 103 | /* various state flags, see below */ |
| 104 | unsigned int flags; |
| 105 | /* parent cfq_data */ |
| 106 | struct cfq_data *cfqd; |
| 107 | /* service_tree member */ |
| 108 | struct rb_node rb_node; |
| 109 | /* service_tree key */ |
| 110 | unsigned long rb_key; |
| 111 | /* prio tree member */ |
| 112 | struct rb_node p_node; |
| 113 | /* prio tree root we belong to, if any */ |
| 114 | struct rb_root *p_root; |
| 115 | /* sorted list of pending requests */ |
| 116 | struct rb_root sort_list; |
| 117 | /* if fifo isn't expired, next request to serve */ |
| 118 | struct request *next_rq; |
| 119 | /* requests queued in sort_list */ |
| 120 | int queued[2]; |
| 121 | /* currently allocated requests */ |
| 122 | int allocated[2]; |
| 123 | /* fifo list of requests in sort_list */ |
| 124 | struct list_head fifo; |
| 125 | |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 126 | /* time when queue got scheduled in to dispatch first request. */ |
| 127 | unsigned long dispatch_start; |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 128 | unsigned int allocated_slice; |
Richard Kennedy | c4081ba | 2010-02-22 13:49:24 +0100 | [diff] [blame] | 129 | unsigned int slice_dispatch; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 130 | /* time when first request from queue completed and slice started. */ |
| 131 | unsigned long slice_start; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 132 | unsigned long slice_end; |
| 133 | long slice_resid; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 134 | |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 135 | /* pending priority requests */ |
| 136 | int prio_pending; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 137 | /* number of requests that are on the dispatch list or inside driver */ |
| 138 | int dispatched; |
| 139 | |
| 140 | /* io prio of this group */ |
| 141 | unsigned short ioprio, org_ioprio; |
Justin TerAvest | 4aede84 | 2011-07-12 08:31:45 +0200 | [diff] [blame] | 142 | unsigned short ioprio_class; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 143 | |
Richard Kennedy | c4081ba | 2010-02-22 13:49:24 +0100 | [diff] [blame] | 144 | pid_t pid; |
| 145 | |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 146 | u32 seek_history; |
Jeff Moyer | b2c18e1 | 2009-10-23 17:14:49 -0400 | [diff] [blame] | 147 | sector_t last_request_pos; |
| 148 | |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 149 | struct cfq_rb_root *service_tree; |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 150 | struct cfq_queue *new_cfqq; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 151 | struct cfq_group *cfqg; |
Vivek Goyal | c4e7893 | 2010-08-23 12:25:03 +0200 | [diff] [blame] | 152 | /* Number of sectors dispatched from queue in single dispatch round */ |
| 153 | unsigned long nr_sectors; |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | /* |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 157 | * First index in the service_trees. |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 158 | * IDLE is handled separately, so it has negative index |
| 159 | */ |
| 160 | enum wl_prio_t { |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 161 | BE_WORKLOAD = 0, |
Vivek Goyal | 615f025 | 2009-12-03 12:59:39 -0500 | [diff] [blame] | 162 | RT_WORKLOAD = 1, |
| 163 | IDLE_WORKLOAD = 2, |
Vivek Goyal | b462732 | 2010-10-22 09:48:43 +0200 | [diff] [blame] | 164 | CFQ_PRIO_NR, |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | /* |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 168 | * Second index in the service_trees. |
| 169 | */ |
| 170 | enum wl_type_t { |
| 171 | ASYNC_WORKLOAD = 0, |
| 172 | SYNC_NOIDLE_WORKLOAD = 1, |
| 173 | SYNC_WORKLOAD = 2 |
| 174 | }; |
| 175 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 176 | /* This is per cgroup per device grouping structure */ |
| 177 | struct cfq_group { |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 178 | /* group service_tree member */ |
| 179 | struct rb_node rb_node; |
| 180 | |
| 181 | /* group service_tree key */ |
| 182 | u64 vdisktime; |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 183 | unsigned int weight; |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 184 | unsigned int new_weight; |
| 185 | bool needs_update; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 186 | |
| 187 | /* number of cfqq currently on this group */ |
| 188 | int nr_cfqq; |
| 189 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 190 | /* |
Kyungmin Park | 4495a7d | 2011-05-31 10:04:09 +0200 | [diff] [blame] | 191 | * Per group busy queues average. Useful for workload slice calc. We |
Vivek Goyal | b462732 | 2010-10-22 09:48:43 +0200 | [diff] [blame] | 192 | * create the array for each prio class but at run time it is used |
| 193 | * only for RT and BE class and slot for IDLE class remains unused. |
| 194 | * This is primarily done to avoid confusion and a gcc warning. |
| 195 | */ |
| 196 | unsigned int busy_queues_avg[CFQ_PRIO_NR]; |
| 197 | /* |
| 198 | * rr lists of queues with requests. We maintain service trees for |
| 199 | * RT and BE classes. These trees are subdivided in subclasses |
| 200 | * of SYNC, SYNC_NOIDLE and ASYNC based on workload type. For IDLE |
| 201 | * class there is no subclassification and all the cfq queues go on |
| 202 | * a single tree service_tree_idle. |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 203 | * Counts are embedded in the cfq_rb_root |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 204 | */ |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 205 | struct cfq_rb_root service_trees[2][3]; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 206 | struct cfq_rb_root service_tree_idle; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 207 | |
| 208 | unsigned long saved_workload_slice; |
| 209 | enum wl_type_t saved_workload; |
| 210 | enum wl_prio_t saved_serving_prio; |
Tejun Heo | 4eef304 | 2012-03-05 13:15:18 -0800 | [diff] [blame] | 211 | |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 212 | /* number of requests that are on the dispatch list or inside driver */ |
| 213 | int dispatched; |
Shaohua Li | 7700fc4 | 2011-07-12 14:24:56 +0200 | [diff] [blame] | 214 | struct cfq_ttime ttime; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 215 | }; |
| 216 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 217 | struct cfq_io_cq { |
| 218 | struct io_cq icq; /* must be the first member */ |
| 219 | struct cfq_queue *cfqq[2]; |
| 220 | struct cfq_ttime ttime; |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 221 | int ioprio; /* the current ioprio */ |
| 222 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
| 223 | uint64_t blkcg_id; /* the current blkcg ID */ |
| 224 | #endif |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 225 | }; |
| 226 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 227 | /* |
| 228 | * Per block device queue structure |
| 229 | */ |
| 230 | struct cfq_data { |
| 231 | struct request_queue *queue; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 232 | /* Root service tree for cfq_groups */ |
| 233 | struct cfq_rb_root grp_service_tree; |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 234 | struct cfq_group *root_group; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 235 | |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 236 | /* |
| 237 | * The priority currently being served |
| 238 | */ |
| 239 | enum wl_prio_t serving_prio; |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 240 | enum wl_type_t serving_type; |
| 241 | unsigned long workload_expires; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 242 | struct cfq_group *serving_group; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 243 | |
| 244 | /* |
| 245 | * Each priority tree is sorted by next_request position. These |
| 246 | * trees are used when determining if two or more queues are |
| 247 | * interleaving requests (see cfq_close_cooperator). |
| 248 | */ |
| 249 | struct rb_root prio_trees[CFQ_PRIO_LISTS]; |
| 250 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 251 | unsigned int busy_queues; |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 252 | unsigned int busy_sync_queues; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 253 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 254 | int rq_in_driver; |
| 255 | int rq_in_flight[2]; |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 256 | |
| 257 | /* |
| 258 | * queue-depth detection |
| 259 | */ |
| 260 | int rq_queued; |
Jens Axboe | 25776e3 | 2006-06-01 10:12:26 +0200 | [diff] [blame] | 261 | int hw_tag; |
Corrado Zoccolo | e459dd0 | 2009-11-26 10:02:57 +0100 | [diff] [blame] | 262 | /* |
| 263 | * hw_tag can be |
| 264 | * -1 => indeterminate, (cfq will behave as if NCQ is present, to allow better detection) |
| 265 | * 1 => NCQ is present (hw_tag_est_depth is the estimated max depth) |
| 266 | * 0 => no NCQ |
| 267 | */ |
| 268 | int hw_tag_est_depth; |
| 269 | unsigned int hw_tag_samples; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 270 | |
| 271 | /* |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 272 | * idle window management |
| 273 | */ |
| 274 | struct timer_list idle_slice_timer; |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 275 | struct work_struct unplug_work; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 276 | |
| 277 | struct cfq_queue *active_queue; |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 278 | struct cfq_io_cq *active_cic; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 279 | |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 280 | /* |
| 281 | * async queue for each priority case |
| 282 | */ |
| 283 | struct cfq_queue *async_cfqq[2][IOPRIO_BE_NR]; |
| 284 | struct cfq_queue *async_idle_cfqq; |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 285 | |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 286 | sector_t last_position; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | /* |
| 289 | * tunables, see top of file |
| 290 | */ |
| 291 | unsigned int cfq_quantum; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 292 | unsigned int cfq_fifo_expire[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | unsigned int cfq_back_penalty; |
| 294 | unsigned int cfq_back_max; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 295 | unsigned int cfq_slice[2]; |
| 296 | unsigned int cfq_slice_async_rq; |
| 297 | unsigned int cfq_slice_idle; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 298 | unsigned int cfq_group_idle; |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 299 | unsigned int cfq_latency; |
Al Viro | d9ff418 | 2006-03-18 13:51:22 -0500 | [diff] [blame] | 300 | |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 301 | /* |
| 302 | * Fallback dummy cfqq for extreme OOM conditions |
| 303 | */ |
| 304 | struct cfq_queue oom_cfqq; |
Vivek Goyal | 365722b | 2009-10-03 15:21:27 +0200 | [diff] [blame] | 305 | |
Corrado Zoccolo | 573412b | 2009-12-06 11:48:52 +0100 | [diff] [blame] | 306 | unsigned long last_delayed_sync; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | }; |
| 308 | |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 309 | static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd); |
| 310 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 311 | static struct cfq_rb_root *service_tree_for(struct cfq_group *cfqg, |
| 312 | enum wl_prio_t prio, |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 313 | enum wl_type_t type) |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 314 | { |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 315 | if (!cfqg) |
| 316 | return NULL; |
| 317 | |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 318 | if (prio == IDLE_WORKLOAD) |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 319 | return &cfqg->service_tree_idle; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 320 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 321 | return &cfqg->service_trees[prio][type]; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 324 | enum cfqq_state_flags { |
Jens Axboe | b0b8d749 | 2007-01-19 11:35:30 +1100 | [diff] [blame] | 325 | CFQ_CFQQ_FLAG_on_rr = 0, /* on round-robin busy list */ |
| 326 | CFQ_CFQQ_FLAG_wait_request, /* waiting for a request */ |
Jens Axboe | b029195 | 2009-04-07 11:38:31 +0200 | [diff] [blame] | 327 | CFQ_CFQQ_FLAG_must_dispatch, /* must be allowed a dispatch */ |
Jens Axboe | b0b8d749 | 2007-01-19 11:35:30 +1100 | [diff] [blame] | 328 | CFQ_CFQQ_FLAG_must_alloc_slice, /* per-slice must_alloc flag */ |
Jens Axboe | b0b8d749 | 2007-01-19 11:35:30 +1100 | [diff] [blame] | 329 | CFQ_CFQQ_FLAG_fifo_expire, /* FIFO checked in this slice */ |
| 330 | CFQ_CFQQ_FLAG_idle_window, /* slice idling enabled */ |
| 331 | CFQ_CFQQ_FLAG_prio_changed, /* task priority has changed */ |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 332 | CFQ_CFQQ_FLAG_slice_new, /* no requests dispatched in slice */ |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 333 | CFQ_CFQQ_FLAG_sync, /* synchronous queue */ |
Jeff Moyer | b3b6d04 | 2009-10-23 17:14:51 -0400 | [diff] [blame] | 334 | CFQ_CFQQ_FLAG_coop, /* cfqq is shared */ |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 335 | CFQ_CFQQ_FLAG_split_coop, /* shared cfqq will be splitted */ |
Corrado Zoccolo | 76280af | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 336 | CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */ |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 337 | CFQ_CFQQ_FLAG_wait_busy, /* Waiting for next request */ |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 338 | }; |
| 339 | |
| 340 | #define CFQ_CFQQ_FNS(name) \ |
| 341 | static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \ |
| 342 | { \ |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 343 | (cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_##name); \ |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 344 | } \ |
| 345 | static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \ |
| 346 | { \ |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 347 | (cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \ |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 348 | } \ |
| 349 | static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \ |
| 350 | { \ |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 351 | return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \ |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | CFQ_CFQQ_FNS(on_rr); |
| 355 | CFQ_CFQQ_FNS(wait_request); |
Jens Axboe | b029195 | 2009-04-07 11:38:31 +0200 | [diff] [blame] | 356 | CFQ_CFQQ_FNS(must_dispatch); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 357 | CFQ_CFQQ_FNS(must_alloc_slice); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 358 | CFQ_CFQQ_FNS(fifo_expire); |
| 359 | CFQ_CFQQ_FNS(idle_window); |
| 360 | CFQ_CFQQ_FNS(prio_changed); |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 361 | CFQ_CFQQ_FNS(slice_new); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 362 | CFQ_CFQQ_FNS(sync); |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 363 | CFQ_CFQQ_FNS(coop); |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 364 | CFQ_CFQQ_FNS(split_coop); |
Corrado Zoccolo | 76280af | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 365 | CFQ_CFQQ_FNS(deep); |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 366 | CFQ_CFQQ_FNS(wait_busy); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 367 | #undef CFQ_CFQQ_FNS |
| 368 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 369 | #if defined(CONFIG_CFQ_GROUP_IOSCHED) && defined(CONFIG_DEBUG_BLK_CGROUP) |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 370 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 371 | /* blkg state flags */ |
| 372 | enum blkg_state_flags { |
| 373 | BLKG_waiting = 0, |
| 374 | BLKG_idling, |
| 375 | BLKG_empty, |
| 376 | }; |
| 377 | |
| 378 | #define BLKG_FLAG_FNS(name) \ |
| 379 | static inline void blkio_mark_blkg_##name( \ |
| 380 | struct blkio_group_stats *stats) \ |
| 381 | { \ |
| 382 | stats->flags |= (1 << BLKG_##name); \ |
| 383 | } \ |
| 384 | static inline void blkio_clear_blkg_##name( \ |
| 385 | struct blkio_group_stats *stats) \ |
| 386 | { \ |
| 387 | stats->flags &= ~(1 << BLKG_##name); \ |
| 388 | } \ |
| 389 | static inline int blkio_blkg_##name(struct blkio_group_stats *stats) \ |
| 390 | { \ |
| 391 | return (stats->flags & (1 << BLKG_##name)) != 0; \ |
| 392 | } \ |
| 393 | |
| 394 | BLKG_FLAG_FNS(waiting) |
| 395 | BLKG_FLAG_FNS(idling) |
| 396 | BLKG_FLAG_FNS(empty) |
| 397 | #undef BLKG_FLAG_FNS |
| 398 | |
| 399 | /* This should be called with the queue_lock held. */ |
| 400 | static void blkio_update_group_wait_time(struct blkio_group_stats *stats) |
| 401 | { |
| 402 | unsigned long long now; |
| 403 | |
| 404 | if (!blkio_blkg_waiting(stats)) |
| 405 | return; |
| 406 | |
| 407 | now = sched_clock(); |
| 408 | if (time_after64(now, stats->start_group_wait_time)) |
| 409 | blkg_stat_add(&stats->group_wait_time, |
| 410 | now - stats->start_group_wait_time); |
| 411 | blkio_clear_blkg_waiting(stats); |
| 412 | } |
| 413 | |
| 414 | /* This should be called with the queue_lock held. */ |
| 415 | static void blkio_set_start_group_wait_time(struct blkio_group *blkg, |
| 416 | struct blkio_policy_type *pol, |
| 417 | struct blkio_group *curr_blkg) |
| 418 | { |
| 419 | struct blkg_policy_data *pd = blkg->pd[pol->plid]; |
| 420 | |
| 421 | if (blkio_blkg_waiting(&pd->stats)) |
| 422 | return; |
| 423 | if (blkg == curr_blkg) |
| 424 | return; |
| 425 | pd->stats.start_group_wait_time = sched_clock(); |
| 426 | blkio_mark_blkg_waiting(&pd->stats); |
| 427 | } |
| 428 | |
| 429 | /* This should be called with the queue_lock held. */ |
| 430 | static void blkio_end_empty_time(struct blkio_group_stats *stats) |
| 431 | { |
| 432 | unsigned long long now; |
| 433 | |
| 434 | if (!blkio_blkg_empty(stats)) |
| 435 | return; |
| 436 | |
| 437 | now = sched_clock(); |
| 438 | if (time_after64(now, stats->start_empty_time)) |
| 439 | blkg_stat_add(&stats->empty_time, |
| 440 | now - stats->start_empty_time); |
| 441 | blkio_clear_blkg_empty(stats); |
| 442 | } |
| 443 | |
| 444 | static void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
| 445 | struct blkio_policy_type *pol, |
| 446 | unsigned long dequeue) |
| 447 | { |
| 448 | struct blkg_policy_data *pd = blkg->pd[pol->plid]; |
| 449 | |
| 450 | lockdep_assert_held(blkg->q->queue_lock); |
| 451 | |
| 452 | blkg_stat_add(&pd->stats.dequeue, dequeue); |
| 453 | } |
| 454 | |
| 455 | static void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 456 | struct blkio_policy_type *pol) |
| 457 | { |
| 458 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 459 | |
| 460 | lockdep_assert_held(blkg->q->queue_lock); |
| 461 | |
| 462 | if (blkg_rwstat_sum(&stats->queued)) |
| 463 | return; |
| 464 | |
| 465 | /* |
| 466 | * group is already marked empty. This can happen if cfqq got new |
| 467 | * request in parent group and moved to this group while being added |
| 468 | * to service tree. Just ignore the event and move on. |
| 469 | */ |
| 470 | if (blkio_blkg_empty(stats)) |
| 471 | return; |
| 472 | |
| 473 | stats->start_empty_time = sched_clock(); |
| 474 | blkio_mark_blkg_empty(stats); |
| 475 | } |
| 476 | |
| 477 | static void cfq_blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 478 | struct blkio_policy_type *pol) |
| 479 | { |
| 480 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 481 | |
| 482 | lockdep_assert_held(blkg->q->queue_lock); |
| 483 | |
| 484 | if (blkio_blkg_idling(stats)) { |
| 485 | unsigned long long now = sched_clock(); |
| 486 | |
| 487 | if (time_after64(now, stats->start_idle_time)) |
| 488 | blkg_stat_add(&stats->idle_time, |
| 489 | now - stats->start_idle_time); |
| 490 | blkio_clear_blkg_idling(stats); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | static void cfq_blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 495 | struct blkio_policy_type *pol) |
| 496 | { |
| 497 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 498 | |
| 499 | lockdep_assert_held(blkg->q->queue_lock); |
| 500 | BUG_ON(blkio_blkg_idling(stats)); |
| 501 | |
| 502 | stats->start_idle_time = sched_clock(); |
| 503 | blkio_mark_blkg_idling(stats); |
| 504 | } |
| 505 | |
| 506 | static void cfq_blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 507 | struct blkio_policy_type *pol) |
| 508 | { |
| 509 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 510 | |
| 511 | lockdep_assert_held(blkg->q->queue_lock); |
| 512 | |
| 513 | blkg_stat_add(&stats->avg_queue_size_sum, |
| 514 | blkg_rwstat_sum(&stats->queued)); |
| 515 | blkg_stat_add(&stats->avg_queue_size_samples, 1); |
| 516 | blkio_update_group_wait_time(stats); |
| 517 | } |
| 518 | |
| 519 | #else /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */ |
| 520 | |
| 521 | static void blkio_set_start_group_wait_time(struct blkio_group *blkg, |
| 522 | struct blkio_policy_type *pol, |
| 523 | struct blkio_group *curr_blkg) { } |
| 524 | static void blkio_end_empty_time(struct blkio_group_stats *stats) { } |
| 525 | static void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg, |
| 526 | struct blkio_policy_type *pol, |
| 527 | unsigned long dequeue) { } |
| 528 | static void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg, |
| 529 | struct blkio_policy_type *pol) { } |
| 530 | static void cfq_blkiocg_update_idle_time_stats(struct blkio_group *blkg, |
| 531 | struct blkio_policy_type *pol) { } |
| 532 | static void cfq_blkiocg_update_set_idle_time_stats(struct blkio_group *blkg, |
| 533 | struct blkio_policy_type *pol) { } |
| 534 | static void cfq_blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg, |
| 535 | struct blkio_policy_type *pol) { } |
| 536 | |
| 537 | #endif /* CONFIG_CFQ_GROUP_IOSCHED && CONFIG_DEBUG_BLK_CGROUP */ |
| 538 | |
| 539 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 540 | |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 541 | static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg) |
| 542 | { |
| 543 | return blkg_to_pdata(blkg, &blkio_policy_cfq); |
| 544 | } |
| 545 | |
| 546 | static inline struct blkio_group *cfqg_to_blkg(struct cfq_group *cfqg) |
| 547 | { |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 548 | return pdata_to_blkg(cfqg); |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static inline void cfqg_get(struct cfq_group *cfqg) |
| 552 | { |
| 553 | return blkg_get(cfqg_to_blkg(cfqg)); |
| 554 | } |
| 555 | |
| 556 | static inline void cfqg_put(struct cfq_group *cfqg) |
| 557 | { |
| 558 | return blkg_put(cfqg_to_blkg(cfqg)); |
| 559 | } |
| 560 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 561 | #define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \ |
| 562 | blk_add_trace_msg((cfqd)->queue, "cfq%d%c %s " fmt, (cfqq)->pid, \ |
| 563 | cfq_cfqq_sync((cfqq)) ? 'S' : 'A', \ |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 564 | blkg_path(cfqg_to_blkg((cfqq)->cfqg)), ##args) |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 565 | |
| 566 | #define cfq_log_cfqg(cfqd, cfqg, fmt, args...) \ |
| 567 | blk_add_trace_msg((cfqd)->queue, "%s " fmt, \ |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 568 | blkg_path(cfqg_to_blkg((cfqg))), ##args) \ |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 569 | |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 570 | static inline void cfq_blkiocg_update_io_add_stats(struct blkio_group *blkg, |
| 571 | struct blkio_policy_type *pol, |
| 572 | struct blkio_group *curr_blkg, |
| 573 | bool direction, bool sync) |
| 574 | { |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 575 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 576 | int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 577 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 578 | lockdep_assert_held(blkg->q->queue_lock); |
| 579 | |
| 580 | blkg_rwstat_add(&stats->queued, rw, 1); |
| 581 | blkio_end_empty_time(stats); |
| 582 | blkio_set_start_group_wait_time(blkg, pol, curr_blkg); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg, |
| 586 | struct blkio_policy_type *pol, unsigned long time, |
| 587 | unsigned long unaccounted_time) |
| 588 | { |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 589 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 590 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 591 | lockdep_assert_held(blkg->q->queue_lock); |
| 592 | |
| 593 | blkg_stat_add(&stats->time, time); |
| 594 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 595 | blkg_stat_add(&stats->unaccounted_time, unaccounted_time); |
| 596 | #endif |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static inline void cfq_blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
| 600 | struct blkio_policy_type *pol, bool direction, |
| 601 | bool sync) |
| 602 | { |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 603 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 604 | int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0); |
| 605 | |
| 606 | lockdep_assert_held(blkg->q->queue_lock); |
| 607 | |
| 608 | blkg_rwstat_add(&stats->queued, rw, -1); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static inline void cfq_blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
| 612 | struct blkio_policy_type *pol, bool direction, |
| 613 | bool sync) |
| 614 | { |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 615 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 616 | int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 617 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 618 | lockdep_assert_held(blkg->q->queue_lock); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 619 | |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 620 | blkg_rwstat_add(&stats->merged, rw, 1); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static inline void cfq_blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
| 624 | struct blkio_policy_type *pol, uint64_t bytes, |
| 625 | bool direction, bool sync) |
| 626 | { |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 627 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 628 | int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0); |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 629 | |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 630 | blkg_stat_add(&stats->sectors, bytes >> 9); |
| 631 | blkg_rwstat_add(&stats->serviced, rw, 1); |
| 632 | blkg_rwstat_add(&stats->service_bytes, rw, bytes); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | static inline void cfq_blkiocg_update_completion_stats(struct blkio_group *blkg, |
| 636 | struct blkio_policy_type *pol, uint64_t start_time, |
| 637 | uint64_t io_start_time, bool direction, bool sync) |
| 638 | { |
Tejun Heo | 629ed0b | 2012-04-01 14:38:44 -0700 | [diff] [blame] | 639 | struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats; |
| 640 | unsigned long long now = sched_clock(); |
| 641 | int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0); |
| 642 | |
| 643 | lockdep_assert_held(blkg->q->queue_lock); |
| 644 | |
| 645 | if (time_after64(now, io_start_time)) |
| 646 | blkg_rwstat_add(&stats->service_time, rw, now - io_start_time); |
| 647 | if (time_after64(io_start_time, start_time)) |
| 648 | blkg_rwstat_add(&stats->wait_time, rw, |
| 649 | io_start_time - start_time); |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 652 | #else /* CONFIG_CFQ_GROUP_IOSCHED */ |
| 653 | |
| 654 | static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg) { return NULL; } |
| 655 | static inline struct blkio_group *cfqg_to_blkg(struct cfq_group *cfqg) { return NULL; } |
| 656 | static inline void cfqg_get(struct cfq_group *cfqg) { } |
| 657 | static inline void cfqg_put(struct cfq_group *cfqg) { } |
| 658 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 659 | #define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \ |
| 660 | blk_add_trace_msg((cfqd)->queue, "cfq%d " fmt, (cfqq)->pid, ##args) |
Kyungmin Park | 4495a7d | 2011-05-31 10:04:09 +0200 | [diff] [blame] | 661 | #define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do {} while (0) |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 662 | |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 663 | static inline void cfq_blkiocg_update_io_add_stats(struct blkio_group *blkg, |
| 664 | struct blkio_policy_type *pol, |
| 665 | struct blkio_group *curr_blkg, bool direction, |
| 666 | bool sync) { } |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 667 | static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg, |
| 668 | struct blkio_policy_type *pol, unsigned long time, |
| 669 | unsigned long unaccounted_time) { } |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 670 | static inline void cfq_blkiocg_update_io_remove_stats(struct blkio_group *blkg, |
| 671 | struct blkio_policy_type *pol, bool direction, |
| 672 | bool sync) { } |
| 673 | static inline void cfq_blkiocg_update_io_merged_stats(struct blkio_group *blkg, |
| 674 | struct blkio_policy_type *pol, bool direction, |
| 675 | bool sync) { } |
Tejun Heo | 2ce4d50 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 676 | static inline void cfq_blkiocg_update_dispatch_stats(struct blkio_group *blkg, |
| 677 | struct blkio_policy_type *pol, uint64_t bytes, |
| 678 | bool direction, bool sync) { } |
| 679 | static inline void cfq_blkiocg_update_completion_stats(struct blkio_group *blkg, |
| 680 | struct blkio_policy_type *pol, uint64_t start_time, |
| 681 | uint64_t io_start_time, bool direction, bool sync) { } |
| 682 | |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 683 | #endif /* CONFIG_CFQ_GROUP_IOSCHED */ |
| 684 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 685 | #define cfq_log(cfqd, fmt, args...) \ |
| 686 | blk_add_trace_msg((cfqd)->queue, "cfq " fmt, ##args) |
| 687 | |
Vivek Goyal | 615f025 | 2009-12-03 12:59:39 -0500 | [diff] [blame] | 688 | /* Traverses through cfq group service trees */ |
| 689 | #define for_each_cfqg_st(cfqg, i, j, st) \ |
| 690 | for (i = 0; i <= IDLE_WORKLOAD; i++) \ |
| 691 | for (j = 0, st = i < IDLE_WORKLOAD ? &cfqg->service_trees[i][j]\ |
| 692 | : &cfqg->service_tree_idle; \ |
| 693 | (i < IDLE_WORKLOAD && j <= SYNC_WORKLOAD) || \ |
| 694 | (i == IDLE_WORKLOAD && j == 0); \ |
| 695 | j++, st = i < IDLE_WORKLOAD ? \ |
| 696 | &cfqg->service_trees[i][j]: NULL) \ |
| 697 | |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 698 | static inline bool cfq_io_thinktime_big(struct cfq_data *cfqd, |
| 699 | struct cfq_ttime *ttime, bool group_idle) |
| 700 | { |
| 701 | unsigned long slice; |
| 702 | if (!sample_valid(ttime->ttime_samples)) |
| 703 | return false; |
| 704 | if (group_idle) |
| 705 | slice = cfqd->cfq_group_idle; |
| 706 | else |
| 707 | slice = cfqd->cfq_slice_idle; |
| 708 | return ttime->ttime_mean > slice; |
| 709 | } |
Vivek Goyal | 615f025 | 2009-12-03 12:59:39 -0500 | [diff] [blame] | 710 | |
Vivek Goyal | 02b3508 | 2010-08-23 12:23:53 +0200 | [diff] [blame] | 711 | static inline bool iops_mode(struct cfq_data *cfqd) |
| 712 | { |
| 713 | /* |
| 714 | * If we are not idling on queues and it is a NCQ drive, parallel |
| 715 | * execution of requests is on and measuring time is not possible |
| 716 | * in most of the cases until and unless we drive shallower queue |
| 717 | * depths and that becomes a performance bottleneck. In such cases |
| 718 | * switch to start providing fairness in terms of number of IOs. |
| 719 | */ |
| 720 | if (!cfqd->cfq_slice_idle && cfqd->hw_tag) |
| 721 | return true; |
| 722 | else |
| 723 | return false; |
| 724 | } |
| 725 | |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 726 | static inline enum wl_prio_t cfqq_prio(struct cfq_queue *cfqq) |
| 727 | { |
| 728 | if (cfq_class_idle(cfqq)) |
| 729 | return IDLE_WORKLOAD; |
| 730 | if (cfq_class_rt(cfqq)) |
| 731 | return RT_WORKLOAD; |
| 732 | return BE_WORKLOAD; |
| 733 | } |
| 734 | |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 735 | |
| 736 | static enum wl_type_t cfqq_type(struct cfq_queue *cfqq) |
| 737 | { |
| 738 | if (!cfq_cfqq_sync(cfqq)) |
| 739 | return ASYNC_WORKLOAD; |
| 740 | if (!cfq_cfqq_idle_window(cfqq)) |
| 741 | return SYNC_NOIDLE_WORKLOAD; |
| 742 | return SYNC_WORKLOAD; |
| 743 | } |
| 744 | |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 745 | static inline int cfq_group_busy_queues_wl(enum wl_prio_t wl, |
| 746 | struct cfq_data *cfqd, |
| 747 | struct cfq_group *cfqg) |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 748 | { |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 749 | if (wl == IDLE_WORKLOAD) |
| 750 | return cfqg->service_tree_idle.count; |
| 751 | |
| 752 | return cfqg->service_trees[wl][ASYNC_WORKLOAD].count |
| 753 | + cfqg->service_trees[wl][SYNC_NOIDLE_WORKLOAD].count |
| 754 | + cfqg->service_trees[wl][SYNC_WORKLOAD].count; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 755 | } |
| 756 | |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 757 | static inline int cfqg_busy_async_queues(struct cfq_data *cfqd, |
| 758 | struct cfq_group *cfqg) |
| 759 | { |
| 760 | return cfqg->service_trees[RT_WORKLOAD][ASYNC_WORKLOAD].count |
| 761 | + cfqg->service_trees[BE_WORKLOAD][ASYNC_WORKLOAD].count; |
| 762 | } |
| 763 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 764 | static void cfq_dispatch_insert(struct request_queue *, struct request *); |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 765 | static struct cfq_queue *cfq_get_queue(struct cfq_data *cfqd, bool is_sync, |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 766 | struct cfq_io_cq *cic, struct bio *bio, |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 767 | gfp_t gfp_mask); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 768 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 769 | static inline struct cfq_io_cq *icq_to_cic(struct io_cq *icq) |
| 770 | { |
| 771 | /* cic->icq is the first member, %NULL will convert to %NULL */ |
| 772 | return container_of(icq, struct cfq_io_cq, icq); |
| 773 | } |
| 774 | |
Tejun Heo | 47fdd4c | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 775 | static inline struct cfq_io_cq *cfq_cic_lookup(struct cfq_data *cfqd, |
| 776 | struct io_context *ioc) |
| 777 | { |
| 778 | if (ioc) |
| 779 | return icq_to_cic(ioc_lookup_icq(ioc, cfqd->queue)); |
| 780 | return NULL; |
| 781 | } |
| 782 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 783 | static inline struct cfq_queue *cic_to_cfqq(struct cfq_io_cq *cic, bool is_sync) |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 784 | { |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 785 | return cic->cfqq[is_sync]; |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 788 | static inline void cic_set_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq, |
| 789 | bool is_sync) |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 790 | { |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 791 | cic->cfqq[is_sync] = cfqq; |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 792 | } |
| 793 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 794 | static inline struct cfq_data *cic_to_cfqd(struct cfq_io_cq *cic) |
Konstantin Khlebnikov | bca4b91 | 2010-05-20 23:21:34 +0400 | [diff] [blame] | 795 | { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 796 | return cic->icq.q->elevator->elevator_data; |
Konstantin Khlebnikov | bca4b91 | 2010-05-20 23:21:34 +0400 | [diff] [blame] | 797 | } |
| 798 | |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 799 | /* |
| 800 | * We regard a request as SYNC, if it's either a read or has the SYNC bit |
| 801 | * set (in which case it could also be direct WRITE). |
| 802 | */ |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 803 | static inline bool cfq_bio_sync(struct bio *bio) |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 804 | { |
Christoph Hellwig | 7b6d91d | 2010-08-07 18:20:39 +0200 | [diff] [blame] | 805 | return bio_data_dir(bio) == READ || (bio->bi_rw & REQ_SYNC); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 806 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | /* |
Andrew Morton | 99f95e5 | 2005-06-27 20:14:05 -0700 | [diff] [blame] | 809 | * scheduler run of queue, if there are requests pending and no one in the |
| 810 | * driver that will restart queueing |
| 811 | */ |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 812 | static inline void cfq_schedule_dispatch(struct cfq_data *cfqd) |
Andrew Morton | 99f95e5 | 2005-06-27 20:14:05 -0700 | [diff] [blame] | 813 | { |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 814 | if (cfqd->busy_queues) { |
| 815 | cfq_log(cfqd, "schedule dispatch"); |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 816 | kblockd_schedule_work(cfqd->queue, &cfqd->unplug_work); |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 817 | } |
Andrew Morton | 99f95e5 | 2005-06-27 20:14:05 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | /* |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 821 | * Scale schedule slice based on io priority. Use the sync time slice only |
| 822 | * if a queue is marked sync and has sync io queued. A sync queue with async |
| 823 | * io only, should not get full sync slice length. |
| 824 | */ |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 825 | static inline int cfq_prio_slice(struct cfq_data *cfqd, bool sync, |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 826 | unsigned short prio) |
| 827 | { |
| 828 | const int base_slice = cfqd->cfq_slice[sync]; |
| 829 | |
| 830 | WARN_ON(prio >= IOPRIO_BE_NR); |
| 831 | |
| 832 | return base_slice + (base_slice/CFQ_SLICE_SCALE * (4 - prio)); |
| 833 | } |
| 834 | |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 835 | static inline int |
| 836 | cfq_prio_to_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 837 | { |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 838 | return cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio); |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 839 | } |
| 840 | |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 841 | static inline u64 cfq_scale_slice(unsigned long delta, struct cfq_group *cfqg) |
| 842 | { |
| 843 | u64 d = delta << CFQ_SERVICE_SHIFT; |
| 844 | |
| 845 | d = d * BLKIO_WEIGHT_DEFAULT; |
| 846 | do_div(d, cfqg->weight); |
| 847 | return d; |
| 848 | } |
| 849 | |
| 850 | static inline u64 max_vdisktime(u64 min_vdisktime, u64 vdisktime) |
| 851 | { |
| 852 | s64 delta = (s64)(vdisktime - min_vdisktime); |
| 853 | if (delta > 0) |
| 854 | min_vdisktime = vdisktime; |
| 855 | |
| 856 | return min_vdisktime; |
| 857 | } |
| 858 | |
| 859 | static inline u64 min_vdisktime(u64 min_vdisktime, u64 vdisktime) |
| 860 | { |
| 861 | s64 delta = (s64)(vdisktime - min_vdisktime); |
| 862 | if (delta < 0) |
| 863 | min_vdisktime = vdisktime; |
| 864 | |
| 865 | return min_vdisktime; |
| 866 | } |
| 867 | |
| 868 | static void update_min_vdisktime(struct cfq_rb_root *st) |
| 869 | { |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 870 | struct cfq_group *cfqg; |
| 871 | |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 872 | if (st->left) { |
| 873 | cfqg = rb_entry_cfqg(st->left); |
Gui Jianfeng | a603271 | 2011-03-07 09:28:09 +0100 | [diff] [blame] | 874 | st->min_vdisktime = max_vdisktime(st->min_vdisktime, |
| 875 | cfqg->vdisktime); |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 876 | } |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 877 | } |
| 878 | |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 879 | /* |
| 880 | * get averaged number of queues of RT/BE priority. |
| 881 | * average is updated, with a formula that gives more weight to higher numbers, |
| 882 | * to quickly follows sudden increases and decrease slowly |
| 883 | */ |
| 884 | |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 885 | static inline unsigned cfq_group_get_avg_queues(struct cfq_data *cfqd, |
| 886 | struct cfq_group *cfqg, bool rt) |
Jens Axboe | 5869619c | 2009-10-28 09:27:07 +0100 | [diff] [blame] | 887 | { |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 888 | unsigned min_q, max_q; |
| 889 | unsigned mult = cfq_hist_divisor - 1; |
| 890 | unsigned round = cfq_hist_divisor / 2; |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 891 | unsigned busy = cfq_group_busy_queues_wl(rt, cfqd, cfqg); |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 892 | |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 893 | min_q = min(cfqg->busy_queues_avg[rt], busy); |
| 894 | max_q = max(cfqg->busy_queues_avg[rt], busy); |
| 895 | cfqg->busy_queues_avg[rt] = (mult * max_q + min_q + round) / |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 896 | cfq_hist_divisor; |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 897 | return cfqg->busy_queues_avg[rt]; |
| 898 | } |
| 899 | |
| 900 | static inline unsigned |
| 901 | cfq_group_slice(struct cfq_data *cfqd, struct cfq_group *cfqg) |
| 902 | { |
| 903 | struct cfq_rb_root *st = &cfqd->grp_service_tree; |
| 904 | |
| 905 | return cfq_target_latency * cfqg->weight / st->total_weight; |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 906 | } |
| 907 | |
Shaohua Li | c553f8e | 2011-01-14 08:41:03 +0100 | [diff] [blame] | 908 | static inline unsigned |
Vivek Goyal | ba5bd52 | 2011-01-19 08:25:02 -0700 | [diff] [blame] | 909 | cfq_scaled_cfqq_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 910 | { |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 911 | unsigned slice = cfq_prio_to_slice(cfqd, cfqq); |
| 912 | if (cfqd->cfq_latency) { |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 913 | /* |
| 914 | * interested queues (we consider only the ones with the same |
| 915 | * priority class in the cfq group) |
| 916 | */ |
| 917 | unsigned iq = cfq_group_get_avg_queues(cfqd, cfqq->cfqg, |
| 918 | cfq_class_rt(cfqq)); |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 919 | unsigned sync_slice = cfqd->cfq_slice[1]; |
| 920 | unsigned expect_latency = sync_slice * iq; |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 921 | unsigned group_slice = cfq_group_slice(cfqd, cfqq->cfqg); |
| 922 | |
| 923 | if (expect_latency > group_slice) { |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 924 | unsigned base_low_slice = 2 * cfqd->cfq_slice_idle; |
| 925 | /* scale low_slice according to IO priority |
| 926 | * and sync vs async */ |
| 927 | unsigned low_slice = |
| 928 | min(slice, base_low_slice * slice / sync_slice); |
| 929 | /* the adapted slice value is scaled to fit all iqs |
| 930 | * into the target latency */ |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 931 | slice = max(slice * group_slice / expect_latency, |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 932 | low_slice); |
| 933 | } |
| 934 | } |
Shaohua Li | c553f8e | 2011-01-14 08:41:03 +0100 | [diff] [blame] | 935 | return slice; |
| 936 | } |
| 937 | |
| 938 | static inline void |
| 939 | cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 940 | { |
Vivek Goyal | ba5bd52 | 2011-01-19 08:25:02 -0700 | [diff] [blame] | 941 | unsigned slice = cfq_scaled_cfqq_slice(cfqd, cfqq); |
Shaohua Li | c553f8e | 2011-01-14 08:41:03 +0100 | [diff] [blame] | 942 | |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 943 | cfqq->slice_start = jiffies; |
Corrado Zoccolo | 5db5d64 | 2009-10-26 22:44:04 +0100 | [diff] [blame] | 944 | cfqq->slice_end = jiffies + slice; |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 945 | cfqq->allocated_slice = slice; |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 946 | cfq_log_cfqq(cfqd, cfqq, "set_slice=%lu", cfqq->slice_end - jiffies); |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /* |
| 950 | * We need to wrap this check in cfq_cfqq_slice_new(), since ->slice_end |
| 951 | * isn't valid until the first request from the dispatch is activated |
| 952 | * and the slice time set. |
| 953 | */ |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 954 | static inline bool cfq_slice_used(struct cfq_queue *cfqq) |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 955 | { |
| 956 | if (cfq_cfqq_slice_new(cfqq)) |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 957 | return false; |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 958 | if (time_before(jiffies, cfqq->slice_end)) |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 959 | return false; |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 960 | |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 961 | return true; |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /* |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 965 | * Lifted from AS - choose which of rq1 and rq2 that is best served now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | * We choose the request that is closest to the head right now. Distance |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 967 | * behind the head is penalized and only allowed to a certain extent. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | */ |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 969 | static struct request * |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 970 | cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2, sector_t last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | { |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 972 | sector_t s1, s2, d1 = 0, d2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | unsigned long back_max; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 974 | #define CFQ_RQ1_WRAP 0x01 /* request 1 wraps */ |
| 975 | #define CFQ_RQ2_WRAP 0x02 /* request 2 wraps */ |
| 976 | unsigned wrap = 0; /* bit mask: requests behind the disk head? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 978 | if (rq1 == NULL || rq1 == rq2) |
| 979 | return rq2; |
| 980 | if (rq2 == NULL) |
| 981 | return rq1; |
Jens Axboe | 9c2c38a | 2005-08-24 14:57:54 +0200 | [diff] [blame] | 982 | |
Namhyung Kim | 229836b | 2011-05-24 10:23:21 +0200 | [diff] [blame] | 983 | if (rq_is_sync(rq1) != rq_is_sync(rq2)) |
| 984 | return rq_is_sync(rq1) ? rq1 : rq2; |
| 985 | |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 986 | if ((rq1->cmd_flags ^ rq2->cmd_flags) & REQ_PRIO) |
| 987 | return rq1->cmd_flags & REQ_PRIO ? rq1 : rq2; |
Jens Axboe | b53d1ed | 2011-08-19 08:34:48 +0200 | [diff] [blame] | 988 | |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 989 | s1 = blk_rq_pos(rq1); |
| 990 | s2 = blk_rq_pos(rq2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | /* |
| 993 | * by definition, 1KiB is 2 sectors |
| 994 | */ |
| 995 | back_max = cfqd->cfq_back_max * 2; |
| 996 | |
| 997 | /* |
| 998 | * Strict one way elevator _except_ in the case where we allow |
| 999 | * short backward seeks which are biased as twice the cost of a |
| 1000 | * similar forward seek. |
| 1001 | */ |
| 1002 | if (s1 >= last) |
| 1003 | d1 = s1 - last; |
| 1004 | else if (s1 + back_max >= last) |
| 1005 | d1 = (last - s1) * cfqd->cfq_back_penalty; |
| 1006 | else |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1007 | wrap |= CFQ_RQ1_WRAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | |
| 1009 | if (s2 >= last) |
| 1010 | d2 = s2 - last; |
| 1011 | else if (s2 + back_max >= last) |
| 1012 | d2 = (last - s2) * cfqd->cfq_back_penalty; |
| 1013 | else |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1014 | wrap |= CFQ_RQ2_WRAP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
| 1016 | /* Found required data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1018 | /* |
| 1019 | * By doing switch() on the bit mask "wrap" we avoid having to |
| 1020 | * check two variables for all permutations: --> faster! |
| 1021 | */ |
| 1022 | switch (wrap) { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1023 | case 0: /* common case for CFQ: rq1 and rq2 not wrapped */ |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1024 | if (d1 < d2) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1025 | return rq1; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1026 | else if (d2 < d1) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1027 | return rq2; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1028 | else { |
| 1029 | if (s1 >= s2) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1030 | return rq1; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1031 | else |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1032 | return rq2; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | case CFQ_RQ2_WRAP: |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1036 | return rq1; |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1037 | case CFQ_RQ1_WRAP: |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1038 | return rq2; |
| 1039 | case (CFQ_RQ1_WRAP|CFQ_RQ2_WRAP): /* both rqs wrapped */ |
Andreas Mohr | e8a9905 | 2006-03-28 08:59:49 +0200 | [diff] [blame] | 1040 | default: |
| 1041 | /* |
| 1042 | * Since both rqs are wrapped, |
| 1043 | * start with the one that's further behind head |
| 1044 | * (--> only *one* back seek required), |
| 1045 | * since back seek takes more time than forward. |
| 1046 | */ |
| 1047 | if (s1 <= s2) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1048 | return rq1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | else |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1050 | return rq2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1054 | /* |
| 1055 | * The below is leftmost cache rbtree addon |
| 1056 | */ |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1057 | static struct cfq_queue *cfq_rb_first(struct cfq_rb_root *root) |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1058 | { |
Vivek Goyal | 615f025 | 2009-12-03 12:59:39 -0500 | [diff] [blame] | 1059 | /* Service tree is empty */ |
| 1060 | if (!root->count) |
| 1061 | return NULL; |
| 1062 | |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1063 | if (!root->left) |
| 1064 | root->left = rb_first(&root->rb); |
| 1065 | |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1066 | if (root->left) |
| 1067 | return rb_entry(root->left, struct cfq_queue, rb_node); |
| 1068 | |
| 1069 | return NULL; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1072 | static struct cfq_group *cfq_rb_first_group(struct cfq_rb_root *root) |
| 1073 | { |
| 1074 | if (!root->left) |
| 1075 | root->left = rb_first(&root->rb); |
| 1076 | |
| 1077 | if (root->left) |
| 1078 | return rb_entry_cfqg(root->left); |
| 1079 | |
| 1080 | return NULL; |
| 1081 | } |
| 1082 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1083 | static void rb_erase_init(struct rb_node *n, struct rb_root *root) |
| 1084 | { |
| 1085 | rb_erase(n, root); |
| 1086 | RB_CLEAR_NODE(n); |
| 1087 | } |
| 1088 | |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1089 | static void cfq_rb_erase(struct rb_node *n, struct cfq_rb_root *root) |
| 1090 | { |
| 1091 | if (root->left == n) |
| 1092 | root->left = NULL; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1093 | rb_erase_init(n, &root->rb); |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1094 | --root->count; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | /* |
| 1098 | * would be nice to take fifo expire time into account as well |
| 1099 | */ |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1100 | static struct request * |
| 1101 | cfq_find_next_rq(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
| 1102 | struct request *last) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | { |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1104 | struct rb_node *rbnext = rb_next(&last->rb_node); |
| 1105 | struct rb_node *rbprev = rb_prev(&last->rb_node); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1106 | struct request *next = NULL, *prev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1108 | BUG_ON(RB_EMPTY_NODE(&last->rb_node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | |
| 1110 | if (rbprev) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1111 | prev = rb_entry_rq(rbprev); |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (rbnext) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1114 | next = rb_entry_rq(rbnext); |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1115 | else { |
| 1116 | rbnext = rb_first(&cfqq->sort_list); |
| 1117 | if (rbnext && rbnext != &last->rb_node) |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1118 | next = rb_entry_rq(rbnext); |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 1121 | return cfq_choose_req(cfqd, next, prev, blk_rq_pos(last)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1124 | static unsigned long cfq_slice_offset(struct cfq_data *cfqd, |
| 1125 | struct cfq_queue *cfqq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | { |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1127 | /* |
| 1128 | * just an approximation, should be ok. |
| 1129 | */ |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 1130 | return (cfqq->cfqg->nr_cfqq - 1) * (cfq_prio_slice(cfqd, 1, 0) - |
Jens Axboe | 464191c | 2009-11-30 09:38:13 +0100 | [diff] [blame] | 1131 | cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio)); |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1134 | static inline s64 |
| 1135 | cfqg_key(struct cfq_rb_root *st, struct cfq_group *cfqg) |
| 1136 | { |
| 1137 | return cfqg->vdisktime - st->min_vdisktime; |
| 1138 | } |
| 1139 | |
| 1140 | static void |
| 1141 | __cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg) |
| 1142 | { |
| 1143 | struct rb_node **node = &st->rb.rb_node; |
| 1144 | struct rb_node *parent = NULL; |
| 1145 | struct cfq_group *__cfqg; |
| 1146 | s64 key = cfqg_key(st, cfqg); |
| 1147 | int left = 1; |
| 1148 | |
| 1149 | while (*node != NULL) { |
| 1150 | parent = *node; |
| 1151 | __cfqg = rb_entry_cfqg(parent); |
| 1152 | |
| 1153 | if (key < cfqg_key(st, __cfqg)) |
| 1154 | node = &parent->rb_left; |
| 1155 | else { |
| 1156 | node = &parent->rb_right; |
| 1157 | left = 0; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | if (left) |
| 1162 | st->left = &cfqg->rb_node; |
| 1163 | |
| 1164 | rb_link_node(&cfqg->rb_node, parent, node); |
| 1165 | rb_insert_color(&cfqg->rb_node, &st->rb); |
| 1166 | } |
| 1167 | |
| 1168 | static void |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1169 | cfq_update_group_weight(struct cfq_group *cfqg) |
| 1170 | { |
| 1171 | BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node)); |
| 1172 | if (cfqg->needs_update) { |
| 1173 | cfqg->weight = cfqg->new_weight; |
| 1174 | cfqg->needs_update = false; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | static void |
| 1179 | cfq_group_service_tree_add(struct cfq_rb_root *st, struct cfq_group *cfqg) |
| 1180 | { |
| 1181 | BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node)); |
| 1182 | |
| 1183 | cfq_update_group_weight(cfqg); |
| 1184 | __cfq_group_service_tree_add(st, cfqg); |
| 1185 | st->total_weight += cfqg->weight; |
| 1186 | } |
| 1187 | |
| 1188 | static void |
| 1189 | cfq_group_notify_queue_add(struct cfq_data *cfqd, struct cfq_group *cfqg) |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1190 | { |
| 1191 | struct cfq_rb_root *st = &cfqd->grp_service_tree; |
| 1192 | struct cfq_group *__cfqg; |
| 1193 | struct rb_node *n; |
| 1194 | |
| 1195 | cfqg->nr_cfqq++; |
Gui Jianfeng | 760701b | 2010-11-30 20:52:47 +0100 | [diff] [blame] | 1196 | if (!RB_EMPTY_NODE(&cfqg->rb_node)) |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1197 | return; |
| 1198 | |
| 1199 | /* |
| 1200 | * Currently put the group at the end. Later implement something |
| 1201 | * so that groups get lesser vtime based on their weights, so that |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1202 | * if group does not loose all if it was not continuously backlogged. |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1203 | */ |
| 1204 | n = rb_last(&st->rb); |
| 1205 | if (n) { |
| 1206 | __cfqg = rb_entry_cfqg(n); |
| 1207 | cfqg->vdisktime = __cfqg->vdisktime + CFQ_IDLE_DELAY; |
| 1208 | } else |
| 1209 | cfqg->vdisktime = st->min_vdisktime; |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1210 | cfq_group_service_tree_add(st, cfqg); |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | static void |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1214 | cfq_group_service_tree_del(struct cfq_rb_root *st, struct cfq_group *cfqg) |
| 1215 | { |
| 1216 | st->total_weight -= cfqg->weight; |
| 1217 | if (!RB_EMPTY_NODE(&cfqg->rb_node)) |
| 1218 | cfq_rb_erase(&cfqg->rb_node, st); |
| 1219 | } |
| 1220 | |
| 1221 | static void |
| 1222 | cfq_group_notify_queue_del(struct cfq_data *cfqd, struct cfq_group *cfqg) |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1223 | { |
| 1224 | struct cfq_rb_root *st = &cfqd->grp_service_tree; |
| 1225 | |
| 1226 | BUG_ON(cfqg->nr_cfqq < 1); |
| 1227 | cfqg->nr_cfqq--; |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 1228 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1229 | /* If there are other cfq queues under this group, don't delete it */ |
| 1230 | if (cfqg->nr_cfqq) |
| 1231 | return; |
| 1232 | |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 1233 | cfq_log_cfqg(cfqd, cfqg, "del_from_rr group"); |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1234 | cfq_group_service_tree_del(st, cfqg); |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1235 | cfqg->saved_workload_slice = 0; |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1236 | cfq_blkiocg_update_dequeue_stats(cfqg_to_blkg(cfqg), |
| 1237 | &blkio_policy_cfq, 1); |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1238 | } |
| 1239 | |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 1240 | static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq, |
| 1241 | unsigned int *unaccounted_time) |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1242 | { |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 1243 | unsigned int slice_used; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1244 | |
| 1245 | /* |
| 1246 | * Queue got expired before even a single request completed or |
| 1247 | * got expired immediately after first request completion. |
| 1248 | */ |
| 1249 | if (!cfqq->slice_start || cfqq->slice_start == jiffies) { |
| 1250 | /* |
| 1251 | * Also charge the seek time incurred to the group, otherwise |
| 1252 | * if there are mutiple queues in the group, each can dispatch |
| 1253 | * a single request on seeky media and cause lots of seek time |
| 1254 | * and group will never know it. |
| 1255 | */ |
| 1256 | slice_used = max_t(unsigned, (jiffies - cfqq->dispatch_start), |
| 1257 | 1); |
| 1258 | } else { |
| 1259 | slice_used = jiffies - cfqq->slice_start; |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 1260 | if (slice_used > cfqq->allocated_slice) { |
| 1261 | *unaccounted_time = slice_used - cfqq->allocated_slice; |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 1262 | slice_used = cfqq->allocated_slice; |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 1263 | } |
| 1264 | if (time_after(cfqq->slice_start, cfqq->dispatch_start)) |
| 1265 | *unaccounted_time += cfqq->slice_start - |
| 1266 | cfqq->dispatch_start; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1267 | } |
| 1268 | |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1269 | return slice_used; |
| 1270 | } |
| 1271 | |
| 1272 | static void cfq_group_served(struct cfq_data *cfqd, struct cfq_group *cfqg, |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 1273 | struct cfq_queue *cfqq) |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1274 | { |
| 1275 | struct cfq_rb_root *st = &cfqd->grp_service_tree; |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 1276 | unsigned int used_sl, charge, unaccounted_sl = 0; |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 1277 | int nr_sync = cfqg->nr_cfqq - cfqg_busy_async_queues(cfqd, cfqg) |
| 1278 | - cfqg->service_tree_idle.count; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1279 | |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 1280 | BUG_ON(nr_sync < 0); |
Justin TerAvest | 167400d | 2011-03-12 16:54:00 +0100 | [diff] [blame] | 1281 | used_sl = charge = cfq_cfqq_slice_usage(cfqq, &unaccounted_sl); |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 1282 | |
Vivek Goyal | 02b3508 | 2010-08-23 12:23:53 +0200 | [diff] [blame] | 1283 | if (iops_mode(cfqd)) |
| 1284 | charge = cfqq->slice_dispatch; |
| 1285 | else if (!cfq_cfqq_sync(cfqq) && !nr_sync) |
| 1286 | charge = cfqq->allocated_slice; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1287 | |
| 1288 | /* Can't update vdisktime while group is on service tree */ |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1289 | cfq_group_service_tree_del(st, cfqg); |
Vivek Goyal | 02b3508 | 2010-08-23 12:23:53 +0200 | [diff] [blame] | 1290 | cfqg->vdisktime += cfq_scale_slice(charge, cfqg); |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1291 | /* If a new weight was requested, update now, off tree */ |
| 1292 | cfq_group_service_tree_add(st, cfqg); |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1293 | |
| 1294 | /* This group is being expired. Save the context */ |
| 1295 | if (time_after(cfqd->workload_expires, jiffies)) { |
| 1296 | cfqg->saved_workload_slice = cfqd->workload_expires |
| 1297 | - jiffies; |
| 1298 | cfqg->saved_workload = cfqd->serving_type; |
| 1299 | cfqg->saved_serving_prio = cfqd->serving_prio; |
| 1300 | } else |
| 1301 | cfqg->saved_workload_slice = 0; |
Vivek Goyal | 2868ef7 | 2009-12-03 12:59:48 -0500 | [diff] [blame] | 1302 | |
| 1303 | cfq_log_cfqg(cfqd, cfqg, "served: vt=%llu min_vt=%llu", cfqg->vdisktime, |
| 1304 | st->min_vdisktime); |
Joe Perches | fd16d26 | 2011-06-13 10:42:49 +0200 | [diff] [blame] | 1305 | cfq_log_cfqq(cfqq->cfqd, cfqq, |
| 1306 | "sl_used=%u disp=%u charge=%u iops=%u sect=%lu", |
| 1307 | used_sl, cfqq->slice_dispatch, charge, |
| 1308 | iops_mode(cfqd), cfqq->nr_sectors); |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1309 | cfq_blkiocg_update_timeslice_used(cfqg_to_blkg(cfqg), &blkio_policy_cfq, |
| 1310 | used_sl, unaccounted_sl); |
| 1311 | cfq_blkiocg_set_start_empty_time(cfqg_to_blkg(cfqg), &blkio_policy_cfq); |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 1312 | } |
| 1313 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 1314 | /** |
| 1315 | * cfq_init_cfqg_base - initialize base part of a cfq_group |
| 1316 | * @cfqg: cfq_group to initialize |
| 1317 | * |
| 1318 | * Initialize the base part which is used whether %CONFIG_CFQ_GROUP_IOSCHED |
| 1319 | * is enabled or not. |
| 1320 | */ |
| 1321 | static void cfq_init_cfqg_base(struct cfq_group *cfqg) |
| 1322 | { |
| 1323 | struct cfq_rb_root *st; |
| 1324 | int i, j; |
| 1325 | |
| 1326 | for_each_cfqg_st(cfqg, i, j, st) |
| 1327 | *st = CFQ_RB_ROOT; |
| 1328 | RB_CLEAR_NODE(&cfqg->rb_node); |
| 1329 | |
| 1330 | cfqg->ttime.last_end_request = jiffies; |
| 1331 | } |
| 1332 | |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1333 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 1334 | static void cfq_update_blkio_group_weight(struct blkio_group *blkg, |
Paul Bolle | 8aea454 | 2011-06-06 05:07:54 +0200 | [diff] [blame] | 1335 | unsigned int weight) |
Vivek Goyal | f8d461d | 2009-12-03 12:59:52 -0500 | [diff] [blame] | 1336 | { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1337 | struct cfq_group *cfqg = blkg_to_cfqg(blkg); |
| 1338 | |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1339 | cfqg->new_weight = weight; |
| 1340 | cfqg->needs_update = true; |
Vivek Goyal | f8d461d | 2009-12-03 12:59:52 -0500 | [diff] [blame] | 1341 | } |
| 1342 | |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1343 | static void cfq_init_blkio_group(struct blkio_group *blkg) |
Vivek Goyal | f469a7b | 2011-05-19 15:38:23 -0400 | [diff] [blame] | 1344 | { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1345 | struct cfq_group *cfqg = blkg_to_cfqg(blkg); |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1346 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 1347 | cfq_init_cfqg_base(cfqg); |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1348 | cfqg->weight = blkg->blkcg->weight; |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | /* |
Vivek Goyal | 3e59cf9 | 2011-05-19 15:38:21 -0400 | [diff] [blame] | 1352 | * Search for the cfq group current task belongs to. request_queue lock must |
| 1353 | * be held. |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1354 | */ |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 1355 | static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd, |
| 1356 | struct blkio_cgroup *blkcg) |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1357 | { |
Vivek Goyal | f469a7b | 2011-05-19 15:38:23 -0400 | [diff] [blame] | 1358 | struct request_queue *q = cfqd->queue; |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 1359 | struct cfq_group *cfqg = NULL; |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1360 | |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 1361 | /* avoid lookup for the common case where there's no blkio cgroup */ |
| 1362 | if (blkcg == &blkio_root_cgroup) { |
| 1363 | cfqg = cfqd->root_group; |
| 1364 | } else { |
| 1365 | struct blkio_group *blkg; |
Vivek Goyal | f469a7b | 2011-05-19 15:38:23 -0400 | [diff] [blame] | 1366 | |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 1367 | blkg = blkg_lookup_create(blkcg, q, false); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 1368 | if (!IS_ERR(blkg)) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1369 | cfqg = blkg_to_cfqg(blkg); |
Vivek Goyal | f469a7b | 2011-05-19 15:38:23 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1372 | return cfqg; |
| 1373 | } |
| 1374 | |
| 1375 | static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg) |
| 1376 | { |
| 1377 | /* Currently, all async queues are mapped to root group */ |
| 1378 | if (!cfq_cfqq_sync(cfqq)) |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 1379 | cfqg = cfqq->cfqd->root_group; |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1380 | |
| 1381 | cfqq->cfqg = cfqg; |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 1382 | /* cfqq reference on cfqg */ |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 1383 | cfqg_get(cfqg); |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 1386 | static u64 blkg_prfill_weight_device(struct seq_file *sf, |
| 1387 | struct blkg_policy_data *pd, int off) |
| 1388 | { |
| 1389 | if (!pd->conf.weight) |
| 1390 | return 0; |
| 1391 | return __blkg_prfill_u64(sf, pd, pd->conf.weight); |
| 1392 | } |
| 1393 | |
| 1394 | static int blkcg_print_weight_device(struct cgroup *cgrp, struct cftype *cft, |
| 1395 | struct seq_file *sf) |
| 1396 | { |
| 1397 | blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp), |
| 1398 | blkg_prfill_weight_device, BLKIO_POLICY_PROP, 0, |
| 1399 | false); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
| 1403 | static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft, |
| 1404 | struct seq_file *sf) |
| 1405 | { |
| 1406 | seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->weight); |
| 1407 | return 0; |
| 1408 | } |
| 1409 | |
| 1410 | static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft, |
| 1411 | const char *buf) |
| 1412 | { |
| 1413 | struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp); |
| 1414 | struct blkg_policy_data *pd; |
| 1415 | struct blkg_conf_ctx ctx; |
| 1416 | int ret; |
| 1417 | |
| 1418 | ret = blkg_conf_prep(blkcg, buf, &ctx); |
| 1419 | if (ret) |
| 1420 | return ret; |
| 1421 | |
| 1422 | ret = -EINVAL; |
| 1423 | pd = ctx.blkg->pd[BLKIO_POLICY_PROP]; |
| 1424 | if (pd && (!ctx.v || (ctx.v >= BLKIO_WEIGHT_MIN && |
| 1425 | ctx.v <= BLKIO_WEIGHT_MAX))) { |
| 1426 | pd->conf.weight = ctx.v; |
| 1427 | cfq_update_blkio_group_weight(ctx.blkg, ctx.v ?: blkcg->weight); |
| 1428 | ret = 0; |
| 1429 | } |
| 1430 | |
| 1431 | blkg_conf_finish(&ctx); |
| 1432 | return ret; |
| 1433 | } |
| 1434 | |
| 1435 | static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val) |
| 1436 | { |
| 1437 | struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp); |
| 1438 | struct blkio_group *blkg; |
| 1439 | struct hlist_node *n; |
| 1440 | |
| 1441 | if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX) |
| 1442 | return -EINVAL; |
| 1443 | |
| 1444 | spin_lock_irq(&blkcg->lock); |
| 1445 | blkcg->weight = (unsigned int)val; |
| 1446 | |
| 1447 | hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) { |
| 1448 | struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_PROP]; |
| 1449 | |
| 1450 | if (pd && !pd->conf.weight) |
| 1451 | cfq_update_blkio_group_weight(blkg, blkcg->weight); |
| 1452 | } |
| 1453 | |
| 1454 | spin_unlock_irq(&blkcg->lock); |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
| 1458 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 1459 | static u64 blkg_prfill_avg_queue_size(struct seq_file *sf, |
| 1460 | struct blkg_policy_data *pd, int off) |
| 1461 | { |
| 1462 | u64 samples = blkg_stat_read(&pd->stats.avg_queue_size_samples); |
| 1463 | u64 v = 0; |
| 1464 | |
| 1465 | if (samples) { |
| 1466 | v = blkg_stat_read(&pd->stats.avg_queue_size_sum); |
| 1467 | do_div(v, samples); |
| 1468 | } |
| 1469 | __blkg_prfill_u64(sf, pd, v); |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
| 1473 | /* print avg_queue_size */ |
| 1474 | static int blkcg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft, |
| 1475 | struct seq_file *sf) |
| 1476 | { |
| 1477 | struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp); |
| 1478 | |
| 1479 | blkcg_print_blkgs(sf, blkcg, blkg_prfill_avg_queue_size, |
| 1480 | BLKIO_POLICY_PROP, 0, false); |
| 1481 | return 0; |
| 1482 | } |
| 1483 | #endif /* CONFIG_DEBUG_BLK_CGROUP */ |
| 1484 | |
| 1485 | static struct cftype cfq_blkcg_files[] = { |
| 1486 | { |
| 1487 | .name = "weight_device", |
| 1488 | .read_seq_string = blkcg_print_weight_device, |
| 1489 | .write_string = blkcg_set_weight_device, |
| 1490 | .max_write_len = 256, |
| 1491 | }, |
| 1492 | { |
| 1493 | .name = "weight", |
| 1494 | .read_seq_string = blkcg_print_weight, |
| 1495 | .write_u64 = blkcg_set_weight, |
| 1496 | }, |
| 1497 | { |
| 1498 | .name = "time", |
| 1499 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1500 | offsetof(struct blkio_group_stats, time)), |
| 1501 | .read_seq_string = blkcg_print_stat, |
| 1502 | }, |
| 1503 | { |
| 1504 | .name = "sectors", |
| 1505 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 1506 | offsetof(struct blkio_group_stats, sectors)), |
| 1507 | .read_seq_string = blkcg_print_stat, |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 1508 | }, |
| 1509 | { |
| 1510 | .name = "io_service_bytes", |
| 1511 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 1512 | offsetof(struct blkio_group_stats, service_bytes)), |
| 1513 | .read_seq_string = blkcg_print_rwstat, |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 1514 | }, |
| 1515 | { |
| 1516 | .name = "io_serviced", |
| 1517 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
Tejun Heo | 41b38b6 | 2012-04-01 14:38:44 -0700 | [diff] [blame^] | 1518 | offsetof(struct blkio_group_stats, serviced)), |
| 1519 | .read_seq_string = blkcg_print_rwstat, |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 1520 | }, |
| 1521 | { |
| 1522 | .name = "io_service_time", |
| 1523 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1524 | offsetof(struct blkio_group_stats, service_time)), |
| 1525 | .read_seq_string = blkcg_print_rwstat, |
| 1526 | }, |
| 1527 | { |
| 1528 | .name = "io_wait_time", |
| 1529 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1530 | offsetof(struct blkio_group_stats, wait_time)), |
| 1531 | .read_seq_string = blkcg_print_rwstat, |
| 1532 | }, |
| 1533 | { |
| 1534 | .name = "io_merged", |
| 1535 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1536 | offsetof(struct blkio_group_stats, merged)), |
| 1537 | .read_seq_string = blkcg_print_rwstat, |
| 1538 | }, |
| 1539 | { |
| 1540 | .name = "io_queued", |
| 1541 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1542 | offsetof(struct blkio_group_stats, queued)), |
| 1543 | .read_seq_string = blkcg_print_rwstat, |
| 1544 | }, |
| 1545 | #ifdef CONFIG_DEBUG_BLK_CGROUP |
| 1546 | { |
| 1547 | .name = "avg_queue_size", |
| 1548 | .read_seq_string = blkcg_print_avg_queue_size, |
| 1549 | }, |
| 1550 | { |
| 1551 | .name = "group_wait_time", |
| 1552 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1553 | offsetof(struct blkio_group_stats, group_wait_time)), |
| 1554 | .read_seq_string = blkcg_print_stat, |
| 1555 | }, |
| 1556 | { |
| 1557 | .name = "idle_time", |
| 1558 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1559 | offsetof(struct blkio_group_stats, idle_time)), |
| 1560 | .read_seq_string = blkcg_print_stat, |
| 1561 | }, |
| 1562 | { |
| 1563 | .name = "empty_time", |
| 1564 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1565 | offsetof(struct blkio_group_stats, empty_time)), |
| 1566 | .read_seq_string = blkcg_print_stat, |
| 1567 | }, |
| 1568 | { |
| 1569 | .name = "dequeue", |
| 1570 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1571 | offsetof(struct blkio_group_stats, dequeue)), |
| 1572 | .read_seq_string = blkcg_print_stat, |
| 1573 | }, |
| 1574 | { |
| 1575 | .name = "unaccounted_time", |
| 1576 | .private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP, |
| 1577 | offsetof(struct blkio_group_stats, unaccounted_time)), |
| 1578 | .read_seq_string = blkcg_print_stat, |
| 1579 | }, |
| 1580 | #endif /* CONFIG_DEBUG_BLK_CGROUP */ |
| 1581 | { } /* terminate */ |
| 1582 | }; |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1583 | #else /* GROUP_IOSCHED */ |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 1584 | static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd, |
| 1585 | struct blkio_cgroup *blkcg) |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1586 | { |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 1587 | return cfqd->root_group; |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1588 | } |
Vivek Goyal | 7f1dc8a | 2010-04-21 17:44:16 +0200 | [diff] [blame] | 1589 | |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 1590 | static inline void |
| 1591 | cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg) { |
| 1592 | cfqq->cfqg = cfqg; |
| 1593 | } |
| 1594 | |
| 1595 | #endif /* GROUP_IOSCHED */ |
| 1596 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1597 | /* |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1598 | * The cfqd->service_trees holds all pending cfq_queue's that have |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1599 | * requests waiting to be processed. It is sorted in the order that |
| 1600 | * we will service the queues. |
| 1601 | */ |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1602 | static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 1603 | bool add_front) |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1604 | { |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1605 | struct rb_node **p, *parent; |
| 1606 | struct cfq_queue *__cfqq; |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1607 | unsigned long rb_key; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1608 | struct cfq_rb_root *service_tree; |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1609 | int left; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1610 | int new_cfqq = 1; |
Vivek Goyal | ae30c28 | 2009-12-03 12:59:55 -0500 | [diff] [blame] | 1611 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 1612 | service_tree = service_tree_for(cfqq->cfqg, cfqq_prio(cfqq), |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 1613 | cfqq_type(cfqq)); |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1614 | if (cfq_class_idle(cfqq)) { |
| 1615 | rb_key = CFQ_IDLE_DELAY; |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1616 | parent = rb_last(&service_tree->rb); |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1617 | if (parent && parent != &cfqq->rb_node) { |
| 1618 | __cfqq = rb_entry(parent, struct cfq_queue, rb_node); |
| 1619 | rb_key += __cfqq->rb_key; |
| 1620 | } else |
| 1621 | rb_key += jiffies; |
| 1622 | } else if (!add_front) { |
Jens Axboe | b9c8946 | 2009-10-06 20:53:44 +0200 | [diff] [blame] | 1623 | /* |
| 1624 | * Get our rb key offset. Subtract any residual slice |
| 1625 | * value carried from last service. A negative resid |
| 1626 | * count indicates slice overrun, and this should position |
| 1627 | * the next service time further away in the tree. |
| 1628 | */ |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 1629 | rb_key = cfq_slice_offset(cfqd, cfqq) + jiffies; |
Jens Axboe | b9c8946 | 2009-10-06 20:53:44 +0200 | [diff] [blame] | 1630 | rb_key -= cfqq->slice_resid; |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 1631 | cfqq->slice_resid = 0; |
Corrado Zoccolo | 48e025e | 2009-10-05 08:49:23 +0200 | [diff] [blame] | 1632 | } else { |
| 1633 | rb_key = -HZ; |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1634 | __cfqq = cfq_rb_first(service_tree); |
Corrado Zoccolo | 48e025e | 2009-10-05 08:49:23 +0200 | [diff] [blame] | 1635 | rb_key += __cfqq ? __cfqq->rb_key : jiffies; |
| 1636 | } |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1637 | |
| 1638 | if (!RB_EMPTY_NODE(&cfqq->rb_node)) { |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1639 | new_cfqq = 0; |
Jens Axboe | 99f9628 | 2007-02-05 11:56:25 +0100 | [diff] [blame] | 1640 | /* |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1641 | * same position, nothing more to do |
Jens Axboe | 99f9628 | 2007-02-05 11:56:25 +0100 | [diff] [blame] | 1642 | */ |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1643 | if (rb_key == cfqq->rb_key && |
| 1644 | cfqq->service_tree == service_tree) |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1645 | return; |
Jens Axboe | 53b0374 | 2006-07-28 09:48:51 +0200 | [diff] [blame] | 1646 | |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1647 | cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree); |
| 1648 | cfqq->service_tree = NULL; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1649 | } |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1650 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1651 | left = 1; |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 1652 | parent = NULL; |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1653 | cfqq->service_tree = service_tree; |
| 1654 | p = &service_tree->rb.rb_node; |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1655 | while (*p) { |
Jens Axboe | 67060e3 | 2007-04-18 20:13:32 +0200 | [diff] [blame] | 1656 | struct rb_node **n; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1657 | |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1658 | parent = *p; |
| 1659 | __cfqq = rb_entry(parent, struct cfq_queue, rb_node); |
| 1660 | |
Jens Axboe | 0c534e0 | 2007-04-18 20:01:57 +0200 | [diff] [blame] | 1661 | /* |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1662 | * sort by key, that represents service time. |
Jens Axboe | 0c534e0 | 2007-04-18 20:01:57 +0200 | [diff] [blame] | 1663 | */ |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1664 | if (time_before(rb_key, __cfqq->rb_key)) |
Jens Axboe | 67060e3 | 2007-04-18 20:13:32 +0200 | [diff] [blame] | 1665 | n = &(*p)->rb_left; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1666 | else { |
Jens Axboe | 67060e3 | 2007-04-18 20:13:32 +0200 | [diff] [blame] | 1667 | n = &(*p)->rb_right; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1668 | left = 0; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 1669 | } |
Jens Axboe | 67060e3 | 2007-04-18 20:13:32 +0200 | [diff] [blame] | 1670 | |
| 1671 | p = n; |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1674 | if (left) |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1675 | service_tree->left = &cfqq->rb_node; |
Jens Axboe | cc09e29 | 2007-04-26 12:53:50 +0200 | [diff] [blame] | 1676 | |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1677 | cfqq->rb_key = rb_key; |
| 1678 | rb_link_node(&cfqq->rb_node, parent, p); |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1679 | rb_insert_color(&cfqq->rb_node, &service_tree->rb); |
| 1680 | service_tree->count++; |
Namhyung Kim | 20359f2 | 2011-05-24 10:23:22 +0200 | [diff] [blame] | 1681 | if (add_front || !new_cfqq) |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 1682 | return; |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1683 | cfq_group_notify_queue_add(cfqd, cfqq->cfqg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1686 | static struct cfq_queue * |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 1687 | cfq_prio_tree_lookup(struct cfq_data *cfqd, struct rb_root *root, |
| 1688 | sector_t sector, struct rb_node **ret_parent, |
| 1689 | struct rb_node ***rb_link) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1690 | { |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1691 | struct rb_node **p, *parent; |
| 1692 | struct cfq_queue *cfqq = NULL; |
| 1693 | |
| 1694 | parent = NULL; |
| 1695 | p = &root->rb_node; |
| 1696 | while (*p) { |
| 1697 | struct rb_node **n; |
| 1698 | |
| 1699 | parent = *p; |
| 1700 | cfqq = rb_entry(parent, struct cfq_queue, p_node); |
| 1701 | |
| 1702 | /* |
| 1703 | * Sort strictly based on sector. Smallest to the left, |
| 1704 | * largest to the right. |
| 1705 | */ |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1706 | if (sector > blk_rq_pos(cfqq->next_rq)) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1707 | n = &(*p)->rb_right; |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1708 | else if (sector < blk_rq_pos(cfqq->next_rq)) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1709 | n = &(*p)->rb_left; |
| 1710 | else |
| 1711 | break; |
| 1712 | p = n; |
Jens Axboe | 3ac6c9f | 2009-04-23 12:14:56 +0200 | [diff] [blame] | 1713 | cfqq = NULL; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | *ret_parent = parent; |
| 1717 | if (rb_link) |
| 1718 | *rb_link = p; |
Jens Axboe | 3ac6c9f | 2009-04-23 12:14:56 +0200 | [diff] [blame] | 1719 | return cfqq; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 1723 | { |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1724 | struct rb_node **p, *parent; |
| 1725 | struct cfq_queue *__cfqq; |
| 1726 | |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 1727 | if (cfqq->p_root) { |
| 1728 | rb_erase(&cfqq->p_node, cfqq->p_root); |
| 1729 | cfqq->p_root = NULL; |
| 1730 | } |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1731 | |
| 1732 | if (cfq_class_idle(cfqq)) |
| 1733 | return; |
| 1734 | if (!cfqq->next_rq) |
| 1735 | return; |
| 1736 | |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 1737 | cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio]; |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 1738 | __cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root, |
| 1739 | blk_rq_pos(cfqq->next_rq), &parent, &p); |
Jens Axboe | 3ac6c9f | 2009-04-23 12:14:56 +0200 | [diff] [blame] | 1740 | if (!__cfqq) { |
| 1741 | rb_link_node(&cfqq->p_node, parent, p); |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 1742 | rb_insert_color(&cfqq->p_node, cfqq->p_root); |
| 1743 | } else |
| 1744 | cfqq->p_root = NULL; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1745 | } |
| 1746 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1747 | /* |
| 1748 | * Update cfqq's position in the service tree. |
| 1749 | */ |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 1750 | static void cfq_resort_rr_list(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 1751 | { |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 1752 | /* |
| 1753 | * Resorting requires the cfqq to be on the RR list already. |
| 1754 | */ |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1755 | if (cfq_cfqq_on_rr(cfqq)) { |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 1756 | cfq_service_tree_add(cfqd, cfqq, 0); |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1757 | cfq_prio_tree_add(cfqd, cfqq); |
| 1758 | } |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 1759 | } |
| 1760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | /* |
| 1762 | * add to busy list of queues for service, trying to be fair in ordering |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1763 | * the pending list according to last request service |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | */ |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 1765 | static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | { |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 1767 | cfq_log_cfqq(cfqd, cfqq, "add_to_rr"); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 1768 | BUG_ON(cfq_cfqq_on_rr(cfqq)); |
| 1769 | cfq_mark_cfqq_on_rr(cfqq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | cfqd->busy_queues++; |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 1771 | if (cfq_cfqq_sync(cfqq)) |
| 1772 | cfqd->busy_sync_queues++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 1774 | cfq_resort_rr_list(cfqd, cfqq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 1777 | /* |
| 1778 | * Called when the cfqq no longer has requests pending, remove it from |
| 1779 | * the service tree. |
| 1780 | */ |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 1781 | static void cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | { |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 1783 | cfq_log_cfqq(cfqd, cfqq, "del_from_rr"); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 1784 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); |
| 1785 | cfq_clear_cfqq_on_rr(cfqq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 1787 | if (!RB_EMPTY_NODE(&cfqq->rb_node)) { |
| 1788 | cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree); |
| 1789 | cfqq->service_tree = NULL; |
| 1790 | } |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 1791 | if (cfqq->p_root) { |
| 1792 | rb_erase(&cfqq->p_node, cfqq->p_root); |
| 1793 | cfqq->p_root = NULL; |
| 1794 | } |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 1795 | |
Justin TerAvest | 8184f93 | 2011-03-17 16:12:36 +0100 | [diff] [blame] | 1796 | cfq_group_notify_queue_del(cfqd, cfqq->cfqg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | BUG_ON(!cfqd->busy_queues); |
| 1798 | cfqd->busy_queues--; |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 1799 | if (cfq_cfqq_sync(cfqq)) |
| 1800 | cfqd->busy_sync_queues--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | /* |
| 1804 | * rb tree support functions |
| 1805 | */ |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 1806 | static void cfq_del_rq_rb(struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1808 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1809 | const int sync = rq_is_sync(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1811 | BUG_ON(!cfqq->queued[sync]); |
| 1812 | cfqq->queued[sync]--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1814 | elv_rb_del(&cfqq->sort_list, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 1816 | if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) { |
| 1817 | /* |
| 1818 | * Queue will be deleted from service tree when we actually |
| 1819 | * expire it later. Right now just remove it from prio tree |
| 1820 | * as it is empty. |
| 1821 | */ |
| 1822 | if (cfqq->p_root) { |
| 1823 | rb_erase(&cfqq->p_node, cfqq->p_root); |
| 1824 | cfqq->p_root = NULL; |
| 1825 | } |
| 1826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1829 | static void cfq_add_rq_rb(struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1831 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | struct cfq_data *cfqd = cfqq->cfqd; |
Jeff Moyer | 796d511 | 2011-06-02 21:19:05 +0200 | [diff] [blame] | 1833 | struct request *prev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | |
Jens Axboe | 5380a10 | 2006-07-13 12:37:56 +0200 | [diff] [blame] | 1835 | cfqq->queued[rq_is_sync(rq)]++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Jeff Moyer | 796d511 | 2011-06-02 21:19:05 +0200 | [diff] [blame] | 1837 | elv_rb_add(&cfqq->sort_list, rq); |
Jens Axboe | 5fccbf6 | 2006-10-31 14:21:55 +0100 | [diff] [blame] | 1838 | |
| 1839 | if (!cfq_cfqq_on_rr(cfqq)) |
| 1840 | cfq_add_cfqq_rr(cfqd, cfqq); |
Jens Axboe | 5044eed | 2007-04-25 11:53:48 +0200 | [diff] [blame] | 1841 | |
| 1842 | /* |
| 1843 | * check if this request is a better next-serve candidate |
| 1844 | */ |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1845 | prev = cfqq->next_rq; |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 1846 | cfqq->next_rq = cfq_choose_req(cfqd, cfqq->next_rq, rq, cfqd->last_position); |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 1847 | |
| 1848 | /* |
| 1849 | * adjust priority tree position, if ->next_rq changes |
| 1850 | */ |
| 1851 | if (prev != cfqq->next_rq) |
| 1852 | cfq_prio_tree_add(cfqd, cfqq); |
| 1853 | |
Jens Axboe | 5044eed | 2007-04-25 11:53:48 +0200 | [diff] [blame] | 1854 | BUG_ON(!cfqq->next_rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 1857 | static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | { |
Jens Axboe | 5380a10 | 2006-07-13 12:37:56 +0200 | [diff] [blame] | 1859 | elv_rb_del(&cfqq->sort_list, rq); |
| 1860 | cfqq->queued[rq_is_sync(rq)]--; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1861 | cfq_blkiocg_update_io_remove_stats(cfqg_to_blkg(RQ_CFQG(rq)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1862 | &blkio_policy_cfq, rq_data_dir(rq), |
| 1863 | rq_is_sync(rq)); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1864 | cfq_add_rq_rb(rq); |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1865 | cfq_blkiocg_update_io_add_stats(cfqg_to_blkg(RQ_CFQG(rq)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1866 | &blkio_policy_cfq, |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1867 | cfqg_to_blkg(cfqq->cfqd->serving_group), |
| 1868 | rq_data_dir(rq), rq_is_sync(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 1871 | static struct request * |
| 1872 | cfq_find_rq_fmerge(struct cfq_data *cfqd, struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | { |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 1874 | struct task_struct *tsk = current; |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 1875 | struct cfq_io_cq *cic; |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 1876 | struct cfq_queue *cfqq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | |
Jens Axboe | 4ac845a | 2008-01-24 08:44:49 +0100 | [diff] [blame] | 1878 | cic = cfq_cic_lookup(cfqd, tsk->io_context); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 1879 | if (!cic) |
| 1880 | return NULL; |
| 1881 | |
| 1882 | cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio)); |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 1883 | if (cfqq) { |
| 1884 | sector_t sector = bio->bi_sector + bio_sectors(bio); |
| 1885 | |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1886 | return elv_rb_find(&cfqq->sort_list, sector); |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 1887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | return NULL; |
| 1890 | } |
| 1891 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1892 | static void cfq_activate_request(struct request_queue *q, struct request *rq) |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1893 | { |
| 1894 | struct cfq_data *cfqd = q->elevator->elevator_data; |
| 1895 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 1896 | cfqd->rq_in_driver++; |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 1897 | cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d", |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 1898 | cfqd->rq_in_driver); |
Jens Axboe | 25776e3 | 2006-06-01 10:12:26 +0200 | [diff] [blame] | 1899 | |
Tejun Heo | 5b93629 | 2009-05-07 22:24:38 +0900 | [diff] [blame] | 1900 | cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1901 | } |
| 1902 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1903 | static void cfq_deactivate_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1905 | struct cfq_data *cfqd = q->elevator->elevator_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 1907 | WARN_ON(!cfqd->rq_in_driver); |
| 1908 | cfqd->rq_in_driver--; |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 1909 | cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "deactivate rq, drv=%d", |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 1910 | cfqd->rq_in_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | } |
| 1912 | |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1913 | static void cfq_remove_request(struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1915 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1916 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1917 | if (cfqq->next_rq == rq) |
| 1918 | cfqq->next_rq = cfq_find_next_rq(cfqq->cfqd, cfqq, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1920 | list_del_init(&rq->queuelist); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1921 | cfq_del_rq_rb(rq); |
Jens Axboe | 374f84a | 2006-07-23 01:42:19 +0200 | [diff] [blame] | 1922 | |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 1923 | cfqq->cfqd->rq_queued--; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1924 | cfq_blkiocg_update_io_remove_stats(cfqg_to_blkg(RQ_CFQG(rq)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1925 | &blkio_policy_cfq, rq_data_dir(rq), |
| 1926 | rq_is_sync(rq)); |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 1927 | if (rq->cmd_flags & REQ_PRIO) { |
| 1928 | WARN_ON(!cfqq->prio_pending); |
| 1929 | cfqq->prio_pending--; |
Jens Axboe | b53d1ed | 2011-08-19 08:34:48 +0200 | [diff] [blame] | 1930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | } |
| 1932 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1933 | static int cfq_merge(struct request_queue *q, struct request **req, |
| 1934 | struct bio *bio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | { |
| 1936 | struct cfq_data *cfqd = q->elevator->elevator_data; |
| 1937 | struct request *__rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 1939 | __rq = cfq_find_rq_fmerge(cfqd, bio); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1940 | if (__rq && elv_rq_merge_ok(__rq, bio)) { |
Jens Axboe | 9817064 | 2006-07-28 09:23:08 +0200 | [diff] [blame] | 1941 | *req = __rq; |
| 1942 | return ELEVATOR_FRONT_MERGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | return ELEVATOR_NO_MERGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1948 | static void cfq_merged_request(struct request_queue *q, struct request *req, |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1949 | int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | { |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 1951 | if (type == ELEVATOR_FRONT_MERGE) { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1952 | struct cfq_queue *cfqq = RQ_CFQQ(req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 1954 | cfq_reposition_rq_rb(cfqq, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 1958 | static void cfq_bio_merged(struct request_queue *q, struct request *req, |
| 1959 | struct bio *bio) |
| 1960 | { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1961 | cfq_blkiocg_update_io_merged_stats(cfqg_to_blkg(RQ_CFQG(req)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1962 | &blkio_policy_cfq, bio_data_dir(bio), |
| 1963 | cfq_bio_sync(bio)); |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | static void |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 1967 | cfq_merged_requests(struct request_queue *q, struct request *rq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | struct request *next) |
| 1969 | { |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 1970 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Shaohua Li | 4a0b75c | 2011-12-16 14:00:22 +0100 | [diff] [blame] | 1971 | struct cfq_data *cfqd = q->elevator->elevator_data; |
| 1972 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1973 | /* |
| 1974 | * reposition in fifo if next is older than rq |
| 1975 | */ |
| 1976 | if (!list_empty(&rq->queuelist) && !list_empty(&next->queuelist) && |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 1977 | time_before(rq_fifo_time(next), rq_fifo_time(rq))) { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1978 | list_move(&rq->queuelist, &next->queuelist); |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 1979 | rq_set_fifo_time(rq, rq_fifo_time(next)); |
| 1980 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1981 | |
Corrado Zoccolo | cf7c25c | 2009-11-08 17:16:46 +0100 | [diff] [blame] | 1982 | if (cfqq->next_rq == next) |
| 1983 | cfqq->next_rq = rq; |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 1984 | cfq_remove_request(next); |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 1985 | cfq_blkiocg_update_io_merged_stats(cfqg_to_blkg(RQ_CFQG(rq)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 1986 | &blkio_policy_cfq, rq_data_dir(next), |
| 1987 | rq_is_sync(next)); |
Shaohua Li | 4a0b75c | 2011-12-16 14:00:22 +0100 | [diff] [blame] | 1988 | |
| 1989 | cfqq = RQ_CFQQ(next); |
| 1990 | /* |
| 1991 | * all requests of this queue are merged to other queues, delete it |
| 1992 | * from the service tree. If it's the active_queue, |
| 1993 | * cfq_dispatch_requests() will choose to expire it or do idle |
| 1994 | */ |
| 1995 | if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list) && |
| 1996 | cfqq != cfqd->active_queue) |
| 1997 | cfq_del_cfqq_rr(cfqd, cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 1998 | } |
| 1999 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 2000 | static int cfq_allow_merge(struct request_queue *q, struct request *rq, |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2001 | struct bio *bio) |
| 2002 | { |
| 2003 | struct cfq_data *cfqd = q->elevator->elevator_data; |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 2004 | struct cfq_io_cq *cic; |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2005 | struct cfq_queue *cfqq; |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2006 | |
| 2007 | /* |
Jens Axboe | ec8acb6 | 2007-01-02 18:32:11 +0100 | [diff] [blame] | 2008 | * Disallow merge of a sync bio into an async request. |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2009 | */ |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 2010 | if (cfq_bio_sync(bio) && !rq_is_sync(rq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 2011 | return false; |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2012 | |
| 2013 | /* |
Tejun Heo | f1a4f4d | 2011-12-14 00:33:39 +0100 | [diff] [blame] | 2014 | * Lookup the cfqq that this bio will be queued with and allow |
Tejun Heo | 07c2bd3 | 2012-02-08 09:19:42 +0100 | [diff] [blame] | 2015 | * merge only if rq is queued there. |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2016 | */ |
Tejun Heo | 07c2bd3 | 2012-02-08 09:19:42 +0100 | [diff] [blame] | 2017 | cic = cfq_cic_lookup(cfqd, current->io_context); |
| 2018 | if (!cic) |
| 2019 | return false; |
Jens Axboe | 719d340 | 2006-12-22 09:38:53 +0100 | [diff] [blame] | 2020 | |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 2021 | cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio)); |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 2022 | return cfqq == RQ_CFQQ(rq); |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 2023 | } |
| 2024 | |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 2025 | static inline void cfq_del_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 2026 | { |
| 2027 | del_timer(&cfqd->idle_slice_timer); |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 2028 | cfq_blkiocg_update_idle_time_stats(cfqg_to_blkg(cfqq->cfqg), |
| 2029 | &blkio_policy_cfq); |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 2032 | static void __cfq_set_active_queue(struct cfq_data *cfqd, |
| 2033 | struct cfq_queue *cfqq) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2034 | { |
| 2035 | if (cfqq) { |
Divyesh Shah | b1ffe73 | 2010-03-25 15:45:03 +0100 | [diff] [blame] | 2036 | cfq_log_cfqq(cfqd, cfqq, "set_active wl_prio:%d wl_type:%d", |
| 2037 | cfqd->serving_prio, cfqd->serving_type); |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 2038 | cfq_blkiocg_update_avg_queue_size_stats(cfqg_to_blkg(cfqq->cfqg), |
| 2039 | &blkio_policy_cfq); |
Justin TerAvest | 62a37f6 | 2011-03-23 08:25:44 +0100 | [diff] [blame] | 2040 | cfqq->slice_start = 0; |
| 2041 | cfqq->dispatch_start = jiffies; |
| 2042 | cfqq->allocated_slice = 0; |
| 2043 | cfqq->slice_end = 0; |
| 2044 | cfqq->slice_dispatch = 0; |
| 2045 | cfqq->nr_sectors = 0; |
| 2046 | |
| 2047 | cfq_clear_cfqq_wait_request(cfqq); |
| 2048 | cfq_clear_cfqq_must_dispatch(cfqq); |
| 2049 | cfq_clear_cfqq_must_alloc_slice(cfqq); |
| 2050 | cfq_clear_cfqq_fifo_expire(cfqq); |
| 2051 | cfq_mark_cfqq_slice_new(cfqq); |
| 2052 | |
| 2053 | cfq_del_timer(cfqd, cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | cfqd->active_queue = cfqq; |
| 2057 | } |
| 2058 | |
| 2059 | /* |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2060 | * current cfqq expired its slice (or was too idle), select new one |
| 2061 | */ |
| 2062 | static void |
| 2063 | __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2064 | bool timed_out) |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2065 | { |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2066 | cfq_log_cfqq(cfqd, cfqq, "slice expired t=%d", timed_out); |
| 2067 | |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2068 | if (cfq_cfqq_wait_request(cfqq)) |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 2069 | cfq_del_timer(cfqd, cfqq); |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2070 | |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2071 | cfq_clear_cfqq_wait_request(cfqq); |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 2072 | cfq_clear_cfqq_wait_busy(cfqq); |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2073 | |
| 2074 | /* |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 2075 | * If this cfqq is shared between multiple processes, check to |
| 2076 | * make sure that those processes are still issuing I/Os within |
| 2077 | * the mean seek distance. If not, it may be time to break the |
| 2078 | * queues apart again. |
| 2079 | */ |
| 2080 | if (cfq_cfqq_coop(cfqq) && CFQQ_SEEKY(cfqq)) |
| 2081 | cfq_mark_cfqq_split_coop(cfqq); |
| 2082 | |
| 2083 | /* |
Jens Axboe | 6084cdd | 2007-04-23 08:25:00 +0200 | [diff] [blame] | 2084 | * store what was left of this slice, if the queue idled/timed out |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2085 | */ |
Shaohua Li | c553f8e | 2011-01-14 08:41:03 +0100 | [diff] [blame] | 2086 | if (timed_out) { |
| 2087 | if (cfq_cfqq_slice_new(cfqq)) |
Vivek Goyal | ba5bd52 | 2011-01-19 08:25:02 -0700 | [diff] [blame] | 2088 | cfqq->slice_resid = cfq_scaled_cfqq_slice(cfqd, cfqq); |
Shaohua Li | c553f8e | 2011-01-14 08:41:03 +0100 | [diff] [blame] | 2089 | else |
| 2090 | cfqq->slice_resid = cfqq->slice_end - jiffies; |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2091 | cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid); |
| 2092 | } |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2093 | |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2094 | cfq_group_served(cfqd, cfqq->cfqg, cfqq); |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 2095 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2096 | if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) |
| 2097 | cfq_del_cfqq_rr(cfqd, cfqq); |
| 2098 | |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 2099 | cfq_resort_rr_list(cfqd, cfqq); |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2100 | |
| 2101 | if (cfqq == cfqd->active_queue) |
| 2102 | cfqd->active_queue = NULL; |
| 2103 | |
| 2104 | if (cfqd->active_cic) { |
Tejun Heo | 11a3122 | 2012-02-07 07:51:30 +0100 | [diff] [blame] | 2105 | put_io_context(cfqd->active_cic->icq.ioc); |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2106 | cfqd->active_cic = NULL; |
| 2107 | } |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2108 | } |
| 2109 | |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2110 | static inline void cfq_slice_expired(struct cfq_data *cfqd, bool timed_out) |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2111 | { |
| 2112 | struct cfq_queue *cfqq = cfqd->active_queue; |
| 2113 | |
| 2114 | if (cfqq) |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2115 | __cfq_slice_expired(cfqd, cfqq, timed_out); |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 2118 | /* |
| 2119 | * Get next queue for service. Unless we have a queue preemption, |
| 2120 | * we'll simply select the first cfqq in the service tree. |
| 2121 | */ |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2122 | static struct cfq_queue *cfq_get_next_queue(struct cfq_data *cfqd) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2123 | { |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 2124 | struct cfq_rb_root *service_tree = |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2125 | service_tree_for(cfqd->serving_group, cfqd->serving_prio, |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2126 | cfqd->serving_type); |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 2127 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2128 | if (!cfqd->rq_queued) |
| 2129 | return NULL; |
| 2130 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2131 | /* There is nothing to dispatch */ |
| 2132 | if (!service_tree) |
| 2133 | return NULL; |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 2134 | if (RB_EMPTY_ROOT(&service_tree->rb)) |
| 2135 | return NULL; |
| 2136 | return cfq_rb_first(service_tree); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2137 | } |
| 2138 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2139 | static struct cfq_queue *cfq_get_next_queue_forced(struct cfq_data *cfqd) |
| 2140 | { |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 2141 | struct cfq_group *cfqg; |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2142 | struct cfq_queue *cfqq; |
| 2143 | int i, j; |
| 2144 | struct cfq_rb_root *st; |
| 2145 | |
| 2146 | if (!cfqd->rq_queued) |
| 2147 | return NULL; |
| 2148 | |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 2149 | cfqg = cfq_get_next_cfqg(cfqd); |
| 2150 | if (!cfqg) |
| 2151 | return NULL; |
| 2152 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2153 | for_each_cfqg_st(cfqg, i, j, st) |
| 2154 | if ((cfqq = cfq_rb_first(st)) != NULL) |
| 2155 | return cfqq; |
| 2156 | return NULL; |
| 2157 | } |
| 2158 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 2159 | /* |
| 2160 | * Get and set a new active queue for service. |
| 2161 | */ |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2162 | static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd, |
| 2163 | struct cfq_queue *cfqq) |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2164 | { |
Jens Axboe | e00ef79 | 2009-11-04 08:54:55 +0100 | [diff] [blame] | 2165 | if (!cfqq) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2166 | cfqq = cfq_get_next_queue(cfqd); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2167 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2168 | __cfq_set_active_queue(cfqd, cfqq); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2169 | return cfqq; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2170 | } |
| 2171 | |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2172 | static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd, |
| 2173 | struct request *rq) |
| 2174 | { |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2175 | if (blk_rq_pos(rq) >= cfqd->last_position) |
| 2176 | return blk_rq_pos(rq) - cfqd->last_position; |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2177 | else |
Tejun Heo | 83096eb | 2009-05-07 22:24:39 +0900 | [diff] [blame] | 2178 | return cfqd->last_position - blk_rq_pos(rq); |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2179 | } |
| 2180 | |
Jeff Moyer | b2c18e1 | 2009-10-23 17:14:49 -0400 | [diff] [blame] | 2181 | static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 2182 | struct request *rq) |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2183 | { |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 2184 | return cfq_dist_from_last(cfqd, rq) <= CFQQ_CLOSE_THR; |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2185 | } |
| 2186 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2187 | static struct cfq_queue *cfqq_close(struct cfq_data *cfqd, |
| 2188 | struct cfq_queue *cur_cfqq) |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2189 | { |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 2190 | struct rb_root *root = &cfqd->prio_trees[cur_cfqq->org_ioprio]; |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2191 | struct rb_node *parent, *node; |
| 2192 | struct cfq_queue *__cfqq; |
| 2193 | sector_t sector = cfqd->last_position; |
| 2194 | |
| 2195 | if (RB_EMPTY_ROOT(root)) |
| 2196 | return NULL; |
| 2197 | |
| 2198 | /* |
| 2199 | * First, if we find a request starting at the end of the last |
| 2200 | * request, choose it. |
| 2201 | */ |
Jens Axboe | f2d1f0a | 2009-04-23 12:19:38 +0200 | [diff] [blame] | 2202 | __cfqq = cfq_prio_tree_lookup(cfqd, root, sector, &parent, NULL); |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2203 | if (__cfqq) |
| 2204 | return __cfqq; |
| 2205 | |
| 2206 | /* |
| 2207 | * If the exact sector wasn't found, the parent of the NULL leaf |
| 2208 | * will contain the closest sector. |
| 2209 | */ |
| 2210 | __cfqq = rb_entry(parent, struct cfq_queue, p_node); |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 2211 | if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq)) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2212 | return __cfqq; |
| 2213 | |
Tejun Heo | 2e46e8b | 2009-05-07 22:24:41 +0900 | [diff] [blame] | 2214 | if (blk_rq_pos(__cfqq->next_rq) < sector) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2215 | node = rb_next(&__cfqq->p_node); |
| 2216 | else |
| 2217 | node = rb_prev(&__cfqq->p_node); |
| 2218 | if (!node) |
| 2219 | return NULL; |
| 2220 | |
| 2221 | __cfqq = rb_entry(node, struct cfq_queue, p_node); |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 2222 | if (cfq_rq_close(cfqd, cur_cfqq, __cfqq->next_rq)) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2223 | return __cfqq; |
| 2224 | |
| 2225 | return NULL; |
| 2226 | } |
| 2227 | |
| 2228 | /* |
| 2229 | * cfqd - obvious |
| 2230 | * cur_cfqq - passed in so that we don't decide that the current queue is |
| 2231 | * closely cooperating with itself. |
| 2232 | * |
| 2233 | * So, basically we're assuming that that cur_cfqq has dispatched at least |
| 2234 | * one request, and that cfqd->last_position reflects a position on the disk |
| 2235 | * associated with the I/O issued by cur_cfqq. I'm not sure this is a valid |
| 2236 | * assumption. |
| 2237 | */ |
| 2238 | static struct cfq_queue *cfq_close_cooperator(struct cfq_data *cfqd, |
Jeff Moyer | b3b6d04 | 2009-10-23 17:14:51 -0400 | [diff] [blame] | 2239 | struct cfq_queue *cur_cfqq) |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2240 | { |
| 2241 | struct cfq_queue *cfqq; |
| 2242 | |
Divyesh Shah | 39c01b2 | 2010-03-25 15:45:57 +0100 | [diff] [blame] | 2243 | if (cfq_class_idle(cur_cfqq)) |
| 2244 | return NULL; |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2245 | if (!cfq_cfqq_sync(cur_cfqq)) |
| 2246 | return NULL; |
| 2247 | if (CFQQ_SEEKY(cur_cfqq)) |
| 2248 | return NULL; |
| 2249 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2250 | /* |
Gui Jianfeng | b9d8f4c | 2009-12-08 08:54:17 +0100 | [diff] [blame] | 2251 | * Don't search priority tree if it's the only queue in the group. |
| 2252 | */ |
| 2253 | if (cur_cfqq->cfqg->nr_cfqq == 1) |
| 2254 | return NULL; |
| 2255 | |
| 2256 | /* |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2257 | * We should notice if some of the queues are cooperating, eg |
| 2258 | * working closely on the same area of the disk. In that case, |
| 2259 | * we can group them together and don't waste time idling. |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2260 | */ |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2261 | cfqq = cfqq_close(cfqd, cur_cfqq); |
| 2262 | if (!cfqq) |
| 2263 | return NULL; |
| 2264 | |
Vivek Goyal | 8682e1f | 2009-12-03 12:59:50 -0500 | [diff] [blame] | 2265 | /* If new queue belongs to different cfq_group, don't choose it */ |
| 2266 | if (cur_cfqq->cfqg != cfqq->cfqg) |
| 2267 | return NULL; |
| 2268 | |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2269 | /* |
| 2270 | * It only makes sense to merge sync queues. |
| 2271 | */ |
| 2272 | if (!cfq_cfqq_sync(cfqq)) |
| 2273 | return NULL; |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2274 | if (CFQQ_SEEKY(cfqq)) |
| 2275 | return NULL; |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2276 | |
Corrado Zoccolo | c0324a0 | 2009-10-27 19:16:03 +0100 | [diff] [blame] | 2277 | /* |
| 2278 | * Do not merge queues of different priority classes |
| 2279 | */ |
| 2280 | if (cfq_class_rt(cfqq) != cfq_class_rt(cur_cfqq)) |
| 2281 | return NULL; |
| 2282 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2283 | return cfqq; |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2284 | } |
| 2285 | |
Corrado Zoccolo | a6d44e9 | 2009-10-26 22:45:11 +0100 | [diff] [blame] | 2286 | /* |
| 2287 | * Determine whether we should enforce idle window for this queue. |
| 2288 | */ |
| 2289 | |
| 2290 | static bool cfq_should_idle(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 2291 | { |
| 2292 | enum wl_prio_t prio = cfqq_prio(cfqq); |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2293 | struct cfq_rb_root *service_tree = cfqq->service_tree; |
Corrado Zoccolo | a6d44e9 | 2009-10-26 22:45:11 +0100 | [diff] [blame] | 2294 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2295 | BUG_ON(!service_tree); |
| 2296 | BUG_ON(!service_tree->count); |
| 2297 | |
Vivek Goyal | b6508c1 | 2010-08-23 12:23:33 +0200 | [diff] [blame] | 2298 | if (!cfqd->cfq_slice_idle) |
| 2299 | return false; |
| 2300 | |
Corrado Zoccolo | a6d44e9 | 2009-10-26 22:45:11 +0100 | [diff] [blame] | 2301 | /* We never do for idle class queues. */ |
| 2302 | if (prio == IDLE_WORKLOAD) |
| 2303 | return false; |
| 2304 | |
| 2305 | /* We do for queues that were marked with idle window flag. */ |
Shaohua Li | 3c764b7 | 2009-12-04 13:12:06 +0100 | [diff] [blame] | 2306 | if (cfq_cfqq_idle_window(cfqq) && |
| 2307 | !(blk_queue_nonrot(cfqd->queue) && cfqd->hw_tag)) |
Corrado Zoccolo | a6d44e9 | 2009-10-26 22:45:11 +0100 | [diff] [blame] | 2308 | return true; |
| 2309 | |
| 2310 | /* |
| 2311 | * Otherwise, we do only if they are the last ones |
| 2312 | * in their service tree. |
| 2313 | */ |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 2314 | if (service_tree->count == 1 && cfq_cfqq_sync(cfqq) && |
| 2315 | !cfq_io_thinktime_big(cfqd, &service_tree->ttime, false)) |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 2316 | return true; |
Divyesh Shah | b1ffe73 | 2010-03-25 15:45:03 +0100 | [diff] [blame] | 2317 | cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d", |
| 2318 | service_tree->count); |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 2319 | return false; |
Corrado Zoccolo | a6d44e9 | 2009-10-26 22:45:11 +0100 | [diff] [blame] | 2320 | } |
| 2321 | |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2322 | static void cfq_arm_slice_timer(struct cfq_data *cfqd) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2323 | { |
Jens Axboe | 1792669 | 2007-01-19 11:59:30 +1100 | [diff] [blame] | 2324 | struct cfq_queue *cfqq = cfqd->active_queue; |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 2325 | struct cfq_io_cq *cic; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2326 | unsigned long sl, group_idle = 0; |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2327 | |
Jens Axboe | a68bbdd | 2008-09-24 13:03:33 +0200 | [diff] [blame] | 2328 | /* |
Jens Axboe | f7d7b7a | 2008-09-25 11:37:50 +0200 | [diff] [blame] | 2329 | * SSD device without seek penalty, disable idling. But only do so |
| 2330 | * for devices that support queuing, otherwise we still have a problem |
| 2331 | * with sync vs async workloads. |
Jens Axboe | a68bbdd | 2008-09-24 13:03:33 +0200 | [diff] [blame] | 2332 | */ |
Jens Axboe | f7d7b7a | 2008-09-25 11:37:50 +0200 | [diff] [blame] | 2333 | if (blk_queue_nonrot(cfqd->queue) && cfqd->hw_tag) |
Jens Axboe | a68bbdd | 2008-09-24 13:03:33 +0200 | [diff] [blame] | 2334 | return; |
| 2335 | |
Jens Axboe | dd67d05 | 2006-06-21 09:36:18 +0200 | [diff] [blame] | 2336 | WARN_ON(!RB_EMPTY_ROOT(&cfqq->sort_list)); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2337 | WARN_ON(cfq_cfqq_slice_new(cfqq)); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2338 | |
| 2339 | /* |
| 2340 | * idle is disabled, either manually or by past process history |
| 2341 | */ |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2342 | if (!cfq_should_idle(cfqd, cfqq)) { |
| 2343 | /* no queue idling. Check for group idling */ |
| 2344 | if (cfqd->cfq_group_idle) |
| 2345 | group_idle = cfqd->cfq_group_idle; |
| 2346 | else |
| 2347 | return; |
| 2348 | } |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2349 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2350 | /* |
Corrado Zoccolo | 8e55063 | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 2351 | * still active requests from this queue, don't idle |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2352 | */ |
Corrado Zoccolo | 8e55063 | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 2353 | if (cfqq->dispatched) |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2354 | return; |
| 2355 | |
| 2356 | /* |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2357 | * task has exited, don't wait |
| 2358 | */ |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 2359 | cic = cfqd->active_cic; |
Tejun Heo | f6e8d01 | 2012-03-05 13:15:26 -0800 | [diff] [blame] | 2360 | if (!cic || !atomic_read(&cic->icq.ioc->active_ref)) |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2361 | return; |
| 2362 | |
Corrado Zoccolo | 355b659 | 2009-10-08 08:43:32 +0200 | [diff] [blame] | 2363 | /* |
| 2364 | * If our average think time is larger than the remaining time |
| 2365 | * slice, then don't idle. This avoids overrunning the allotted |
| 2366 | * time slice. |
| 2367 | */ |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 2368 | if (sample_valid(cic->ttime.ttime_samples) && |
| 2369 | (cfqq->slice_end - jiffies < cic->ttime.ttime_mean)) { |
Joe Perches | fd16d26 | 2011-06-13 10:42:49 +0200 | [diff] [blame] | 2370 | cfq_log_cfqq(cfqd, cfqq, "Not idling. think_time:%lu", |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 2371 | cic->ttime.ttime_mean); |
Corrado Zoccolo | 355b659 | 2009-10-08 08:43:32 +0200 | [diff] [blame] | 2372 | return; |
Divyesh Shah | b1ffe73 | 2010-03-25 15:45:03 +0100 | [diff] [blame] | 2373 | } |
Corrado Zoccolo | 355b659 | 2009-10-08 08:43:32 +0200 | [diff] [blame] | 2374 | |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2375 | /* There are other queues in the group, don't do group idle */ |
| 2376 | if (group_idle && cfqq->cfqg->nr_cfqq > 1) |
| 2377 | return; |
| 2378 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2379 | cfq_mark_cfqq_wait_request(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2380 | |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2381 | if (group_idle) |
| 2382 | sl = cfqd->cfq_group_idle; |
| 2383 | else |
| 2384 | sl = cfqd->cfq_slice_idle; |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 2385 | |
Jens Axboe | 7b14e3b | 2006-02-28 09:35:11 +0100 | [diff] [blame] | 2386 | mod_timer(&cfqd->idle_slice_timer, jiffies + sl); |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 2387 | cfq_blkiocg_update_set_idle_time_stats(cfqg_to_blkg(cfqq->cfqg), |
| 2388 | &blkio_policy_cfq); |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2389 | cfq_log_cfqq(cfqd, cfqq, "arm_idle: %lu group_idle: %d", sl, |
| 2390 | group_idle ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 2393 | /* |
| 2394 | * Move request from internal lists to the request queue dispatch list. |
| 2395 | */ |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 2396 | static void cfq_dispatch_insert(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | { |
Jens Axboe | 3ed9a29 | 2007-04-23 08:33:33 +0200 | [diff] [blame] | 2398 | struct cfq_data *cfqd = q->elevator->elevator_data; |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 2399 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2400 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2401 | cfq_log_cfqq(cfqd, cfqq, "dispatch_insert"); |
| 2402 | |
Jeff Moyer | 06d2188 | 2009-09-11 17:08:59 +0200 | [diff] [blame] | 2403 | cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq); |
Jens Axboe | 5380a10 | 2006-07-13 12:37:56 +0200 | [diff] [blame] | 2404 | cfq_remove_request(rq); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2405 | cfqq->dispatched++; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2406 | (RQ_CFQG(rq))->dispatched++; |
Jens Axboe | 5380a10 | 2006-07-13 12:37:56 +0200 | [diff] [blame] | 2407 | elv_dispatch_sort(q, rq); |
Jens Axboe | 3ed9a29 | 2007-04-23 08:33:33 +0200 | [diff] [blame] | 2408 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 2409 | cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++; |
Vivek Goyal | c4e7893 | 2010-08-23 12:25:03 +0200 | [diff] [blame] | 2410 | cfqq->nr_sectors += blk_rq_sectors(rq); |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 2411 | cfq_blkiocg_update_dispatch_stats(cfqg_to_blkg(cfqq->cfqg), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 2412 | &blkio_policy_cfq, blk_rq_bytes(rq), |
| 2413 | rq_data_dir(rq), rq_is_sync(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | /* |
| 2417 | * return expired entry, or NULL to just start from scratch in rbtree |
| 2418 | */ |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 2419 | static struct request *cfq_check_fifo(struct cfq_queue *cfqq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | { |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 2421 | struct request *rq = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2423 | if (cfq_cfqq_fifo_expire(cfqq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | return NULL; |
Jens Axboe | cb88741 | 2007-01-19 12:01:16 +1100 | [diff] [blame] | 2425 | |
| 2426 | cfq_mark_cfqq_fifo_expire(cfqq); |
| 2427 | |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 2428 | if (list_empty(&cfqq->fifo)) |
| 2429 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 2431 | rq = rq_entry_fifo(cfqq->fifo.next); |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 2432 | if (time_before(jiffies, rq_fifo_time(rq))) |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2433 | rq = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 2435 | cfq_log_cfqq(cfqq->cfqd, cfqq, "fifo=%p", rq); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2436 | return rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2439 | static inline int |
| 2440 | cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 2441 | { |
| 2442 | const int base_rq = cfqd->cfq_slice_async_rq; |
| 2443 | |
| 2444 | WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR); |
| 2445 | |
Namhyung Kim | b9f8ce0 | 2011-05-24 10:23:21 +0200 | [diff] [blame] | 2446 | return 2 * base_rq * (IOPRIO_BE_NR - cfqq->ioprio); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | /* |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2450 | * Must be called with the queue_lock held. |
| 2451 | */ |
| 2452 | static int cfqq_process_refs(struct cfq_queue *cfqq) |
| 2453 | { |
| 2454 | int process_refs, io_refs; |
| 2455 | |
| 2456 | io_refs = cfqq->allocated[READ] + cfqq->allocated[WRITE]; |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 2457 | process_refs = cfqq->ref - io_refs; |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2458 | BUG_ON(process_refs < 0); |
| 2459 | return process_refs; |
| 2460 | } |
| 2461 | |
| 2462 | static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq) |
| 2463 | { |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2464 | int process_refs, new_process_refs; |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2465 | struct cfq_queue *__cfqq; |
| 2466 | |
Jeff Moyer | c10b61f | 2010-06-17 10:19:11 -0400 | [diff] [blame] | 2467 | /* |
| 2468 | * If there are no process references on the new_cfqq, then it is |
| 2469 | * unsafe to follow the ->new_cfqq chain as other cfqq's in the |
| 2470 | * chain may have dropped their last reference (not just their |
| 2471 | * last process reference). |
| 2472 | */ |
| 2473 | if (!cfqq_process_refs(new_cfqq)) |
| 2474 | return; |
| 2475 | |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2476 | /* Avoid a circular list and skip interim queue merges */ |
| 2477 | while ((__cfqq = new_cfqq->new_cfqq)) { |
| 2478 | if (__cfqq == cfqq) |
| 2479 | return; |
| 2480 | new_cfqq = __cfqq; |
| 2481 | } |
| 2482 | |
| 2483 | process_refs = cfqq_process_refs(cfqq); |
Jeff Moyer | c10b61f | 2010-06-17 10:19:11 -0400 | [diff] [blame] | 2484 | new_process_refs = cfqq_process_refs(new_cfqq); |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2485 | /* |
| 2486 | * If the process for the cfqq has gone away, there is no |
| 2487 | * sense in merging the queues. |
| 2488 | */ |
Jeff Moyer | c10b61f | 2010-06-17 10:19:11 -0400 | [diff] [blame] | 2489 | if (process_refs == 0 || new_process_refs == 0) |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2490 | return; |
| 2491 | |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2492 | /* |
| 2493 | * Merge in the direction of the lesser amount of work. |
| 2494 | */ |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2495 | if (new_process_refs >= process_refs) { |
| 2496 | cfqq->new_cfqq = new_cfqq; |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 2497 | new_cfqq->ref += process_refs; |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2498 | } else { |
| 2499 | new_cfqq->new_cfqq = cfqq; |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 2500 | cfqq->ref += new_process_refs; |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 2501 | } |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2502 | } |
| 2503 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2504 | static enum wl_type_t cfq_choose_wl(struct cfq_data *cfqd, |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2505 | struct cfq_group *cfqg, enum wl_prio_t prio) |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2506 | { |
| 2507 | struct cfq_queue *queue; |
| 2508 | int i; |
| 2509 | bool key_valid = false; |
| 2510 | unsigned long lowest_key = 0; |
| 2511 | enum wl_type_t cur_best = SYNC_NOIDLE_WORKLOAD; |
| 2512 | |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2513 | for (i = 0; i <= SYNC_WORKLOAD; ++i) { |
| 2514 | /* select the one with lowest rb_key */ |
| 2515 | queue = cfq_rb_first(service_tree_for(cfqg, prio, i)); |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2516 | if (queue && |
| 2517 | (!key_valid || time_before(queue->rb_key, lowest_key))) { |
| 2518 | lowest_key = queue->rb_key; |
| 2519 | cur_best = i; |
| 2520 | key_valid = true; |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | return cur_best; |
| 2525 | } |
| 2526 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2527 | static void choose_service_tree(struct cfq_data *cfqd, struct cfq_group *cfqg) |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2528 | { |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2529 | unsigned slice; |
| 2530 | unsigned count; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2531 | struct cfq_rb_root *st; |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 2532 | unsigned group_slice; |
Shaohua Li writes | e4ea0c1 | 2010-12-13 14:32:22 +0100 | [diff] [blame] | 2533 | enum wl_prio_t original_prio = cfqd->serving_prio; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2534 | |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2535 | /* Choose next priority. RT > BE > IDLE */ |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 2536 | if (cfq_group_busy_queues_wl(RT_WORKLOAD, cfqd, cfqg)) |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2537 | cfqd->serving_prio = RT_WORKLOAD; |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 2538 | else if (cfq_group_busy_queues_wl(BE_WORKLOAD, cfqd, cfqg)) |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2539 | cfqd->serving_prio = BE_WORKLOAD; |
| 2540 | else { |
| 2541 | cfqd->serving_prio = IDLE_WORKLOAD; |
| 2542 | cfqd->workload_expires = jiffies + 1; |
| 2543 | return; |
| 2544 | } |
| 2545 | |
Shaohua Li writes | e4ea0c1 | 2010-12-13 14:32:22 +0100 | [diff] [blame] | 2546 | if (original_prio != cfqd->serving_prio) |
| 2547 | goto new_workload; |
| 2548 | |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2549 | /* |
| 2550 | * For RT and BE, we have to choose also the type |
| 2551 | * (SYNC, SYNC_NOIDLE, ASYNC), and to compute a workload |
| 2552 | * expiration time |
| 2553 | */ |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2554 | st = service_tree_for(cfqg, cfqd->serving_prio, cfqd->serving_type); |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2555 | count = st->count; |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2556 | |
| 2557 | /* |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2558 | * check workload expiration, and that we still have other queues ready |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2559 | */ |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2560 | if (count && !time_after(jiffies, cfqd->workload_expires)) |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2561 | return; |
| 2562 | |
Shaohua Li writes | e4ea0c1 | 2010-12-13 14:32:22 +0100 | [diff] [blame] | 2563 | new_workload: |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2564 | /* otherwise select new workload type */ |
| 2565 | cfqd->serving_type = |
Vivek Goyal | 65b32a5 | 2009-12-16 17:52:59 -0500 | [diff] [blame] | 2566 | cfq_choose_wl(cfqd, cfqg, cfqd->serving_prio); |
| 2567 | st = service_tree_for(cfqg, cfqd->serving_prio, cfqd->serving_type); |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2568 | count = st->count; |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2569 | |
| 2570 | /* |
| 2571 | * the workload slice is computed as a fraction of target latency |
| 2572 | * proportional to the number of queues in that workload, over |
| 2573 | * all the queues in the same priority class |
| 2574 | */ |
Vivek Goyal | 58ff82f | 2009-12-03 12:59:44 -0500 | [diff] [blame] | 2575 | group_slice = cfq_group_slice(cfqd, cfqg); |
| 2576 | |
| 2577 | slice = group_slice * count / |
| 2578 | max_t(unsigned, cfqg->busy_queues_avg[cfqd->serving_prio], |
| 2579 | cfq_group_busy_queues_wl(cfqd->serving_prio, cfqd, cfqg)); |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2580 | |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 2581 | if (cfqd->serving_type == ASYNC_WORKLOAD) { |
| 2582 | unsigned int tmp; |
| 2583 | |
| 2584 | /* |
| 2585 | * Async queues are currently system wide. Just taking |
| 2586 | * proportion of queues with-in same group will lead to higher |
| 2587 | * async ratio system wide as generally root group is going |
| 2588 | * to have higher weight. A more accurate thing would be to |
| 2589 | * calculate system wide asnc/sync ratio. |
| 2590 | */ |
| 2591 | tmp = cfq_target_latency * cfqg_busy_async_queues(cfqd, cfqg); |
| 2592 | tmp = tmp/cfqd->busy_queues; |
| 2593 | slice = min_t(unsigned, slice, tmp); |
| 2594 | |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2595 | /* async workload slice is scaled down according to |
| 2596 | * the sync/async slice ratio. */ |
| 2597 | slice = slice * cfqd->cfq_slice[0] / cfqd->cfq_slice[1]; |
Vivek Goyal | f26bd1f | 2009-12-03 12:59:54 -0500 | [diff] [blame] | 2598 | } else |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2599 | /* sync workload slice is at least 2 * cfq_slice_idle */ |
| 2600 | slice = max(slice, 2 * cfqd->cfq_slice_idle); |
| 2601 | |
| 2602 | slice = max_t(unsigned, slice, CFQ_MIN_TT); |
Divyesh Shah | b1ffe73 | 2010-03-25 15:45:03 +0100 | [diff] [blame] | 2603 | cfq_log(cfqd, "workload slice:%d", slice); |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2604 | cfqd->workload_expires = jiffies + slice; |
| 2605 | } |
| 2606 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2607 | static struct cfq_group *cfq_get_next_cfqg(struct cfq_data *cfqd) |
| 2608 | { |
| 2609 | struct cfq_rb_root *st = &cfqd->grp_service_tree; |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 2610 | struct cfq_group *cfqg; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2611 | |
| 2612 | if (RB_EMPTY_ROOT(&st->rb)) |
| 2613 | return NULL; |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 2614 | cfqg = cfq_rb_first_group(st); |
Vivek Goyal | 25bc6b0 | 2009-12-03 12:59:43 -0500 | [diff] [blame] | 2615 | update_min_vdisktime(st); |
| 2616 | return cfqg; |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2617 | } |
| 2618 | |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2619 | static void cfq_choose_cfqg(struct cfq_data *cfqd) |
| 2620 | { |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2621 | struct cfq_group *cfqg = cfq_get_next_cfqg(cfqd); |
| 2622 | |
| 2623 | cfqd->serving_group = cfqg; |
Vivek Goyal | dae739e | 2009-12-03 12:59:45 -0500 | [diff] [blame] | 2624 | |
| 2625 | /* Restore the workload type data */ |
| 2626 | if (cfqg->saved_workload_slice) { |
| 2627 | cfqd->workload_expires = jiffies + cfqg->saved_workload_slice; |
| 2628 | cfqd->serving_type = cfqg->saved_workload; |
| 2629 | cfqd->serving_prio = cfqg->saved_serving_prio; |
Gui Jianfeng | 66ae291 | 2009-12-15 10:08:45 +0100 | [diff] [blame] | 2630 | } else |
| 2631 | cfqd->workload_expires = jiffies - 1; |
| 2632 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 2633 | choose_service_tree(cfqd, cfqg); |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2634 | } |
| 2635 | |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2636 | /* |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 2637 | * Select a queue for service. If we have a current active queue, |
| 2638 | * check whether to continue servicing it, or retrieve and set a new one. |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2639 | */ |
Tejun Heo | 1b5ed5e1 | 2005-11-10 08:49:19 +0100 | [diff] [blame] | 2640 | static struct cfq_queue *cfq_select_queue(struct cfq_data *cfqd) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2641 | { |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2642 | struct cfq_queue *cfqq, *new_cfqq = NULL; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2643 | |
| 2644 | cfqq = cfqd->active_queue; |
| 2645 | if (!cfqq) |
| 2646 | goto new_queue; |
| 2647 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2648 | if (!cfqd->rq_queued) |
| 2649 | return NULL; |
Vivek Goyal | c244bb5 | 2009-12-08 17:52:57 -0500 | [diff] [blame] | 2650 | |
| 2651 | /* |
| 2652 | * We were waiting for group to get backlogged. Expire the queue |
| 2653 | */ |
| 2654 | if (cfq_cfqq_wait_busy(cfqq) && !RB_EMPTY_ROOT(&cfqq->sort_list)) |
| 2655 | goto expire; |
| 2656 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2657 | /* |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2658 | * The active queue has run out of time, expire it and select new. |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2659 | */ |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 2660 | if (cfq_slice_used(cfqq) && !cfq_cfqq_must_dispatch(cfqq)) { |
| 2661 | /* |
| 2662 | * If slice had not expired at the completion of last request |
| 2663 | * we might not have turned on wait_busy flag. Don't expire |
| 2664 | * the queue yet. Allow the group to get backlogged. |
| 2665 | * |
| 2666 | * The very fact that we have used the slice, that means we |
| 2667 | * have been idling all along on this queue and it should be |
| 2668 | * ok to wait for this request to complete. |
| 2669 | */ |
Vivek Goyal | 82bbbf2 | 2009-12-10 19:25:41 +0100 | [diff] [blame] | 2670 | if (cfqq->cfqg->nr_cfqq == 1 && RB_EMPTY_ROOT(&cfqq->sort_list) |
| 2671 | && cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) { |
| 2672 | cfqq = NULL; |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 2673 | goto keep_queue; |
Vivek Goyal | 82bbbf2 | 2009-12-10 19:25:41 +0100 | [diff] [blame] | 2674 | } else |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2675 | goto check_group_idle; |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 2676 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2677 | |
| 2678 | /* |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2679 | * The active queue has requests and isn't expired, allow it to |
| 2680 | * dispatch. |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2681 | */ |
Jens Axboe | dd67d05 | 2006-06-21 09:36:18 +0200 | [diff] [blame] | 2682 | if (!RB_EMPTY_ROOT(&cfqq->sort_list)) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2683 | goto keep_queue; |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2684 | |
| 2685 | /* |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2686 | * If another queue has a request waiting within our mean seek |
| 2687 | * distance, let it run. The expire code will check for close |
| 2688 | * cooperators and put the close queue at the front of the service |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2689 | * tree. If possible, merge the expiring queue with the new cfqq. |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2690 | */ |
Jeff Moyer | b3b6d04 | 2009-10-23 17:14:51 -0400 | [diff] [blame] | 2691 | new_cfqq = cfq_close_cooperator(cfqd, cfqq); |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2692 | if (new_cfqq) { |
| 2693 | if (!cfqq->new_cfqq) |
| 2694 | cfq_setup_merge(cfqq, new_cfqq); |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2695 | goto expire; |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 2696 | } |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2697 | |
| 2698 | /* |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 2699 | * No requests pending. If the active queue still has requests in |
| 2700 | * flight or is idling for a new request, allow either of these |
| 2701 | * conditions to happen (or time out) before selecting a new queue. |
| 2702 | */ |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2703 | if (timer_pending(&cfqd->idle_slice_timer)) { |
| 2704 | cfqq = NULL; |
| 2705 | goto keep_queue; |
| 2706 | } |
| 2707 | |
Shaohua Li | 8e1ac66 | 2010-11-08 15:01:04 +0100 | [diff] [blame] | 2708 | /* |
| 2709 | * This is a deep seek queue, but the device is much faster than |
| 2710 | * the queue can deliver, don't idle |
| 2711 | **/ |
| 2712 | if (CFQQ_SEEKY(cfqq) && cfq_cfqq_idle_window(cfqq) && |
| 2713 | (cfq_cfqq_slice_new(cfqq) || |
| 2714 | (cfqq->slice_end - jiffies > jiffies - cfqq->slice_start))) { |
| 2715 | cfq_clear_cfqq_deep(cfqq); |
| 2716 | cfq_clear_cfqq_idle_window(cfqq); |
| 2717 | } |
| 2718 | |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 2719 | if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) { |
| 2720 | cfqq = NULL; |
| 2721 | goto keep_queue; |
| 2722 | } |
| 2723 | |
| 2724 | /* |
| 2725 | * If group idle is enabled and there are requests dispatched from |
| 2726 | * this group, wait for requests to complete. |
| 2727 | */ |
| 2728 | check_group_idle: |
Shaohua Li | 7700fc4 | 2011-07-12 14:24:56 +0200 | [diff] [blame] | 2729 | if (cfqd->cfq_group_idle && cfqq->cfqg->nr_cfqq == 1 && |
| 2730 | cfqq->cfqg->dispatched && |
| 2731 | !cfq_io_thinktime_big(cfqd, &cfqq->cfqg->ttime, true)) { |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 2732 | cfqq = NULL; |
| 2733 | goto keep_queue; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2734 | } |
| 2735 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2736 | expire: |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2737 | cfq_slice_expired(cfqd, 0); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2738 | new_queue: |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2739 | /* |
| 2740 | * Current queue expired. Check if we have to switch to a new |
| 2741 | * service tree |
| 2742 | */ |
| 2743 | if (!new_cfqq) |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2744 | cfq_choose_cfqg(cfqd); |
Corrado Zoccolo | 718eee0 | 2009-10-26 22:45:29 +0100 | [diff] [blame] | 2745 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 2746 | cfqq = cfq_set_active_queue(cfqd, new_cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2747 | keep_queue: |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 2748 | return cfqq; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2749 | } |
| 2750 | |
Jens Axboe | febffd6 | 2008-01-28 13:19:43 +0100 | [diff] [blame] | 2751 | static int __cfq_forced_dispatch_cfqq(struct cfq_queue *cfqq) |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2752 | { |
| 2753 | int dispatched = 0; |
| 2754 | |
| 2755 | while (cfqq->next_rq) { |
| 2756 | cfq_dispatch_insert(cfqq->cfqd->queue, cfqq->next_rq); |
| 2757 | dispatched++; |
| 2758 | } |
| 2759 | |
| 2760 | BUG_ON(!list_empty(&cfqq->fifo)); |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2761 | |
| 2762 | /* By default cfqq is not expired if it is empty. Do it explicitly */ |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2763 | __cfq_slice_expired(cfqq->cfqd, cfqq, 0); |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2764 | return dispatched; |
| 2765 | } |
| 2766 | |
Jens Axboe | 498d3aa2 | 2007-04-26 12:54:48 +0200 | [diff] [blame] | 2767 | /* |
| 2768 | * Drain our current requests. Used for barriers and when switching |
| 2769 | * io schedulers on-the-fly. |
| 2770 | */ |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2771 | static int cfq_forced_dispatch(struct cfq_data *cfqd) |
Tejun Heo | 1b5ed5e1 | 2005-11-10 08:49:19 +0100 | [diff] [blame] | 2772 | { |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 2773 | struct cfq_queue *cfqq; |
Jens Axboe | d9e7620 | 2007-04-20 14:27:50 +0200 | [diff] [blame] | 2774 | int dispatched = 0; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 2775 | |
Divyesh Shah | 3440c49 | 2010-04-09 09:29:57 +0200 | [diff] [blame] | 2776 | /* Expire the timeslice of the current active queue first */ |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2777 | cfq_slice_expired(cfqd, 0); |
Divyesh Shah | 3440c49 | 2010-04-09 09:29:57 +0200 | [diff] [blame] | 2778 | while ((cfqq = cfq_get_next_queue_forced(cfqd)) != NULL) { |
| 2779 | __cfq_set_active_queue(cfqd, cfqq); |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2780 | dispatched += __cfq_forced_dispatch_cfqq(cfqq); |
Divyesh Shah | 3440c49 | 2010-04-09 09:29:57 +0200 | [diff] [blame] | 2781 | } |
Tejun Heo | 1b5ed5e1 | 2005-11-10 08:49:19 +0100 | [diff] [blame] | 2782 | |
Tejun Heo | 1b5ed5e1 | 2005-11-10 08:49:19 +0100 | [diff] [blame] | 2783 | BUG_ON(cfqd->busy_queues); |
| 2784 | |
Jeff Moyer | 6923715 | 2009-06-12 15:29:30 +0200 | [diff] [blame] | 2785 | cfq_log(cfqd, "forced_dispatch=%d", dispatched); |
Tejun Heo | 1b5ed5e1 | 2005-11-10 08:49:19 +0100 | [diff] [blame] | 2786 | return dispatched; |
| 2787 | } |
| 2788 | |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2789 | static inline bool cfq_slice_used_soon(struct cfq_data *cfqd, |
| 2790 | struct cfq_queue *cfqq) |
| 2791 | { |
| 2792 | /* the queue hasn't finished any request, can't estimate */ |
| 2793 | if (cfq_cfqq_slice_new(cfqq)) |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 2794 | return true; |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2795 | if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched, |
| 2796 | cfqq->slice_end)) |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 2797 | return true; |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2798 | |
Shaohua Li | c1e4475 | 2010-11-08 15:01:02 +0100 | [diff] [blame] | 2799 | return false; |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2800 | } |
| 2801 | |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2802 | static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2803 | { |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2804 | unsigned int max_dispatch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2806 | /* |
Jens Axboe | 5ad531d | 2009-07-03 12:57:48 +0200 | [diff] [blame] | 2807 | * Drain async requests before we start sync IO |
| 2808 | */ |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 2809 | if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_flight[BLK_RW_ASYNC]) |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2810 | return false; |
Jens Axboe | 5ad531d | 2009-07-03 12:57:48 +0200 | [diff] [blame] | 2811 | |
| 2812 | /* |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2813 | * If this is an async queue and we have sync IO in flight, let it wait |
| 2814 | */ |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 2815 | if (cfqd->rq_in_flight[BLK_RW_SYNC] && !cfq_cfqq_sync(cfqq)) |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2816 | return false; |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2817 | |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2818 | max_dispatch = max_t(unsigned int, cfqd->cfq_quantum / 2, 1); |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2819 | if (cfq_class_idle(cfqq)) |
| 2820 | max_dispatch = 1; |
| 2821 | |
| 2822 | /* |
| 2823 | * Does this cfqq already have too much IO in flight? |
| 2824 | */ |
| 2825 | if (cfqq->dispatched >= max_dispatch) { |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 2826 | bool promote_sync = false; |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2827 | /* |
| 2828 | * idle queue must always only have a single IO in flight |
| 2829 | */ |
Jens Axboe | 3ed9a29 | 2007-04-23 08:33:33 +0200 | [diff] [blame] | 2830 | if (cfq_class_idle(cfqq)) |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2831 | return false; |
Jens Axboe | 3ed9a29 | 2007-04-23 08:33:33 +0200 | [diff] [blame] | 2832 | |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2833 | /* |
Li, Shaohua | c4ade94 | 2011-03-23 08:30:34 +0100 | [diff] [blame] | 2834 | * If there is only one sync queue |
| 2835 | * we can ignore async queue here and give the sync |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 2836 | * queue no dispatch limit. The reason is a sync queue can |
| 2837 | * preempt async queue, limiting the sync queue doesn't make |
| 2838 | * sense. This is useful for aiostress test. |
| 2839 | */ |
Li, Shaohua | c4ade94 | 2011-03-23 08:30:34 +0100 | [diff] [blame] | 2840 | if (cfq_cfqq_sync(cfqq) && cfqd->busy_sync_queues == 1) |
| 2841 | promote_sync = true; |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 2842 | |
| 2843 | /* |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2844 | * We have other queues, don't allow more IO from this one |
| 2845 | */ |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 2846 | if (cfqd->busy_queues > 1 && cfq_slice_used_soon(cfqd, cfqq) && |
| 2847 | !promote_sync) |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2848 | return false; |
Jens Axboe | 9ede209 | 2007-01-19 12:11:44 +1100 | [diff] [blame] | 2849 | |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2850 | /* |
Shaohua Li | 474b18c | 2009-12-03 12:58:05 +0100 | [diff] [blame] | 2851 | * Sole queue user, no limit |
Vivek Goyal | 365722b | 2009-10-03 15:21:27 +0200 | [diff] [blame] | 2852 | */ |
Shaohua Li | ef8a41d | 2011-03-07 09:26:29 +0100 | [diff] [blame] | 2853 | if (cfqd->busy_queues == 1 || promote_sync) |
Shaohua Li | abc3c74 | 2010-03-01 09:20:54 +0100 | [diff] [blame] | 2854 | max_dispatch = -1; |
| 2855 | else |
| 2856 | /* |
| 2857 | * Normally we start throttling cfqq when cfq_quantum/2 |
| 2858 | * requests have been dispatched. But we can drive |
| 2859 | * deeper queue depths at the beginning of slice |
| 2860 | * subjected to upper limit of cfq_quantum. |
| 2861 | * */ |
| 2862 | max_dispatch = cfqd->cfq_quantum; |
Jens Axboe | 8e29675 | 2009-10-03 16:26:03 +0200 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | /* |
| 2866 | * Async queues must wait a bit before being allowed dispatch. |
| 2867 | * We also ramp up the dispatch depth gradually for async IO, |
| 2868 | * based on the last sync IO we serviced |
| 2869 | */ |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 2870 | if (!cfq_cfqq_sync(cfqq) && cfqd->cfq_latency) { |
Corrado Zoccolo | 573412b | 2009-12-06 11:48:52 +0100 | [diff] [blame] | 2871 | unsigned long last_sync = jiffies - cfqd->last_delayed_sync; |
Jens Axboe | 8e29675 | 2009-10-03 16:26:03 +0200 | [diff] [blame] | 2872 | unsigned int depth; |
Vivek Goyal | 365722b | 2009-10-03 15:21:27 +0200 | [diff] [blame] | 2873 | |
Jens Axboe | 61f0c1d | 2009-10-03 19:46:03 +0200 | [diff] [blame] | 2874 | depth = last_sync / cfqd->cfq_slice[1]; |
Jens Axboe | e00c54c | 2009-10-04 20:36:19 +0200 | [diff] [blame] | 2875 | if (!depth && !cfqq->dispatched) |
| 2876 | depth = 1; |
Jens Axboe | 8e29675 | 2009-10-03 16:26:03 +0200 | [diff] [blame] | 2877 | if (depth < max_dispatch) |
| 2878 | max_dispatch = depth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | } |
| 2880 | |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2881 | /* |
| 2882 | * If we're below the current max, allow a dispatch |
| 2883 | */ |
| 2884 | return cfqq->dispatched < max_dispatch; |
| 2885 | } |
| 2886 | |
| 2887 | /* |
| 2888 | * Dispatch a request from cfqq, moving them to the request queue |
| 2889 | * dispatch list. |
| 2890 | */ |
| 2891 | static bool cfq_dispatch_request(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 2892 | { |
| 2893 | struct request *rq; |
| 2894 | |
| 2895 | BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list)); |
| 2896 | |
| 2897 | if (!cfq_may_dispatch(cfqd, cfqq)) |
| 2898 | return false; |
| 2899 | |
| 2900 | /* |
| 2901 | * follow expired path, else get first next available |
| 2902 | */ |
| 2903 | rq = cfq_check_fifo(cfqq); |
| 2904 | if (!rq) |
| 2905 | rq = cfqq->next_rq; |
| 2906 | |
| 2907 | /* |
| 2908 | * insert request into driver dispatch list |
| 2909 | */ |
| 2910 | cfq_dispatch_insert(cfqd->queue, rq); |
| 2911 | |
| 2912 | if (!cfqd->active_cic) { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 2913 | struct cfq_io_cq *cic = RQ_CIC(rq); |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2914 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 2915 | atomic_long_inc(&cic->icq.ioc->refcount); |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2916 | cfqd->active_cic = cic; |
| 2917 | } |
| 2918 | |
| 2919 | return true; |
| 2920 | } |
| 2921 | |
| 2922 | /* |
| 2923 | * Find the cfqq that we need to service and move a request from that to the |
| 2924 | * dispatch list |
| 2925 | */ |
| 2926 | static int cfq_dispatch_requests(struct request_queue *q, int force) |
| 2927 | { |
| 2928 | struct cfq_data *cfqd = q->elevator->elevator_data; |
| 2929 | struct cfq_queue *cfqq; |
| 2930 | |
| 2931 | if (!cfqd->busy_queues) |
| 2932 | return 0; |
| 2933 | |
| 2934 | if (unlikely(force)) |
| 2935 | return cfq_forced_dispatch(cfqd); |
| 2936 | |
| 2937 | cfqq = cfq_select_queue(cfqd); |
| 2938 | if (!cfqq) |
Jens Axboe | 8e29675 | 2009-10-03 16:26:03 +0200 | [diff] [blame] | 2939 | return 0; |
| 2940 | |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2941 | /* |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2942 | * Dispatch a request from this cfqq, if it is allowed |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2943 | */ |
Jens Axboe | 0b182d6 | 2009-10-06 20:49:37 +0200 | [diff] [blame] | 2944 | if (!cfq_dispatch_request(cfqd, cfqq)) |
| 2945 | return 0; |
| 2946 | |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2947 | cfqq->slice_dispatch++; |
Jens Axboe | b029195 | 2009-04-07 11:38:31 +0200 | [diff] [blame] | 2948 | cfq_clear_cfqq_must_dispatch(cfqq); |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2949 | |
| 2950 | /* |
| 2951 | * expire an async queue immediately if it has used up its slice. idle |
| 2952 | * queue always expire after 1 dispatch round. |
| 2953 | */ |
| 2954 | if (cfqd->busy_queues > 1 && ((!cfq_cfqq_sync(cfqq) && |
| 2955 | cfqq->slice_dispatch >= cfq_prio_to_maxrq(cfqd, cfqq)) || |
| 2956 | cfq_class_idle(cfqq))) { |
| 2957 | cfqq->slice_end = jiffies + 1; |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2958 | cfq_slice_expired(cfqd, 0); |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2959 | } |
| 2960 | |
Shan Wei | b217a90 | 2009-09-01 10:06:42 +0200 | [diff] [blame] | 2961 | cfq_log_cfqq(cfqd, cfqq, "dispatched a request"); |
Jens Axboe | 2f5cb73 | 2009-04-07 08:51:19 +0200 | [diff] [blame] | 2962 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | } |
| 2964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | /* |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 2966 | * task holds one reference to the queue, dropped when task exits. each rq |
| 2967 | * in-flight on this queue also holds a reference, dropped when rq is freed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | * |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 2969 | * Each cfq queue took a reference on the parent group. Drop it now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | * queue lock must be held here. |
| 2971 | */ |
| 2972 | static void cfq_put_queue(struct cfq_queue *cfqq) |
| 2973 | { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2974 | struct cfq_data *cfqd = cfqq->cfqd; |
Justin TerAvest | 0bbfeb8 | 2011-03-01 15:05:08 -0500 | [diff] [blame] | 2975 | struct cfq_group *cfqg; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2976 | |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 2977 | BUG_ON(cfqq->ref <= 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 2979 | cfqq->ref--; |
| 2980 | if (cfqq->ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | return; |
| 2982 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 2983 | cfq_log_cfqq(cfqd, cfqq, "put_queue"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | BUG_ON(rb_first(&cfqq->sort_list)); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2985 | BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]); |
Vivek Goyal | b1c3576 | 2009-12-03 12:59:47 -0500 | [diff] [blame] | 2986 | cfqg = cfqq->cfqg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | |
Jens Axboe | 28f95cbc | 2007-01-19 12:09:53 +1100 | [diff] [blame] | 2988 | if (unlikely(cfqd->active_queue == cfqq)) { |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 2989 | __cfq_slice_expired(cfqd, cfqq, 0); |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 2990 | cfq_schedule_dispatch(cfqd); |
Jens Axboe | 28f95cbc | 2007-01-19 12:09:53 +1100 | [diff] [blame] | 2991 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 2992 | |
Vivek Goyal | f04a642 | 2009-12-03 12:59:40 -0500 | [diff] [blame] | 2993 | BUG_ON(cfq_cfqq_on_rr(cfqq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2994 | kmem_cache_free(cfq_pool, cfqq); |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 2995 | cfqg_put(cfqg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
Shaohua Li | d02a2c0 | 2010-05-25 10:16:53 +0200 | [diff] [blame] | 2998 | static void cfq_put_cooperator(struct cfq_queue *cfqq) |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 2999 | { |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3000 | struct cfq_queue *__cfqq, *next; |
| 3001 | |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3002 | /* |
| 3003 | * If this queue was scheduled to merge with another queue, be |
| 3004 | * sure to drop the reference taken on that queue (and others in |
| 3005 | * the merge chain). See cfq_setup_merge and cfq_merge_cfqqs. |
| 3006 | */ |
| 3007 | __cfqq = cfqq->new_cfqq; |
| 3008 | while (__cfqq) { |
| 3009 | if (__cfqq == cfqq) { |
| 3010 | WARN(1, "cfqq->new_cfqq loop detected\n"); |
| 3011 | break; |
| 3012 | } |
| 3013 | next = __cfqq->new_cfqq; |
| 3014 | cfq_put_queue(__cfqq); |
| 3015 | __cfqq = next; |
| 3016 | } |
Shaohua Li | d02a2c0 | 2010-05-25 10:16:53 +0200 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 3020 | { |
| 3021 | if (unlikely(cfqq == cfqd->active_queue)) { |
| 3022 | __cfq_slice_expired(cfqd, cfqq, 0); |
| 3023 | cfq_schedule_dispatch(cfqd); |
| 3024 | } |
| 3025 | |
| 3026 | cfq_put_cooperator(cfqq); |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3027 | |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3028 | cfq_put_queue(cfqq); |
| 3029 | } |
| 3030 | |
Tejun Heo | 9b84cac | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 3031 | static void cfq_init_icq(struct io_cq *icq) |
| 3032 | { |
| 3033 | struct cfq_io_cq *cic = icq_to_cic(icq); |
| 3034 | |
| 3035 | cic->ttime.last_end_request = jiffies; |
| 3036 | } |
| 3037 | |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3038 | static void cfq_exit_icq(struct io_cq *icq) |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3039 | { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3040 | struct cfq_io_cq *cic = icq_to_cic(icq); |
Tejun Heo | 283287a | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 3041 | struct cfq_data *cfqd = cic_to_cfqd(cic); |
Fabio Checconi | 4faa3c8 | 2008-04-10 08:28:01 +0200 | [diff] [blame] | 3042 | |
Jens Axboe | ff6657c | 2009-04-08 10:58:57 +0200 | [diff] [blame] | 3043 | if (cic->cfqq[BLK_RW_ASYNC]) { |
| 3044 | cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_ASYNC]); |
| 3045 | cic->cfqq[BLK_RW_ASYNC] = NULL; |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3046 | } |
| 3047 | |
Jens Axboe | ff6657c | 2009-04-08 10:58:57 +0200 | [diff] [blame] | 3048 | if (cic->cfqq[BLK_RW_SYNC]) { |
| 3049 | cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_SYNC]); |
| 3050 | cic->cfqq[BLK_RW_SYNC] = NULL; |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3051 | } |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3052 | } |
| 3053 | |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3054 | static void cfq_init_prio_data(struct cfq_queue *cfqq, struct cfq_io_cq *cic) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3055 | { |
| 3056 | struct task_struct *tsk = current; |
| 3057 | int ioprio_class; |
| 3058 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3059 | if (!cfq_cfqq_prio_changed(cfqq)) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3060 | return; |
| 3061 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3062 | ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3063 | switch (ioprio_class) { |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3064 | default: |
| 3065 | printk(KERN_ERR "cfq: bad prio %x\n", ioprio_class); |
| 3066 | case IOPRIO_CLASS_NONE: |
| 3067 | /* |
Jens Axboe | 6d63c27 | 2008-05-07 09:51:23 +0200 | [diff] [blame] | 3068 | * no prio set, inherit CPU scheduling settings |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3069 | */ |
| 3070 | cfqq->ioprio = task_nice_ioprio(tsk); |
Jens Axboe | 6d63c27 | 2008-05-07 09:51:23 +0200 | [diff] [blame] | 3071 | cfqq->ioprio_class = task_nice_ioclass(tsk); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3072 | break; |
| 3073 | case IOPRIO_CLASS_RT: |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3074 | cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3075 | cfqq->ioprio_class = IOPRIO_CLASS_RT; |
| 3076 | break; |
| 3077 | case IOPRIO_CLASS_BE: |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3078 | cfqq->ioprio = IOPRIO_PRIO_DATA(cic->ioprio); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3079 | cfqq->ioprio_class = IOPRIO_CLASS_BE; |
| 3080 | break; |
| 3081 | case IOPRIO_CLASS_IDLE: |
| 3082 | cfqq->ioprio_class = IOPRIO_CLASS_IDLE; |
| 3083 | cfqq->ioprio = 7; |
| 3084 | cfq_clear_cfqq_idle_window(cfqq); |
| 3085 | break; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | /* |
| 3089 | * keep track of original prio settings in case we have to temporarily |
| 3090 | * elevate the priority of this queue |
| 3091 | */ |
| 3092 | cfqq->org_ioprio = cfqq->ioprio; |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3093 | cfq_clear_cfqq_prio_changed(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3094 | } |
| 3095 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3096 | static void check_ioprio_changed(struct cfq_io_cq *cic, struct bio *bio) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3097 | { |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3098 | int ioprio = cic->icq.ioc->ioprio; |
Konstantin Khlebnikov | bca4b91 | 2010-05-20 23:21:34 +0400 | [diff] [blame] | 3099 | struct cfq_data *cfqd = cic_to_cfqd(cic); |
Al Viro | 478a82b | 2006-03-18 13:25:24 -0500 | [diff] [blame] | 3100 | struct cfq_queue *cfqq; |
Jens Axboe | 35e6077 | 2006-06-14 09:10:45 +0200 | [diff] [blame] | 3101 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3102 | /* |
| 3103 | * Check whether ioprio has changed. The condition may trigger |
| 3104 | * spuriously on a newly created cic but there's no harm. |
| 3105 | */ |
| 3106 | if (unlikely(!cfqd) || likely(cic->ioprio == ioprio)) |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3107 | return; |
| 3108 | |
Jens Axboe | ff6657c | 2009-04-08 10:58:57 +0200 | [diff] [blame] | 3109 | cfqq = cic->cfqq[BLK_RW_ASYNC]; |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3110 | if (cfqq) { |
| 3111 | struct cfq_queue *new_cfqq; |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3112 | new_cfqq = cfq_get_queue(cfqd, BLK_RW_ASYNC, cic, bio, |
| 3113 | GFP_ATOMIC); |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3114 | if (new_cfqq) { |
Jens Axboe | ff6657c | 2009-04-08 10:58:57 +0200 | [diff] [blame] | 3115 | cic->cfqq[BLK_RW_ASYNC] = new_cfqq; |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3116 | cfq_put_queue(cfqq); |
| 3117 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3118 | } |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3119 | |
Jens Axboe | ff6657c | 2009-04-08 10:58:57 +0200 | [diff] [blame] | 3120 | cfqq = cic->cfqq[BLK_RW_SYNC]; |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3121 | if (cfqq) |
| 3122 | cfq_mark_cfqq_prio_changed(cfqq); |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3123 | |
| 3124 | cic->ioprio = ioprio; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3125 | } |
| 3126 | |
Jens Axboe | d5036d7 | 2009-06-26 10:44:34 +0200 | [diff] [blame] | 3127 | static void cfq_init_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3128 | pid_t pid, bool is_sync) |
Jens Axboe | d5036d7 | 2009-06-26 10:44:34 +0200 | [diff] [blame] | 3129 | { |
| 3130 | RB_CLEAR_NODE(&cfqq->rb_node); |
| 3131 | RB_CLEAR_NODE(&cfqq->p_node); |
| 3132 | INIT_LIST_HEAD(&cfqq->fifo); |
| 3133 | |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 3134 | cfqq->ref = 0; |
Jens Axboe | d5036d7 | 2009-06-26 10:44:34 +0200 | [diff] [blame] | 3135 | cfqq->cfqd = cfqd; |
| 3136 | |
| 3137 | cfq_mark_cfqq_prio_changed(cfqq); |
| 3138 | |
| 3139 | if (is_sync) { |
| 3140 | if (!cfq_class_idle(cfqq)) |
| 3141 | cfq_mark_cfqq_idle_window(cfqq); |
| 3142 | cfq_mark_cfqq_sync(cfqq); |
| 3143 | } |
| 3144 | cfqq->pid = pid; |
| 3145 | } |
| 3146 | |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3147 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3148 | static void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3149 | { |
Konstantin Khlebnikov | bca4b91 | 2010-05-20 23:21:34 +0400 | [diff] [blame] | 3150 | struct cfq_data *cfqd = cic_to_cfqd(cic); |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3151 | struct cfq_queue *sync_cfqq; |
| 3152 | uint64_t id; |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3153 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3154 | rcu_read_lock(); |
| 3155 | id = bio_blkio_cgroup(bio)->id; |
| 3156 | rcu_read_unlock(); |
| 3157 | |
| 3158 | /* |
| 3159 | * Check whether blkcg has changed. The condition may trigger |
| 3160 | * spuriously on a newly created cic but there's no harm. |
| 3161 | */ |
| 3162 | if (unlikely(!cfqd) || likely(cic->blkcg_id == id)) |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3163 | return; |
| 3164 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3165 | sync_cfqq = cic_to_cfqq(cic, 1); |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3166 | if (sync_cfqq) { |
| 3167 | /* |
| 3168 | * Drop reference to sync queue. A new sync queue will be |
| 3169 | * assigned in new group upon arrival of a fresh request. |
| 3170 | */ |
| 3171 | cfq_log_cfqq(cfqd, sync_cfqq, "changed cgroup"); |
| 3172 | cic_set_cfqq(cic, NULL, 1); |
| 3173 | cfq_put_queue(sync_cfqq); |
| 3174 | } |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3175 | |
| 3176 | cic->blkcg_id = id; |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3177 | } |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3178 | #else |
| 3179 | static inline void check_blkcg_changed(struct cfq_io_cq *cic, struct bio *bio) { } |
Vivek Goyal | 24610333 | 2009-12-03 12:59:51 -0500 | [diff] [blame] | 3180 | #endif /* CONFIG_CFQ_GROUP_IOSCHED */ |
| 3181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | static struct cfq_queue * |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3183 | cfq_find_alloc_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic, |
| 3184 | struct bio *bio, gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | { |
Tejun Heo | 0a5a7d0 | 2012-03-05 13:15:02 -0800 | [diff] [blame] | 3186 | struct blkio_cgroup *blkcg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | struct cfq_queue *cfqq, *new_cfqq = NULL; |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 3188 | struct cfq_group *cfqg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
| 3190 | retry: |
Tejun Heo | 2a7f124 | 2012-03-05 13:15:01 -0800 | [diff] [blame] | 3191 | rcu_read_lock(); |
| 3192 | |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 3193 | blkcg = bio_blkio_cgroup(bio); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 3194 | cfqg = cfq_lookup_create_cfqg(cfqd, blkcg); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 3195 | cfqq = cic_to_cfqq(cic, is_sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3197 | /* |
| 3198 | * Always try a new alloc if we fell back to the OOM cfqq |
| 3199 | * originally, since it should just be a temporary situation. |
| 3200 | */ |
| 3201 | if (!cfqq || cfqq == &cfqd->oom_cfqq) { |
| 3202 | cfqq = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | if (new_cfqq) { |
| 3204 | cfqq = new_cfqq; |
| 3205 | new_cfqq = NULL; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3206 | } else if (gfp_mask & __GFP_WAIT) { |
Tejun Heo | 2a7f124 | 2012-03-05 13:15:01 -0800 | [diff] [blame] | 3207 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | spin_unlock_irq(cfqd->queue->queue_lock); |
Christoph Lameter | 94f6030 | 2007-07-17 04:03:29 -0700 | [diff] [blame] | 3209 | new_cfqq = kmem_cache_alloc_node(cfq_pool, |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3210 | gfp_mask | __GFP_ZERO, |
Christoph Lameter | 94f6030 | 2007-07-17 04:03:29 -0700 | [diff] [blame] | 3211 | cfqd->queue->node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | spin_lock_irq(cfqd->queue->queue_lock); |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3213 | if (new_cfqq) |
| 3214 | goto retry; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3215 | } else { |
Christoph Lameter | 94f6030 | 2007-07-17 04:03:29 -0700 | [diff] [blame] | 3216 | cfqq = kmem_cache_alloc_node(cfq_pool, |
| 3217 | gfp_mask | __GFP_ZERO, |
| 3218 | cfqd->queue->node); |
Kiyoshi Ueda | db3b584 | 2005-06-17 16:15:10 +0200 | [diff] [blame] | 3219 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3221 | if (cfqq) { |
| 3222 | cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync); |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3223 | cfq_init_prio_data(cfqq, cic); |
Vivek Goyal | cdb16e8 | 2009-12-03 12:59:38 -0500 | [diff] [blame] | 3224 | cfq_link_cfqq_cfqg(cfqq, cfqg); |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3225 | cfq_log_cfqq(cfqd, cfqq, "alloced"); |
| 3226 | } else |
| 3227 | cfqq = &cfqd->oom_cfqq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | } |
| 3229 | |
| 3230 | if (new_cfqq) |
| 3231 | kmem_cache_free(cfq_pool, new_cfqq); |
| 3232 | |
Tejun Heo | 2a7f124 | 2012-03-05 13:15:01 -0800 | [diff] [blame] | 3233 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3234 | return cfqq; |
| 3235 | } |
| 3236 | |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3237 | static struct cfq_queue ** |
| 3238 | cfq_async_queue_prio(struct cfq_data *cfqd, int ioprio_class, int ioprio) |
| 3239 | { |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3240 | switch (ioprio_class) { |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3241 | case IOPRIO_CLASS_RT: |
| 3242 | return &cfqd->async_cfqq[0][ioprio]; |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3243 | case IOPRIO_CLASS_NONE: |
| 3244 | ioprio = IOPRIO_NORM; |
| 3245 | /* fall through */ |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3246 | case IOPRIO_CLASS_BE: |
| 3247 | return &cfqd->async_cfqq[1][ioprio]; |
| 3248 | case IOPRIO_CLASS_IDLE: |
| 3249 | return &cfqd->async_idle_cfqq; |
| 3250 | default: |
| 3251 | BUG(); |
| 3252 | } |
| 3253 | } |
| 3254 | |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3255 | static struct cfq_queue * |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3256 | cfq_get_queue(struct cfq_data *cfqd, bool is_sync, struct cfq_io_cq *cic, |
Tejun Heo | 4f85cb9 | 2012-03-05 13:15:28 -0800 | [diff] [blame] | 3257 | struct bio *bio, gfp_t gfp_mask) |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3258 | { |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3259 | const int ioprio_class = IOPRIO_PRIO_CLASS(cic->ioprio); |
| 3260 | const int ioprio = IOPRIO_PRIO_DATA(cic->ioprio); |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3261 | struct cfq_queue **async_cfqq = NULL; |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3262 | struct cfq_queue *cfqq = NULL; |
| 3263 | |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3264 | if (!is_sync) { |
| 3265 | async_cfqq = cfq_async_queue_prio(cfqd, ioprio_class, ioprio); |
| 3266 | cfqq = *async_cfqq; |
| 3267 | } |
| 3268 | |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 3269 | if (!cfqq) |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3270 | cfqq = cfq_find_alloc_queue(cfqd, is_sync, cic, bio, gfp_mask); |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3271 | |
| 3272 | /* |
| 3273 | * pin the queue now that it's allocated, scheduler exit will prune it |
| 3274 | */ |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3275 | if (!is_sync && !(*async_cfqq)) { |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 3276 | cfqq->ref++; |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3277 | *async_cfqq = cfqq; |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3278 | } |
| 3279 | |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 3280 | cfqq->ref++; |
Jens Axboe | 15c31be | 2007-07-10 13:43:25 +0200 | [diff] [blame] | 3281 | return cfqq; |
| 3282 | } |
| 3283 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3284 | static void |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3285 | __cfq_update_io_thinktime(struct cfq_ttime *ttime, unsigned long slice_idle) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3286 | { |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3287 | unsigned long elapsed = jiffies - ttime->last_end_request; |
| 3288 | elapsed = min(elapsed, 2UL * slice_idle); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3289 | |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3290 | ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8; |
| 3291 | ttime->ttime_total = (7*ttime->ttime_total + 256*elapsed) / 8; |
| 3292 | ttime->ttime_mean = (ttime->ttime_total + 128) / ttime->ttime_samples; |
| 3293 | } |
| 3294 | |
| 3295 | static void |
| 3296 | cfq_update_io_thinktime(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3297 | struct cfq_io_cq *cic) |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3298 | { |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 3299 | if (cfq_cfqq_sync(cfqq)) { |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3300 | __cfq_update_io_thinktime(&cic->ttime, cfqd->cfq_slice_idle); |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 3301 | __cfq_update_io_thinktime(&cfqq->service_tree->ttime, |
| 3302 | cfqd->cfq_slice_idle); |
| 3303 | } |
Shaohua Li | 7700fc4 | 2011-07-12 14:24:56 +0200 | [diff] [blame] | 3304 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
| 3305 | __cfq_update_io_thinktime(&cfqq->cfqg->ttime, cfqd->cfq_group_idle); |
| 3306 | #endif |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3307 | } |
| 3308 | |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 3309 | static void |
Jeff Moyer | b2c18e1 | 2009-10-23 17:14:49 -0400 | [diff] [blame] | 3310 | cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3311 | struct request *rq) |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 3312 | { |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 3313 | sector_t sdist = 0; |
Corrado Zoccolo | 41647e7 | 2010-02-27 19:45:40 +0100 | [diff] [blame] | 3314 | sector_t n_sec = blk_rq_sectors(rq); |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 3315 | if (cfqq->last_request_pos) { |
| 3316 | if (cfqq->last_request_pos < blk_rq_pos(rq)) |
| 3317 | sdist = blk_rq_pos(rq) - cfqq->last_request_pos; |
| 3318 | else |
| 3319 | sdist = cfqq->last_request_pos - blk_rq_pos(rq); |
| 3320 | } |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 3321 | |
Corrado Zoccolo | 3dde36d | 2010-02-27 19:45:39 +0100 | [diff] [blame] | 3322 | cfqq->seek_history <<= 1; |
Corrado Zoccolo | 41647e7 | 2010-02-27 19:45:40 +0100 | [diff] [blame] | 3323 | if (blk_queue_nonrot(cfqd->queue)) |
| 3324 | cfqq->seek_history |= (n_sec < CFQQ_SECT_THR_NONROT); |
| 3325 | else |
| 3326 | cfqq->seek_history |= (sdist > CFQQ_SEEK_THR); |
Jens Axboe | 206dc69 | 2006-03-28 13:03:44 +0200 | [diff] [blame] | 3327 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3328 | |
| 3329 | /* |
| 3330 | * Disable idle window if the process thinks too long or seeks so much that |
| 3331 | * it doesn't matter |
| 3332 | */ |
| 3333 | static void |
| 3334 | cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3335 | struct cfq_io_cq *cic) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3336 | { |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 3337 | int old_idle, enable_idle; |
Jens Axboe | 1be92f2 | 2007-04-19 14:32:26 +0200 | [diff] [blame] | 3338 | |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 3339 | /* |
| 3340 | * Don't idle for async or idle io prio class |
| 3341 | */ |
| 3342 | if (!cfq_cfqq_sync(cfqq) || cfq_class_idle(cfqq)) |
Jens Axboe | 1be92f2 | 2007-04-19 14:32:26 +0200 | [diff] [blame] | 3343 | return; |
| 3344 | |
Jens Axboe | c265a7f | 2008-06-26 13:49:33 +0200 | [diff] [blame] | 3345 | enable_idle = old_idle = cfq_cfqq_idle_window(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3346 | |
Corrado Zoccolo | 76280af | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 3347 | if (cfqq->queued[0] + cfqq->queued[1] >= 4) |
| 3348 | cfq_mark_cfqq_deep(cfqq); |
| 3349 | |
Corrado Zoccolo | 749ef9f | 2010-09-20 15:24:50 +0200 | [diff] [blame] | 3350 | if (cfqq->next_rq && (cfqq->next_rq->cmd_flags & REQ_NOIDLE)) |
| 3351 | enable_idle = 0; |
Tejun Heo | f6e8d01 | 2012-03-05 13:15:26 -0800 | [diff] [blame] | 3352 | else if (!atomic_read(&cic->icq.ioc->active_ref) || |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3353 | !cfqd->cfq_slice_idle || |
| 3354 | (!cfq_cfqq_deep(cfqq) && CFQQ_SEEKY(cfqq))) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3355 | enable_idle = 0; |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3356 | else if (sample_valid(cic->ttime.ttime_samples)) { |
| 3357 | if (cic->ttime.ttime_mean > cfqd->cfq_slice_idle) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3358 | enable_idle = 0; |
| 3359 | else |
| 3360 | enable_idle = 1; |
| 3361 | } |
| 3362 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 3363 | if (old_idle != enable_idle) { |
| 3364 | cfq_log_cfqq(cfqd, cfqq, "idle=%d", enable_idle); |
| 3365 | if (enable_idle) |
| 3366 | cfq_mark_cfqq_idle_window(cfqq); |
| 3367 | else |
| 3368 | cfq_clear_cfqq_idle_window(cfqq); |
| 3369 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3370 | } |
| 3371 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3372 | /* |
| 3373 | * Check if new_cfqq should preempt the currently active queue. Return 0 for |
| 3374 | * no or if we aren't sure, a 1 will cause a preempt. |
| 3375 | */ |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3376 | static bool |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3377 | cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq, |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3378 | struct request *rq) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3379 | { |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3380 | struct cfq_queue *cfqq; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3381 | |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3382 | cfqq = cfqd->active_queue; |
| 3383 | if (!cfqq) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3384 | return false; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3385 | |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3386 | if (cfq_class_idle(new_cfqq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3387 | return false; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3388 | |
| 3389 | if (cfq_class_idle(cfqq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3390 | return true; |
Jens Axboe | 1e3335d | 2007-02-14 19:59:49 +0100 | [diff] [blame] | 3391 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3392 | /* |
Divyesh Shah | 875feb6 | 2010-01-06 18:58:20 -0800 | [diff] [blame] | 3393 | * Don't allow a non-RT request to preempt an ongoing RT cfqq timeslice. |
| 3394 | */ |
| 3395 | if (cfq_class_rt(cfqq) && !cfq_class_rt(new_cfqq)) |
| 3396 | return false; |
| 3397 | |
| 3398 | /* |
Jens Axboe | 374f84a | 2006-07-23 01:42:19 +0200 | [diff] [blame] | 3399 | * if the new request is sync, but the currently running queue is |
| 3400 | * not, let the sync request have priority. |
| 3401 | */ |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3402 | if (rq_is_sync(rq) && !cfq_cfqq_sync(cfqq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3403 | return true; |
Jens Axboe | 1e3335d | 2007-02-14 19:59:49 +0100 | [diff] [blame] | 3404 | |
Vivek Goyal | 8682e1f | 2009-12-03 12:59:50 -0500 | [diff] [blame] | 3405 | if (new_cfqq->cfqg != cfqq->cfqg) |
| 3406 | return false; |
| 3407 | |
| 3408 | if (cfq_slice_used(cfqq)) |
| 3409 | return true; |
| 3410 | |
| 3411 | /* Allow preemption only if we are idling on sync-noidle tree */ |
| 3412 | if (cfqd->serving_type == SYNC_NOIDLE_WORKLOAD && |
| 3413 | cfqq_type(new_cfqq) == SYNC_NOIDLE_WORKLOAD && |
| 3414 | new_cfqq->service_tree->count == 2 && |
| 3415 | RB_EMPTY_ROOT(&cfqq->sort_list)) |
| 3416 | return true; |
| 3417 | |
Jens Axboe | 374f84a | 2006-07-23 01:42:19 +0200 | [diff] [blame] | 3418 | /* |
Jens Axboe | b53d1ed | 2011-08-19 08:34:48 +0200 | [diff] [blame] | 3419 | * So both queues are sync. Let the new request get disk time if |
| 3420 | * it's a metadata request and the current queue is doing regular IO. |
| 3421 | */ |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 3422 | if ((rq->cmd_flags & REQ_PRIO) && !cfqq->prio_pending) |
Jens Axboe | b53d1ed | 2011-08-19 08:34:48 +0200 | [diff] [blame] | 3423 | return true; |
| 3424 | |
| 3425 | /* |
Divyesh Shah | 3a9a3f6 | 2009-01-30 12:46:41 +0100 | [diff] [blame] | 3426 | * Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice. |
| 3427 | */ |
| 3428 | if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3429 | return true; |
Divyesh Shah | 3a9a3f6 | 2009-01-30 12:46:41 +0100 | [diff] [blame] | 3430 | |
Shaohua Li | d2d59e1 | 2010-11-08 15:01:03 +0100 | [diff] [blame] | 3431 | /* An idle queue should not be idle now for some reason */ |
| 3432 | if (RB_EMPTY_ROOT(&cfqq->sort_list) && !cfq_should_idle(cfqd, cfqq)) |
| 3433 | return true; |
| 3434 | |
Jens Axboe | 1e3335d | 2007-02-14 19:59:49 +0100 | [diff] [blame] | 3435 | if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3436 | return false; |
Jens Axboe | 1e3335d | 2007-02-14 19:59:49 +0100 | [diff] [blame] | 3437 | |
| 3438 | /* |
| 3439 | * if this request is as-good as one we would expect from the |
| 3440 | * current cfqq, let it preempt |
| 3441 | */ |
Shaohua Li | e9ce335 | 2010-03-19 08:03:04 +0100 | [diff] [blame] | 3442 | if (cfq_rq_close(cfqd, cfqq, rq)) |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3443 | return true; |
Jens Axboe | 1e3335d | 2007-02-14 19:59:49 +0100 | [diff] [blame] | 3444 | |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3445 | return false; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | /* |
| 3449 | * cfqq preempts the active queue. if we allowed preempt with no slice left, |
| 3450 | * let it have half of its nominal slice. |
| 3451 | */ |
| 3452 | static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 3453 | { |
Shaohua Li | df0793a | 2012-01-19 09:20:09 +0100 | [diff] [blame] | 3454 | enum wl_type_t old_type = cfqq_type(cfqd->active_queue); |
| 3455 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 3456 | cfq_log_cfqq(cfqd, cfqq, "preempt"); |
Shaohua Li | df0793a | 2012-01-19 09:20:09 +0100 | [diff] [blame] | 3457 | cfq_slice_expired(cfqd, 1); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3458 | |
Jens Axboe | bf57225 | 2006-07-19 20:29:12 +0200 | [diff] [blame] | 3459 | /* |
Shaohua Li | f8ae6e3e | 2011-01-14 08:41:02 +0100 | [diff] [blame] | 3460 | * workload type is changed, don't save slice, otherwise preempt |
| 3461 | * doesn't happen |
| 3462 | */ |
Shaohua Li | df0793a | 2012-01-19 09:20:09 +0100 | [diff] [blame] | 3463 | if (old_type != cfqq_type(cfqq)) |
Shaohua Li | f8ae6e3e | 2011-01-14 08:41:02 +0100 | [diff] [blame] | 3464 | cfqq->cfqg->saved_workload_slice = 0; |
| 3465 | |
| 3466 | /* |
Jens Axboe | bf57225 | 2006-07-19 20:29:12 +0200 | [diff] [blame] | 3467 | * Put the new queue at the front of the of the current list, |
| 3468 | * so we know that it will be selected next. |
| 3469 | */ |
| 3470 | BUG_ON(!cfq_cfqq_on_rr(cfqq)); |
Jens Axboe | edd75ff | 2007-04-19 12:03:34 +0200 | [diff] [blame] | 3471 | |
| 3472 | cfq_service_tree_add(cfqd, cfqq, 1); |
Justin TerAvest | eda5e0c | 2011-03-22 21:26:49 +0100 | [diff] [blame] | 3473 | |
Justin TerAvest | 62a37f6 | 2011-03-23 08:25:44 +0100 | [diff] [blame] | 3474 | cfqq->slice_end = 0; |
| 3475 | cfq_mark_cfqq_slice_new(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | /* |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3479 | * Called when a new fs request (rq) is added (to cfqq). Check if there's |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3480 | * something we should do about it |
| 3481 | */ |
| 3482 | static void |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3483 | cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, |
| 3484 | struct request *rq) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3485 | { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3486 | struct cfq_io_cq *cic = RQ_CIC(rq); |
Jens Axboe | 12e9fdd | 2006-06-01 10:09:56 +0200 | [diff] [blame] | 3487 | |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3488 | cfqd->rq_queued++; |
Christoph Hellwig | 65299a3 | 2011-08-23 14:50:29 +0200 | [diff] [blame] | 3489 | if (rq->cmd_flags & REQ_PRIO) |
| 3490 | cfqq->prio_pending++; |
Jens Axboe | 374f84a | 2006-07-23 01:42:19 +0200 | [diff] [blame] | 3491 | |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3492 | cfq_update_io_thinktime(cfqd, cfqq, cic); |
Jeff Moyer | b2c18e1 | 2009-10-23 17:14:49 -0400 | [diff] [blame] | 3493 | cfq_update_io_seektime(cfqd, cfqq, rq); |
Jens Axboe | 9c2c38a | 2005-08-24 14:57:54 +0200 | [diff] [blame] | 3494 | cfq_update_idle_window(cfqd, cfqq, cic); |
| 3495 | |
Jeff Moyer | b2c18e1 | 2009-10-23 17:14:49 -0400 | [diff] [blame] | 3496 | cfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3497 | |
| 3498 | if (cfqq == cfqd->active_queue) { |
| 3499 | /* |
Jens Axboe | b029195 | 2009-04-07 11:38:31 +0200 | [diff] [blame] | 3500 | * Remember that we saw a request from this process, but |
| 3501 | * don't start queuing just yet. Otherwise we risk seeing lots |
| 3502 | * of tiny requests, because we disrupt the normal plugging |
Jens Axboe | d6ceb25 | 2009-04-14 14:18:16 +0200 | [diff] [blame] | 3503 | * and merging. If the request is already larger than a single |
| 3504 | * page, let it rip immediately. For that case we assume that |
Jens Axboe | 2d87072 | 2009-04-15 12:12:46 +0200 | [diff] [blame] | 3505 | * merging is already done. Ditto for a busy system that |
| 3506 | * has other work pending, don't risk delaying until the |
| 3507 | * idle timer unplug to continue working. |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3508 | */ |
Jens Axboe | d6ceb25 | 2009-04-14 14:18:16 +0200 | [diff] [blame] | 3509 | if (cfq_cfqq_wait_request(cfqq)) { |
Jens Axboe | 2d87072 | 2009-04-15 12:12:46 +0200 | [diff] [blame] | 3510 | if (blk_rq_bytes(rq) > PAGE_CACHE_SIZE || |
| 3511 | cfqd->busy_queues > 1) { |
Divyesh Shah | 812df48 | 2010-04-08 21:15:35 -0700 | [diff] [blame] | 3512 | cfq_del_timer(cfqd, cfqq); |
Gui Jianfeng | 554554f | 2009-12-10 09:38:39 +0100 | [diff] [blame] | 3513 | cfq_clear_cfqq_wait_request(cfqq); |
Christoph Hellwig | 24ecfbe | 2011-04-18 11:41:33 +0200 | [diff] [blame] | 3514 | __blk_run_queue(cfqd->queue); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 3515 | } else { |
Vivek Goyal | e98ef89 | 2010-06-18 10:39:47 -0400 | [diff] [blame] | 3516 | cfq_blkiocg_update_idle_time_stats( |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 3517 | cfqg_to_blkg(cfqq->cfqg), |
| 3518 | &blkio_policy_cfq); |
Vivek Goyal | bf791937 | 2009-12-03 12:59:37 -0500 | [diff] [blame] | 3519 | cfq_mark_cfqq_must_dispatch(cfqq); |
Divyesh Shah | a11cdaa | 2010-04-13 19:59:17 +0200 | [diff] [blame] | 3520 | } |
Jens Axboe | d6ceb25 | 2009-04-14 14:18:16 +0200 | [diff] [blame] | 3521 | } |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3522 | } else if (cfq_should_preempt(cfqd, cfqq, rq)) { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3523 | /* |
| 3524 | * not the active queue - expire current slice if it is |
| 3525 | * idle and has expired it's mean thinktime or this new queue |
Divyesh Shah | 3a9a3f6 | 2009-01-30 12:46:41 +0100 | [diff] [blame] | 3526 | * has some old slice time left and is of higher priority or |
| 3527 | * this new queue is RT and the current one is BE |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3528 | */ |
| 3529 | cfq_preempt_queue(cfqd, cfqq); |
Christoph Hellwig | 24ecfbe | 2011-04-18 11:41:33 +0200 | [diff] [blame] | 3530 | __blk_run_queue(cfqd->queue); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3531 | } |
| 3532 | } |
| 3533 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3534 | static void cfq_insert_request(struct request_queue *q, struct request *rq) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3535 | { |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 3536 | struct cfq_data *cfqd = q->elevator->elevator_data; |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3537 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3538 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 3539 | cfq_log_cfqq(cfqd, cfqq, "insert_request"); |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3540 | cfq_init_prio_data(cfqq, RQ_CIC(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | |
Jens Axboe | 30996f4 | 2009-10-05 11:03:39 +0200 | [diff] [blame] | 3542 | rq_set_fifo_time(rq, jiffies + cfqd->cfq_fifo_expire[rq_is_sync(rq)]); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3543 | list_add_tail(&rq->queuelist, &cfqq->fifo); |
Corrado Zoccolo | aa6f6a3 | 2009-10-26 22:44:33 +0100 | [diff] [blame] | 3544 | cfq_add_rq_rb(rq); |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 3545 | cfq_blkiocg_update_io_add_stats(cfqg_to_blkg(RQ_CFQG(rq)), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 3546 | &blkio_policy_cfq, |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 3547 | cfqg_to_blkg(cfqd->serving_group), |
| 3548 | rq_data_dir(rq), rq_is_sync(rq)); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3549 | cfq_rq_enqueued(cfqd, cfqq, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3552 | /* |
| 3553 | * Update hw_tag based on peak queue depth over 50 samples under |
| 3554 | * sufficient load. |
| 3555 | */ |
| 3556 | static void cfq_update_hw_tag(struct cfq_data *cfqd) |
| 3557 | { |
Shaohua Li | 1a1238a | 2009-10-27 08:46:23 +0100 | [diff] [blame] | 3558 | struct cfq_queue *cfqq = cfqd->active_queue; |
| 3559 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3560 | if (cfqd->rq_in_driver > cfqd->hw_tag_est_depth) |
| 3561 | cfqd->hw_tag_est_depth = cfqd->rq_in_driver; |
Corrado Zoccolo | e459dd0 | 2009-11-26 10:02:57 +0100 | [diff] [blame] | 3562 | |
| 3563 | if (cfqd->hw_tag == 1) |
| 3564 | return; |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3565 | |
| 3566 | if (cfqd->rq_queued <= CFQ_HW_QUEUE_MIN && |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3567 | cfqd->rq_in_driver <= CFQ_HW_QUEUE_MIN) |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3568 | return; |
| 3569 | |
Shaohua Li | 1a1238a | 2009-10-27 08:46:23 +0100 | [diff] [blame] | 3570 | /* |
| 3571 | * If active queue hasn't enough requests and can idle, cfq might not |
| 3572 | * dispatch sufficient requests to hardware. Don't zero hw_tag in this |
| 3573 | * case |
| 3574 | */ |
| 3575 | if (cfqq && cfq_cfqq_idle_window(cfqq) && |
| 3576 | cfqq->dispatched + cfqq->queued[0] + cfqq->queued[1] < |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3577 | CFQ_HW_QUEUE_MIN && cfqd->rq_in_driver < CFQ_HW_QUEUE_MIN) |
Shaohua Li | 1a1238a | 2009-10-27 08:46:23 +0100 | [diff] [blame] | 3578 | return; |
| 3579 | |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3580 | if (cfqd->hw_tag_samples++ < 50) |
| 3581 | return; |
| 3582 | |
Corrado Zoccolo | e459dd0 | 2009-11-26 10:02:57 +0100 | [diff] [blame] | 3583 | if (cfqd->hw_tag_est_depth >= CFQ_HW_QUEUE_MIN) |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3584 | cfqd->hw_tag = 1; |
| 3585 | else |
| 3586 | cfqd->hw_tag = 0; |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3587 | } |
| 3588 | |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3589 | static bool cfq_should_wait_busy(struct cfq_data *cfqd, struct cfq_queue *cfqq) |
| 3590 | { |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3591 | struct cfq_io_cq *cic = cfqd->active_cic; |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3592 | |
Justin TerAvest | 02a8f01 | 2011-02-09 14:20:03 +0100 | [diff] [blame] | 3593 | /* If the queue already has requests, don't wait */ |
| 3594 | if (!RB_EMPTY_ROOT(&cfqq->sort_list)) |
| 3595 | return false; |
| 3596 | |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3597 | /* If there are other queues in the group, don't wait */ |
| 3598 | if (cfqq->cfqg->nr_cfqq > 1) |
| 3599 | return false; |
| 3600 | |
Shaohua Li | 7700fc4 | 2011-07-12 14:24:56 +0200 | [diff] [blame] | 3601 | /* the only queue in the group, but think time is big */ |
| 3602 | if (cfq_io_thinktime_big(cfqd, &cfqq->cfqg->ttime, true)) |
| 3603 | return false; |
| 3604 | |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3605 | if (cfq_slice_used(cfqq)) |
| 3606 | return true; |
| 3607 | |
| 3608 | /* if slice left is less than think time, wait busy */ |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3609 | if (cic && sample_valid(cic->ttime.ttime_samples) |
| 3610 | && (cfqq->slice_end - jiffies < cic->ttime.ttime_mean)) |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3611 | return true; |
| 3612 | |
| 3613 | /* |
| 3614 | * If think times is less than a jiffy than ttime_mean=0 and above |
| 3615 | * will not be true. It might happen that slice has not expired yet |
| 3616 | * but will expire soon (4-5 ns) during select_queue(). To cover the |
| 3617 | * case where think time is less than a jiffy, mark the queue wait |
| 3618 | * busy if only 1 jiffy is left in the slice. |
| 3619 | */ |
| 3620 | if (cfqq->slice_end - jiffies == 1) |
| 3621 | return true; |
| 3622 | |
| 3623 | return false; |
| 3624 | } |
| 3625 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3626 | static void cfq_completed_request(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3628 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 3629 | struct cfq_data *cfqd = cfqq->cfqd; |
Jens Axboe | 5380a10 | 2006-07-13 12:37:56 +0200 | [diff] [blame] | 3630 | const int sync = rq_is_sync(rq); |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 3631 | unsigned long now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 3633 | now = jiffies; |
Christoph Hellwig | 33659eb | 2010-08-07 18:17:56 +0200 | [diff] [blame] | 3634 | cfq_log_cfqq(cfqd, cfqq, "complete rqnoidle %d", |
| 3635 | !!(rq->cmd_flags & REQ_NOIDLE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | |
Aaron Carroll | 45333d5 | 2008-08-26 15:52:36 +0200 | [diff] [blame] | 3637 | cfq_update_hw_tag(cfqd); |
| 3638 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3639 | WARN_ON(!cfqd->rq_in_driver); |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3640 | WARN_ON(!cfqq->dispatched); |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3641 | cfqd->rq_in_driver--; |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3642 | cfqq->dispatched--; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 3643 | (RQ_CFQG(rq))->dispatched--; |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 3644 | cfq_blkiocg_update_completion_stats(cfqg_to_blkg(cfqq->cfqg), |
Tejun Heo | c176826 | 2012-03-05 13:15:17 -0800 | [diff] [blame] | 3645 | &blkio_policy_cfq, rq_start_time_ns(rq), |
| 3646 | rq_io_start_time_ns(rq), rq_data_dir(rq), |
| 3647 | rq_is_sync(rq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3648 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3649 | cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--; |
Jens Axboe | 3ed9a29 | 2007-04-23 08:33:33 +0200 | [diff] [blame] | 3650 | |
Vivek Goyal | 365722b | 2009-10-03 15:21:27 +0200 | [diff] [blame] | 3651 | if (sync) { |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 3652 | struct cfq_rb_root *service_tree; |
| 3653 | |
Shaohua Li | 383cd72 | 2011-07-12 14:24:35 +0200 | [diff] [blame] | 3654 | RQ_CIC(rq)->ttime.last_end_request = now; |
Shaohua Li | f5f2b6c | 2011-07-12 14:24:55 +0200 | [diff] [blame] | 3655 | |
| 3656 | if (cfq_cfqq_on_rr(cfqq)) |
| 3657 | service_tree = cfqq->service_tree; |
| 3658 | else |
| 3659 | service_tree = service_tree_for(cfqq->cfqg, |
| 3660 | cfqq_prio(cfqq), cfqq_type(cfqq)); |
| 3661 | service_tree->ttime.last_end_request = now; |
Corrado Zoccolo | 573412b | 2009-12-06 11:48:52 +0100 | [diff] [blame] | 3662 | if (!time_after(rq->start_time + cfqd->cfq_fifo_expire[1], now)) |
| 3663 | cfqd->last_delayed_sync = now; |
Vivek Goyal | 365722b | 2009-10-03 15:21:27 +0200 | [diff] [blame] | 3664 | } |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3665 | |
Shaohua Li | 7700fc4 | 2011-07-12 14:24:56 +0200 | [diff] [blame] | 3666 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
| 3667 | cfqq->cfqg->ttime.last_end_request = now; |
| 3668 | #endif |
| 3669 | |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3670 | /* |
| 3671 | * If this is the active queue, check if it needs to be expired, |
| 3672 | * or if we want to idle in case it has no pending requests. |
| 3673 | */ |
| 3674 | if (cfqd->active_queue == cfqq) { |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 3675 | const bool cfqq_empty = RB_EMPTY_ROOT(&cfqq->sort_list); |
| 3676 | |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 3677 | if (cfq_cfqq_slice_new(cfqq)) { |
| 3678 | cfq_set_prio_slice(cfqd, cfqq); |
| 3679 | cfq_clear_cfqq_slice_new(cfqq); |
| 3680 | } |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 3681 | |
| 3682 | /* |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3683 | * Should we wait for next request to come in before we expire |
| 3684 | * the queue. |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 3685 | */ |
Vivek Goyal | 7667aa0 | 2009-12-08 17:52:58 -0500 | [diff] [blame] | 3686 | if (cfq_should_wait_busy(cfqd, cfqq)) { |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 3687 | unsigned long extend_sl = cfqd->cfq_slice_idle; |
| 3688 | if (!cfqd->cfq_slice_idle) |
| 3689 | extend_sl = cfqd->cfq_group_idle; |
| 3690 | cfqq->slice_end = jiffies + extend_sl; |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 3691 | cfq_mark_cfqq_wait_busy(cfqq); |
Divyesh Shah | b1ffe73 | 2010-03-25 15:45:03 +0100 | [diff] [blame] | 3692 | cfq_log_cfqq(cfqd, cfqq, "will busy wait"); |
Vivek Goyal | f75edf2 | 2009-12-03 12:59:53 -0500 | [diff] [blame] | 3693 | } |
| 3694 | |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 3695 | /* |
Corrado Zoccolo | 8e55063 | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 3696 | * Idling is not enabled on: |
| 3697 | * - expired queues |
| 3698 | * - idle-priority queues |
| 3699 | * - async queues |
| 3700 | * - queues with still some requests queued |
| 3701 | * - when there is a close cooperator |
Jens Axboe | a36e71f | 2009-04-15 12:15:11 +0200 | [diff] [blame] | 3702 | */ |
Jens Axboe | 0871714 | 2008-01-28 11:38:15 +0100 | [diff] [blame] | 3703 | if (cfq_slice_used(cfqq) || cfq_class_idle(cfqq)) |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 3704 | cfq_slice_expired(cfqd, 1); |
Corrado Zoccolo | 8e55063 | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 3705 | else if (sync && cfqq_empty && |
| 3706 | !cfq_close_cooperator(cfqd, cfqq)) { |
Corrado Zoccolo | 749ef9f | 2010-09-20 15:24:50 +0200 | [diff] [blame] | 3707 | cfq_arm_slice_timer(cfqd); |
Corrado Zoccolo | 8e55063 | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 3708 | } |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3709 | } |
Jens Axboe | 6d048f5 | 2007-04-25 12:44:27 +0200 | [diff] [blame] | 3710 | |
Corrado Zoccolo | 53c583d | 2010-02-28 19:45:05 +0100 | [diff] [blame] | 3711 | if (!cfqd->rq_in_driver) |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 3712 | cfq_schedule_dispatch(cfqd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3715 | static inline int __cfq_may_queue(struct cfq_queue *cfqq) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3716 | { |
Jens Axboe | 1b379d8 | 2009-08-11 08:26:11 +0200 | [diff] [blame] | 3717 | if (cfq_cfqq_wait_request(cfqq) && !cfq_cfqq_must_alloc_slice(cfqq)) { |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3718 | cfq_mark_cfqq_must_alloc_slice(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3719 | return ELV_MQUEUE_MUST; |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3720 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3721 | |
| 3722 | return ELV_MQUEUE_MAY; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3723 | } |
| 3724 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3725 | static int cfq_may_queue(struct request_queue *q, int rw) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3726 | { |
| 3727 | struct cfq_data *cfqd = q->elevator->elevator_data; |
| 3728 | struct task_struct *tsk = current; |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3729 | struct cfq_io_cq *cic; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3730 | struct cfq_queue *cfqq; |
| 3731 | |
| 3732 | /* |
| 3733 | * don't force setup of a queue from here, as a call to may_queue |
| 3734 | * does not necessarily imply that a request actually will be queued. |
| 3735 | * so just lookup a possibly existing queue, or return 'may queue' |
| 3736 | * if that fails |
| 3737 | */ |
Jens Axboe | 4ac845a | 2008-01-24 08:44:49 +0100 | [diff] [blame] | 3738 | cic = cfq_cic_lookup(cfqd, tsk->io_context); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 3739 | if (!cic) |
| 3740 | return ELV_MQUEUE_MAY; |
| 3741 | |
Jens Axboe | b0b78f8 | 2009-04-08 10:56:08 +0200 | [diff] [blame] | 3742 | cfqq = cic_to_cfqq(cic, rw_is_sync(rw)); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3743 | if (cfqq) { |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3744 | cfq_init_prio_data(cfqq, cic); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3745 | |
Jens Axboe | 89850f7 | 2006-07-22 16:48:31 +0200 | [diff] [blame] | 3746 | return __cfq_may_queue(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | return ELV_MQUEUE_MAY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | } |
| 3751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | /* |
| 3753 | * queue lock held here |
| 3754 | */ |
Jens Axboe | bb37b94 | 2006-12-01 10:42:33 +0100 | [diff] [blame] | 3755 | static void cfq_put_request(struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | { |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3757 | struct cfq_queue *cfqq = RQ_CFQQ(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3759 | if (cfqq) { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3760 | const int rw = rq_data_dir(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3762 | BUG_ON(!cfqq->allocated[rw]); |
| 3763 | cfqq->allocated[rw]--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | |
Vivek Goyal | 7f1dc8a | 2010-04-21 17:44:16 +0200 | [diff] [blame] | 3765 | /* Put down rq reference on cfqg */ |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 3766 | cfqg_put(RQ_CFQG(rq)); |
Tejun Heo | a612fdd | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3767 | rq->elv.priv[0] = NULL; |
| 3768 | rq->elv.priv[1] = NULL; |
Vivek Goyal | 7f1dc8a | 2010-04-21 17:44:16 +0200 | [diff] [blame] | 3769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | cfq_put_queue(cfqq); |
| 3771 | } |
| 3772 | } |
| 3773 | |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3774 | static struct cfq_queue * |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3775 | cfq_merge_cfqqs(struct cfq_data *cfqd, struct cfq_io_cq *cic, |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3776 | struct cfq_queue *cfqq) |
| 3777 | { |
| 3778 | cfq_log_cfqq(cfqd, cfqq, "merging with queue %p", cfqq->new_cfqq); |
| 3779 | cic_set_cfqq(cic, cfqq->new_cfqq, 1); |
Jeff Moyer | b3b6d04 | 2009-10-23 17:14:51 -0400 | [diff] [blame] | 3780 | cfq_mark_cfqq_coop(cfqq->new_cfqq); |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3781 | cfq_put_queue(cfqq); |
| 3782 | return cic_to_cfqq(cic, 1); |
| 3783 | } |
| 3784 | |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3785 | /* |
| 3786 | * Returns NULL if a new cfqq should be allocated, or the old cfqq if this |
| 3787 | * was the last process referring to said cfqq. |
| 3788 | */ |
| 3789 | static struct cfq_queue * |
Tejun Heo | c586980 | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3790 | split_cfqq(struct cfq_io_cq *cic, struct cfq_queue *cfqq) |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3791 | { |
| 3792 | if (cfqq_process_refs(cfqq) == 1) { |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3793 | cfqq->pid = current->pid; |
| 3794 | cfq_clear_cfqq_coop(cfqq); |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 3795 | cfq_clear_cfqq_split_coop(cfqq); |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3796 | return cfqq; |
| 3797 | } |
| 3798 | |
| 3799 | cic_set_cfqq(cic, NULL, 1); |
Shaohua Li | d02a2c0 | 2010-05-25 10:16:53 +0200 | [diff] [blame] | 3800 | |
| 3801 | cfq_put_cooperator(cfqq); |
| 3802 | |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3803 | cfq_put_queue(cfqq); |
| 3804 | return NULL; |
| 3805 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | /* |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3807 | * Allocate cfq data structures associated with this request. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | */ |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3809 | static int |
Tejun Heo | 852c788 | 2012-03-05 13:15:27 -0800 | [diff] [blame] | 3810 | cfq_set_request(struct request_queue *q, struct request *rq, struct bio *bio, |
| 3811 | gfp_t gfp_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | { |
| 3813 | struct cfq_data *cfqd = q->elevator->elevator_data; |
Tejun Heo | f1f8cc9 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 3814 | struct cfq_io_cq *cic = icq_to_cic(rq->elv.icq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | const int rw = rq_data_dir(rq); |
Jens Axboe | a6151c3 | 2009-10-07 20:02:57 +0200 | [diff] [blame] | 3816 | const bool is_sync = rq_is_sync(rq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3817 | struct cfq_queue *cfqq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | |
| 3819 | might_sleep_if(gfp_mask & __GFP_WAIT); |
| 3820 | |
Tejun Heo | 216284c | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 3821 | spin_lock_irq(q->queue_lock); |
Tejun Heo | f1f8cc9 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 3822 | |
Tejun Heo | 598971b | 2012-03-19 15:10:58 -0700 | [diff] [blame] | 3823 | check_ioprio_changed(cic, bio); |
| 3824 | check_blkcg_changed(cic, bio); |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3825 | new_queue: |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 3826 | cfqq = cic_to_cfqq(cic, is_sync); |
Vivek Goyal | 32f2e80 | 2009-07-09 22:13:16 +0200 | [diff] [blame] | 3827 | if (!cfqq || cfqq == &cfqd->oom_cfqq) { |
Tejun Heo | abede6d | 2012-03-19 15:10:57 -0700 | [diff] [blame] | 3828 | cfqq = cfq_get_queue(cfqd, is_sync, cic, bio, gfp_mask); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 3829 | cic_set_cfqq(cic, cfqq, is_sync); |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3830 | } else { |
| 3831 | /* |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3832 | * If the queue was seeky for too long, break it apart. |
| 3833 | */ |
Shaohua Li | ae54abe | 2010-02-05 13:11:45 +0100 | [diff] [blame] | 3834 | if (cfq_cfqq_coop(cfqq) && cfq_cfqq_split_coop(cfqq)) { |
Jeff Moyer | e6c5bc7 | 2009-10-23 17:14:52 -0400 | [diff] [blame] | 3835 | cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq"); |
| 3836 | cfqq = split_cfqq(cic, cfqq); |
| 3837 | if (!cfqq) |
| 3838 | goto new_queue; |
| 3839 | } |
| 3840 | |
| 3841 | /* |
Jeff Moyer | df5fe3e | 2009-10-23 17:14:50 -0400 | [diff] [blame] | 3842 | * Check to see if this queue is scheduled to merge with |
| 3843 | * another, closely cooperating queue. The merging of |
| 3844 | * queues happens here as it must be done in process context. |
| 3845 | * The reference on new_cfqq was taken in merge_cfqqs. |
| 3846 | */ |
| 3847 | if (cfqq->new_cfqq) |
| 3848 | cfqq = cfq_merge_cfqqs(cfqd, cic, cfqq); |
Vasily Tarasov | 91fac31 | 2007-04-25 12:29:51 +0200 | [diff] [blame] | 3849 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3850 | |
| 3851 | cfqq->allocated[rw]++; |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3852 | |
Jens Axboe | 6fae9c2 | 2011-03-01 15:04:39 -0500 | [diff] [blame] | 3853 | cfqq->ref++; |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 3854 | cfqg_get(cfqq->cfqg); |
Tejun Heo | a612fdd | 2011-12-14 00:33:41 +0100 | [diff] [blame] | 3855 | rq->elv.priv[0] = cfqq; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 3856 | rq->elv.priv[1] = cfqq->cfqg; |
Tejun Heo | 216284c | 2011-12-14 00:33:38 +0100 | [diff] [blame] | 3857 | spin_unlock_irq(q->queue_lock); |
Jens Axboe | 5e70537 | 2006-07-13 12:39:25 +0200 | [diff] [blame] | 3858 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | } |
| 3860 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3861 | static void cfq_kick_queue(struct work_struct *work) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3862 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 3863 | struct cfq_data *cfqd = |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 3864 | container_of(work, struct cfq_data, unplug_work); |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3865 | struct request_queue *q = cfqd->queue; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3866 | |
Jens Axboe | 40bb54d | 2009-04-15 12:11:10 +0200 | [diff] [blame] | 3867 | spin_lock_irq(q->queue_lock); |
Christoph Hellwig | 24ecfbe | 2011-04-18 11:41:33 +0200 | [diff] [blame] | 3868 | __blk_run_queue(cfqd->queue); |
Jens Axboe | 40bb54d | 2009-04-15 12:11:10 +0200 | [diff] [blame] | 3869 | spin_unlock_irq(q->queue_lock); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3870 | } |
| 3871 | |
| 3872 | /* |
| 3873 | * Timer running if the active_queue is currently idling inside its time slice |
| 3874 | */ |
| 3875 | static void cfq_idle_slice_timer(unsigned long data) |
| 3876 | { |
| 3877 | struct cfq_data *cfqd = (struct cfq_data *) data; |
| 3878 | struct cfq_queue *cfqq; |
| 3879 | unsigned long flags; |
Jens Axboe | 3c6bd2f | 2007-01-19 12:06:33 +1100 | [diff] [blame] | 3880 | int timed_out = 1; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3881 | |
Jens Axboe | 7b67913 | 2008-05-30 12:23:07 +0200 | [diff] [blame] | 3882 | cfq_log(cfqd, "idle timer fired"); |
| 3883 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3884 | spin_lock_irqsave(cfqd->queue->queue_lock, flags); |
| 3885 | |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 3886 | cfqq = cfqd->active_queue; |
| 3887 | if (cfqq) { |
Jens Axboe | 3c6bd2f | 2007-01-19 12:06:33 +1100 | [diff] [blame] | 3888 | timed_out = 0; |
| 3889 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3890 | /* |
Jens Axboe | b029195 | 2009-04-07 11:38:31 +0200 | [diff] [blame] | 3891 | * We saw a request before the queue expired, let it through |
| 3892 | */ |
| 3893 | if (cfq_cfqq_must_dispatch(cfqq)) |
| 3894 | goto out_kick; |
| 3895 | |
| 3896 | /* |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3897 | * expired |
| 3898 | */ |
Jens Axboe | 44f7c16 | 2007-01-19 11:51:58 +1100 | [diff] [blame] | 3899 | if (cfq_slice_used(cfqq)) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3900 | goto expire; |
| 3901 | |
| 3902 | /* |
| 3903 | * only expire and reinvoke request handler, if there are |
| 3904 | * other queues with pending requests |
| 3905 | */ |
Jens Axboe | caaa5f9 | 2006-06-16 11:23:00 +0200 | [diff] [blame] | 3906 | if (!cfqd->busy_queues) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3907 | goto out_cont; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3908 | |
| 3909 | /* |
| 3910 | * not expired and it has a request pending, let it dispatch |
| 3911 | */ |
Jens Axboe | 75e5098 | 2009-04-07 08:56:14 +0200 | [diff] [blame] | 3912 | if (!RB_EMPTY_ROOT(&cfqq->sort_list)) |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3913 | goto out_kick; |
Corrado Zoccolo | 76280af | 2009-11-26 10:02:58 +0100 | [diff] [blame] | 3914 | |
| 3915 | /* |
| 3916 | * Queue depth flag is reset only when the idle didn't succeed |
| 3917 | */ |
| 3918 | cfq_clear_cfqq_deep(cfqq); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3919 | } |
| 3920 | expire: |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 3921 | cfq_slice_expired(cfqd, timed_out); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3922 | out_kick: |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 3923 | cfq_schedule_dispatch(cfqd); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3924 | out_cont: |
| 3925 | spin_unlock_irqrestore(cfqd->queue->queue_lock, flags); |
| 3926 | } |
| 3927 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3928 | static void cfq_shutdown_timer_wq(struct cfq_data *cfqd) |
| 3929 | { |
| 3930 | del_timer_sync(&cfqd->idle_slice_timer); |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 3931 | cancel_work_sync(&cfqd->unplug_work); |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3932 | } |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3933 | |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3934 | static void cfq_put_async_queues(struct cfq_data *cfqd) |
| 3935 | { |
| 3936 | int i; |
| 3937 | |
| 3938 | for (i = 0; i < IOPRIO_BE_NR; i++) { |
| 3939 | if (cfqd->async_cfqq[0][i]) |
| 3940 | cfq_put_queue(cfqd->async_cfqq[0][i]); |
| 3941 | if (cfqd->async_cfqq[1][i]) |
| 3942 | cfq_put_queue(cfqd->async_cfqq[1][i]); |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3943 | } |
Oleg Nesterov | 2389d1e | 2007-11-05 08:58:05 +0100 | [diff] [blame] | 3944 | |
| 3945 | if (cfqd->async_idle_cfqq) |
| 3946 | cfq_put_queue(cfqd->async_idle_cfqq); |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3947 | } |
| 3948 | |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 3949 | static void cfq_exit_queue(struct elevator_queue *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | { |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3951 | struct cfq_data *cfqd = e->elevator_data; |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 3952 | struct request_queue *q = cfqd->queue; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 3953 | |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 3954 | cfq_shutdown_timer_wq(cfqd); |
Jens Axboe | e2d74ac | 2006-03-28 08:59:01 +0200 | [diff] [blame] | 3955 | |
Al Viro | d9ff418 | 2006-03-18 13:51:22 -0500 | [diff] [blame] | 3956 | spin_lock_irq(q->queue_lock); |
Jens Axboe | e2d74ac | 2006-03-28 08:59:01 +0200 | [diff] [blame] | 3957 | |
Al Viro | d9ff418 | 2006-03-18 13:51:22 -0500 | [diff] [blame] | 3958 | if (cfqd->active_queue) |
Vivek Goyal | e5ff082 | 2010-04-26 19:25:11 +0200 | [diff] [blame] | 3959 | __cfq_slice_expired(cfqd, cfqd->active_queue, 0); |
Jens Axboe | e2d74ac | 2006-03-28 08:59:01 +0200 | [diff] [blame] | 3960 | |
Vasily Tarasov | c2dea2d | 2007-07-20 10:06:38 +0200 | [diff] [blame] | 3961 | cfq_put_async_queues(cfqd); |
Tejun Heo | 03aa264a | 2012-03-05 13:15:19 -0800 | [diff] [blame] | 3962 | |
| 3963 | spin_unlock_irq(q->queue_lock); |
| 3964 | |
Al Viro | a90d742 | 2006-03-18 12:05:37 -0500 | [diff] [blame] | 3965 | cfq_shutdown_timer_wq(cfqd); |
| 3966 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3967 | #ifndef CONFIG_CFQ_GROUP_IOSCHED |
| 3968 | kfree(cfqd->root_group); |
Vivek Goyal | 2abae55 | 2011-05-23 10:02:19 +0200 | [diff] [blame] | 3969 | #endif |
Tejun Heo | e8989fa | 2012-03-05 13:15:20 -0800 | [diff] [blame] | 3970 | update_root_blkg_pd(q, BLKIO_POLICY_PROP); |
Vivek Goyal | 56edf7d | 2011-05-19 15:38:22 -0400 | [diff] [blame] | 3971 | kfree(cfqd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3972 | } |
| 3973 | |
Tejun Heo | b2fab5a | 2012-03-05 13:14:57 -0800 | [diff] [blame] | 3974 | static int cfq_init_queue(struct request_queue *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | { |
| 3976 | struct cfq_data *cfqd; |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 3977 | struct blkio_group *blkg __maybe_unused; |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3978 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | |
Christoph Lameter | 94f6030 | 2007-07-17 04:03:29 -0700 | [diff] [blame] | 3980 | cfqd = kmalloc_node(sizeof(*cfqd), GFP_KERNEL | __GFP_ZERO, q->node); |
Tejun Heo | a73f730 | 2011-12-14 00:33:37 +0100 | [diff] [blame] | 3981 | if (!cfqd) |
Tejun Heo | b2fab5a | 2012-03-05 13:14:57 -0800 | [diff] [blame] | 3982 | return -ENOMEM; |
Konstantin Khlebnikov | 80b15c7 | 2010-05-20 23:21:41 +0400 | [diff] [blame] | 3983 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3984 | cfqd->queue = q; |
| 3985 | q->elevator->elevator_data = cfqd; |
| 3986 | |
Vivek Goyal | 1fa8f6d | 2009-12-03 12:59:41 -0500 | [diff] [blame] | 3987 | /* Init root service tree */ |
| 3988 | cfqd->grp_service_tree = CFQ_RB_ROOT; |
| 3989 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3990 | /* Init root group and prefer root group over other groups by default */ |
Vivek Goyal | 25fb516 | 2009-12-03 12:59:46 -0500 | [diff] [blame] | 3991 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3992 | rcu_read_lock(); |
| 3993 | spin_lock_irq(q->queue_lock); |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 3994 | |
Tejun Heo | aaec55a | 2012-04-01 14:38:42 -0700 | [diff] [blame] | 3995 | blkg = blkg_lookup_create(&blkio_root_cgroup, q, true); |
Tejun Heo | cd1604f | 2012-03-05 13:15:06 -0800 | [diff] [blame] | 3996 | if (!IS_ERR(blkg)) |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 3997 | cfqd->root_group = blkg_to_cfqg(blkg); |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 3998 | |
| 3999 | spin_unlock_irq(q->queue_lock); |
| 4000 | rcu_read_unlock(); |
| 4001 | #else |
| 4002 | cfqd->root_group = kzalloc_node(sizeof(*cfqd->root_group), |
| 4003 | GFP_KERNEL, cfqd->queue->node); |
| 4004 | if (cfqd->root_group) |
| 4005 | cfq_init_cfqg_base(cfqd->root_group); |
| 4006 | #endif |
| 4007 | if (!cfqd->root_group) { |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 4008 | kfree(cfqd); |
Tejun Heo | b2fab5a | 2012-03-05 13:14:57 -0800 | [diff] [blame] | 4009 | return -ENOMEM; |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 4010 | } |
| 4011 | |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 4012 | cfqd->root_group->weight = 2*BLKIO_WEIGHT_DEFAULT; |
Vivek Goyal | 5624a4e | 2011-05-19 15:38:28 -0400 | [diff] [blame] | 4013 | |
Jens Axboe | 26a2ac0 | 2009-04-23 12:13:27 +0200 | [diff] [blame] | 4014 | /* |
| 4015 | * Not strictly needed (since RB_ROOT just clears the node and we |
| 4016 | * zeroed cfqd on alloc), but better be safe in case someone decides |
| 4017 | * to add magic to the rb code |
| 4018 | */ |
| 4019 | for (i = 0; i < CFQ_PRIO_LISTS; i++) |
| 4020 | cfqd->prio_trees[i] = RB_ROOT; |
| 4021 | |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 4022 | /* |
| 4023 | * Our fallback cfqq if cfq_find_alloc_queue() runs into OOM issues. |
| 4024 | * Grab a permanent reference to it, so that the normal code flow |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 4025 | * will not attempt to free it. oom_cfqq is linked to root_group |
| 4026 | * but shouldn't hold a reference as it'll never be unlinked. Lose |
| 4027 | * the reference from linking right away. |
Jens Axboe | 6118b70 | 2009-06-30 09:34:12 +0200 | [diff] [blame] | 4028 | */ |
| 4029 | cfq_init_cfqq(cfqd, &cfqd->oom_cfqq, 1, 0); |
Shaohua Li | 30d7b94 | 2011-01-07 08:46:59 +0100 | [diff] [blame] | 4030 | cfqd->oom_cfqq.ref++; |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 4031 | |
| 4032 | spin_lock_irq(q->queue_lock); |
Tejun Heo | f51b802 | 2012-03-05 13:15:05 -0800 | [diff] [blame] | 4033 | cfq_link_cfqq_cfqg(&cfqd->oom_cfqq, cfqd->root_group); |
Tejun Heo | eb7d8c07 | 2012-03-23 14:02:53 +0100 | [diff] [blame] | 4034 | cfqg_put(cfqd->root_group); |
Tejun Heo | 1adaf3d | 2012-03-05 13:15:15 -0800 | [diff] [blame] | 4035 | spin_unlock_irq(q->queue_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4037 | init_timer(&cfqd->idle_slice_timer); |
| 4038 | cfqd->idle_slice_timer.function = cfq_idle_slice_timer; |
| 4039 | cfqd->idle_slice_timer.data = (unsigned long) cfqd; |
| 4040 | |
Jens Axboe | 23e018a | 2009-10-05 08:52:35 +0200 | [diff] [blame] | 4041 | INIT_WORK(&cfqd->unplug_work, cfq_kick_queue); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | cfqd->cfq_quantum = cfq_quantum; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4044 | cfqd->cfq_fifo_expire[0] = cfq_fifo_expire[0]; |
| 4045 | cfqd->cfq_fifo_expire[1] = cfq_fifo_expire[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4046 | cfqd->cfq_back_max = cfq_back_max; |
| 4047 | cfqd->cfq_back_penalty = cfq_back_penalty; |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4048 | cfqd->cfq_slice[0] = cfq_slice_async; |
| 4049 | cfqd->cfq_slice[1] = cfq_slice_sync; |
| 4050 | cfqd->cfq_slice_async_rq = cfq_slice_async_rq; |
| 4051 | cfqd->cfq_slice_idle = cfq_slice_idle; |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 4052 | cfqd->cfq_group_idle = cfq_group_idle; |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 4053 | cfqd->cfq_latency = 1; |
Corrado Zoccolo | e459dd0 | 2009-11-26 10:02:57 +0100 | [diff] [blame] | 4054 | cfqd->hw_tag = -1; |
Corrado Zoccolo | edc7113 | 2009-12-09 20:56:04 +0100 | [diff] [blame] | 4055 | /* |
| 4056 | * we optimistically start assuming sync ops weren't delayed in last |
| 4057 | * second, in order to have larger depth for async operations. |
| 4058 | */ |
Corrado Zoccolo | 573412b | 2009-12-06 11:48:52 +0100 | [diff] [blame] | 4059 | cfqd->last_delayed_sync = jiffies - HZ; |
Tejun Heo | b2fab5a | 2012-03-05 13:14:57 -0800 | [diff] [blame] | 4060 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | } |
| 4062 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | /* |
| 4064 | * sysfs parts below --> |
| 4065 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4066 | static ssize_t |
| 4067 | cfq_var_show(unsigned int var, char *page) |
| 4068 | { |
| 4069 | return sprintf(page, "%d\n", var); |
| 4070 | } |
| 4071 | |
| 4072 | static ssize_t |
| 4073 | cfq_var_store(unsigned int *var, const char *page, size_t count) |
| 4074 | { |
| 4075 | char *p = (char *) page; |
| 4076 | |
| 4077 | *var = simple_strtoul(p, &p, 10); |
| 4078 | return count; |
| 4079 | } |
| 4080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | #define SHOW_FUNCTION(__FUNC, __VAR, __CONV) \ |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 4082 | static ssize_t __FUNC(struct elevator_queue *e, char *page) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | { \ |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 4084 | struct cfq_data *cfqd = e->elevator_data; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4085 | unsigned int __data = __VAR; \ |
| 4086 | if (__CONV) \ |
| 4087 | __data = jiffies_to_msecs(__data); \ |
| 4088 | return cfq_var_show(__data, (page)); \ |
| 4089 | } |
| 4090 | SHOW_FUNCTION(cfq_quantum_show, cfqd->cfq_quantum, 0); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4091 | SHOW_FUNCTION(cfq_fifo_expire_sync_show, cfqd->cfq_fifo_expire[1], 1); |
| 4092 | SHOW_FUNCTION(cfq_fifo_expire_async_show, cfqd->cfq_fifo_expire[0], 1); |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4093 | SHOW_FUNCTION(cfq_back_seek_max_show, cfqd->cfq_back_max, 0); |
| 4094 | SHOW_FUNCTION(cfq_back_seek_penalty_show, cfqd->cfq_back_penalty, 0); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4095 | SHOW_FUNCTION(cfq_slice_idle_show, cfqd->cfq_slice_idle, 1); |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 4096 | SHOW_FUNCTION(cfq_group_idle_show, cfqd->cfq_group_idle, 1); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4097 | SHOW_FUNCTION(cfq_slice_sync_show, cfqd->cfq_slice[1], 1); |
| 4098 | SHOW_FUNCTION(cfq_slice_async_show, cfqd->cfq_slice[0], 1); |
| 4099 | SHOW_FUNCTION(cfq_slice_async_rq_show, cfqd->cfq_slice_async_rq, 0); |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 4100 | SHOW_FUNCTION(cfq_low_latency_show, cfqd->cfq_latency, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | #undef SHOW_FUNCTION |
| 4102 | |
| 4103 | #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \ |
Jens Axboe | b374d18 | 2008-10-31 10:05:07 +0100 | [diff] [blame] | 4104 | static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | { \ |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 4106 | struct cfq_data *cfqd = e->elevator_data; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | unsigned int __data; \ |
| 4108 | int ret = cfq_var_store(&__data, (page), count); \ |
| 4109 | if (__data < (MIN)) \ |
| 4110 | __data = (MIN); \ |
| 4111 | else if (__data > (MAX)) \ |
| 4112 | __data = (MAX); \ |
| 4113 | if (__CONV) \ |
| 4114 | *(__PTR) = msecs_to_jiffies(__data); \ |
| 4115 | else \ |
| 4116 | *(__PTR) = __data; \ |
| 4117 | return ret; \ |
| 4118 | } |
| 4119 | STORE_FUNCTION(cfq_quantum_store, &cfqd->cfq_quantum, 1, UINT_MAX, 0); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 4120 | STORE_FUNCTION(cfq_fifo_expire_sync_store, &cfqd->cfq_fifo_expire[1], 1, |
| 4121 | UINT_MAX, 1); |
| 4122 | STORE_FUNCTION(cfq_fifo_expire_async_store, &cfqd->cfq_fifo_expire[0], 1, |
| 4123 | UINT_MAX, 1); |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4124 | STORE_FUNCTION(cfq_back_seek_max_store, &cfqd->cfq_back_max, 0, UINT_MAX, 0); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 4125 | STORE_FUNCTION(cfq_back_seek_penalty_store, &cfqd->cfq_back_penalty, 1, |
| 4126 | UINT_MAX, 0); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4127 | STORE_FUNCTION(cfq_slice_idle_store, &cfqd->cfq_slice_idle, 0, UINT_MAX, 1); |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 4128 | STORE_FUNCTION(cfq_group_idle_store, &cfqd->cfq_group_idle, 0, UINT_MAX, 1); |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4129 | STORE_FUNCTION(cfq_slice_sync_store, &cfqd->cfq_slice[1], 1, UINT_MAX, 1); |
| 4130 | STORE_FUNCTION(cfq_slice_async_store, &cfqd->cfq_slice[0], 1, UINT_MAX, 1); |
Jens Axboe | fe094d9 | 2008-01-31 13:08:54 +0100 | [diff] [blame] | 4131 | STORE_FUNCTION(cfq_slice_async_rq_store, &cfqd->cfq_slice_async_rq, 1, |
| 4132 | UINT_MAX, 0); |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 4133 | STORE_FUNCTION(cfq_low_latency_store, &cfqd->cfq_latency, 0, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4134 | #undef STORE_FUNCTION |
| 4135 | |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4136 | #define CFQ_ATTR(name) \ |
| 4137 | __ATTR(name, S_IRUGO|S_IWUSR, cfq_##name##_show, cfq_##name##_store) |
Jens Axboe | 3b18152 | 2005-06-27 10:56:24 +0200 | [diff] [blame] | 4138 | |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4139 | static struct elv_fs_entry cfq_attrs[] = { |
| 4140 | CFQ_ATTR(quantum), |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4141 | CFQ_ATTR(fifo_expire_sync), |
| 4142 | CFQ_ATTR(fifo_expire_async), |
| 4143 | CFQ_ATTR(back_seek_max), |
| 4144 | CFQ_ATTR(back_seek_penalty), |
| 4145 | CFQ_ATTR(slice_sync), |
| 4146 | CFQ_ATTR(slice_async), |
| 4147 | CFQ_ATTR(slice_async_rq), |
| 4148 | CFQ_ATTR(slice_idle), |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 4149 | CFQ_ATTR(group_idle), |
Jens Axboe | 963b72f | 2009-10-03 19:42:18 +0200 | [diff] [blame] | 4150 | CFQ_ATTR(low_latency), |
Al Viro | e572ec7 | 2006-03-18 22:27:18 -0500 | [diff] [blame] | 4151 | __ATTR_NULL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | }; |
| 4153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | static struct elevator_type iosched_cfq = { |
| 4155 | .ops = { |
| 4156 | .elevator_merge_fn = cfq_merge, |
| 4157 | .elevator_merged_fn = cfq_merged_request, |
| 4158 | .elevator_merge_req_fn = cfq_merged_requests, |
Jens Axboe | da77526 | 2006-12-20 11:04:12 +0100 | [diff] [blame] | 4159 | .elevator_allow_merge_fn = cfq_allow_merge, |
Divyesh Shah | 812d402 | 2010-04-08 21:14:23 -0700 | [diff] [blame] | 4160 | .elevator_bio_merged_fn = cfq_bio_merged, |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 4161 | .elevator_dispatch_fn = cfq_dispatch_requests, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | .elevator_add_req_fn = cfq_insert_request, |
Jens Axboe | b4878f2 | 2005-10-20 16:42:29 +0200 | [diff] [blame] | 4163 | .elevator_activate_req_fn = cfq_activate_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | .elevator_deactivate_req_fn = cfq_deactivate_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | .elevator_completed_req_fn = cfq_completed_request, |
Jens Axboe | 21183b0 | 2006-07-13 12:33:14 +0200 | [diff] [blame] | 4166 | .elevator_former_req_fn = elv_rb_former_request, |
| 4167 | .elevator_latter_req_fn = elv_rb_latter_request, |
Tejun Heo | 9b84cac | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4168 | .elevator_init_icq_fn = cfq_init_icq, |
Tejun Heo | 7e5a879 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4169 | .elevator_exit_icq_fn = cfq_exit_icq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | .elevator_set_req_fn = cfq_set_request, |
| 4171 | .elevator_put_req_fn = cfq_put_request, |
| 4172 | .elevator_may_queue_fn = cfq_may_queue, |
| 4173 | .elevator_init_fn = cfq_init_queue, |
| 4174 | .elevator_exit_fn = cfq_exit_queue, |
| 4175 | }, |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4176 | .icq_size = sizeof(struct cfq_io_cq), |
| 4177 | .icq_align = __alignof__(struct cfq_io_cq), |
Al Viro | 3d1ab40 | 2006-03-18 18:35:43 -0500 | [diff] [blame] | 4178 | .elevator_attrs = cfq_attrs, |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4179 | .elevator_name = "cfq", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | .elevator_owner = THIS_MODULE, |
| 4181 | }; |
| 4182 | |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4183 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
| 4184 | static struct blkio_policy_type blkio_policy_cfq = { |
| 4185 | .ops = { |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 4186 | .blkio_init_group_fn = cfq_init_blkio_group, |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4187 | }, |
Vivek Goyal | 062a644 | 2010-09-15 17:06:33 -0400 | [diff] [blame] | 4188 | .plid = BLKIO_POLICY_PROP, |
Tejun Heo | 0381411 | 2012-03-05 13:15:14 -0800 | [diff] [blame] | 4189 | .pdata_size = sizeof(struct cfq_group), |
Tejun Heo | 60c2bc2 | 2012-04-01 14:38:43 -0700 | [diff] [blame] | 4190 | .cftypes = cfq_blkcg_files, |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4191 | }; |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4192 | #endif |
| 4193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | static int __init cfq_init(void) |
| 4195 | { |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4196 | int ret; |
| 4197 | |
Jens Axboe | 22e2c50 | 2005-06-27 10:55:12 +0200 | [diff] [blame] | 4198 | /* |
| 4199 | * could be 0 on HZ < 1000 setups |
| 4200 | */ |
| 4201 | if (!cfq_slice_async) |
| 4202 | cfq_slice_async = 1; |
| 4203 | if (!cfq_slice_idle) |
| 4204 | cfq_slice_idle = 1; |
| 4205 | |
Vivek Goyal | 80bdf0c | 2010-08-23 12:24:26 +0200 | [diff] [blame] | 4206 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
| 4207 | if (!cfq_group_idle) |
| 4208 | cfq_group_idle = 1; |
| 4209 | #else |
| 4210 | cfq_group_idle = 0; |
| 4211 | #endif |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4212 | cfq_pool = KMEM_CACHE(cfq_queue, 0); |
| 4213 | if (!cfq_pool) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | return -ENOMEM; |
| 4215 | |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4216 | ret = elv_register(&iosched_cfq); |
| 4217 | if (ret) { |
| 4218 | kmem_cache_destroy(cfq_pool); |
| 4219 | return ret; |
| 4220 | } |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4221 | |
Tejun Heo | b95ada5 | 2012-03-05 13:14:55 -0800 | [diff] [blame] | 4222 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4223 | blkio_policy_register(&blkio_policy_cfq); |
Tejun Heo | b95ada5 | 2012-03-05 13:14:55 -0800 | [diff] [blame] | 4224 | #endif |
Adrian Bunk | 2fdd82b | 2007-12-12 18:51:56 +0100 | [diff] [blame] | 4225 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | } |
| 4227 | |
| 4228 | static void __exit cfq_exit(void) |
| 4229 | { |
Tejun Heo | b95ada5 | 2012-03-05 13:14:55 -0800 | [diff] [blame] | 4230 | #ifdef CONFIG_CFQ_GROUP_IOSCHED |
Vivek Goyal | 3e25206 | 2009-12-04 10:36:42 -0500 | [diff] [blame] | 4231 | blkio_policy_unregister(&blkio_policy_cfq); |
Tejun Heo | b95ada5 | 2012-03-05 13:14:55 -0800 | [diff] [blame] | 4232 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | elv_unregister(&iosched_cfq); |
Tejun Heo | 3d3c237 | 2011-12-14 00:33:42 +0100 | [diff] [blame] | 4234 | kmem_cache_destroy(cfq_pool); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | module_init(cfq_init); |
| 4238 | module_exit(cfq_exit); |
| 4239 | |
| 4240 | MODULE_AUTHOR("Jens Axboe"); |
| 4241 | MODULE_LICENSE("GPL"); |
| 4242 | MODULE_DESCRIPTION("Completely Fair Queueing IO scheduler"); |