• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/block/

Lines Matching defs:cfqq

54 #define CFQQ_SEEKY(cfqq)	(hweight32(cfqq->seek_history) > 32/8)
72 #define cfq_class_idle(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
73 #define cfq_class_rt(cfqq) ((cfqq)->ioprio_class == IOPRIO_CLASS_RT)
184 /* number of cfqq currently on this group */
287 * Fallback dummy cfqq for extreme OOM conditions
323 CFQ_CFQQ_FLAG_coop, /* cfqq is shared */
324 CFQ_CFQQ_FLAG_split_coop, /* shared cfqq will be splitted */
325 CFQ_CFQQ_FLAG_deep, /* sync cfqq experienced large depth */
330 static inline void cfq_mark_cfqq_##name(struct cfq_queue *cfqq) \
332 (cfqq)->flags |= (1 << CFQ_CFQQ_FLAG_##name); \
334 static inline void cfq_clear_cfqq_##name(struct cfq_queue *cfqq) \
336 (cfqq)->flags &= ~(1 << CFQ_CFQQ_FLAG_##name); \
338 static inline int cfq_cfqq_##name(const struct cfq_queue *cfqq) \
340 return ((cfqq)->flags & (1 << CFQ_CFQQ_FLAG_##name)) != 0; \
359 #define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
360 blk_add_trace_msg((cfqd)->queue, "cfq%d%c %s " fmt, (cfqq)->pid, \
361 cfq_cfqq_sync((cfqq)) ? 'S' : 'A', \
362 blkg_path(&(cfqq)->cfqg->blkg), ##args);
369 #define cfq_log_cfqq(cfqd, cfqq, fmt, args...) \
370 blk_add_trace_msg((cfqd)->queue, "cfq%d " fmt, (cfqq)->pid, ##args)
402 static inline enum wl_prio_t cfqq_prio(struct cfq_queue *cfqq)
404 if (cfq_class_idle(cfqq))
406 if (cfq_class_rt(cfqq))
412 static enum wl_type_t cfqq_type(struct cfq_queue *cfqq)
414 if (!cfq_cfqq_sync(cfqq))
416 if (!cfq_cfqq_idle_window(cfqq))
449 return cic->cfqq[is_sync];
453 struct cfq_queue *cfqq, bool is_sync)
455 cic->cfqq[is_sync] = cfqq;
520 cfq_prio_to_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
522 return cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio);
600 cfq_set_prio_slice(struct cfq_data *cfqd, struct cfq_queue *cfqq)
602 unsigned slice = cfq_prio_to_slice(cfqd, cfqq);
608 unsigned iq = cfq_group_get_avg_queues(cfqd, cfqq->cfqg,
609 cfq_class_rt(cfqq));
612 unsigned group_slice = cfq_group_slice(cfqd, cfqq->cfqg);
626 cfqq->slice_start = jiffies;
627 cfqq->slice_end = jiffies + slice;
628 cfqq->allocated_slice = slice;
629 cfq_log_cfqq(cfqd, cfqq, "set_slice=%lu", cfqq->slice_end - jiffies);
637 static inline bool cfq_slice_used(struct cfq_queue *cfqq)
639 if (cfq_cfqq_slice_new(cfqq))
641 if (time_before(jiffies, cfqq->slice_end))
788 cfq_find_next_rq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
803 rbnext = rb_first(&cfqq->sort_list);
812 struct cfq_queue *cfqq)
817 return (cfqq->cfqg->nr_cfqq - 1) * (cfq_prio_slice(cfqd, 1, 0) -
818 cfq_prio_slice(cfqd, cfq_cfqq_sync(cfqq), cfqq->ioprio));
907 static inline unsigned int cfq_cfqq_slice_usage(struct cfq_queue *cfqq)
915 if (!cfqq->slice_start || cfqq->slice_start == jiffies) {
922 slice_used = max_t(unsigned, (jiffies - cfqq->dispatch_start),
925 slice_used = jiffies - cfqq->slice_start;
926 if (slice_used > cfqq->allocated_slice)
927 slice_used = cfqq->allocated_slice;
934 struct cfq_queue *cfqq)
942 used_sl = charge = cfq_cfqq_slice_usage(cfqq);
945 charge = cfqq->slice_dispatch;
946 else if (!cfq_cfqq_sync(cfqq) && !nr_sync)
947 charge = cfqq->allocated_slice;
965 cfq_log_cfqq(cfqq->cfqd, cfqq, "sl_used=%u disp=%u charge=%u iops=%u"
966 " sect=%u", used_sl, cfqq->slice_dispatch, charge,
967 iops_mode(cfqd), cfqq->nr_sectors);
1069 static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
1072 if (!cfq_cfqq_sync(cfqq))
1073 cfqg = &cfqq->cfqd->root_group;
1075 cfqq->cfqg = cfqg;
1076 /* cfqq reference on cfqg */
1077 atomic_inc(&cfqq->cfqg->ref);
1159 cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg) {
1160 cfqq->cfqg = cfqg;
1173 static void cfq_service_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1186 && cfqq_type(cfqq) == SYNC_NOIDLE_WORKLOAD
1187 && cfqq->cfqg && cfqq->cfqg != &cfqd->root_group) {
1189 cfq_log_cfqq(cfqd, cfqq, "moving to root group");
1190 if (!RB_EMPTY_NODE(&cfqq->rb_node))
1191 cfq_group_service_tree_del(cfqd, cfqq->cfqg);
1192 cfqq->orig_cfqg = cfqq->cfqg;
1193 cfqq->cfqg = &cfqd->root_group;
1197 && cfqq_type(cfqq) == SYNC_WORKLOAD && cfqq->orig_cfqg) {
1198 /* cfqq is sequential now needs to go to its original group */
1199 BUG_ON(cfqq->cfqg != &cfqd->root_group);
1200 if (!RB_EMPTY_NODE(&cfqq->rb_node))
1201 cfq_group_service_tree_del(cfqd, cfqq->cfqg);
1202 cfq_put_cfqg(cfqq->cfqg);
1203 cfqq->cfqg = cfqq->orig_cfqg;
1204 cfqq->orig_cfqg = NULL;
1206 cfq_log_cfqq(cfqd, cfqq, "moved to origin group");
1210 service_tree = service_tree_for(cfqq->cfqg, cfqq_prio(cfqq),
1211 cfqq_type(cfqq));
1212 if (cfq_class_idle(cfqq)) {
1215 if (parent && parent != &cfqq->rb_node) {
1227 rb_key = cfq_slice_offset(cfqd, cfqq) + jiffies;
1228 rb_key -= cfqq->slice_resid;
1229 cfqq->slice_resid = 0;
1236 if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
1241 if (rb_key == cfqq->rb_key &&
1242 cfqq->service_tree == service_tree)
1245 cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
1246 cfqq->service_tree = NULL;
1251 cfqq->service_tree = service_tree;
1273 service_tree->left = &cfqq->rb_node;
1275 cfqq->rb_key = rb_key;
1276 rb_link_node(&cfqq->rb_node, parent, p);
1277 rb_insert_color(&cfqq->rb_node, &service_tree->rb);
1281 cfq_group_service_tree_add(cfqd, cfqq->cfqg);
1290 struct cfq_queue *cfqq = NULL;
1298 cfqq = rb_entry(parent, struct cfq_queue, p_node);
1304 if (sector > blk_rq_pos(cfqq->next_rq))
1306 else if (sector < blk_rq_pos(cfqq->next_rq))
1311 cfqq = NULL;
1317 return cfqq;
1320 static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1325 if (cfqq->p_root) {
1326 rb_erase(&cfqq->p_node, cfqq->p_root);
1327 cfqq->p_root = NULL;
1330 if (cfq_class_idle(cfqq))
1332 if (!cfqq->next_rq)
1335 cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
1336 __cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
1337 blk_rq_pos(cfqq->next_rq), &parent, &p);
1339 rb_link_node(&cfqq->p_node, parent, p);
1340 rb_insert_color(&cfqq->p_node, cfqq->p_root);
1342 cfqq->p_root = NULL;
1346 * Update cfqq's position in the service tree.
1348 static void cfq_resort_rr_list(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1351 * Resorting requires the cfqq to be on the RR list already.
1353 if (cfq_cfqq_on_rr(cfqq)) {
1354 cfq_service_tree_add(cfqd, cfqq, 0);
1355 cfq_prio_tree_add(cfqd, cfqq);
1363 static void cfq_add_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1365 cfq_log_cfqq(cfqd, cfqq, "add_to_rr");
1366 BUG_ON(cfq_cfqq_on_rr(cfqq));
1367 cfq_mark_cfqq_on_rr(cfqq);
1370 cfq_resort_rr_list(cfqd, cfqq);
1374 * Called when the cfqq no longer has requests pending, remove it from
1377 static void cfq_del_cfqq_rr(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1379 cfq_log_cfqq(cfqd, cfqq, "del_from_rr");
1380 BUG_ON(!cfq_cfqq_on_rr(cfqq));
1381 cfq_clear_cfqq_on_rr(cfqq);
1383 if (!RB_EMPTY_NODE(&cfqq->rb_node)) {
1384 cfq_rb_erase(&cfqq->rb_node, cfqq->service_tree);
1385 cfqq->service_tree = NULL;
1387 if (cfqq->p_root) {
1388 rb_erase(&cfqq->p_node, cfqq->p_root);
1389 cfqq->p_root = NULL;
1392 cfq_group_service_tree_del(cfqd, cfqq->cfqg);
1402 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1405 BUG_ON(!cfqq->queued[sync]);
1406 cfqq->queued[sync]--;
1408 elv_rb_del(&cfqq->sort_list, rq);
1410 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list)) {
1416 if (cfqq->p_root) {
1417 rb_erase(&cfqq->p_node, cfqq->p_root);
1418 cfqq->p_root = NULL;
1425 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1426 struct cfq_data *cfqd = cfqq->cfqd;
1429 cfqq->queued[rq_is_sync(rq)]++;
1435 while ((__alias = elv_rb_add(&cfqq->sort_list, rq)) != NULL)
1438 if (!cfq_cfqq_on_rr(cfqq))
1439 cfq_add_cfqq_rr(cfqd, cfqq);
1444 prev = cfqq->next_rq;
1445 cfqq->next_rq = cfq_choose_req(cfqd, cfqq->next_rq, rq, cfqd->last_position);
1450 if (prev != cfqq->next_rq)
1451 cfq_prio_tree_add(cfqd, cfqq);
1453 BUG_ON(!cfqq->next_rq);
1456 static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq)
1458 elv_rb_del(&cfqq->sort_list, rq);
1459 cfqq->queued[rq_is_sync(rq)]--;
1464 &cfqq->cfqd->serving_group->blkg, rq_data_dir(rq),
1473 struct cfq_queue *cfqq;
1479 cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio));
1480 if (cfqq) {
1483 return elv_rb_find(&cfqq->sort_list, sector);
1512 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1514 if (cfqq->next_rq == rq)
1515 cfqq->next_rq = cfq_find_next_rq(cfqq->cfqd, cfqq, rq);
1520 cfqq->cfqd->rq_queued--;
1524 WARN_ON(!cfqq->meta_pending);
1525 cfqq->meta_pending--;
1548 struct cfq_queue *cfqq = RQ_CFQQ(req);
1550 cfq_reposition_rq_rb(cfqq, req);
1565 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1575 if (cfqq->next_rq == next)
1576 cfqq->next_rq = rq;
1587 struct cfq_queue *cfqq;
1596 * Lookup the cfqq that this bio will be queued with. Allow
1603 cfqq = cic_to_cfqq(cic, cfq_bio_sync(bio));
1604 return cfqq == RQ_CFQQ(rq);
1607 static inline void cfq_del_timer(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1610 cfq_blkiocg_update_idle_time_stats(&cfqq->cfqg->blkg);
1614 struct cfq_queue *cfqq)
1616 if (cfqq) {
1617 cfq_log_cfqq(cfqd, cfqq, "set_active wl_prio:%d wl_type:%d",
1619 cfq_blkiocg_update_avg_queue_size_stats(&cfqq->cfqg->blkg);
1620 cfqq->slice_start = 0;
1621 cfqq->dispatch_start = jiffies;
1622 cfqq->allocated_slice = 0;
1623 cfqq->slice_end = 0;
1624 cfqq->slice_dispatch = 0;
1625 cfqq->nr_sectors = 0;
1627 cfq_clear_cfqq_wait_request(cfqq);
1628 cfq_clear_cfqq_must_dispatch(cfqq);
1629 cfq_clear_cfqq_must_alloc_slice(cfqq);
1630 cfq_clear_cfqq_fifo_expire(cfqq);
1631 cfq_mark_cfqq_slice_new(cfqq);
1633 cfq_del_timer(cfqd, cfqq);
1636 cfqd->active_queue = cfqq;
1640 * current cfqq expired its slice (or was too idle), select new one
1643 __cfq_slice_expired(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1646 cfq_log_cfqq(cfqd, cfqq, "slice expired t=%d", timed_out);
1648 if (cfq_cfqq_wait_request(cfqq))
1649 cfq_del_timer(cfqd, cfqq);
1651 cfq_clear_cfqq_wait_request(cfqq);
1652 cfq_clear_cfqq_wait_busy(cfqq);
1655 * If this cfqq is shared between multiple processes, check to
1660 if (cfq_cfqq_coop(cfqq) && CFQQ_SEEKY(cfqq))
1661 cfq_mark_cfqq_split_coop(cfqq);
1666 if (timed_out && !cfq_cfqq_slice_new(cfqq)) {
1667 cfqq->slice_resid = cfqq->slice_end - jiffies;
1668 cfq_log_cfqq(cfqd, cfqq, "resid=%ld", cfqq->slice_resid);
1671 cfq_group_served(cfqd, cfqq->cfqg, cfqq);
1673 if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list))
1674 cfq_del_cfqq_rr(cfqd, cfqq);
1676 cfq_resort_rr_list(cfqd, cfqq);
1678 if (cfqq == cfqd->active_queue)
1681 if (&cfqq->cfqg->rb_node == cfqd->grp_service_tree.active)
1692 struct cfq_queue *cfqq = cfqd->active_queue;
1694 if (cfqq)
1695 __cfq_slice_expired(cfqd, cfqq, timed_out);
1700 * we'll simply select the first cfqq in the service tree.
1722 struct cfq_queue *cfqq;
1734 if ((cfqq = cfq_rb_first(st)) != NULL)
1735 return cfqq;
1743 struct cfq_queue *cfqq)
1745 if (!cfqq)
1746 cfqq = cfq_get_next_queue(cfqd);
1748 __cfq_set_active_queue(cfqd, cfqq);
1749 return cfqq;
1761 static inline int cfq_rq_close(struct cfq_data *cfqd, struct cfq_queue *cfqq,
1821 struct cfq_queue *cfqq;
1841 cfqq = cfqq_close(cfqd, cur_cfqq);
1842 if (!cfqq)
1846 if (cur_cfqq->cfqg != cfqq->cfqg)
1852 if (!cfq_cfqq_sync(cfqq))
1854 if (CFQQ_SEEKY(cfqq))
1860 if (cfq_class_rt(cfqq) != cfq_class_rt(cur_cfqq))
1863 return cfqq;
1870 static bool cfq_should_idle(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1872 enum wl_prio_t prio = cfqq_prio(cfqq);
1873 struct cfq_rb_root *service_tree = cfqq->service_tree;
1886 if (cfq_cfqq_idle_window(cfqq) &&
1894 if (service_tree->count == 1 && cfq_cfqq_sync(cfqq))
1896 cfq_log_cfqq(cfqd, cfqq, "Not idling. st->count:%d",
1903 struct cfq_queue *cfqq = cfqd->active_queue;
1915 WARN_ON(!RB_EMPTY_ROOT(&cfqq->sort_list));
1916 WARN_ON(cfq_cfqq_slice_new(cfqq));
1921 if (!cfq_should_idle(cfqd, cfqq)) {
1932 if (cfqq->dispatched)
1948 (cfqq->slice_end - jiffies < cic->ttime_mean)) {
1949 cfq_log_cfqq(cfqd, cfqq, "Not idling. think_time:%d",
1955 if (group_idle && cfqq->cfqg->nr_cfqq > 1)
1958 cfq_mark_cfqq_wait_request(cfqq);
1966 cfq_blkiocg_update_set_idle_time_stats(&cfqq->cfqg->blkg);
1967 cfq_log_cfqq(cfqd, cfqq, "arm_idle: %lu group_idle: %d", sl,
1977 struct cfq_queue *cfqq = RQ_CFQQ(rq);
1979 cfq_log_cfqq(cfqd, cfqq, "dispatch_insert");
1981 cfqq->next_rq = cfq_find_next_rq(cfqd, cfqq, rq);
1983 cfqq->dispatched++;
1987 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]++;
1988 cfqq->nr_sectors += blk_rq_sectors(rq);
1989 cfq_blkiocg_update_dispatch_stats(&cfqq->cfqg->blkg, blk_rq_bytes(rq),
1996 static struct request *cfq_check_fifo(struct cfq_queue *cfqq)
2000 if (cfq_cfqq_fifo_expire(cfqq))
2003 cfq_mark_cfqq_fifo_expire(cfqq);
2005 if (list_empty(&cfqq->fifo))
2008 rq = rq_entry_fifo(cfqq->fifo.next);
2012 cfq_log_cfqq(cfqq->cfqd, cfqq, "fifo=%p", rq);
2017 cfq_prio_to_maxrq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2021 WARN_ON(cfqq->ioprio >= IOPRIO_BE_NR);
2023 return 2 * (base_rq + base_rq * (CFQ_PRIO_LISTS - 1 - cfqq->ioprio));
2029 static int cfqq_process_refs(struct cfq_queue *cfqq)
2033 io_refs = cfqq->allocated[READ] + cfqq->allocated[WRITE];
2034 process_refs = atomic_read(&cfqq->ref) - io_refs;
2039 static void cfq_setup_merge(struct cfq_queue *cfqq, struct cfq_queue *new_cfqq)
2046 * unsafe to follow the ->new_cfqq chain as other cfqq's in the
2055 if (__cfqq == cfqq)
2060 process_refs = cfqq_process_refs(cfqq);
2063 * If the process for the cfqq has gone away, there is no
2073 cfqq->new_cfqq = new_cfqq;
2076 new_cfqq->new_cfqq = cfqq;
2077 atomic_add(new_process_refs, &cfqq->ref);
2222 struct cfq_queue *cfqq, *new_cfqq = NULL;
2224 cfqq = cfqd->active_queue;
2225 if (!cfqq)
2234 if (cfq_cfqq_wait_busy(cfqq) && !RB_EMPTY_ROOT(&cfqq->sort_list))
2240 if (cfq_slice_used(cfqq) && !cfq_cfqq_must_dispatch(cfqq)) {
2250 if (cfqq->cfqg->nr_cfqq == 1 && RB_EMPTY_ROOT(&cfqq->sort_list)
2251 && cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
2252 cfqq = NULL;
2262 if (!RB_EMPTY_ROOT(&cfqq->sort_list))
2269 * tree. If possible, merge the expiring queue with the new cfqq.
2271 new_cfqq = cfq_close_cooperator(cfqd, cfqq);
2273 if (!cfqq->new_cfqq)
2274 cfq_setup_merge(cfqq, new_cfqq);
2284 cfqq = NULL;
2288 if (cfqq->dispatched && cfq_should_idle(cfqd, cfqq)) {
2289 cfqq = NULL;
2298 if (cfqd->cfq_group_idle && cfqq->cfqg->nr_cfqq == 1
2299 && cfqq->cfqg->dispatched) {
2300 cfqq = NULL;
2314 cfqq = cfq_set_active_queue(cfqd, new_cfqq);
2316 return cfqq;
2319 static int __cfq_forced_dispatch_cfqq(struct cfq_queue *cfqq)
2323 while (cfqq->next_rq) {
2324 cfq_dispatch_insert(cfqq->cfqd->queue, cfqq->next_rq);
2328 BUG_ON(!list_empty(&cfqq->fifo));
2330 /* By default cfqq is not expired if it is empty. Do it explicitly */
2331 __cfq_slice_expired(cfqq->cfqd, cfqq, 0);
2341 struct cfq_queue *cfqq;
2346 while ((cfqq = cfq_get_next_queue_forced(cfqd)) != NULL) {
2347 __cfq_set_active_queue(cfqd, cfqq);
2348 dispatched += __cfq_forced_dispatch_cfqq(cfqq);
2358 struct cfq_queue *cfqq)
2361 if (cfq_cfqq_slice_new(cfqq))
2363 if (time_after(jiffies + cfqd->cfq_slice_idle * cfqq->dispatched,
2364 cfqq->slice_end))
2370 static bool cfq_may_dispatch(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2377 if (cfq_should_idle(cfqd, cfqq) && cfqd->rq_in_flight[BLK_RW_ASYNC])
2383 if (cfqd->rq_in_flight[BLK_RW_SYNC] && !cfq_cfqq_sync(cfqq))
2387 if (cfq_class_idle(cfqq))
2391 * Does this cfqq already have too much IO in flight?
2393 if (cfqq->dispatched >= max_dispatch) {
2397 if (cfq_class_idle(cfqq))
2403 if (cfqd->busy_queues > 1 && cfq_slice_used_soon(cfqd, cfqq))
2413 * Normally we start throttling cfqq when cfq_quantum/2
2426 if (!cfq_cfqq_sync(cfqq) && cfqd->cfq_latency) {
2431 if (!depth && !cfqq->dispatched)
2440 return cfqq->dispatched < max_dispatch;
2444 * Dispatch a request from cfqq, moving them to the request queue
2447 static bool cfq_dispatch_request(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2451 BUG_ON(RB_EMPTY_ROOT(&cfqq->sort_list));
2453 if (!cfq_may_dispatch(cfqd, cfqq))
2459 rq = cfq_check_fifo(cfqq);
2461 rq = cfqq->next_rq;
2479 * Find the cfqq that we need to service and move a request from that to the
2485 struct cfq_queue *cfqq;
2493 cfqq = cfq_select_queue(cfqd);
2494 if (!cfqq)
2498 * Dispatch a request from this cfqq, if it is allowed
2500 if (!cfq_dispatch_request(cfqd, cfqq))
2503 cfqq->slice_dispatch++;
2504 cfq_clear_cfqq_must_dispatch(cfqq);
2510 if (cfqd->busy_queues > 1 && ((!cfq_cfqq_sync(cfqq) &&
2511 cfqq->slice_dispatch >= cfq_prio_to_maxrq(cfqd, cfqq)) ||
2512 cfq_class_idle(cfqq))) {
2513 cfqq->slice_end = jiffies + 1;
2517 cfq_log_cfqq(cfqd, cfqq, "dispatched a request");
2528 static void cfq_put_queue(struct cfq_queue *cfqq)
2530 struct cfq_data *cfqd = cfqq->cfqd;
2533 BUG_ON(atomic_read(&cfqq->ref) <= 0);
2535 if (!atomic_dec_and_test(&cfqq->ref))
2538 cfq_log_cfqq(cfqd, cfqq, "put_queue");
2539 BUG_ON(rb_first(&cfqq->sort_list));
2540 BUG_ON(cfqq->allocated[READ] + cfqq->allocated[WRITE]);
2541 cfqg = cfqq->cfqg;
2542 orig_cfqg = cfqq->orig_cfqg;
2544 if (unlikely(cfqd->active_queue == cfqq)) {
2545 __cfq_slice_expired(cfqd, cfqq, 0);
2549 BUG_ON(cfq_cfqq_on_rr(cfqq));
2550 kmem_cache_free(cfq_pool, cfqq);
2642 static void cfq_put_cooperator(struct cfq_queue *cfqq)
2651 __cfqq = cfqq->new_cfqq;
2653 if (__cfqq == cfqq) {
2654 WARN(1, "cfqq->new_cfqq loop detected\n");
2663 static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq)
2665 if (unlikely(cfqq == cfqd->active_queue)) {
2666 __cfq_slice_expired(cfqd, cfqq, 0);
2670 cfq_put_cooperator(cfqq);
2672 cfq_put_queue(cfqq);
2691 if (cic->cfqq[BLK_RW_ASYNC]) {
2692 cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_ASYNC]);
2693 cic->cfqq[BLK_RW_ASYNC] = NULL;
2696 if (cic->cfqq[BLK_RW_SYNC]) {
2697 cfq_exit_cfqq(cfqd, cic->cfqq[BLK_RW_SYNC]);
2698 cic->cfqq[BLK_RW_SYNC] = NULL;
2753 static void cfq_init_prio_data(struct cfq_queue *cfqq, struct io_context *ioc)
2758 if (!cfq_cfqq_prio_changed(cfqq))
2769 cfqq->ioprio = task_nice_ioprio(tsk);
2770 cfqq->ioprio_class = task_nice_ioclass(tsk);
2773 cfqq->ioprio = task_ioprio(ioc);
2774 cfqq->ioprio_class = IOPRIO_CLASS_RT;
2777 cfqq->ioprio = task_ioprio(ioc);
2778 cfqq->ioprio_class = IOPRIO_CLASS_BE;
2781 cfqq->ioprio_class = IOPRIO_CLASS_IDLE;
2782 cfqq->ioprio = 7;
2783 cfq_clear_cfqq_idle_window(cfqq);
2791 cfqq->org_ioprio = cfqq->ioprio;
2792 cfqq->org_ioprio_class = cfqq->ioprio_class;
2793 cfq_clear_cfqq_prio_changed(cfqq);
2799 struct cfq_queue *cfqq;
2807 cfqq = cic->cfqq[BLK_RW_ASYNC];
2808 if (cfqq) {
2813 cic->cfqq[BLK_RW_ASYNC] = new_cfqq;
2814 cfq_put_queue(cfqq);
2818 cfqq = cic->cfqq[BLK_RW_SYNC];
2819 if (cfqq)
2820 cfq_mark_cfqq_prio_changed(cfqq);
2831 static void cfq_init_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq,
2834 RB_CLEAR_NODE(&cfqq->rb_node);
2835 RB_CLEAR_NODE(&cfqq->p_node);
2836 INIT_LIST_HEAD(&cfqq->fifo);
2838 atomic_set(&cfqq->ref, 0);
2839 cfqq->cfqd = cfqd;
2841 cfq_mark_cfqq_prio_changed(cfqq);
2844 if (!cfq_class_idle(cfqq))
2845 cfq_mark_cfqq_idle_window(cfqq);
2846 cfq_mark_cfqq_sync(cfqq);
2848 cfqq->pid = pid;
2890 struct cfq_queue *cfqq, *new_cfqq = NULL;
2898 cfqq = cic_to_cfqq(cic, is_sync);
2901 * Always try a new alloc if we fell back to the OOM cfqq
2904 if (!cfqq || cfqq == &cfqd->oom_cfqq) {
2905 cfqq = NULL;
2907 cfqq = new_cfqq;
2918 cfqq = kmem_cache_alloc_node(cfq_pool,
2923 if (cfqq) {
2924 cfq_init_cfqq(cfqd, cfqq, current->pid, is_sync);
2925 cfq_init_prio_data(cfqq, ioc);
2926 cfq_link_cfqq_cfqg(cfqq, cfqg);
2927 cfq_log_cfqq(cfqd, cfqq, "alloced");
2929 cfqq = &cfqd->oom_cfqq;
2935 return cfqq;
2960 struct cfq_queue *cfqq = NULL;
2964 cfqq = *async_cfqq;
2967 if (!cfqq)
2968 cfqq = cfq_find_alloc_queue(cfqd, is_sync, ioc, gfp_mask);
2974 atomic_inc(&cfqq->ref);
2975 *async_cfqq = cfqq;
2978 atomic_inc(&cfqq->ref);
2979 return cfqq;
3140 cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_queue *cfqq,
3145 if (cfqq->last_request_pos) {
3146 if (cfqq->last_request_pos < blk_rq_pos(rq))
3147 sdist = blk_rq_pos(rq) - cfqq->last_request_pos;
3149 sdist = cfqq->last_request_pos - blk_rq_pos(rq);
3152 cfqq->seek_history <<= 1;
3154 cfqq->seek_history |= (n_sec < CFQQ_SECT_THR_NONROT);
3156 cfqq->seek_history |= (sdist > CFQQ_SEEK_THR);
3164 cfq_update_idle_window(struct cfq_data *cfqd, struct cfq_queue *cfqq,
3172 if (!cfq_cfqq_sync(cfqq) || cfq_class_idle(cfqq))
3175 enable_idle = old_idle = cfq_cfqq_idle_window(cfqq);
3177 if (cfqq->queued[0] + cfqq->queued[1] >= 4)
3178 cfq_mark_cfqq_deep(cfqq);
3181 (!cfq_cfqq_deep(cfqq) && CFQQ_SEEKY(cfqq)))
3191 cfq_log_cfqq(cfqd, cfqq, "idle=%d", enable_idle);
3193 cfq_mark_cfqq_idle_window(cfqq);
3195 cfq_clear_cfqq_idle_window(cfqq);
3207 struct cfq_queue *cfqq;
3209 cfqq = cfqd->active_queue;
3210 if (!cfqq)
3216 if (cfq_class_idle(cfqq))
3220 * Don't allow a non-RT request to preempt an ongoing RT cfqq timeslice.
3222 if (cfq_class_rt(cfqq) && !cfq_class_rt(new_cfqq))
3229 if (rq_is_sync(rq) && !cfq_cfqq_sync(cfqq))
3232 if (new_cfqq->cfqg != cfqq->cfqg)
3235 if (cfq_slice_used(cfqq))
3242 RB_EMPTY_ROOT(&cfqq->sort_list))
3249 if ((rq->cmd_flags & REQ_META) && !cfqq->meta_pending)
3253 * Allow an RT request to pre-empt an ongoing non-RT cfqq timeslice.
3255 if (cfq_class_rt(new_cfqq) && !cfq_class_rt(cfqq))
3258 if (!cfqd->active_cic || !cfq_cfqq_wait_request(cfqq))
3263 * current cfqq, let it preempt
3265 if (cfq_rq_close(cfqd, cfqq, rq))
3272 * cfqq preempts the active queue. if we allowed preempt with no slice left,
3275 static void cfq_preempt_queue(struct cfq_data *cfqd, struct cfq_queue *cfqq)
3277 cfq_log_cfqq(cfqd, cfqq, "preempt");
3284 BUG_ON(!cfq_cfqq_on_rr(cfqq));
3286 cfq_service_tree_add(cfqd, cfqq, 1);
3288 cfqq->slice_end = 0;
3289 cfq_mark_cfqq_slice_new(cfqq);
3293 * Called when a new fs request (rq) is added (to cfqq). Check if there's
3297 cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
3304 cfqq->meta_pending++;
3307 cfq_update_io_seektime(cfqd, cfqq, rq);
3308 cfq_update_idle_window(cfqd, cfqq, cic);
3310 cfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
3312 if (cfqq == cfqd->active_queue) {
3323 if (cfq_cfqq_wait_request(cfqq)) {
3326 cfq_del_timer(cfqd, cfqq);
3327 cfq_clear_cfqq_wait_request(cfqq);
3331 &cfqq->cfqg->blkg);
3332 cfq_mark_cfqq_must_dispatch(cfqq);
3335 } else if (cfq_should_preempt(cfqd, cfqq, rq)) {
3342 cfq_preempt_queue(cfqd, cfqq);
3350 struct cfq_queue *cfqq = RQ_CFQQ(rq);
3352 cfq_log_cfqq(cfqd, cfqq, "insert_request");
3353 cfq_init_prio_data(cfqq, RQ_CIC(rq)->ioc);
3356 list_add_tail(&rq->queuelist, &cfqq->fifo);
3361 cfq_rq_enqueued(cfqd, cfqq, rq);
3370 struct cfq_queue *cfqq = cfqd->active_queue;
3387 if (cfqq && cfq_cfqq_idle_window(cfqq) &&
3388 cfqq->dispatched + cfqq->queued[0] + cfqq->queued[1] <
3401 static bool cfq_should_wait_busy(struct cfq_data *cfqd, struct cfq_queue *cfqq)
3406 if (!RB_EMPTY_ROOT(&cfqq->sort_list))
3410 if (cfqq->cfqg->nr_cfqq > 1)
3413 if (cfq_slice_used(cfqq))
3418 && (cfqq->slice_end - jiffies < cic->ttime_mean))
3428 if (cfqq->slice_end - jiffies == 1)
3436 struct cfq_queue *cfqq = RQ_CFQQ(rq);
3437 struct cfq_data *cfqd = cfqq->cfqd;
3442 cfq_log_cfqq(cfqd, cfqq, "complete rqnoidle %d",
3448 WARN_ON(!cfqq->dispatched);
3450 cfqq->dispatched--;
3452 cfq_blkiocg_update_completion_stats(&cfqq->cfqg->blkg,
3456 cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--;
3468 if (cfqd->active_queue == cfqq) {
3469 const bool cfqq_empty = RB_EMPTY_ROOT(&cfqq->sort_list);
3471 if (cfq_cfqq_slice_new(cfqq)) {
3472 cfq_set_prio_slice(cfqd, cfqq);
3473 cfq_clear_cfqq_slice_new(cfqq);
3480 if (cfq_should_wait_busy(cfqd, cfqq)) {
3484 cfqq->slice_end = jiffies + extend_sl;
3485 cfq_mark_cfqq_wait_busy(cfqq);
3486 cfq_log_cfqq(cfqd, cfqq, "will busy wait");
3497 if (cfq_slice_used(cfqq) || cfq_class_idle(cfqq))
3500 !cfq_close_cooperator(cfqd, cfqq)) {
3510 || cfqq->cfqg->nr_cfqq == 1)
3523 static void cfq_prio_boost(struct cfq_queue *cfqq)
3530 if (cfq_class_idle(cfqq))
3531 cfqq->ioprio_class = IOPRIO_CLASS_BE;
3532 if (cfqq->ioprio > IOPRIO_NORM)
3533 cfqq->ioprio = IOPRIO_NORM;
3538 cfqq->ioprio_class = cfqq->org_ioprio_class;
3539 cfqq->ioprio = cfqq->org_ioprio;
3543 static inline int __cfq_may_queue(struct cfq_queue *cfqq)
3545 if (cfq_cfqq_wait_request(cfqq) && !cfq_cfqq_must_alloc_slice(cfqq)) {
3546 cfq_mark_cfqq_must_alloc_slice(cfqq);
3558 struct cfq_queue *cfqq;
3570 cfqq = cic_to_cfqq(cic, rw_is_sync(rw));
3571 if (cfqq) {
3572 cfq_init_prio_data(cfqq, cic->ioc);
3573 cfq_prio_boost(cfqq);
3575 return __cfq_may_queue(cfqq);
3586 struct cfq_queue *cfqq = RQ_CFQQ(rq);
3588 if (cfqq) {
3591 BUG_ON(!cfqq->allocated[rw]);
3592 cfqq->allocated[rw]--;
3603 cfq_put_queue(cfqq);
3609 struct cfq_queue *cfqq)
3611 cfq_log_cfqq(cfqd, cfqq, "merging with queue %p", cfqq->new_cfqq);
3612 cic_set_cfqq(cic, cfqq->new_cfqq, 1);
3613 cfq_mark_cfqq_coop(cfqq->new_cfqq);
3614 cfq_put_queue(cfqq);
3619 * Returns NULL if a new cfqq should be allocated, or the old cfqq if this
3620 * was the last process referring to said cfqq.
3623 split_cfqq(struct cfq_io_context *cic, struct cfq_queue *cfqq)
3625 if (cfqq_process_refs(cfqq) == 1) {
3626 cfqq->pid = current->pid;
3627 cfq_clear_cfqq_coop(cfqq);
3628 cfq_clear_cfqq_split_coop(cfqq);
3629 return cfqq;
3634 cfq_put_cooperator(cfqq);
3636 cfq_put_queue(cfqq);
3649 struct cfq_queue *cfqq;
3662 cfqq = cic_to_cfqq(cic, is_sync);
3663 if (!cfqq || cfqq == &cfqd->oom_cfqq) {
3664 cfqq = cfq_get_queue(cfqd, is_sync, cic->ioc, gfp_mask);
3665 cic_set_cfqq(cic, cfqq, is_sync);
3670 if (cfq_cfqq_coop(cfqq) && cfq_cfqq_split_coop(cfqq)) {
3671 cfq_log_cfqq(cfqd, cfqq, "breaking apart cfqq");
3672 cfqq = split_cfqq(cic, cfqq);
3673 if (!cfqq)
3683 if (cfqq->new_cfqq)
3684 cfqq = cfq_merge_cfqqs(cfqd, cic, cfqq);
3687 cfqq->allocated[rw]++;
3688 atomic_inc(&cfqq->ref);
3693 rq->elevator_private2 = cfqq;
3694 rq->elevator_private3 = cfq_ref_get_cfqg(cfqq->cfqg);
3724 struct cfq_queue *cfqq;
3732 cfqq = cfqd->active_queue;
3733 if (cfqq) {
3739 if (cfq_cfqq_must_dispatch(cfqq))
3745 if (cfq_slice_used(cfqq))
3758 if (!RB_EMPTY_ROOT(&cfqq->sort_list))
3764 cfq_clear_cfqq_deep(cfqq);
3903 * Our fallback cfqq if cfq_find_alloc_queue() runs into OOM issues.