Lines Matching +full:burst +full:- +full:wrap

1 // SPDX-License-Identifier: GPL-2.0-or-later
16 * BFQ is a proportional-share I/O scheduler, with some extra
17 * low-latency capabilities. BFQ also supports full hierarchical
20 * limitations can be found in Documentation/block/bfq-iosched.rst.
22 * BFQ is a proportional-share storage-I/O scheduling algorithm based
23 * on the slice-by-slice service scheme of CFQ. But BFQ assigns
25 * time slices. The device is not granted to the in-service process
31 * B-WF2Q+, to schedule processes according to their budgets. More
33 * process/queue is assigned a user-configurable weight, and B-WF2Q+
36 * B-WF2Q+, BFQ can afford to assign high budgets to I/O-bound
38 * and yet guarantee a low latency to interactive and soft real-time
41 * In particular, to provide these low-latency guarantees, BFQ
42 * explicitly privileges the I/O of two classes of time-sensitive
43 * applications: interactive and soft real-time. In more detail, BFQ
50 * real-time application. For brevity, in these cases, the queue is
51 * said to be interactive or soft real-time. In both cases, BFQ
52 * privileges the service of the queue, over that of non-interactive
53 * and non-soft-real-time queues. This privileging is performed,
55 * call just weight-raising periods the time periods during which a
56 * queue is privileged, because deemed interactive or soft real-time.
58 * The detection of soft real-time queues/applications is described in
70 * non-empty queue stops being deemed interactive. Since a queue is
71 * weight-raised while it is deemed interactive, this maximum time
73 * weight-raising for interactive queues.
76 * preserving both a low latency and a high throughput on NCQ-capable,
77 * rotational or flash-based devices, and to get the job done quickly
78 * for applications consisting in many I/O-bound processes.
81 * the maximum-possible throughput at all times, then do switch off
82 * all low-latency heuristics for that device, by setting low_latency
91 * ones that guarantee a low latency to interactive and soft real-time
92 * applications, and a hierarchical extension based on H-WF2Q+.
94 * B-WF2Q+ is based on WF2Q+, which is described in [2], together with
95 * H-WF2Q+, while the augmented tree used here to implement B-WF2Q+
101 * Technologies (MST-2015), May 2015.
102 * http://algogroup.unimore.it/people/paolo/disk_sched/mst-2015.pdf
105 * Algorithms", IEEE/ACM Transactions on Networking, 5(5):675-689,
108 * http://www.cs.cmu.edu/~hzhang/papers/TON-97-Oct.ps.gz
110 * [3] I. Stoica and H. Abdel-Wahab, "Earliest Eligible Virtual Deadline
114 * http://www.cs.berkeley.edu/~istoica/papers/eevdf-tr-95.pdf
125 #include <linux/backing-dev.h>
131 #include "blk-mq.h"
132 #include "blk-mq-sched.h"
133 #include "bfq-iosched.h"
134 #include "blk-wbt.h"
139 __set_bit(BFQQF_##name, &(bfqq)->flags); \
143 __clear_bit(BFQQF_##name, &(bfqq)->flags); \
147 return test_bit(BFQQF_##name, &(bfqq)->flags); \
198 * - when the group does writes, w.r.t. to when it does reads;
199 * - when other groups do reads, w.r.t. to when they do writes.
234 (!blk_queue_nonrot(bfqd->queue) || \
237 #define BFQQ_SEEKY(bfqq) (hweight32(bfqq->seek_history) > 19)
239 * Sync random I/O is likely to be confused with soft real-time I/O,
243 * as soft real-time.
245 #define BFQQ_TOTALLY_SEEKY(bfqq) (bfqq->seek_history == -1)
247 /* Min number of samples required to perform peak-rate update */
249 /* Min observation time interval required to perform a peak-rate update (ns) */
251 /* Target observation time interval for a peak-rate update (ns) */
255 * Shift used for peak-rate fixed precision calculations.
257 * - the current shift: 16 positions
258 * - the current type used to store rate: u32
259 * - the current unit of measure for rate: [sectors/usec], or, more precisely,
262 * [1 / 2^BFQ_RATE_SHIFT, 2^(32 - BFQ_RATE_SHIFT)] sectors/usec =
263 * [1 / 2^16, 2^16] sectors/usec = [15e-6, 65536] sectors/usec =
271 * When configured for computing the duration of the weight-raising
288 * depending on whether the device is rotational or non-rotational.
293 * non-rotational device. The reference rates are not the actual peak
296 * peak-rate estimator tends to yield slightly lower values than the
301 * The reference peak rates are measured in sectors/usec, left-shifted
313 * BFQ uses the above-detailed, time-based weight-raising mechanism to
315 * following false positives: I/O-bound applications that will go on
318 * weight-raised at the beginning of their I/O. On the opposite end,
319 * while being weight-raised, these applications
323 * in loss of device throughput with most flash-based storage, and may
328 * finish explaining how the duration of weight-raising for
337 * reference interactive task is the start-up of LibreOffice Writer,
342 * duration of weight-raising for at least one class of I/O-bound
343 * applications: those doing sequential or quasi-sequential I/O. An
344 * example is file copy. In fact, once started, the main I/O-bound
347 * is starting, because these I/O-bound processes will greedily devote
349 * throughput-friendly I/O operations. This is even more true if BFQ
353 * have no right to be weight-raised any longer.
355 * Basing on the last consideration, BFQ ends weight-raising for a
360 * This early ending of weight-raising reduces the amount of time
376 #define RQ_BIC(rq) ((struct bfq_io_cq *)((rq)->elv.priv[0]))
377 #define RQ_BFQQ(rq) ((rq)->elv.priv[1])
383 return bic->bfqq[1][actuator_idx]; in bic_to_bfqq()
385 return bic->bfqq[0][actuator_idx]; in bic_to_bfqq()
395 struct bfq_queue *old_bfqq = bic->bfqq[is_sync][actuator_idx]; in bic_set_bfqq()
398 * If bfqq != NULL, then a non-stable queue merge between in bic_set_bfqq()
399 * bic->bfqq and bfqq is happening here. This causes troubles in bic_set_bfqq()
400 * in the following case: bic->bfqq has also been scheduled in bic_set_bfqq()
401 * for a possible stable merge with bic->stable_merge_bfqq, in bic_set_bfqq()
402 * and bic->stable_merge_bfqq == bfqq happens to in bic_set_bfqq()
405 * bic->stable_merge_bfqq points exactly to bfqq, then bfqq in bic_set_bfqq()
408 * bic->stable_merge_bfqq == bfqq. in bic_set_bfqq()
410 struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[actuator_idx]; in bic_set_bfqq()
413 if (old_bfqq && old_bfqq->bic == bic) in bic_set_bfqq()
414 old_bfqq->bic = NULL; in bic_set_bfqq()
417 bic->bfqq[1][actuator_idx] = bfqq; in bic_set_bfqq()
419 bic->bfqq[0][actuator_idx] = bfqq; in bic_set_bfqq()
421 if (bfqq && bfqq_data->stable_merge_bfqq == bfqq) { in bic_set_bfqq()
430 bfq_put_stable_ref(bfqq_data->stable_merge_bfqq); in bic_set_bfqq()
432 bfqq_data->stable_merge_bfqq = NULL; in bic_set_bfqq()
438 return bic->icq.q->elevator->elevator_data; in bic_to_bfqd()
442 * icq_to_bic - convert iocontext queue structure to bfq_io_cq.
447 /* bic->icq is the first member, %NULL will convert to %NULL */ in icq_to_bic()
452 * bfq_bic_lookup - search into @ioc a bic associated to @bfqd.
460 if (!current->io_context) in bfq_bic_lookup()
463 spin_lock_irqsave(&q->queue_lock, flags); in bfq_bic_lookup()
465 spin_unlock_irqrestore(&q->queue_lock, flags); in bfq_bic_lookup()
476 lockdep_assert_held(&bfqd->lock); in bfq_schedule_dispatch()
478 if (bfqd->queued != 0) { in bfq_schedule_dispatch()
480 blk_mq_run_hw_queues(bfqd->queue, true); in bfq_schedule_dispatch()
484 #define bfq_class_idle(bfqq) ((bfqq)->ioprio_class == IOPRIO_CLASS_IDLE)
489 * Lifted from AS - choose which of rq1 and rq2 that is best served now.
502 unsigned int wrap = 0; /* bit mask: requests behind the disk head? */ in bfq_choose_req() local
513 if ((rq1->cmd_flags & REQ_META) && !(rq2->cmd_flags & REQ_META)) in bfq_choose_req()
515 else if ((rq2->cmd_flags & REQ_META) && !(rq1->cmd_flags & REQ_META)) in bfq_choose_req()
524 back_max = bfqd->bfq_back_max * 2; in bfq_choose_req()
532 d1 = s1 - last; in bfq_choose_req()
534 d1 = (last - s1) * bfqd->bfq_back_penalty; in bfq_choose_req()
536 wrap |= BFQ_RQ1_WRAP; in bfq_choose_req()
539 d2 = s2 - last; in bfq_choose_req()
541 d2 = (last - s2) * bfqd->bfq_back_penalty; in bfq_choose_req()
543 wrap |= BFQ_RQ2_WRAP; in bfq_choose_req()
548 * By doing switch() on the bit mask "wrap" we avoid having to in bfq_choose_req()
549 * check two variables for all permutations: --> faster! in bfq_choose_req()
551 switch (wrap) { in bfq_choose_req()
572 * (--> only *one* back seek required), in bfq_choose_req()
601 spin_lock_irq(&bfqd->lock); in bfqq_request_over_limit()
606 entity = &bfqq->entity; in bfqq_request_over_limit()
607 if (!entity->on_st_or_in_serv) in bfqq_request_over_limit()
611 depth = bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css.cgroup->level + 1; in bfqq_request_over_limit()
613 spin_unlock_irq(&bfqd->lock); in bfqq_request_over_limit()
623 sched_data = entity->sched_data; in bfqq_request_over_limit()
632 if (!entity->on_st_or_in_serv) in bfqq_request_over_limit()
640 for (level--; level >= 0; level--) { in bfqq_request_over_limit()
643 wsum = bfq_entity_service_tree(entity)->wsum; in bfqq_request_over_limit()
654 for (i = 0; i <= bfqq->ioprio_class - 1; i++) { in bfqq_request_over_limit()
656 sched_data->service_tree[i].wsum; in bfqq_request_over_limit()
661 limit = DIV_ROUND_CLOSEST(limit * entity->weight, wsum); in bfqq_request_over_limit()
662 if (entity->allocated >= limit) { in bfqq_request_over_limit()
663 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfqq_request_over_limit()
665 entity->allocated, limit, level); in bfqq_request_over_limit()
671 spin_unlock_irq(&bfqd->lock); in bfqq_request_over_limit()
702 struct bfq_data *bfqd = data->q->elevator->elevator_data; in bfq_limit_depth()
703 struct bfq_io_cq *bic = bfq_bic_lookup(data->q); in bfq_limit_depth()
705 unsigned limit = data->q->nr_requests; in bfq_limit_depth()
712 depth = bfqd->word_depths[!!bfqd->wr_busy_queues][op_is_sync(opf)]; in bfq_limit_depth()
713 limit = (limit * depth) >> bfqd->full_depth_shift; in bfq_limit_depth()
716 for (act_idx = 0; bic && act_idx < bfqd->num_actuators; act_idx++) { in bfq_limit_depth()
733 __func__, bfqd->wr_busy_queues, op_is_sync(opf), depth); in bfq_limit_depth()
735 data->shallow_depth = depth; in bfq_limit_depth()
747 p = &root->rb_node; in bfq_rq_pos_tree_lookup()
758 if (sector > blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
759 n = &(*p)->rb_right; in bfq_rq_pos_tree_lookup()
760 else if (sector < blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
761 n = &(*p)->rb_left; in bfq_rq_pos_tree_lookup()
774 bfqq ? bfqq->pid : 0); in bfq_rq_pos_tree_lookup()
781 return bfqq->service_from_backlogged > 0 && in bfq_too_late_for_merging()
782 time_is_before_jiffies(bfqq->first_IO_time + in bfq_too_late_for_merging()
800 if (bfqq->pos_root) { in bfq_pos_tree_add_move()
801 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
802 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
806 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
819 if (!bfqq->next_rq) in bfq_pos_tree_add_move()
822 bfqq->pos_root = &bfqq_group(bfqq)->rq_pos_tree; in bfq_pos_tree_add_move()
823 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
824 blk_rq_pos(bfqq->next_rq), &parent, &p); in bfq_pos_tree_add_move()
826 rb_link_node(&bfqq->pos_node, parent, p); in bfq_pos_tree_add_move()
827 rb_insert_color(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
829 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
842 * of this function is used to check whether I/O-dispatch plugging can
847 * 2) all active queues belong to the same I/O-priority class,
854 * the last two symmetry sub-conditions above would be quite complex
856 * only the following stronger three sub-conditions, for which it is
859 * 2) all active queues belong to the same I/O-priority class,
869 bfqq->weight_counter && in bfq_asymmetric_scenario()
870 bfqq->weight_counter == in bfq_asymmetric_scenario()
872 rb_first_cached(&bfqd->queue_weights_tree), in bfq_asymmetric_scenario()
881 !RB_EMPTY_ROOT(&bfqd->queue_weights_tree.rb_root) && in bfq_asymmetric_scenario()
882 (bfqd->queue_weights_tree.rb_root.rb_node->rb_left || in bfq_asymmetric_scenario()
883 bfqd->queue_weights_tree.rb_root.rb_node->rb_right); in bfq_asymmetric_scenario()
886 (bfqd->busy_queues[0] && bfqd->busy_queues[1]) || in bfq_asymmetric_scenario()
887 (bfqd->busy_queues[0] && bfqd->busy_queues[2]) || in bfq_asymmetric_scenario()
888 (bfqd->busy_queues[1] && bfqd->busy_queues[2]); in bfq_asymmetric_scenario()
892 || bfqd->num_groups_with_pending_reqs > 1 in bfq_asymmetric_scenario()
898 * If the weight-counter tree passed as input contains no counter for
902 * Note that weight-counter trees contain few nodes in mostly symmetric
904 * weight-counter tree for the queues may contain at most one node.
905 * This holds even if low_latency is on, because weight-raised queues
912 struct rb_root_cached *root = &bfqq->bfqd->queue_weights_tree; in bfq_weights_tree_add()
913 struct bfq_entity *entity = &bfqq->entity; in bfq_weights_tree_add()
914 struct rb_node **new = &(root->rb_root.rb_node), *parent = NULL; in bfq_weights_tree_add()
921 * non-weight-raised, and hence change its weight, and in bfq_weights_tree_add()
929 if (bfqq->weight_counter) in bfq_weights_tree_add()
938 if (entity->weight == __counter->weight) { in bfq_weights_tree_add()
939 bfqq->weight_counter = __counter; in bfq_weights_tree_add()
942 if (entity->weight < __counter->weight) in bfq_weights_tree_add()
943 new = &((*new)->rb_left); in bfq_weights_tree_add()
945 new = &((*new)->rb_right); in bfq_weights_tree_add()
950 bfqq->weight_counter = kzalloc(sizeof(struct bfq_weight_counter), in bfq_weights_tree_add()
963 * if !bfqq->weight_counter. in bfq_weights_tree_add()
965 if (unlikely(!bfqq->weight_counter)) in bfq_weights_tree_add()
968 bfqq->weight_counter->weight = entity->weight; in bfq_weights_tree_add()
969 rb_link_node(&bfqq->weight_counter->weights_node, parent, new); in bfq_weights_tree_add()
970 rb_insert_color_cached(&bfqq->weight_counter->weights_node, root, in bfq_weights_tree_add()
974 bfqq->weight_counter->num_active++; in bfq_weights_tree_add()
975 bfqq->ref++; in bfq_weights_tree_add()
988 if (!bfqq->weight_counter) in bfq_weights_tree_remove()
991 root = &bfqq->bfqd->queue_weights_tree; in bfq_weights_tree_remove()
992 bfqq->weight_counter->num_active--; in bfq_weights_tree_remove()
993 if (bfqq->weight_counter->num_active > 0) in bfq_weights_tree_remove()
996 rb_erase_cached(&bfqq->weight_counter->weights_node, root); in bfq_weights_tree_remove()
997 kfree(bfqq->weight_counter); in bfq_weights_tree_remove()
1000 bfqq->weight_counter = NULL; in bfq_weights_tree_remove()
1017 rq = rq_entry_fifo(bfqq->fifo.next); in bfq_check_fifo()
1019 if (rq == last || blk_time_get_ns() < rq->fifo_time) in bfq_check_fifo()
1022 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
1030 struct rb_node *rbnext = rb_next(&last->rb_node); in bfq_find_next_rq()
1031 struct rb_node *rbprev = rb_prev(&last->rb_node); in bfq_find_next_rq()
1045 rbnext = rb_first(&bfqq->sort_list); in bfq_find_next_rq()
1046 if (rbnext && rbnext != &last->rb_node) in bfq_find_next_rq()
1057 if (bfq_bfqq_sync(bfqq) || bfqq->wr_coeff > 1 || in bfq_serv_to_charge()
1058 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
1065 * bfq_updated_next_req - update the queue after a new next_rq selection.
1078 struct bfq_entity *entity = &bfqq->entity; in bfq_updated_next_req()
1079 struct request *next_rq = bfqq->next_rq; in bfq_updated_next_req()
1085 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
1093 max_t(unsigned long, bfqq->max_budget, in bfq_updated_next_req()
1095 entity->service); in bfq_updated_next_req()
1096 if (entity->budget != new_budget) { in bfq_updated_next_req()
1097 entity->budget = new_budget; in bfq_updated_next_req()
1108 dur = bfqd->rate_dur_prod; in bfq_wr_duration()
1109 do_div(dur, bfqd->peak_rate); in bfq_wr_duration()
1115 * - running in a slow PC in bfq_wr_duration()
1116 * - with a virtual disk stacked on a slow low-end 5400rpm HDD in bfq_wr_duration()
1117 * - serving a heavy I/O workload, such as the sequential reading in bfq_wr_duration()
1119 * mplayer took 23 seconds to start, if constantly weight-raised. in bfq_wr_duration()
1124 * responsiveness by allowing non-interactive applications to in bfq_wr_duration()
1129 * before weight-raising finishes. in bfq_wr_duration()
1134 /* switch back from soft real-time to interactive weight raising */
1138 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1139 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1140 bfqq->last_wr_start_finish = bfqq->wr_start_at_switch_to_srt; in switch_back_to_interactive_wr()
1149 unsigned int a_idx = bfqq->actuator_idx; in bfq_bfqq_resume_state()
1150 struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[a_idx]; in bfq_bfqq_resume_state()
1152 if (bfqq_data->saved_has_short_ttime) in bfq_bfqq_resume_state()
1157 if (bfqq_data->saved_IO_bound) in bfq_bfqq_resume_state()
1162 bfqq->last_serv_time_ns = bfqq_data->saved_last_serv_time_ns; in bfq_bfqq_resume_state()
1163 bfqq->inject_limit = bfqq_data->saved_inject_limit; in bfq_bfqq_resume_state()
1164 bfqq->decrease_time_jif = bfqq_data->saved_decrease_time_jif; in bfq_bfqq_resume_state()
1166 bfqq->entity.new_weight = bfqq_data->saved_weight; in bfq_bfqq_resume_state()
1167 bfqq->ttime = bfqq_data->saved_ttime; in bfq_bfqq_resume_state()
1168 bfqq->io_start_time = bfqq_data->saved_io_start_time; in bfq_bfqq_resume_state()
1169 bfqq->tot_idle_time = bfqq_data->saved_tot_idle_time; in bfq_bfqq_resume_state()
1173 if (bfqd->low_latency) { in bfq_bfqq_resume_state()
1174 old_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_resume_state()
1175 bfqq->wr_coeff = bfqq_data->saved_wr_coeff; in bfq_bfqq_resume_state()
1177 bfqq->service_from_wr = bfqq_data->saved_service_from_wr; in bfq_bfqq_resume_state()
1178 bfqq->wr_start_at_switch_to_srt = in bfq_bfqq_resume_state()
1179 bfqq_data->saved_wr_start_at_switch_to_srt; in bfq_bfqq_resume_state()
1180 bfqq->last_wr_start_finish = bfqq_data->saved_last_wr_start_finish; in bfq_bfqq_resume_state()
1181 bfqq->wr_cur_max_time = bfqq_data->saved_wr_cur_max_time; in bfq_bfqq_resume_state()
1183 if (bfqq->wr_coeff > 1 && (bfq_bfqq_in_large_burst(bfqq) || in bfq_bfqq_resume_state()
1184 time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_bfqq_resume_state()
1185 bfqq->wr_cur_max_time))) { in bfq_bfqq_resume_state()
1186 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1188 time_is_after_eq_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_bfqq_resume_state()
1192 bfqq->wr_coeff = 1; in bfq_bfqq_resume_state()
1193 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1199 bfqq->entity.prio_changed = 1; in bfq_bfqq_resume_state()
1204 if (old_wr_coeff == 1 && bfqq->wr_coeff > 1) in bfq_bfqq_resume_state()
1205 bfqd->wr_busy_queues++; in bfq_bfqq_resume_state()
1206 else if (old_wr_coeff > 1 && bfqq->wr_coeff == 1) in bfq_bfqq_resume_state()
1207 bfqd->wr_busy_queues--; in bfq_bfqq_resume_state()
1212 return bfqq->ref - bfqq->entity.allocated - in bfqq_process_refs()
1213 bfqq->entity.on_st_or_in_serv - in bfqq_process_refs()
1214 (bfqq->weight_counter != NULL) - bfqq->stable_ref; in bfqq_process_refs()
1217 /* Empty burst list and add just bfqq (see comments on bfq_handle_burst) */
1223 hlist_for_each_entry_safe(item, n, &bfqd->burst_list, burst_list_node) in bfq_reset_burst_list()
1224 hlist_del_init(&item->burst_list_node); in bfq_reset_burst_list()
1227 * Start the creation of a new burst list only if there is no in bfq_reset_burst_list()
1232 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1233 bfqd->burst_size = 1; in bfq_reset_burst_list()
1235 bfqd->burst_size = 0; in bfq_reset_burst_list()
1237 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1240 /* Add bfqq to the list of queues in current burst (see bfq_handle_burst) */
1243 /* Increment burst size to take into account also bfqq */ in bfq_add_to_burst()
1244 bfqd->burst_size++; in bfq_add_to_burst()
1246 if (bfqd->burst_size == bfqd->bfq_large_burst_thresh) { in bfq_add_to_burst()
1252 * other to consider this burst as large. in bfq_add_to_burst()
1254 bfqd->large_burst = true; in bfq_add_to_burst()
1257 * We can now mark all queues in the burst list as in bfq_add_to_burst()
1258 * belonging to a large burst. in bfq_add_to_burst()
1260 hlist_for_each_entry(bfqq_item, &bfqd->burst_list, in bfq_add_to_burst()
1266 * From now on, and until the current burst finishes, any in bfq_add_to_burst()
1268 * was inserted in the burst can be immediately marked as in bfq_add_to_burst()
1269 * belonging to a large burst. So the burst list is not in bfq_add_to_burst()
1272 hlist_for_each_entry_safe(pos, n, &bfqd->burst_list, in bfq_add_to_burst()
1274 hlist_del_init(&pos->burst_list_node); in bfq_add_to_burst()
1276 * Burst not yet large: add bfqq to the burst list. Do in bfq_add_to_burst()
1278 * is removed from the burst list before freeing bfqq in bfq_add_to_burst()
1281 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1291 * possible, it is usually better to not grant either weight-raising
1303 * completed. As a consequence, weight-raising any of these queues,
1307 * weight-raising these new queues just lowers throughput in most
1310 * On the other hand, a burst of queue creations may be caused also by
1312 * parallel I/O-bound threads. In fact, with a complex application,
1313 * several short processes may need to be executed to start-up the
1318 * an application that causes a burst of queue creations is to
1319 * weight-raise all the queues created during the burst. This is the
1329 * weight-raise queues whose creation occurs in a large burst. In
1344 * same, possible burst bfqq would belong to), and it implements all
1345 * the steps needed to detect the occurrence of a large burst and to
1348 * maintaining a "burst list" that holds, temporarily, the queues that
1349 * belong to the burst in progress. The list is then used to mark
1350 * these queues as belonging to a large burst if the burst does become
1354 * list (as it could be the first queue in a possible burst)
1356 * . if the current burst has not yet become large, and a queue Q that does
1357 * not yet belong to the burst is activated shortly after the last time
1358 * at which a new queue entered the burst list, then the function appends
1359 * Q to the burst list
1361 * . if, as a consequence of the previous step, the burst size reaches
1362 * the large-burst threshold, then
1364 * . all the queues in the burst list are marked as belonging to a
1365 * large burst
1367 * . the burst list is deleted; in fact, the burst list already served
1368 * its purpose (keeping temporarily track of the queues in a burst,
1369 * so as to be able to mark them as belonging to a large burst in the
1370 * previous sub-step), and now is not needed any more
1372 * . the device enters a large-burst mode
1374 * . if a queue Q that does not belong to the burst is created while
1375 * the device is in large-burst mode and shortly after the last time
1376 * at which a queue either entered the burst list or was marked as
1377 * belonging to the current large burst, then Q is immediately marked
1378 * as belonging to a large burst.
1380 * . if a queue Q that does not belong to the burst is created a while
1382 * either entered the burst list or was marked as belonging to the
1383 * current large burst, then the current burst is deemed as finished and:
1385 * . the large-burst mode is reset if set
1387 * . the burst list is emptied
1389 * . Q is inserted in the burst list, as Q may be the first queue
1390 * in a possible new burst (then the burst list contains just Q
1396 * If bfqq is already in the burst list or is part of a large in bfq_handle_burst()
1397 * burst, or finally has just been split, then there is in bfq_handle_burst()
1400 if (!hlist_unhashed(&bfqq->burst_list_node) || in bfq_handle_burst()
1402 time_is_after_eq_jiffies(bfqq->split_time + in bfq_handle_burst()
1408 * a different group than the burst group, then the current in bfq_handle_burst()
1409 * burst is finished, and related data structures must be in bfq_handle_burst()
1418 * inserted into the burst list. In particular the list will in bfq_handle_burst()
1421 * burst. in bfq_handle_burst()
1423 if (time_is_before_jiffies(bfqd->last_ins_in_burst + in bfq_handle_burst()
1424 bfqd->bfq_burst_interval) || in bfq_handle_burst()
1425 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1426 bfqd->large_burst = false; in bfq_handle_burst()
1433 * last queue. So, if the current burst is also large, we can mark in bfq_handle_burst()
1434 * bfqq as belonging to this large burst immediately. in bfq_handle_burst()
1436 if (bfqd->large_burst) { in bfq_handle_burst()
1442 * If we get here, then a large-burst state has not yet been in bfq_handle_burst()
1444 * queue. Then we add bfqq to the burst. in bfq_handle_burst()
1450 * burst or has caused the current burst to terminate and a in bfq_handle_burst()
1451 * possible new burst to start. In particular, in the second in bfq_handle_burst()
1453 * burst. In both cases last_ins_in_burst needs to be moved in bfq_handle_burst()
1456 bfqd->last_ins_in_burst = jiffies; in bfq_handle_burst()
1461 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_budget_left()
1463 return entity->budget - entity->service; in bfq_bfqq_budget_left()
1473 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_max_budget()
1476 return bfqd->bfq_max_budget; in bfq_max_budget()
1485 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_min_budget()
1488 return bfqd->bfq_max_budget / 32; in bfq_min_budget()
1494 * whether the in-service queue should be expired, by returning
1495 * true. The purpose of expiring the in-service queue is to give bfqq
1496 * the chance to possibly preempt the in-service queue, and the reason
1497 * for preempting the in-service queue is to achieve one of the two
1504 * - BFQQE_NO_MORE_REQUESTS bfqq did not enjoy any device idling
1508 * - BFQQE_TOO_IDLE bfqq did enjoy device idling, but did not issue
1509 * a new request before the expiration of the idling-time.
1538 * before last expiration. Thus timestamps need to be back-shifted
1542 * Secondly, to allow the process to recover the hole, the in-service
1545 * in-service queue to be completed, then it may become impossible to
1546 * let the process recover the hole, even if the back-shifted
1547 * timestamps of bfqq are lower than those of the in-service queue. If
1563 * above-described special way, and signals that the in-service queue
1564 * should be expired. Timestamp back-shifting is done later in
1570 * timestamp than the in-service queue. That is, the next budget of
1571 * bfqq may have to be completed before the one of the in-service
1572 * queue. If this is the case, then preempting the in-service queue
1578 * the in-service queue must be preempted. To have service trees
1579 * correctly updated, the in-service queue must be expired and
1582 * mechanism may be re-designed in such a way to make it possible to
1586 * even be no in-service queue when the next function is invoked (so,
1591 * in-service queue (unconditionally) only for queues that need to
1599 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_update_budg_for_activation()
1613 * that timestamps need to be back-shifted (and is in bfq_bfqq_update_budg_for_activation()
1619 * entity->service or entity->budget are not updated in bfq_bfqq_update_budg_for_activation()
1624 * entity->budget the remaining budget on such an in bfq_bfqq_update_budg_for_activation()
1627 entity->budget = min_t(unsigned long, in bfq_bfqq_update_budg_for_activation()
1629 bfqq->max_budget); in bfq_bfqq_update_budg_for_activation()
1632 * At this point, we have used entity->service to get in bfq_bfqq_update_budg_for_activation()
1634 * entity->budget). Thus we finally can, and have to, in bfq_bfqq_update_budg_for_activation()
1635 * reset entity->service. The latter must be reset in bfq_bfqq_update_budg_for_activation()
1640 entity->service = 0; in bfq_bfqq_update_budg_for_activation()
1648 entity->service = 0; in bfq_bfqq_update_budg_for_activation()
1649 entity->budget = max_t(unsigned long, bfqq->max_budget, in bfq_bfqq_update_budg_for_activation()
1650 bfq_serv_to_charge(bfqq->next_rq, bfqq)); in bfq_bfqq_update_budg_for_activation()
1661 return jiffies - MAX_JIFFY_OFFSET; in bfq_smallest_from_now()
1673 /* start a weight-raising period */ in bfq_update_bfqq_wr_on_rq_arrival()
1675 bfqq->service_from_wr = 0; in bfq_update_bfqq_wr_on_rq_arrival()
1676 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1677 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1683 * that, at the end of the soft-real-time in bfq_update_bfqq_wr_on_rq_arrival()
1685 * now, no interactive weight-raising period in bfq_update_bfqq_wr_on_rq_arrival()
1690 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1692 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1694 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1695 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1701 * scheduling-error component due to a too large in bfq_update_bfqq_wr_on_rq_arrival()
1707 bfqq->entity.budget = min_t(unsigned long, in bfq_update_bfqq_wr_on_rq_arrival()
1708 bfqq->entity.budget, in bfq_update_bfqq_wr_on_rq_arrival()
1712 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1713 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1715 bfqq->wr_coeff = 1; in bfq_update_bfqq_wr_on_rq_arrival()
1721 * the weight-raising duration for the in bfq_update_bfqq_wr_on_rq_arrival()
1722 * application with the weight-raising in bfq_update_bfqq_wr_on_rq_arrival()
1726 * before the weight-raising period for the in bfq_update_bfqq_wr_on_rq_arrival()
1733 * at a certain time weight-raising is in bfq_update_bfqq_wr_on_rq_arrival()
1744 * weight-raised while they are pending. in bfq_update_bfqq_wr_on_rq_arrival()
1746 if (bfqq->wr_cur_max_time != in bfq_update_bfqq_wr_on_rq_arrival()
1747 bfqd->bfq_wr_rt_max_time) { in bfq_update_bfqq_wr_on_rq_arrival()
1748 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1749 bfqq->last_wr_start_finish; in bfq_update_bfqq_wr_on_rq_arrival()
1751 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1752 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1753 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1756 bfqq->last_wr_start_finish = jiffies; in bfq_update_bfqq_wr_on_rq_arrival()
1764 return bfqq->dispatched == 0 && in bfq_bfqq_idle_for_long_time()
1766 bfqq->budget_timeout + in bfq_bfqq_idle_for_long_time()
1767 bfqd->bfq_wr_min_idle_time); in bfq_bfqq_idle_for_long_time()
1773 * weight than the in-service queue.
1780 if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class) in bfq_bfqq_higher_class_or_weight()
1783 if (in_serv_bfqq->entity.parent == bfqq->entity.parent) { in bfq_bfqq_higher_class_or_weight()
1784 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1785 in_serv_weight = in_serv_bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1787 if (bfqq->entity.parent) in bfq_bfqq_higher_class_or_weight()
1788 bfqq_weight = bfqq->entity.parent->weight; in bfq_bfqq_higher_class_or_weight()
1790 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1791 if (in_serv_bfqq->entity.parent) in bfq_bfqq_higher_class_or_weight()
1792 in_serv_weight = in_serv_bfqq->entity.parent->weight; in bfq_bfqq_higher_class_or_weight()
1794 in_serv_weight = in_serv_bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1809 if (bfqd->num_actuators == 1) in bfq_actuator_index()
1813 end = bio_end_sector(bio) - 1; in bfq_actuator_index()
1815 for (i = 0; i < bfqd->num_actuators; i++) { in bfq_actuator_index()
1816 if (end >= bfqd->sector[i] && in bfq_actuator_index()
1817 end < bfqd->sector[i] + bfqd->nr_sectors[i]) in bfq_actuator_index()
1844 bfqq->ttime.last_end_request + in bfq_bfqq_handle_idle_busy_switch()
1845 bfqd->bfq_slice_idle * 3; in bfq_bfqq_handle_idle_busy_switch()
1846 unsigned int act_idx = bfq_actuator_index(bfqd, rq->bio); in bfq_bfqq_handle_idle_busy_switch()
1848 bfqq->bic || RQ_BIC(rq)->bfqq_data[act_idx].stably_merged; in bfq_bfqq_handle_idle_busy_switch()
1851 * bfqq deserves to be weight-raised if: in bfq_bfqq_handle_idle_busy_switch()
1852 * - it is sync, in bfq_bfqq_handle_idle_busy_switch()
1853 * - it does not belong to a large burst, in bfq_bfqq_handle_idle_busy_switch()
1854 * - it has been idle for enough time or is soft real-time, in bfq_bfqq_handle_idle_busy_switch()
1855 * - is linked to a bfq_io_cq (it is not shared in any sense), in bfq_bfqq_handle_idle_busy_switch()
1856 * - has a default weight (otherwise we assume the user wanted in bfq_bfqq_handle_idle_busy_switch()
1860 soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_handle_idle_busy_switch()
1863 time_is_before_jiffies(bfqq->soft_rt_next_start) && in bfq_bfqq_handle_idle_busy_switch()
1864 bfqq->dispatched == 0 && in bfq_bfqq_handle_idle_busy_switch()
1865 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1867 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1869 * Merged bfq_queues are kept out of weight-raising in bfq_bfqq_handle_idle_busy_switch()
1870 * (low-latency) mechanisms. The reason is that these queues in bfq_bfqq_handle_idle_busy_switch()
1871 * are usually created for non-interactive and in bfq_bfqq_handle_idle_busy_switch()
1872 * non-soft-real-time tasks. Yet this is not the case for in bfq_bfqq_handle_idle_busy_switch()
1873 * stably-merged queues. These queues are merged just because in bfq_bfqq_handle_idle_busy_switch()
1875 * easily serve the I/O of an interactive or soft-real time in bfq_bfqq_handle_idle_busy_switch()
1877 * processes. So let also stably-merged queued enjoy weight in bfq_bfqq_handle_idle_busy_switch()
1880 wr_or_deserves_wr = bfqd->low_latency && in bfq_bfqq_handle_idle_busy_switch()
1881 (bfqq->wr_coeff > 1 || in bfq_bfqq_handle_idle_busy_switch()
1887 * may want to preempt the in-service queue. in bfq_bfqq_handle_idle_busy_switch()
1894 * If bfqq happened to be activated in a burst, but has been in bfq_bfqq_handle_idle_busy_switch()
1896 * assume that, in the overall I/O initiated in the burst, the in bfq_bfqq_handle_idle_busy_switch()
1898 * to be treated as a queue belonging to a burst in bfq_bfqq_handle_idle_busy_switch()
1900 * if set, and remove bfqq from the burst list if it's in bfq_bfqq_handle_idle_busy_switch()
1902 * that bfqq does not need to belong to the burst list any in bfq_bfqq_handle_idle_busy_switch()
1904 * a burst. in bfq_bfqq_handle_idle_busy_switch()
1909 bfqq->budget_timeout + in bfq_bfqq_handle_idle_busy_switch()
1911 hlist_del_init(&bfqq->burst_list_node); in bfq_bfqq_handle_idle_busy_switch()
1917 if (bfqd->low_latency) { in bfq_bfqq_handle_idle_busy_switch()
1918 if (unlikely(time_is_after_jiffies(bfqq->split_time))) in bfq_bfqq_handle_idle_busy_switch()
1920 bfqq->split_time = in bfq_bfqq_handle_idle_busy_switch()
1921 jiffies - bfqd->bfq_wr_min_idle_time - 1; in bfq_bfqq_handle_idle_busy_switch()
1923 if (time_is_before_jiffies(bfqq->split_time + in bfq_bfqq_handle_idle_busy_switch()
1924 bfqd->bfq_wr_min_idle_time)) { in bfq_bfqq_handle_idle_busy_switch()
1932 if (old_wr_coeff != bfqq->wr_coeff) in bfq_bfqq_handle_idle_busy_switch()
1933 bfqq->entity.prio_changed = 1; in bfq_bfqq_handle_idle_busy_switch()
1937 bfqq->last_idle_bklogged = jiffies; in bfq_bfqq_handle_idle_busy_switch()
1938 bfqq->service_from_backlogged = 0; in bfq_bfqq_handle_idle_busy_switch()
1944 * Expire in-service queue if preemption may be needed for in bfq_bfqq_handle_idle_busy_switch()
1950 * carry time-critical I/O, then bfqq's bandwidth is less in bfq_bfqq_handle_idle_busy_switch()
1951 * important than that of queues that carry time-critical I/O. in bfq_bfqq_handle_idle_busy_switch()
1953 * bfqq is at least as weight-raised, i.e., at least as time in bfq_bfqq_handle_idle_busy_switch()
1954 * critical, as the in-service queue. in bfq_bfqq_handle_idle_busy_switch()
1957 * or has a higher weight than the in-service queue. If this in bfq_bfqq_handle_idle_busy_switch()
1964 * the timestamps of both bfqq and of the in-service queue, in bfq_bfqq_handle_idle_busy_switch()
1971 * timestamps of the in-service queue would need to be in bfq_bfqq_handle_idle_busy_switch()
1983 * request to arrive for the currently in-service queue, but in bfq_bfqq_handle_idle_busy_switch()
1986 if (bfqd->in_service_queue && in bfq_bfqq_handle_idle_busy_switch()
1988 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1989 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) || in bfq_bfqq_handle_idle_busy_switch()
1990 !bfq_better_to_idle(bfqd->in_service_queue)) && in bfq_bfqq_handle_idle_busy_switch()
1992 bfq_bfqq_expire(bfqd, bfqd->in_service_queue, in bfq_bfqq_handle_idle_busy_switch()
2000 bfqq->last_serv_time_ns = 0; in bfq_reset_inject_limit()
2006 bfqd->waited_rq = NULL; in bfq_reset_inject_limit()
2019 * get new I/O enqueued---and then completed---before being in bfq_reset_inject_limit()
2021 * limit-update algorithm the chance to measure the effect of in bfq_reset_inject_limit()
2051 * limit-update algorithm and possibly raise the limit to more in bfq_reset_inject_limit()
2055 bfqq->inject_limit = 0; in bfq_reset_inject_limit()
2057 bfqq->inject_limit = 1; in bfq_reset_inject_limit()
2059 bfqq->decrease_time_jif = jiffies; in bfq_reset_inject_limit()
2064 u64 tot_io_time = now_ns - bfqq->io_start_time; in bfq_update_io_intensity()
2066 if (RB_EMPTY_ROOT(&bfqq->sort_list) && bfqq->dispatched == 0) in bfq_update_io_intensity()
2067 bfqq->tot_idle_time += in bfq_update_io_intensity()
2068 now_ns - bfqq->ttime.last_end_request; in bfq_update_io_intensity()
2077 if (bfqq->tot_idle_time * 5 > tot_io_time) in bfq_update_io_intensity()
2087 bfqq->io_start_time = now_ns - (tot_io_time>>1); in bfq_update_io_intensity()
2088 bfqq->tot_idle_time >>= 1; in bfq_update_io_intensity()
2114 * if it still has some in-flight I/O. In fact, in this case bfqq is actually
2116 * of some of the in-flight requests. In particular, on the first time, Q is
2122 * above three-times requirement and time limit for detection, make false
2134 * first I/O-plugging time interval for bfqq. This triggers the first
2137 * during the next I/O-plugging interval for bfqq.
2148 if (!bfqd->last_completed_rq_bfqq || in bfq_check_waker()
2149 bfqd->last_completed_rq_bfqq == bfqq || in bfq_check_waker()
2151 now_ns - bfqd->last_completion >= 4 * NSEC_PER_MSEC || in bfq_check_waker()
2152 bfqd->last_completed_rq_bfqq == &bfqd->oom_bfqq || in bfq_check_waker()
2153 bfqq == &bfqd->oom_bfqq) in bfq_check_waker()
2162 if (bfqd->last_completed_rq_bfqq != in bfq_check_waker()
2163 bfqq->tentative_waker_bfqq || in bfq_check_waker()
2164 now_ns > bfqq->waker_detection_started + in bfq_check_waker()
2165 128 * (u64)bfqd->bfq_slice_idle) { in bfq_check_waker()
2171 bfqq->tentative_waker_bfqq = in bfq_check_waker()
2172 bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2173 bfqq->num_waker_detections = 1; in bfq_check_waker()
2174 bfqq->waker_detection_started = now_ns; in bfq_check_waker()
2175 bfq_bfqq_name(bfqq->tentative_waker_bfqq, waker_name, in bfq_check_waker()
2179 bfqq->num_waker_detections++; in bfq_check_waker()
2181 if (bfqq->num_waker_detections == 3) { in bfq_check_waker()
2182 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2183 bfqq->tentative_waker_bfqq = NULL; in bfq_check_waker()
2184 bfq_bfqq_name(bfqq->waker_bfqq, waker_name, in bfq_check_waker()
2190 * bfqq->waker_bfqq must be reset. To in bfq_check_waker()
2208 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_check_waker()
2209 hlist_del_init(&bfqq->woken_list_node); in bfq_check_waker()
2210 hlist_add_head(&bfqq->woken_list_node, in bfq_check_waker()
2211 &bfqd->last_completed_rq_bfqq->woken_list); in bfq_check_waker()
2218 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request()
2220 unsigned int old_wr_coeff = bfqq->wr_coeff; in bfq_add_request()
2225 bfqq->queued[rq_is_sync(rq)]++; in bfq_add_request()
2227 * Updating of 'bfqd->queued' is protected by 'bfqd->lock', however, it in bfq_add_request()
2230 WRITE_ONCE(bfqd->queued, bfqd->queued + 1); in bfq_add_request()
2232 if (bfq_bfqq_sync(bfqq) && RQ_BIC(rq)->requests <= 1) { in bfq_add_request()
2241 if (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2249 * - bfqq is in service, because the total service in bfq_add_request()
2252 * - this is the right occasion to compute or to in bfq_add_request()
2263 * hole, and there are still in-flight requests, in bfq_add_request()
2266 * - the minimum interval for sampling the total in bfq_add_request()
2270 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2271 (bfqd->tot_rq_in_driver == 0 || in bfq_add_request()
2272 (bfqq->last_serv_time_ns > 0 && in bfq_add_request()
2273 bfqd->rqs_injected && bfqd->tot_rq_in_driver > 0)) && in bfq_add_request()
2274 time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2276 bfqd->last_empty_occupied_ns = blk_time_get_ns(); in bfq_add_request()
2280 * wait_dispatch will cause bfqd->waited_rq to in bfq_add_request()
2283 bfqd->wait_dispatch = true; in bfq_add_request()
2297 if (bfqd->tot_rq_in_driver == 0) in bfq_add_request()
2298 bfqd->rqs_injected = false; in bfq_add_request()
2305 elv_rb_add(&bfqq->sort_list, rq); in bfq_add_request()
2308 * Check if this request is a better next-serve candidate. in bfq_add_request()
2310 prev = bfqq->next_rq; in bfq_add_request()
2311 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2312 bfqq->next_rq = next_rq; in bfq_add_request()
2318 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2325 if (bfqd->low_latency && old_wr_coeff == 1 && !rq_is_sync(rq) && in bfq_add_request()
2327 bfqq->last_wr_start_finish + in bfq_add_request()
2328 bfqd->bfq_wr_min_inter_arr_async)) { in bfq_add_request()
2329 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2330 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2332 bfqd->wr_busy_queues++; in bfq_add_request()
2333 bfqq->entity.prio_changed = 1; in bfq_add_request()
2335 if (prev != bfqq->next_rq) in bfq_add_request()
2343 * . if bfqq is not going to be weight-raised, because, for in bfq_add_request()
2344 * non weight-raised queues, last_wr_start_finish stores the in bfq_add_request()
2347 * weight-raise async queues in bfq_add_request()
2349 * . if bfqq is not weight-raised, because, if bfqq is now in bfq_add_request()
2350 * switching to weight-raised, then last_wr_start_finish in bfq_add_request()
2351 * stores the time when weight-raising starts in bfq_add_request()
2354 * bfqq is currently weight-raised, the weight-raising in bfq_add_request()
2357 * conditions, if bfqq is already weight-raised) in bfq_add_request()
2360 * real-time, because the weight-raising period is constantly in bfq_add_request()
2361 * restarted on idle-to-busy transitions for these queues, but in bfq_add_request()
2365 if (bfqd->low_latency && in bfq_add_request()
2366 (old_wr_coeff == 1 || bfqq->wr_coeff == 1 || interactive)) in bfq_add_request()
2367 bfqq->last_wr_start_finish = jiffies; in bfq_add_request()
2374 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge()
2378 return elv_rb_find(&bfqq->sort_list, bio_end_sector(bio)); in bfq_find_rq_fmerge()
2386 return abs(blk_rq_pos(rq) - last_pos); in get_sdist()
2395 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request()
2398 if (bfqq->next_rq == rq) { in bfq_remove_request()
2399 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2403 if (rq->queuelist.prev != &rq->queuelist) in bfq_remove_request()
2404 list_del_init(&rq->queuelist); in bfq_remove_request()
2405 bfqq->queued[sync]--; in bfq_remove_request()
2407 * Updating of 'bfqd->queued' is protected by 'bfqd->lock', however, it in bfq_remove_request()
2410 WRITE_ONCE(bfqd->queued, bfqd->queued - 1); in bfq_remove_request()
2411 elv_rb_del(&bfqq->sort_list, rq); in bfq_remove_request()
2414 if (q->last_merge == rq) in bfq_remove_request()
2415 q->last_merge = NULL; in bfq_remove_request()
2417 if (RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_remove_request()
2418 bfqq->next_rq = NULL; in bfq_remove_request()
2420 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2424 * bfqq is empty, bfqq->entity.service and in bfq_remove_request()
2425 * bfqq->entity.budget must contain, in bfq_remove_request()
2431 * reset both bfqq->entity.service and in bfq_remove_request()
2432 * bfqq->entity.budget, if bfqq has still a in bfq_remove_request()
2435 bfqq->entity.budget = bfqq->entity.service = 0; in bfq_remove_request()
2439 * Remove queue from request-position tree as it is empty. in bfq_remove_request()
2441 if (bfqq->pos_root) { in bfq_remove_request()
2442 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_remove_request()
2443 bfqq->pos_root = NULL; in bfq_remove_request()
2447 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_remove_request()
2451 if (rq->cmd_flags & REQ_META) in bfq_remove_request()
2452 bfqq->meta_pending--; in bfq_remove_request()
2459 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_bio_merge()
2464 * queue_lock inside the bfqd->lock. We assume that the bic in bfq_bio_merge()
2466 * bfqd->lock is taken. in bfq_bio_merge()
2471 spin_lock_irq(&bfqd->lock); in bfq_bio_merge()
2480 bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf), in bfq_bio_merge()
2483 bfqd->bio_bfqq = NULL; in bfq_bio_merge()
2485 bfqd->bio_bic = bic; in bfq_bio_merge()
2489 spin_unlock_irq(&bfqd->lock); in bfq_bio_merge()
2499 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_request_merge()
2518 rb_prev(&req->rb_node) && in bfq_request_merged()
2520 blk_rq_pos(container_of(rb_prev(&req->rb_node), in bfq_request_merged()
2529 bfqd = bfqq->bfqd; in bfq_request_merged()
2532 elv_rb_del(&bfqq->sort_list, req); in bfq_request_merged()
2533 elv_rb_add(&bfqq->sort_list, req); in bfq_request_merged()
2536 prev = bfqq->next_rq; in bfq_request_merged()
2537 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2538 bfqd->last_position); in bfq_request_merged()
2539 bfqq->next_rq = next_rq; in bfq_request_merged()
2545 if (prev != bfqq->next_rq) { in bfq_request_merged()
2551 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_request_merged()
2565 * on that rq is picked from the hash table q->elevator->hash, which,
2590 !list_empty(&rq->queuelist) && !list_empty(&next->queuelist) && in bfq_requests_merged()
2591 next->fifo_time < rq->fifo_time) { in bfq_requests_merged()
2592 list_del_init(&rq->queuelist); in bfq_requests_merged()
2593 list_replace_init(&next->queuelist, &rq->queuelist); in bfq_requests_merged()
2594 rq->fifo_time = next->fifo_time; in bfq_requests_merged()
2597 if (bfqq->next_rq == next) in bfq_requests_merged()
2598 bfqq->next_rq = rq; in bfq_requests_merged()
2600 bfqg_stats_update_io_merged(bfqq_group(bfqq), next->cmd_flags); in bfq_requests_merged()
2603 if (!RB_EMPTY_NODE(&next->rb_node)) { in bfq_requests_merged()
2604 bfq_remove_request(next->q, next); in bfq_requests_merged()
2607 next->cmd_flags); in bfq_requests_merged()
2615 * If bfqq has been enjoying interactive weight-raising, then in bfq_bfqq_end_wr()
2618 * a soft real-time application. Such an application actually in bfq_bfqq_end_wr()
2619 * exhibits a soft real-time I/O pattern after it finishes in bfq_bfqq_end_wr()
2628 if (bfqq->wr_cur_max_time != in bfq_bfqq_end_wr()
2629 bfqq->bfqd->bfq_wr_rt_max_time) in bfq_bfqq_end_wr()
2630 bfqq->soft_rt_next_start = jiffies; in bfq_bfqq_end_wr()
2633 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2634 bfqq->wr_coeff = 1; in bfq_bfqq_end_wr()
2635 bfqq->wr_cur_max_time = 0; in bfq_bfqq_end_wr()
2636 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_end_wr()
2641 bfqq->entity.prio_changed = 1; in bfq_bfqq_end_wr()
2649 for (k = 0; k < bfqd->num_actuators; k++) { in bfq_end_wr_async_queues()
2652 if (bfqg->async_bfqq[i][j][k]) in bfq_end_wr_async_queues()
2653 bfq_bfqq_end_wr(bfqg->async_bfqq[i][j][k]); in bfq_end_wr_async_queues()
2654 if (bfqg->async_idle_bfqq[k]) in bfq_end_wr_async_queues()
2655 bfq_bfqq_end_wr(bfqg->async_idle_bfqq[k]); in bfq_end_wr_async_queues()
2664 spin_lock_irq(&bfqd->lock); in bfq_end_wr()
2666 for (i = 0; i < bfqd->num_actuators; i++) { in bfq_end_wr()
2667 list_for_each_entry(bfqq, &bfqd->active_list[i], bfqq_list) in bfq_end_wr()
2670 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2674 spin_unlock_irq(&bfqd->lock); in bfq_end_wr()
2682 return ((struct bio *)io_struct)->bi_iter.bi_sector; in bfq_io_struct_pos()
2688 return abs(bfq_io_struct_pos(io_struct, request) - sector) <= in bfq_rq_close_to_sector()
2696 struct rb_root *root = &bfqq_group(bfqq)->rq_pos_tree; in bfqq_find_close()
2717 if (bfq_rq_close_to_sector(__bfqq->next_rq, true, sector)) in bfqq_find_close()
2720 if (blk_rq_pos(__bfqq->next_rq) < sector) in bfqq_find_close()
2721 node = rb_next(&__bfqq->pos_node); in bfqq_find_close()
2723 node = rb_prev(&__bfqq->pos_node); in bfqq_find_close()
2728 if (bfq_rq_close_to_sector(__bfqq->next_rq, true, sector)) in bfqq_find_close()
2762 * unsafe to follow the ->new_bfqq chain as other bfqq's in the chain in bfq_setup_merge()
2770 while ((__bfqq = new_bfqq->new_bfqq)) { in bfq_setup_merge()
2790 if (new_bfqq->entity.parent != bfqq->entity.parent) in bfq_setup_merge()
2793 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2794 new_bfqq->pid); in bfq_setup_merge()
2808 * not available any more (new_bfqq->bic == NULL). in bfq_setup_merge()
2810 * Anyway, even in case new_bfqq coincides with the in-service in bfq_setup_merge()
2811 * queue, redirecting requests the in-service queue is the in bfq_setup_merge()
2812 * best option, as we feed the in-service queue with new in bfq_setup_merge()
2816 bfqq->new_bfqq = new_bfqq; in bfq_setup_merge()
2821 * associated with new_bfqq. Here we increases new_bfqq->ref in bfq_setup_merge()
2826 new_bfqq->ref += process_refs; in bfq_setup_merge()
2837 (bfqq->ioprio_class != new_bfqq->ioprio_class)) in bfq_may_be_close_cooperator()
2871 bfqq_data->stable_merge_bfqq = NULL; in bfq_setup_stable_merge()
2879 bfqq_data->stably_merged = true; in bfq_setup_stable_merge()
2880 if (new_bfqq->bic) { in bfq_setup_stable_merge()
2881 unsigned int new_a_idx = new_bfqq->actuator_idx; in bfq_setup_stable_merge()
2883 &new_bfqq->bic->bfqq_data[new_a_idx]; in bfq_setup_stable_merge()
2885 new_bfqq_data->stably_merged = true; in bfq_setup_stable_merge()
2897 * Attempt to schedule a merge of bfqq with the currently in-service
2909 * WARNING: queue merging may impair fairness among non-weight raised
2913 * requests than the ones produced by its originally-associated
2921 unsigned int a_idx = bfqq->actuator_idx; in bfq_setup_cooperator()
2922 struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[a_idx]; in bfq_setup_cooperator()
2925 new_bfqq = bfqq->new_bfqq; in bfq_setup_cooperator()
2927 while (new_bfqq->new_bfqq) in bfq_setup_cooperator()
2928 new_bfqq = new_bfqq->new_bfqq; in bfq_setup_cooperator()
2933 * Check delayed stable merge for rotational or non-queueing in bfq_setup_cooperator()
2935 * currently merged with some other queue (i.e., bfqq->bic in bfq_setup_cooperator()
2938 * merged with bic->stable_merge_bfqq. But this would be in bfq_setup_cooperator()
2941 if (unlikely(!bfqd->nonrot_with_queueing)) { in bfq_setup_cooperator()
2944 * bic->stable_merge_bfqq may point to some queue (for in bfq_setup_cooperator()
2948 if (bfq_bfqq_sync(bfqq) && bfqq_data->stable_merge_bfqq && in bfq_setup_cooperator()
2950 time_is_before_jiffies(bfqq->split_time + in bfq_setup_cooperator()
2952 time_is_before_jiffies(bfqq->creation_time + in bfq_setup_cooperator()
2955 bfqq_data->stable_merge_bfqq; in bfq_setup_cooperator()
2981 * non-merged queues. This may accentuate workload in bfq_setup_cooperator()
3000 if (likely(bfqd->nonrot_with_queueing)) in bfq_setup_cooperator()
3010 * probability that two non-cooperating processes, which just in bfq_setup_cooperator()
3017 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
3024 in_service_bfqq = bfqd->in_service_queue; in bfq_setup_cooperator()
3027 likely(in_service_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
3029 bfqd->in_serv_last_pos) && in bfq_setup_cooperator()
3030 bfqq->entity.parent == in_service_bfqq->entity.parent && in bfq_setup_cooperator()
3044 if (new_bfqq && likely(new_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
3053 struct bfq_io_cq *bic = bfqq->bic; in bfq_bfqq_save_state()
3054 unsigned int a_idx = bfqq->actuator_idx; in bfq_bfqq_save_state()
3055 struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[a_idx]; in bfq_bfqq_save_state()
3058 * If !bfqq->bic, the queue is already shared or its requests in bfq_bfqq_save_state()
3065 bfqq_data->saved_last_serv_time_ns = bfqq->last_serv_time_ns; in bfq_bfqq_save_state()
3066 bfqq_data->saved_inject_limit = bfqq->inject_limit; in bfq_bfqq_save_state()
3067 bfqq_data->saved_decrease_time_jif = bfqq->decrease_time_jif; in bfq_bfqq_save_state()
3069 bfqq_data->saved_weight = bfqq->entity.orig_weight; in bfq_bfqq_save_state()
3070 bfqq_data->saved_ttime = bfqq->ttime; in bfq_bfqq_save_state()
3071 bfqq_data->saved_has_short_ttime = in bfq_bfqq_save_state()
3073 bfqq_data->saved_IO_bound = bfq_bfqq_IO_bound(bfqq); in bfq_bfqq_save_state()
3074 bfqq_data->saved_io_start_time = bfqq->io_start_time; in bfq_bfqq_save_state()
3075 bfqq_data->saved_tot_idle_time = bfqq->tot_idle_time; in bfq_bfqq_save_state()
3076 bfqq_data->saved_in_large_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_save_state()
3077 bfqq_data->was_in_burst_list = in bfq_bfqq_save_state()
3078 !hlist_unhashed(&bfqq->burst_list_node); in bfq_bfqq_save_state()
3082 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
3086 * did not make it to be set in a weight-raised state, in bfq_bfqq_save_state()
3088 * weight-raising state that would have been assigned in bfq_bfqq_save_state()
3092 bfqq_data->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
3093 bfqq_data->saved_wr_start_at_switch_to_srt = in bfq_bfqq_save_state()
3095 bfqq_data->saved_wr_cur_max_time = in bfq_bfqq_save_state()
3096 bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
3097 bfqq_data->saved_last_wr_start_finish = jiffies; in bfq_bfqq_save_state()
3099 bfqq_data->saved_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_save_state()
3100 bfqq_data->saved_wr_start_at_switch_to_srt = in bfq_bfqq_save_state()
3101 bfqq->wr_start_at_switch_to_srt; in bfq_bfqq_save_state()
3102 bfqq_data->saved_service_from_wr = in bfq_bfqq_save_state()
3103 bfqq->service_from_wr; in bfq_bfqq_save_state()
3104 bfqq_data->saved_last_wr_start_finish = in bfq_bfqq_save_state()
3105 bfqq->last_wr_start_finish; in bfq_bfqq_save_state()
3106 bfqq_data->saved_wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_bfqq_save_state()
3114 if (cur_bfqq->entity.parent && in bfq_reassign_last_bfqq()
3115 cur_bfqq->entity.parent->last_bfqq_created == cur_bfqq) in bfq_reassign_last_bfqq()
3116 cur_bfqq->entity.parent->last_bfqq_created = new_bfqq; in bfq_reassign_last_bfqq()
3117 else if (cur_bfqq->bfqd && cur_bfqq->bfqd->last_bfqq_created == cur_bfqq) in bfq_reassign_last_bfqq()
3118 cur_bfqq->bfqd->last_bfqq_created = new_bfqq; in bfq_reassign_last_bfqq()
3134 if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_release_process_ref()
3135 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
3147 struct bfq_queue *new_bfqq = bfqq->new_bfqq; in bfq_merge_bfqqs()
3150 (unsigned long)new_bfqq->pid); in bfq_merge_bfqqs()
3165 if (bfqq->waker_bfqq && !new_bfqq->waker_bfqq && in bfq_merge_bfqqs()
3166 bfqq->waker_bfqq != new_bfqq) { in bfq_merge_bfqqs()
3167 new_bfqq->waker_bfqq = bfqq->waker_bfqq; in bfq_merge_bfqqs()
3168 new_bfqq->tentative_waker_bfqq = NULL; in bfq_merge_bfqqs()
3172 * new_bfqq->waker_bfqq must be reset. So insert in bfq_merge_bfqqs()
3176 hlist_add_head(&new_bfqq->woken_list_node, in bfq_merge_bfqqs()
3177 &new_bfqq->waker_bfqq->woken_list); in bfq_merge_bfqqs()
3182 * If bfqq is weight-raised, then let new_bfqq inherit in bfq_merge_bfqqs()
3183 * weight-raising. To reduce false positives, neglect the case in bfq_merge_bfqqs()
3185 * to be weight-raised (which may happen because EQM may merge in bfq_merge_bfqqs()
3190 if (new_bfqq->wr_coeff == 1 && bfqq->wr_coeff > 1) { in bfq_merge_bfqqs()
3191 new_bfqq->wr_coeff = bfqq->wr_coeff; in bfq_merge_bfqqs()
3192 new_bfqq->wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_merge_bfqqs()
3193 new_bfqq->last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_merge_bfqqs()
3194 new_bfqq->wr_start_at_switch_to_srt = in bfq_merge_bfqqs()
3195 bfqq->wr_start_at_switch_to_srt; in bfq_merge_bfqqs()
3197 bfqd->wr_busy_queues++; in bfq_merge_bfqqs()
3198 new_bfqq->entity.prio_changed = 1; in bfq_merge_bfqqs()
3201 if (bfqq->wr_coeff > 1) { /* bfqq has given its wr to new_bfqq */ in bfq_merge_bfqqs()
3202 bfqq->wr_coeff = 1; in bfq_merge_bfqqs()
3203 bfqq->entity.prio_changed = 1; in bfq_merge_bfqqs()
3205 bfqd->wr_busy_queues--; in bfq_merge_bfqqs()
3209 bfqd->wr_busy_queues); in bfq_merge_bfqqs()
3214 bic_set_bfqq(bic, new_bfqq, true, bfqq->actuator_idx); in bfq_merge_bfqqs()
3218 * set new_bfqq->bic to NULL. bfqq either: in bfq_merge_bfqqs()
3219 * - does not belong to any bic any more, and hence bfqq->bic must in bfq_merge_bfqqs()
3221 * - is a queue whose owning bics have already been redirected to a in bfq_merge_bfqqs()
3223 * any bic soon and bfqq->bic is already NULL (therefore the next in bfq_merge_bfqqs()
3226 new_bfqq->bic = NULL; in bfq_merge_bfqqs()
3233 * We mark such a queue with a pid -1, and then print SHARED instead of in bfq_merge_bfqqs()
3236 new_bfqq->pid = -1; in bfq_merge_bfqqs()
3237 bfqq->bic = NULL; in bfq_merge_bfqqs()
3249 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_allow_bio_merge()
3250 bool is_sync = op_is_sync(bio->bi_opf); in bfq_allow_bio_merge()
3251 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge()
3270 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false, bfqd->bio_bic); in bfq_allow_bio_merge()
3280 bfqq = bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq); in bfq_allow_bio_merge()
3283 * Change also bqfd->bio_bfqq, as in bfq_allow_bio_merge()
3284 * bfqd->bio_bic now points to new_bfqq, and in bfq_allow_bio_merge()
3286 * use again bqfd->bio_bfqq). in bfq_allow_bio_merge()
3288 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
3295 * Set the maximum time for the in-service queue to consume its
3297 * In practice, a time-slice service scheme is used with seeky
3305 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
3308 timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight; in bfq_set_budget_timeout()
3310 bfqd->last_budget_start = blk_time_get(); in bfq_set_budget_timeout()
3312 bfqq->budget_timeout = jiffies + in bfq_set_budget_timeout()
3313 bfqd->bfq_timeout * timeout_coeff; in bfq_set_budget_timeout()
3322 bfqd->budgets_assigned = (bfqd->budgets_assigned * 7 + 256) / 8; in __bfq_set_in_service_queue()
3324 if (time_is_before_jiffies(bfqq->last_wr_start_finish) && in __bfq_set_in_service_queue()
3325 bfqq->wr_coeff > 1 && in __bfq_set_in_service_queue()
3326 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
3327 time_is_before_jiffies(bfqq->budget_timeout)) { in __bfq_set_in_service_queue()
3329 * For soft real-time queues, move the start in __bfq_set_in_service_queue()
3330 * of the weight-raising period forward by the in __bfq_set_in_service_queue()
3334 * weight-raising period of the queue to end, in __bfq_set_in_service_queue()
3336 * weight-raising period of a soft real-time in __bfq_set_in_service_queue()
3339 * because soft real-time queues are not in __bfq_set_in_service_queue()
3352 if (time_after(bfqq->budget_timeout, in __bfq_set_in_service_queue()
3353 bfqq->last_wr_start_finish)) in __bfq_set_in_service_queue()
3354 bfqq->last_wr_start_finish += in __bfq_set_in_service_queue()
3355 jiffies - bfqq->budget_timeout; in __bfq_set_in_service_queue()
3357 bfqq->last_wr_start_finish = jiffies; in __bfq_set_in_service_queue()
3362 "set_in_service_queue, cur-budget = %d", in __bfq_set_in_service_queue()
3363 bfqq->entity.budget); in __bfq_set_in_service_queue()
3366 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
3367 bfqd->in_serv_last_pos = 0; in __bfq_set_in_service_queue()
3383 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer()
3390 * fair distribution of slice time for a process doing back-to-back in bfq_arm_slice_timer()
3393 sl = bfqd->bfq_slice_idle; in bfq_arm_slice_timer()
3395 * Unless the queue is being weight-raised or the scenario is in bfq_arm_slice_timer()
3397 * is seeky. A long idling is preserved for a weight-raised in bfq_arm_slice_timer()
3404 if (BFQQ_SEEKY(bfqq) && bfqq->wr_coeff == 1 && in bfq_arm_slice_timer()
3407 else if (bfqq->wr_coeff > 1) in bfq_arm_slice_timer()
3410 bfqd->last_idling_start = blk_time_get(); in bfq_arm_slice_timer()
3411 bfqd->last_idling_start_jiffies = jiffies; in bfq_arm_slice_timer()
3413 hrtimer_start(&bfqd->idle_slice_timer, ns_to_ktime(sl), in bfq_arm_slice_timer()
3422 * budget, even if the in-service queue is served at peak rate. And
3427 return (u64)bfqd->peak_rate * USEC_PER_MSEC * in bfq_calc_max_budget()
3428 jiffies_to_msecs(bfqd->bfq_timeout)>>BFQ_RATE_SHIFT; in bfq_calc_max_budget()
3438 if (bfqd->bfq_user_max_budget == 0) { in update_thr_responsiveness_params()
3439 bfqd->bfq_max_budget = in update_thr_responsiveness_params()
3441 bfq_log(bfqd, "new max_budget = %d", bfqd->bfq_max_budget); in update_thr_responsiveness_params()
3449 bfqd->last_dispatch = bfqd->first_dispatch = blk_time_get_ns(); in bfq_reset_rate_computation()
3450 bfqd->peak_rate_samples = 1; in bfq_reset_rate_computation()
3451 bfqd->sequential_samples = 0; in bfq_reset_rate_computation()
3452 bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size = in bfq_reset_rate_computation()
3455 bfqd->peak_rate_samples = 0; /* full re-init on next disp. */ in bfq_reset_rate_computation()
3459 bfqd->peak_rate_samples, bfqd->sequential_samples, in bfq_reset_rate_computation()
3460 bfqd->tot_sectors_dispatched); in bfq_reset_rate_computation()
3475 if (bfqd->peak_rate_samples < BFQ_RATE_MIN_SAMPLES || in bfq_update_rate_reset()
3476 bfqd->delta_from_first < BFQ_RATE_MIN_INTERVAL) in bfq_update_rate_reset()
3485 bfqd->delta_from_first = in bfq_update_rate_reset()
3486 max_t(u64, bfqd->delta_from_first, in bfq_update_rate_reset()
3487 bfqd->last_completion - bfqd->first_dispatch); in bfq_update_rate_reset()
3493 rate = div64_ul(bfqd->tot_sectors_dispatched<<BFQ_RATE_SHIFT, in bfq_update_rate_reset()
3494 div_u64(bfqd->delta_from_first, NSEC_PER_USEC)); in bfq_update_rate_reset()
3498 * - the percentage of sequential dispatches is below 3/4 of the in bfq_update_rate_reset()
3500 * - rate is unreasonably high (> 20M sectors/sec) in bfq_update_rate_reset()
3502 if ((bfqd->sequential_samples < (3 * bfqd->peak_rate_samples)>>2 && in bfq_update_rate_reset()
3503 rate <= bfqd->peak_rate) || in bfq_update_rate_reset()
3509 * we use a low-pass filter. We compute the smoothing constant in bfq_update_rate_reset()
3525 * cannot reach 9, because bfqd->sequential_samples cannot in bfq_update_rate_reset()
3526 * become equal to bfqd->peak_rate_samples, which, in its in bfq_update_rate_reset()
3527 * turn, holds true because bfqd->sequential_samples is not in bfq_update_rate_reset()
3530 weight = (9 * bfqd->sequential_samples) / bfqd->peak_rate_samples; in bfq_update_rate_reset()
3537 div_u64(weight * bfqd->delta_from_first, in bfq_update_rate_reset()
3544 divisor = 10 - weight; in bfq_update_rate_reset()
3549 * peak_rate = peak_rate * (divisor-1) / divisor + rate / divisor in bfq_update_rate_reset()
3551 bfqd->peak_rate *= divisor-1; in bfq_update_rate_reset()
3552 bfqd->peak_rate /= divisor; in bfq_update_rate_reset()
3555 bfqd->peak_rate += rate; in bfq_update_rate_reset()
3558 * For a very slow device, bfqd->peak_rate can reach 0 (see in bfq_update_rate_reset()
3561 * divisions by zero where bfqd->peak_rate is used as a in bfq_update_rate_reset()
3564 bfqd->peak_rate = max_t(u32, 1, bfqd->peak_rate); in bfq_update_rate_reset()
3574 * auto-tuning, see update_thr_responsiveness_params()).
3589 * unknown, namely in-device request service rate.
3608 if (bfqd->peak_rate_samples == 0) { /* first dispatch */ in bfq_update_peak_rate()
3610 bfqd->peak_rate_samples); in bfq_update_peak_rate()
3618 * for computing a new peak rate (similarly to the late- in bfq_update_peak_rate()
3622 * - close the observation interval at the last (previous) in bfq_update_peak_rate()
3624 * - compute rate, if possible, for that observation interval in bfq_update_peak_rate()
3625 * - start a new observation interval with this dispatch in bfq_update_peak_rate()
3627 if (now_ns - bfqd->last_dispatch > 100*NSEC_PER_MSEC && in bfq_update_peak_rate()
3628 bfqd->tot_rq_in_driver == 0) in bfq_update_peak_rate()
3632 bfqd->peak_rate_samples++; in bfq_update_peak_rate()
3634 if ((bfqd->tot_rq_in_driver > 0 || in bfq_update_peak_rate()
3635 now_ns - bfqd->last_completion < BFQ_MIN_TT) in bfq_update_peak_rate()
3636 && !BFQ_RQ_SEEKY(bfqd, bfqd->last_position, rq)) in bfq_update_peak_rate()
3637 bfqd->sequential_samples++; in bfq_update_peak_rate()
3639 bfqd->tot_sectors_dispatched += blk_rq_sectors(rq); in bfq_update_peak_rate()
3642 if (likely(bfqd->peak_rate_samples % 32)) in bfq_update_peak_rate()
3643 bfqd->last_rq_max_size = in bfq_update_peak_rate()
3644 max_t(u32, blk_rq_sectors(rq), bfqd->last_rq_max_size); in bfq_update_peak_rate()
3646 bfqd->last_rq_max_size = blk_rq_sectors(rq); in bfq_update_peak_rate()
3648 bfqd->delta_from_first = now_ns - bfqd->first_dispatch; in bfq_update_peak_rate()
3651 if (bfqd->delta_from_first < BFQ_RATE_REF_INTERVAL) in bfq_update_peak_rate()
3657 bfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_update_peak_rate()
3658 if (RQ_BFQQ(rq) == bfqd->in_service_queue) in bfq_update_peak_rate()
3659 bfqd->in_serv_last_pos = bfqd->last_position; in bfq_update_peak_rate()
3660 bfqd->last_dispatch = now_ns; in bfq_update_peak_rate()
3676 * dispatch occur for a non in-service bfqq, this anticipated in bfq_dispatch_remove()
3677 * increment prevents two counters related to bfqq->dispatched in bfq_dispatch_remove()
3679 * incremented again when the (new) value of bfqq->dispatched in bfq_dispatch_remove()
3682 bfqq->dispatched++; in bfq_dispatch_remove()
3683 bfq_update_peak_rate(q->elevator->elevator_data, rq); in bfq_dispatch_remove()
3701 * the service order of the internally-queued requests, does
3704 * concern about per-process throughput distribution, and
3705 * makes its decisions only on a per-request basis. Therefore,
3710 * (i-a) each of these processes must get the same throughput as
3712 * (i-b) in case (i-a) does not hold, it holds that the process
3718 * (from I/O-bound to sporadic), and so on;
3724 * distribution if (i-a) holds, or, if (i-b) holds instead, this is an
3729 * idling (I/O-dispatch plugging) is certainly needed to guarantee
3737 * throughput, it is important to check conditions (i-a), i(-b) and
3743 * very difficult to check conditions (i-a) and (i-b) too. In fact,
3744 * if there are active groups, then, for conditions (i-a) or (i-b) to
3746 * contains more active processes or sub-groups than some other active
3747 * group. More precisely, for conditions (i-a) or (i-b) to become
3755 * inactive while still having in-flight requests, and if, when this
3761 * bi-modal behavior, implemented in the function
3768 * conditions (i-a), (i-b) or (ii). So the device is idled for bfqq.
3774 * for completion, then only conditions (i-a) and (i-b) are actually
3775 * controlled, i.e., provided that conditions (i-a) or (i-b) holds,
3777 * holds. In other words, only if conditions (i-a) and (i-b) do not
3781 * control conditions (i-a) and (i-b) it is enough to check just
3794 * can still preempt the new in-service queue if the next
3798 * combined with the hole-recovery heuristic described in the
3805 * minimum of mid-term fairness.
3807 * More precisely, this preemption-based, idleless approach
3831 * We are now left only with explaining the two sub-conditions in the
3834 * sub-condition, we need to add that the function
3836 * non-weight-raised queues, for efficiency reasons (see comments on
3837 * bfq_weights_tree_add()). Then the fact that bfqq is weight-raised
3840 * weight-raised, the scenario is still symmetric if all queues with
3842 * weight-raised. Actually, we should be even more precise here, and
3843 * differentiate between interactive weight raising and soft real-time
3846 * The second sub-condition checked in the compound condition is
3847 * whether there is a fair amount of already in-flight I/O not
3849 * following reason. The drive may decide to serve in-flight
3850 * non-bfqq's I/O requests before bfqq's ones, thereby delaying the
3852 * I/O-dispatching is not plugged, then, while bfqq remains empty, a
3860 * in-flight I/O, and enables bfqq to recover the bandwidth it may
3864 * device-idling countermeasures may however fail in the following
3865 * unlucky scenario: if I/O-dispatch plugging is (correctly) disabled
3866 * in a time period during which all symmetry sub-conditions hold, and
3868 * some later point in time some sub-condition stops to hold, then it
3871 * served. The last sub-condition commented above somewhat mitigates
3872 * this problem for weight-raised queues.
3898 return (bfqq->wr_coeff > 1 && in idling_needed_for_service_guarantees()
3899 (bfqd->wr_busy_queues < tot_busy_queues || in idling_needed_for_service_guarantees()
3900 bfqd->tot_rq_in_driver >= bfqq->dispatched + 4)) || in idling_needed_for_service_guarantees()
3925 * not re-scheduled. To prevent this from happening, re-queue in __bfq_bfqq_expire()
3926 * bfqq if it needs I/O-dispatch plugging, even if it is in __bfq_bfqq_expire()
3930 if (RB_EMPTY_ROOT(&bfqq->sort_list) && in __bfq_bfqq_expire()
3933 if (bfqq->dispatched == 0) in __bfq_bfqq_expire()
3938 * the weight-raising mechanism. in __bfq_bfqq_expire()
3940 bfqq->budget_timeout = jiffies; in __bfq_bfqq_expire()
3949 if (unlikely(!bfqd->nonrot_with_queueing && in __bfq_bfqq_expire()
3950 !RB_EMPTY_ROOT(&bfqq->sort_list))) in __bfq_bfqq_expire()
3955 * All in-service entities must have been properly deactivated in __bfq_bfqq_expire()
3957 * resets all in-service entities as no more in service. This in __bfq_bfqq_expire()
3965 * __bfq_bfqq_recalc_budget - try to adapt the budget to the @bfqq behavior.
3982 if (bfqq->wr_coeff == 1) in __bfq_bfqq_recalc_budget()
3983 budget = bfqq->max_budget; in __bfq_bfqq_recalc_budget()
3985 * Use a constant, low budget for weight-raised queues, in __bfq_bfqq_recalc_budget()
3993 bfqq->entity.budget, bfq_bfqq_budget_left(bfqq)); in __bfq_bfqq_recalc_budget()
3997 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
3999 if (bfq_bfqq_sync(bfqq) && bfqq->wr_coeff == 1) { in __bfq_bfqq_recalc_budget()
4030 if (bfqq->dispatched > 0) /* still outstanding reqs */ in __bfq_bfqq_recalc_budget()
4031 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4034 budget -= 4 * min_budget; in __bfq_bfqq_recalc_budget()
4046 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4058 budget = min(budget * 4, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4072 * back-shifting. The larger the budget of the in __bfq_bfqq_recalc_budget()
4081 * many re-activations a lower finish time in __bfq_bfqq_recalc_budget()
4085 * quite precisely by bfqq->entity.service. in __bfq_bfqq_recalc_budget()
4087 * bfqq->entity.service is equal to the number in __bfq_bfqq_recalc_budget()
4093 budget = max_t(int, bfqq->entity.service, min_budget); in __bfq_bfqq_recalc_budget()
4105 budget = bfqd->bfq_max_budget; in __bfq_bfqq_recalc_budget()
4108 bfqq->max_budget = budget; in __bfq_bfqq_recalc_budget()
4110 if (bfqd->budgets_assigned >= bfq_stats_min_budgets && in __bfq_bfqq_recalc_budget()
4111 !bfqd->bfq_user_max_budget) in __bfq_bfqq_recalc_budget()
4112 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4124 next_rq = bfqq->next_rq; in __bfq_bfqq_recalc_budget()
4126 bfqq->entity.budget = max_t(unsigned long, bfqq->max_budget, in __bfq_bfqq_recalc_budget()
4131 bfqq->entity.budget); in __bfq_bfqq_recalc_budget()
4154 * service slots. On the opposite end, the requests of the in-service
4176 delta_ktime = bfqd->last_idling_start; in bfq_bfqq_is_slow()
4179 delta_ktime = ktime_sub(delta_ktime, bfqd->last_budget_start); in bfq_bfqq_is_slow()
4184 if (blk_queue_nonrot(bfqd->queue)) in bfq_bfqq_is_slow()
4186 * give same worst-case guarantees as idling in bfq_bfqq_is_slow()
4213 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
4222 * To be deemed as soft real-time, an application must meet two
4225 * record a compressed high-definition video.
4227 * batch, to compute the next-start time instant, soft_rt_next_start, such
4241 * Unfortunately, even a greedy (i.e., I/O-bound) application may
4248 * device: the storage device is highly loaded or reaches a low-enough
4253 * that greedy applications are deemed as soft real-time in these
4260 * namely bfqd->bfq_slice_idle, and (2) a few extra jiffies. We
4262 * jiffies; we get back to it after next item (b). Lower-bounding
4264 * bfqd->bfq_slice_idle tends to filter out greedy applications,
4267 * real-time application spends some time processing data, after a
4270 * (b) Current value of bfqq->soft_rt_next_start. As pointed out
4273 * storage-device load. In more detail, in these scenarios, these
4276 * including the filtering in above item (a). These slow-speed
4280 * I/O in the high-speed intervals, the values returned by this
4282 * high-speed interval, to be likely to fall *after* the end of
4283 * the low-speed time interval that follows. These high values are
4284 * stored in bfqq->soft_rt_next_start after each invocation of
4286 * bfqq->soft_rt_next_start is constantly used to lower-bound the
4288 * beginning of a low-speed interval, bfqq->soft_rt_next_start is
4290 * issued during the low-speed interval is considered as arriving
4292 * real-time. Then, in the high-speed interval that follows, the
4293 * application will not be deemed as soft real-time, just because
4299 * bfqd->bfq_slice_idle:
4301 * higher than bfqd->bfq_slice_idle. This happens, e.g., on slow
4303 * that the approximation, in jiffies, of bfqd->bfq_slice_idle
4309 * reference time interval just bfqd->bfq_slice_idle, but
4310 * bfqd->bfq_slice_idle plus a few jiffies. In particular, we add the
4317 return max3(bfqq->soft_rt_next_start, in bfq_bfqq_softrt_next_start()
4318 bfqq->last_idle_bklogged + in bfq_bfqq_softrt_next_start()
4319 HZ * bfqq->service_from_backlogged / in bfq_bfqq_softrt_next_start()
4320 bfqd->bfq_wr_max_softrt_rate, in bfq_bfqq_softrt_next_start()
4321 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
4325 * bfq_bfqq_expire - expire a queue.
4340 * tends to lower the throughput). In addition, this time-charging
4357 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_expire()
4366 * timed-out queues with the time and not the service in bfq_bfqq_expire()
4377 * or quasi-sequential processes. in bfq_bfqq_expire()
4379 if (bfqq->wr_coeff == 1 && in bfq_bfqq_expire()
4382 bfq_bfqq_budget_left(bfqq) >= entity->budget / 3))) in bfq_bfqq_expire()
4385 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
4386 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_expire()
4388 if (bfqd->low_latency && bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_expire()
4389 RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_bfqq_expire()
4402 if (bfqq->dispatched == 0) in bfq_bfqq_expire()
4403 bfqq->soft_rt_next_start = in bfq_bfqq_expire()
4405 else if (bfqq->dispatched > 0) { in bfq_bfqq_expire()
4416 slow, bfqq->dispatched, bfq_bfqq_has_short_ttime(bfqq)); in bfq_bfqq_expire()
4423 bfqd->rqs_injected = bfqd->wait_dispatch = false; in bfq_bfqq_expire()
4424 bfqd->waited_rq = NULL; in bfq_bfqq_expire()
4446 entity->service = 0; in bfq_bfqq_expire()
4449 * Reset the received-service counter for every parent entity. in bfq_bfqq_expire()
4450 * Differently from what happens with bfqq->entity.service, in bfq_bfqq_expire()
4454 * consumed budget, bfqq->entity.service needs to be kept, in bfq_bfqq_expire()
4456 * the same budget, the last value of bfqq->entity.service is in bfq_bfqq_expire()
4457 * needed to properly decrement bfqq->entity.budget by the in bfq_bfqq_expire()
4459 * to keep entity->service for parent entities too, because in bfq_bfqq_expire()
4460 * the bubble up of the new value of bfqq->entity.budget will in bfq_bfqq_expire()
4465 entity = entity->parent; in bfq_bfqq_expire()
4467 entity->service = 0; in bfq_bfqq_expire()
4477 return time_is_before_eq_jiffies(bfqq->budget_timeout); in bfq_bfqq_budget_timeout()
4490 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4493 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3, in bfq_may_expire_for_budg_timeout()
4497 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3) in bfq_may_expire_for_budg_timeout()
4506 !blk_queue_nonrot(bfqd->queue) && !bfqd->hw_tag, in idling_boosts_thr_without_issues()
4523 * (a) the device is not NCQ-capable and rotational, or in idling_boosts_thr_without_issues()
4525 * the request pattern for bfqq is I/O-bound and sequential, or in idling_boosts_thr_without_issues()
4527 * not NCQ-capable and the request pattern for bfqq is in idling_boosts_thr_without_issues()
4528 * I/O-bound and sequential. in idling_boosts_thr_without_issues()
4531 * NCQ-capable flash-based device would not boost the in idling_boosts_thr_without_issues()
4536 * particular, happens to be false if bfqd is an NCQ-capable in idling_boosts_thr_without_issues()
4537 * flash-based device. in idling_boosts_thr_without_issues()
4540 ((!blk_queue_nonrot(bfqd->queue) || !bfqd->hw_tag) && in idling_boosts_thr_without_issues()
4547 * weight-raised queues. in idling_boosts_thr_without_issues()
4551 * non-weight-raised queues ask for requests at a lower rate, in idling_boosts_thr_without_issues()
4552 * then processes associated with weight-raised queues have a in idling_boosts_thr_without_issues()
4557 * weight. This is especially true with NCQ-capable drives, in idling_boosts_thr_without_issues()
4559 * reorder internally-queued requests. in idling_boosts_thr_without_issues()
4562 * there are weight-raised busy queues. In this case, and if in idling_boosts_thr_without_issues()
4563 * bfqq is not weight-raised, this guarantees that the device in idling_boosts_thr_without_issues()
4564 * is not idled for bfqq (if, instead, bfqq is weight-raised, in idling_boosts_thr_without_issues()
4568 * sync non-weight-raised queue, to get a lower number of in idling_boosts_thr_without_issues()
4571 * weight-raised queues get served again. This often mitigates in idling_boosts_thr_without_issues()
4578 bfqd->wr_busy_queues == 0; in idling_boosts_thr_without_issues()
4592 * NCQ-capable devices, this function tries to return false, so as to
4594 * device boost the throughput without causing any service-guarantee
4604 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle()
4611 if (unlikely(bfqd->strict_guarantees)) in bfq_better_to_idle()
4620 * queues in this class can steal to higher-priority queues in bfq_better_to_idle()
4622 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4643 * If the in-service queue is empty but the function bfq_better_to_idle
4655 return RB_EMPTY_ROOT(&bfqq->sort_list) && bfq_better_to_idle(bfqq); in bfq_bfqq_must_idle()
4668 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection()
4669 unsigned int limit = in_serv_bfqq->inject_limit; in bfq_choose_bfqq_for_injection()
4674 * - bfqq is not weight-raised and therefore does not carry in bfq_choose_bfqq_for_injection()
4675 * time-critical I/O, in bfq_choose_bfqq_for_injection()
4677 * - regardless of whether bfqq is weight-raised, bfqq has in bfq_choose_bfqq_for_injection()
4684 bool in_serv_always_inject = in_serv_bfqq->wr_coeff == 1 || in bfq_choose_bfqq_for_injection()
4689 * - the baseline total service time could not be sampled yet, in bfq_choose_bfqq_for_injection()
4691 * - a lot of time has elapsed since the plugging of I/O in bfq_choose_bfqq_for_injection()
4696 if (limit == 0 && in_serv_bfqq->last_serv_time_ns == 0 && in bfq_choose_bfqq_for_injection()
4698 time_is_before_eq_jiffies(bfqd->last_idling_start_jiffies + in bfq_choose_bfqq_for_injection()
4699 bfqd->bfq_slice_idle) in bfq_choose_bfqq_for_injection()
4703 if (bfqd->tot_rq_in_driver >= limit) in bfq_choose_bfqq_for_injection()
4711 * - BFQ dynamically updates the budget of every queue so as in bfq_choose_bfqq_for_injection()
4713 * - if a queue gets all its requests dispatched as injected in bfq_choose_bfqq_for_injection()
4715 * (and re-added only if it gets new requests, but then it in bfq_choose_bfqq_for_injection()
4718 for (i = 0; i < bfqd->num_actuators; i++) { in bfq_choose_bfqq_for_injection()
4719 list_for_each_entry(bfqq, &bfqd->active_list[i], bfqq_list) in bfq_choose_bfqq_for_injection()
4720 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_choose_bfqq_for_injection()
4721 (in_serv_always_inject || bfqq->wr_coeff > 1) && in bfq_choose_bfqq_for_injection()
4722 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_choose_bfqq_for_injection()
4725 * Allow for only one large in-flight request in bfq_choose_bfqq_for_injection()
4726 * on non-rotational devices, for the in bfq_choose_bfqq_for_injection()
4727 * following reason. On non-rotationl drives, in bfq_choose_bfqq_for_injection()
4734 * request of the in-service queue wait for so in bfq_choose_bfqq_for_injection()
4738 * there is only one in-flight large request in bfq_choose_bfqq_for_injection()
4741 if (blk_queue_nonrot(bfqd->queue) && in bfq_choose_bfqq_for_injection()
4742 blk_rq_sectors(bfqq->next_rq) >= in bfq_choose_bfqq_for_injection()
4744 bfqd->tot_rq_in_driver >= 1) in bfq_choose_bfqq_for_injection()
4747 bfqd->rqs_injected = true; in bfq_choose_bfqq_for_injection()
4761 if (bfqd->in_service_queue && in bfq_find_active_bfqq_for_actuator()
4762 bfqd->in_service_queue->actuator_idx == idx) in bfq_find_active_bfqq_for_actuator()
4763 return bfqd->in_service_queue; in bfq_find_active_bfqq_for_actuator()
4765 list_for_each_entry(bfqq, &bfqd->active_list[idx], bfqq_list) { in bfq_find_active_bfqq_for_actuator()
4766 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_find_active_bfqq_for_actuator()
4767 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_find_active_bfqq_for_actuator()
4794 for (i = 0 ; i < bfqd->num_actuators; i++) { in bfq_find_bfqq_for_underused_actuator()
4795 if (bfqd->rq_in_driver[i] < bfqd->actuator_load_threshold && in bfq_find_bfqq_for_underused_actuator()
4796 (i == bfqd->num_actuators - 1 || in bfq_find_bfqq_for_underused_actuator()
4797 bfqd->rq_in_driver[i] < bfqd->rq_in_driver[i+1])) { in bfq_find_bfqq_for_underused_actuator()
4820 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4824 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4839 * If some actuator is underutilized, but the in-service in bfq_select_queue()
4849 * happens, it is much more convenient to re-execute this loop in bfq_select_queue()
4853 next_rq = bfqq->next_rq; in bfq_select_queue()
4890 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_select_queue()
4897 * No requests pending. However, if the in-service queue is idling in bfq_select_queue()
4905 (bfqq->dispatched != 0 && bfq_better_to_idle(bfqq))) { in bfq_select_queue()
4906 unsigned int act_idx = bfqq->actuator_idx; in bfq_select_queue()
4909 !hlist_empty(&bfqq->woken_list) ? in bfq_select_queue()
4910 container_of(bfqq->woken_list.first, in bfq_select_queue()
4915 if (bfqq->bic && bfqq->bic->bfqq[0][act_idx] && in bfq_select_queue()
4916 bfq_bfqq_busy(bfqq->bic->bfqq[0][act_idx]) && in bfq_select_queue()
4917 bfqq->bic->bfqq[0][act_idx]->next_rq) in bfq_select_queue()
4918 async_bfqq = bfqq->bic->bfqq[0][act_idx]; in bfq_select_queue()
4920 * The next four mutually-exclusive ifs decide in bfq_select_queue()
4932 * non-empty waker queue for bfqq, i.e., a queue whose in bfq_select_queue()
4983 * I/O-plugging timeout fires. So one may deem the in bfq_select_queue()
5000 icq_to_bic(async_bfqq->next_rq->elv.icq) == bfqq->bic && in bfq_select_queue()
5001 bfq_serv_to_charge(async_bfqq->next_rq, async_bfqq) <= in bfq_select_queue()
5004 else if (bfqq->waker_bfqq && in bfq_select_queue()
5005 bfq_bfqq_busy(bfqq->waker_bfqq) && in bfq_select_queue()
5006 bfqq->waker_bfqq->next_rq && in bfq_select_queue()
5007 bfq_serv_to_charge(bfqq->waker_bfqq->next_rq, in bfq_select_queue()
5008 bfqq->waker_bfqq) <= in bfq_select_queue()
5009 bfq_bfqq_budget_left(bfqq->waker_bfqq) in bfq_select_queue()
5011 bfqq = bfqq->waker_bfqq; in bfq_select_queue()
5014 blocked_bfqq->next_rq && in bfq_select_queue()
5015 bfq_serv_to_charge(blocked_bfqq->next_rq, in bfq_select_queue()
5021 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
5050 struct bfq_entity *entity = &bfqq->entity; in bfq_update_wr_data()
5052 if (bfqq->wr_coeff > 1) { /* queue is being weight-raised */ in bfq_update_wr_data()
5055 jiffies_to_msecs(jiffies - bfqq->last_wr_start_finish), in bfq_update_wr_data()
5056 jiffies_to_msecs(bfqq->wr_cur_max_time), in bfq_update_wr_data()
5057 bfqq->wr_coeff, in bfq_update_wr_data()
5058 bfqq->entity.weight, bfqq->entity.orig_weight); in bfq_update_wr_data()
5060 if (entity->prio_changed) in bfq_update_wr_data()
5064 * If the queue was activated in a burst, or too much in bfq_update_wr_data()
5066 * weight-raising period, then end weight raising. in bfq_update_wr_data()
5070 else if (time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_update_wr_data()
5071 bfqq->wr_cur_max_time)) { in bfq_update_wr_data()
5072 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
5073 time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_wr_data()
5079 * interactive-weight-raising period in bfq_update_wr_data()
5090 bfqq->entity.prio_changed = 1; in bfq_update_wr_data()
5093 if (bfqq->wr_coeff > 1 && in bfq_update_wr_data()
5094 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
5095 bfqq->service_from_wr > max_service_from_wr) { in bfq_update_wr_data()
5108 if ((entity->weight > entity->orig_weight) != (bfqq->wr_coeff > 1)) in bfq_update_wr_data()
5119 struct request *rq = bfqq->next_rq; in bfq_dispatch_rq_from_bfqq()
5126 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
5127 bfqd->wait_dispatch = false; in bfq_dispatch_rq_from_bfqq()
5128 bfqd->waited_rq = rq; in bfq_dispatch_rq_from_bfqq()
5131 bfq_dispatch_remove(bfqd->queue, rq); in bfq_dispatch_rq_from_bfqq()
5133 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
5141 * weight-raised during this service slot, even if it has in bfq_dispatch_rq_from_bfqq()
5143 * weight-raised queue. This inflates bfqq's timestamps, which in bfq_dispatch_rq_from_bfqq()
5145 * device immediately to possible other weight-raised queues. in bfq_dispatch_rq_from_bfqq()
5162 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_has_work()
5165 * Avoiding lock: a race on bfqd->queued should cause at in bfq_has_work()
5168 return !list_empty_careful(&bfqd->dispatch) || in bfq_has_work()
5169 READ_ONCE(bfqd->queued); in bfq_has_work()
5174 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in __bfq_dispatch_request()
5178 if (!list_empty(&bfqd->dispatch)) { in __bfq_dispatch_request()
5179 rq = list_first_entry(&bfqd->dispatch, struct request, in __bfq_dispatch_request()
5181 list_del_init(&rq->queuelist); in __bfq_dispatch_request()
5192 bfqq->dispatched++; in __bfq_dispatch_request()
5217 * being the frequency of non-elevator-private in __bfq_dispatch_request()
5241 if (bfqd->strict_guarantees && bfqd->tot_rq_in_driver > 0) in __bfq_dispatch_request()
5252 bfqd->rq_in_driver[bfqq->actuator_idx]++; in __bfq_dispatch_request()
5253 bfqd->tot_rq_in_driver++; in __bfq_dispatch_request()
5255 rq->rq_flags |= RQF_STARTED; in __bfq_dispatch_request()
5285 spin_lock_irq(&q->queue_lock); in bfq_update_dispatch_stats()
5302 bfqg_stats_update_io_remove(bfqg, rq->cmd_flags); in bfq_update_dispatch_stats()
5304 spin_unlock_irq(&q->queue_lock); in bfq_update_dispatch_stats()
5315 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_dispatch_request()
5320 spin_lock_irq(&bfqd->lock); in bfq_dispatch_request()
5322 in_serv_queue = bfqd->in_service_queue; in bfq_dispatch_request()
5326 if (in_serv_queue == bfqd->in_service_queue) { in bfq_dispatch_request()
5331 spin_unlock_irq(&bfqd->lock); in bfq_dispatch_request()
5332 bfq_update_dispatch_stats(hctx->queue, rq, in bfq_dispatch_request()
5341 * in-flight on this queue also holds a reference, dropped when rq is freed.
5352 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", bfqq, bfqq->ref); in bfq_put_queue()
5354 bfqq->ref--; in bfq_put_queue()
5355 if (bfqq->ref) in bfq_put_queue()
5358 if (!hlist_unhashed(&bfqq->burst_list_node)) { in bfq_put_queue()
5359 hlist_del_init(&bfqq->burst_list_node); in bfq_put_queue()
5361 * Decrement also burst size after the removal, if the in bfq_put_queue()
5363 * does not contribute to the burst any longer. This in bfq_put_queue()
5365 * bursts, when some short-lived process (often due to in bfq_put_queue()
5370 * burst, see comments on bfq_handle_burst). in bfq_put_queue()
5380 * the current burst list--without incrementing in bfq_put_queue()
5381 * bust_size--because of a split, but the current in bfq_put_queue()
5382 * burst list is not the burst list bfqq belonged to in bfq_put_queue()
5386 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
5387 bfqq->bfqd->burst_size--; in bfq_put_queue()
5406 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_put_queue()
5407 hlist_del_init(&bfqq->woken_list_node); in bfq_put_queue()
5410 hlist_for_each_entry_safe(item, n, &bfqq->woken_list, in bfq_put_queue()
5412 item->waker_bfqq = NULL; in bfq_put_queue()
5413 hlist_del_init(&item->woken_list_node); in bfq_put_queue()
5416 if (bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
5417 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
5419 WARN_ON_ONCE(!list_empty(&bfqq->fifo)); in bfq_put_queue()
5420 WARN_ON_ONCE(!RB_EMPTY_ROOT(&bfqq->sort_list)); in bfq_put_queue()
5421 WARN_ON_ONCE(bfqq->dispatched); in bfq_put_queue()
5429 bfqq->stable_ref--; in bfq_put_stable_ref()
5442 __bfqq = bfqq->new_bfqq; in bfq_put_cooperator()
5444 next = __bfqq->new_bfqq; in bfq_put_cooperator()
5452 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
5457 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
5471 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
5481 struct bfq_iocq_bfqq_data *bfqq_data = bic->bfqq_data; in _bfq_exit_icq()
5500 * If bfqd and thus bfqd->num_actuators is not available any in bfq_exit_icq()
5501 * longer, then cycle over all possible per-actuator bfqqs in in bfq_exit_icq()
5503 * therefore on its unused per-actuator fields being NULL. in bfq_exit_icq()
5509 spin_lock_irqsave(&bfqd->lock, flags); in bfq_exit_icq()
5510 _bfq_exit_icq(bic, bfqd->num_actuators); in bfq_exit_icq()
5511 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_exit_icq()
5526 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data()
5531 ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio); in bfq_set_next_ioprio_data()
5535 bdi_dev_name(bfqq->bfqd->queue->disk->bdi), in bfq_set_next_ioprio_data()
5542 bfqq->new_ioprio = task_nice_ioprio(tsk); in bfq_set_next_ioprio_data()
5543 bfqq->new_ioprio_class = task_nice_ioclass(tsk); in bfq_set_next_ioprio_data()
5546 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); in bfq_set_next_ioprio_data()
5547 bfqq->new_ioprio_class = IOPRIO_CLASS_RT; in bfq_set_next_ioprio_data()
5550 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); in bfq_set_next_ioprio_data()
5551 bfqq->new_ioprio_class = IOPRIO_CLASS_BE; in bfq_set_next_ioprio_data()
5554 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; in bfq_set_next_ioprio_data()
5555 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; in bfq_set_next_ioprio_data()
5559 if (bfqq->new_ioprio >= IOPRIO_NR_LEVELS) { in bfq_set_next_ioprio_data()
5561 bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5562 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; in bfq_set_next_ioprio_data()
5565 bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5567 bfqq->new_ioprio, bfqq->entity.new_weight); in bfq_set_next_ioprio_data()
5568 bfqq->entity.prio_changed = 1; in bfq_set_next_ioprio_data()
5580 int ioprio = bic->icq.ioc->ioprio; in bfq_check_ioprio_change()
5586 if (unlikely(!bfqd) || likely(bic->ioprio == ioprio)) in bfq_check_ioprio_change()
5589 bic->ioprio = ioprio; in bfq_check_ioprio_change()
5611 bfqq->actuator_idx = act_idx; in bfq_init_bfqq()
5612 RB_CLEAR_NODE(&bfqq->entity.rb_node); in bfq_init_bfqq()
5613 INIT_LIST_HEAD(&bfqq->fifo); in bfq_init_bfqq()
5614 INIT_HLIST_NODE(&bfqq->burst_list_node); in bfq_init_bfqq()
5615 INIT_HLIST_NODE(&bfqq->woken_list_node); in bfq_init_bfqq()
5616 INIT_HLIST_HEAD(&bfqq->woken_list); in bfq_init_bfqq()
5618 bfqq->ref = 0; in bfq_init_bfqq()
5619 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5639 bfqq->ttime.last_end_request = now_ns + 1; in bfq_init_bfqq()
5641 bfqq->creation_time = jiffies; in bfq_init_bfqq()
5643 bfqq->io_start_time = now_ns; in bfq_init_bfqq()
5647 bfqq->pid = pid; in bfq_init_bfqq()
5650 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5651 bfqq->budget_timeout = bfq_smallest_from_now(); in bfq_init_bfqq()
5653 bfqq->wr_coeff = 1; in bfq_init_bfqq()
5654 bfqq->last_wr_start_finish = jiffies; in bfq_init_bfqq()
5655 bfqq->wr_start_at_switch_to_srt = bfq_smallest_from_now(); in bfq_init_bfqq()
5656 bfqq->split_time = bfq_smallest_from_now(); in bfq_init_bfqq()
5662 * to the current value of bfqq->soft_rt_next_start (see in bfq_init_bfqq()
5667 bfqq->soft_rt_next_start = jiffies; in bfq_init_bfqq()
5670 bfqq->seek_history = 1; in bfq_init_bfqq()
5672 bfqq->decrease_time_jif = jiffies; in bfq_init_bfqq()
5681 return &bfqg->async_bfqq[0][ioprio][act_idx]; in bfq_async_queue_prio()
5686 return &bfqg->async_bfqq[1][ioprio][act_idx]; in bfq_async_queue_prio()
5688 return &bfqg->async_idle_bfqq[act_idx]; in bfq_async_queue_prio()
5699 unsigned int a_idx = last_bfqq_created->actuator_idx; in bfq_do_early_stable_merge()
5706 if (new_bfqq->bic) in bfq_do_early_stable_merge()
5707 new_bfqq->bic->bfqq_data[a_idx].stably_merged = true; in bfq_do_early_stable_merge()
5708 bic->bfqq_data[a_idx].stably_merged = true; in bfq_do_early_stable_merge()
5712 * bfqq->bic must be set too, for in bfq_do_early_stable_merge()
5716 bfqq->bic = bic; in bfq_do_early_stable_merge()
5721 * Many throughput-sensitive workloads are made of several parallel
5728 * To avoid this plugging, BFQ has been using a burst-handling
5737 * throughput of the flows and task-wide I/O latency. In particular,
5753 * - very little time has elapsed since when Q1 was created
5754 * - Q2 has the same ioprio as Q1
5755 * - Q2 belongs to the same group as Q1
5760 * the total per-request processing time, the above throughput boost
5764 * burst-handling heuristics. We keep those heuristics for the moment.
5770 struct bfq_queue **source_bfqq = bfqq->entity.parent ? in bfq_do_or_sched_stable_merge()
5771 &bfqq->entity.parent->last_bfqq_created : in bfq_do_or_sched_stable_merge()
5772 &bfqd->last_bfqq_created; in bfq_do_or_sched_stable_merge()
5791 * throughput-beneficial if not merged. Currently this is in bfq_do_or_sched_stable_merge()
5800 time_before(last_bfqq_created->creation_time + in bfq_do_or_sched_stable_merge()
5802 bfqq->creation_time) || in bfq_do_or_sched_stable_merge()
5803 bfqq->entity.parent != last_bfqq_created->entity.parent || in bfq_do_or_sched_stable_merge()
5804 bfqq->ioprio != last_bfqq_created->ioprio || in bfq_do_or_sched_stable_merge()
5805 bfqq->ioprio_class != last_bfqq_created->ioprio_class || in bfq_do_or_sched_stable_merge()
5806 bfqq->actuator_idx != last_bfqq_created->actuator_idx) in bfq_do_or_sched_stable_merge()
5808 else if (time_after_eq(last_bfqq_created->creation_time + in bfq_do_or_sched_stable_merge()
5809 bfqd->bfq_burst_interval, in bfq_do_or_sched_stable_merge()
5810 bfqq->creation_time)) { in bfq_do_or_sched_stable_merge()
5811 if (likely(bfqd->nonrot_with_queueing)) in bfq_do_or_sched_stable_merge()
5827 last_bfqq_created->ref++; in bfq_do_or_sched_stable_merge()
5832 last_bfqq_created->stable_ref++; in bfq_do_or_sched_stable_merge()
5836 bic->bfqq_data[last_bfqq_created->actuator_idx].stable_merge_bfqq = in bfq_do_or_sched_stable_merge()
5850 const int ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); in bfq_get_queue()
5851 const int ioprio_class = IOPRIO_PRIO_CLASS(bic->ioprio); in bfq_get_queue()
5868 bfqd->queue->node); in bfq_get_queue()
5871 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5873 bfq_init_entity(&bfqq->entity, bfqg); in bfq_get_queue()
5876 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5886 bfqq->ref++; /* in bfq_get_queue()
5889 * only if bfqq->bfqg disappears, to in bfq_get_queue()
5894 bfqq, bfqq->ref); in bfq_get_queue()
5899 bfqq->ref++; /* get a process reference to this queue */ in bfq_get_queue()
5901 if (bfqq != &bfqd->oom_bfqq && is_sync && !respawn) in bfq_get_queue()
5909 struct bfq_ttime *ttime = &bfqq->ttime; in bfq_update_io_thinktime()
5917 if (bfqq->dispatched || bfq_bfqq_busy(bfqq)) in bfq_update_io_thinktime()
5919 elapsed = blk_time_get_ns() - bfqq->ttime.last_end_request; in bfq_update_io_thinktime()
5920 elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle); in bfq_update_io_thinktime()
5922 ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8; in bfq_update_io_thinktime()
5923 ttime->ttime_total = div_u64(7*ttime->ttime_total + 256*elapsed, 8); in bfq_update_io_thinktime()
5924 ttime->ttime_mean = div64_ul(ttime->ttime_total + 128, in bfq_update_io_thinktime()
5925 ttime->ttime_samples); in bfq_update_io_thinktime()
5932 bfqq->seek_history <<= 1; in bfq_update_io_seektime()
5933 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5935 if (bfqq->wr_coeff > 1 && in bfq_update_io_seektime()
5936 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5938 if (time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_io_seektime()
5942 * interactive-weight-raising period in bfq_update_io_seektime()
5954 bfqq->entity.prio_changed = 1; in bfq_update_io_seektime()
5971 bfqd->bfq_slice_idle == 0) in bfq_update_has_short_ttime()
5975 if (time_is_after_eq_jiffies(bfqq->split_time + in bfq_update_has_short_ttime()
5976 bfqd->bfq_wr_min_idle_time)) in bfq_update_has_short_ttime()
5982 * think time with half the I/O-plugging timeout. in bfq_update_has_short_ttime()
5984 if (atomic_read(&bic->icq.ioc->active_ref) == 0 || in bfq_update_has_short_ttime()
5985 (bfq_sample_valid(bfqq->ttime.ttime_samples) && in bfq_update_has_short_ttime()
5986 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle>>1)) in bfq_update_has_short_ttime()
5999 * the think-time state (short|long). In particular, the limit in bfq_update_has_short_ttime()
6003 * instructions reset the inject limit if the think-time state in bfq_update_has_short_ttime()
6022 * I/O-dispatch-plugging, then bfqq remains empty, and no I/O in bfq_update_has_short_ttime()
6027 * On the opposite end, a non-zero inject limit may allow the in bfq_update_has_short_ttime()
6032 * next think-time sample for bfqq may be very low. This in in bfq_update_has_short_ttime()
6040 * of such a steady oscillation between the two think-time in bfq_update_has_short_ttime()
6066 * more frequently than once per I/O-plugging timeout, makes in bfq_update_has_short_ttime()
6080 if (state_changed && bfqq->last_serv_time_ns == 0 && in bfq_update_has_short_ttime()
6081 (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_update_has_short_ttime()
6094 if (rq->cmd_flags & REQ_META) in bfq_rq_enqueued()
6095 bfqq->meta_pending++; in bfq_rq_enqueued()
6097 bfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_rq_enqueued()
6099 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
6100 bool small_req = bfqq->queued[rq_is_sync(rq)] == 1 && in bfq_rq_enqueued()
6106 * - the request is small, and in bfq_rq_enqueued()
6107 * - we are idling to boost throughput, and in bfq_rq_enqueued()
6108 * - the queue is not to be expired, in bfq_rq_enqueued()
6112 * for a new request from the in-service queue, we in bfq_rq_enqueued()
6132 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_rq_enqueued()
6149 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_allocated()
6152 entity->allocated++; in bfqq_request_allocated()
6157 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_freed()
6160 entity->allocated--; in bfqq_request_freed()
6179 new_bfqq->ref++; in __bfq_insert_request()
6189 bfq_actuator_index(bfqd, rq->bio)) == bfqq) { in __bfq_insert_request()
6200 rq->elv.priv[1] = new_bfqq; in __bfq_insert_request()
6211 rq->fifo_time = blk_time_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; in __bfq_insert_request()
6212 list_add_tail(&rq->queuelist, &bfqq->fifo); in __bfq_insert_request()
6238 spin_lock_irq(&q->queue_lock); in bfq_update_insert_stats()
6242 spin_unlock_irq(&q->queue_lock); in bfq_update_insert_stats()
6256 struct request_queue *q = hctx->queue; in bfq_insert_request()
6257 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_insert_request()
6264 if (!cgroup_subsys_on_dfl(io_cgrp_subsys) && rq->bio) in bfq_insert_request()
6267 spin_lock_irq(&bfqd->lock); in bfq_insert_request()
6270 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
6278 list_add(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
6280 list_add_tail(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
6292 if (!q->last_merge) in bfq_insert_request()
6293 q->last_merge = rq; in bfq_insert_request()
6302 cmd_flags = rq->cmd_flags; in bfq_insert_request()
6303 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
6317 list_del_init(&rq->queuelist); in bfq_insert_requests()
6324 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag()
6326 bfqd->max_rq_in_driver = max_t(int, bfqd->max_rq_in_driver, in bfq_update_hw_tag()
6327 bfqd->tot_rq_in_driver); in bfq_update_hw_tag()
6329 if (bfqd->hw_tag == 1) in bfq_update_hw_tag()
6338 if (bfqd->tot_rq_in_driver + bfqd->queued <= BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
6347 bfqq->dispatched + bfqq->queued[0] + bfqq->queued[1] < in bfq_update_hw_tag()
6349 bfqd->tot_rq_in_driver < BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
6352 if (bfqd->hw_tag_samples++ < BFQ_HW_QUEUE_SAMPLES) in bfq_update_hw_tag()
6355 bfqd->hw_tag = bfqd->max_rq_in_driver > BFQ_HW_QUEUE_THRESHOLD; in bfq_update_hw_tag()
6356 bfqd->max_rq_in_driver = 0; in bfq_update_hw_tag()
6357 bfqd->hw_tag_samples = 0; in bfq_update_hw_tag()
6359 bfqd->nonrot_with_queueing = in bfq_update_hw_tag()
6360 blk_queue_nonrot(bfqd->queue) && bfqd->hw_tag; in bfq_update_hw_tag()
6370 bfqd->rq_in_driver[bfqq->actuator_idx]--; in bfq_completed_request()
6371 bfqd->tot_rq_in_driver--; in bfq_completed_request()
6372 bfqq->dispatched--; in bfq_completed_request()
6374 if (!bfqq->dispatched && !bfq_bfqq_busy(bfqq)) { in bfq_completed_request()
6378 * no outstanding request; used by the weight-raising in bfq_completed_request()
6381 bfqq->budget_timeout = jiffies; in bfq_completed_request()
6389 bfqq->ttime.last_end_request = now_ns; in bfq_completed_request()
6395 delta_us = div_u64(now_ns - bfqd->last_completion, NSEC_PER_USEC); in bfq_completed_request()
6406 * - close the observation interval at the last (previous) in bfq_completed_request()
6408 * - compute rate, if possible, for that observation interval in bfq_completed_request()
6409 * - reset to zero samples, which will trigger a proper in bfq_completed_request()
6410 * re-initialization of the observation interval on next in bfq_completed_request()
6414 (bfqd->last_rq_max_size<<BFQ_RATE_SHIFT)/delta_us < in bfq_completed_request()
6415 1UL<<(BFQ_RATE_SHIFT - 10)) in bfq_completed_request()
6417 bfqd->last_completion = now_ns; in bfq_completed_request()
6428 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
6430 bfqd->last_completed_rq_bfqq = NULL; in bfq_completed_request()
6441 * expires, if it still has in-flight requests. in bfq_completed_request()
6443 if (bfq_bfqq_softrt_update(bfqq) && bfqq->dispatched == 0 && in bfq_completed_request()
6444 RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6445 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
6446 bfqq->soft_rt_next_start = in bfq_completed_request()
6450 * If this is the in-service queue, check if it needs to be expired, in bfq_completed_request()
6453 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
6455 if (bfqq->dispatched == 0) in bfq_completed_request()
6464 * Here bfqq->dispatched > 0 holds, but in bfq_completed_request()
6467 * for bfqq before bfqq->dispatched reaches 0, in bfq_completed_request()
6469 * completion event that causes bfqq->dispatch in bfq_completed_request()
6472 * (I/O-dispatch plugging). in bfq_completed_request()
6476 * when bfqq->dispatched finally reaches in bfq_completed_request()
6484 else if (RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6485 (bfqq->dispatched == 0 || in bfq_completed_request()
6491 if (!bfqd->tot_rq_in_driver) in bfq_completed_request()
6504 * allowed to switch to another queue---because bfqq is sync and
6505 * I/O-dispatch needs to be plugged while bfqq is temporarily
6506 * empty---then, during the service of bfqq, there will be frequent
6519 * guarantees. In this respect, the mechanism maintains a per-queue
6522 * of I/O requests in flight---i.e., already dispatched but not yet
6523 * completed---remains lower than this limit.
6528 * service, and causes bfqq to switch from empty to non-empty. The
6553 * The limit-update algorithm works as follows. On the arrival of a
6558 * (1) If there is no in-flight request. This gives a baseline for the
6566 * (2) If the limit is higher than 0 and there are in-flight
6602 u64 tot_time_ns = blk_time_get_ns() - bfqd->last_empty_occupied_ns; in bfq_update_inject_limit()
6603 unsigned int old_limit = bfqq->inject_limit; in bfq_update_inject_limit()
6605 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
6606 u64 threshold = (bfqq->last_serv_time_ns * 3)>>1; in bfq_update_inject_limit()
6609 bfqq->inject_limit--; in bfq_update_inject_limit()
6610 bfqq->decrease_time_jif = jiffies; in bfq_update_inject_limit()
6612 old_limit <= bfqd->max_rq_in_driver) in bfq_update_inject_limit()
6613 bfqq->inject_limit++; in bfq_update_inject_limit()
6622 * NOTE: (bfqd->tot_rq_in_driver == 1) means that there is no I/O in bfq_update_inject_limit()
6626 * bfqd->tot_rq_in_driver is decremented in such a code path. in bfq_update_inject_limit()
6628 if ((bfqq->last_serv_time_ns == 0 && bfqd->tot_rq_in_driver == 1) || in bfq_update_inject_limit()
6629 tot_time_ns < bfqq->last_serv_time_ns) { in bfq_update_inject_limit()
6630 if (bfqq->last_serv_time_ns == 0) { in bfq_update_inject_limit()
6635 bfqq->inject_limit = max_t(unsigned int, 1, old_limit); in bfq_update_inject_limit()
6637 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6638 } else if (!bfqd->rqs_injected && bfqd->tot_rq_in_driver == 1) in bfq_update_inject_limit()
6648 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6652 bfqd->waited_rq = NULL; in bfq_update_inject_limit()
6653 bfqd->rqs_injected = false; in bfq_update_inject_limit()
6670 * requeued request that has not (yet) been re-inserted into in bfq_finish_requeue_request()
6673 if (!rq->elv.icq || !bfqq) in bfq_finish_requeue_request()
6676 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
6678 if (rq->rq_flags & RQF_STARTED) in bfq_finish_requeue_request()
6680 rq->start_time_ns, in bfq_finish_requeue_request()
6681 rq->io_start_time_ns, in bfq_finish_requeue_request()
6682 rq->cmd_flags); in bfq_finish_requeue_request()
6684 spin_lock_irqsave(&bfqd->lock, flags); in bfq_finish_requeue_request()
6685 if (likely(rq->rq_flags & RQF_STARTED)) { in bfq_finish_requeue_request()
6686 if (rq == bfqd->waited_rq) in bfq_finish_requeue_request()
6693 RQ_BIC(rq)->requests--; in bfq_finish_requeue_request()
6694 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_finish_requeue_request()
6701 * design would be to prevent blk-mq from invoking the requeue in bfq_finish_requeue_request()
6706 * request-insertion logic if rq is re-inserted into a bfq in bfq_finish_requeue_request()
6707 * internal queue, without a re-preparation. Here we assume in bfq_finish_requeue_request()
6708 * that re-insertions of requeued requests, without in bfq_finish_requeue_request()
6709 * re-preparation, can happen only for pass_through or at_head in bfq_finish_requeue_request()
6710 * requests (which are not re-inserted into bfq internal in bfq_finish_requeue_request()
6713 rq->elv.priv[0] = NULL; in bfq_finish_requeue_request()
6714 rq->elv.priv[1] = NULL; in bfq_finish_requeue_request()
6721 if (rq->elv.icq) { in bfq_finish_request()
6722 put_io_context(rq->elv.icq->ioc); in bfq_finish_request()
6723 rq->elv.icq = NULL; in bfq_finish_request()
6736 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6738 if (bfqq_process_refs(bfqq) == 1 && !bfqq->new_bfqq) { in bfq_split_bfqq()
6739 bfqq->pid = current->pid; in bfq_split_bfqq()
6745 bic_set_bfqq(bic, NULL, true, bfqq->actuator_idx); in bfq_split_bfqq()
6749 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6760 struct bfq_iocq_bfqq_data *bfqq_data = &bic->bfqq_data[act_idx]; in __bfq_get_bfqq_handle_split()
6762 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in __bfq_get_bfqq_handle_split()
6774 if ((bfqq_data->was_in_burst_list && bfqd->large_burst) || in __bfq_get_bfqq_handle_split()
6775 bfqq_data->saved_in_large_burst) in __bfq_get_bfqq_handle_split()
6779 if (bfqq_data->was_in_burst_list) in __bfq_get_bfqq_handle_split()
6782 * burst list before being in __bfq_get_bfqq_handle_split()
6788 * bfqq from the burst list as in __bfq_get_bfqq_handle_split()
6794 * current burst list is still in __bfq_get_bfqq_handle_split()
6795 * the same burst list from in __bfq_get_bfqq_handle_split()
6799 * burst list, then we add in __bfq_get_bfqq_handle_split()
6800 * bfqq to the current burst in __bfq_get_bfqq_handle_split()
6808 hlist_add_head(&bfqq->burst_list_node, in __bfq_get_bfqq_handle_split()
6809 &bfqd->burst_list); in __bfq_get_bfqq_handle_split()
6811 bfqq->split_time = jiffies; in __bfq_get_bfqq_handle_split()
6825 rq->elv.icq = ioc_find_get_icq(rq->q); in bfq_prepare_request()
6832 rq->elv.priv[0] = rq->elv.priv[1] = NULL; in bfq_prepare_request()
6837 struct bfq_queue *new_bfqq = bfqq->new_bfqq; in bfq_waker_bfqq()
6838 struct bfq_queue *waker_bfqq = bfqq->waker_bfqq; in bfq_waker_bfqq()
6854 new_bfqq = new_bfqq->new_bfqq; in bfq_waker_bfqq()
6877 bic->bfqq_data[idx].stably_merged) in bfq_get_bfqq_handle_split()
6884 bic->bfqq_data[idx].saved_in_large_burst = true; in bfq_get_bfqq_handle_split()
6893 if (unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6897 bfqq->waker_bfqq = waker_bfqq; in bfq_get_bfqq_handle_split()
6898 bfqq->tentative_waker_bfqq = NULL; in bfq_get_bfqq_handle_split()
6901 * If the waker queue disappears, then new_bfqq->waker_bfqq must be in bfq_get_bfqq_handle_split()
6907 hlist_add_head(&bfqq->woken_list_node, in bfq_get_bfqq_handle_split()
6908 &bfqq->waker_bfqq->woken_list); in bfq_get_bfqq_handle_split()
6938 struct request_queue *q = rq->q; in bfq_init_rq()
6939 struct bio *bio = rq->bio; in bfq_init_rq()
6940 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_init_rq()
6946 if (unlikely(!rq->elv.icq)) in bfq_init_rq()
6959 bic = icq_to_bic(rq->elv.icq); in bfq_init_rq()
6965 bfqq->ref++; in bfq_init_rq()
6966 bic->requests++; in bfq_init_rq()
6968 rq, bfqq, bfqq->ref); in bfq_init_rq()
6970 rq->elv.priv[0] = bic; in bfq_init_rq()
6971 rq->elv.priv[1] = bfqq; in bfq_init_rq()
6975 * by only this bic: we can then set bfqq->bic = bic. in in bfq_init_rq()
6979 if (likely(bfqq != &bfqd->oom_bfqq) && !bfqq->new_bfqq && in bfq_init_rq()
6981 bfqq->bic = bic; in bfq_init_rq()
6984 * Consider bfqq as possibly belonging to a burst of newly in bfq_init_rq()
6986 * 1) A burst is actually happening (bfqd->burst_size > 0) in bfq_init_rq()
6990 * possible burst bfqq may belong to, then there is no gain in bfq_init_rq()
6991 * in considering bfqq as belonging to a burst, and in bfq_init_rq()
6992 * therefore in not weight-raising bfqq. See comments on in bfq_init_rq()
6997 * burst, but some background task (e.g., a service) happens in bfq_init_rq()
7004 (bfqd->burst_size > 0 || in bfq_init_rq()
7017 spin_lock_irqsave(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
7026 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
7027 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
7040 else if (bfqq->queued[0] == 0 && bfqq->queued[1] == 0) in bfq_idle_slice_timer_body()
7044 * first request of the in-service queue arrives in bfq_idle_slice_timer_body()
7055 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
7059 * Handler of the expiration of the timer running if the in-service queue
7066 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer()
7069 * Theoretical race here: the in-service queue can be NULL or in bfq_idle_slice_timer()
7072 * cycle that changes the in-service queue. This can hardly in bfq_idle_slice_timer()
7089 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
7092 bfqq, bfqq->ref); in __bfq_put_async_bfqq()
7108 for (k = 0; k < bfqd->num_actuators; k++) { in bfq_put_async_queues()
7111 __bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j][k]); in bfq_put_async_queues()
7113 __bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq[k]); in bfq_put_async_queues()
7123 unsigned int depth = 1U << bt->sb.shift; in bfq_update_depths()
7125 bfqd->full_depth_shift = bt->sb.shift; in bfq_update_depths()
7127 * In-word depths if no bfq_queue is being weight-raised: in bfq_update_depths()
7130 * In next formulas, right-shift the value in bfq_update_depths()
7131 * (1U<<bt->sb.shift), instead of computing directly in bfq_update_depths()
7132 * (1U<<(bt->sb.shift - something)), to be robust against in bfq_update_depths()
7133 * any possible value of bt->sb.shift, without having to in bfq_update_depths()
7137 bfqd->word_depths[0][0] = max(depth >> 1, 1U); in bfq_update_depths()
7143 bfqd->word_depths[0][1] = max((depth * 3) >> 2, 1U); in bfq_update_depths()
7146 * In-word depths in case some bfq_queue is being weight- in bfq_update_depths()
7149 * start-up times didn't suffer from any regression due to tag in bfq_update_depths()
7153 bfqd->word_depths[1][0] = max((depth * 3) >> 4, 1U); in bfq_update_depths()
7155 bfqd->word_depths[1][1] = max((depth * 6) >> 4, 1U); in bfq_update_depths()
7160 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_depth_updated()
7161 struct blk_mq_tags *tags = hctx->sched_tags; in bfq_depth_updated()
7163 bfq_update_depths(bfqd, &tags->bitmap_tags); in bfq_depth_updated()
7164 sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, 1); in bfq_depth_updated()
7175 struct bfq_data *bfqd = e->elevator_data; in bfq_exit_queue()
7179 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
7181 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
7182 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
7184 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
7186 for (actuator = 0; actuator < bfqd->num_actuators; actuator++) in bfq_exit_queue()
7187 WARN_ON_ONCE(bfqd->rq_in_driver[actuator]); in bfq_exit_queue()
7188 WARN_ON_ONCE(bfqd->tot_rq_in_driver); in bfq_exit_queue()
7190 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
7192 /* release oom-queue reference to root group */ in bfq_exit_queue()
7193 bfqg_and_blkg_put(bfqd->root_group); in bfq_exit_queue()
7196 blkcg_deactivate_policy(bfqd->queue->disk, &blkcg_policy_bfq); in bfq_exit_queue()
7198 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
7199 bfq_put_async_queues(bfqd, bfqd->root_group); in bfq_exit_queue()
7200 kfree(bfqd->root_group); in bfq_exit_queue()
7201 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
7204 blk_stat_disable_accounting(bfqd->queue); in bfq_exit_queue()
7205 clear_bit(ELEVATOR_FLAG_DISABLE_WBT, &e->flags); in bfq_exit_queue()
7206 wbt_enable_default(bfqd->queue->disk); in bfq_exit_queue()
7217 root_group->entity.parent = NULL; in bfq_init_root_group()
7218 root_group->my_entity = NULL; in bfq_init_root_group()
7219 root_group->bfqd = bfqd; in bfq_init_root_group()
7221 root_group->rq_pos_tree = RB_ROOT; in bfq_init_root_group()
7223 root_group->sched_data.service_tree[i] = BFQ_SERVICE_TREE_INIT; in bfq_init_root_group()
7224 root_group->sched_data.bfq_class_idle_last_service = jiffies; in bfq_init_root_group()
7232 struct blk_independent_access_ranges *ia_ranges = q->disk->ia_ranges; in bfq_init_queue()
7236 return -ENOMEM; in bfq_init_queue()
7238 bfqd = kzalloc_node(sizeof(*bfqd), GFP_KERNEL, q->node); in bfq_init_queue()
7240 kobject_put(&eq->kobj); in bfq_init_queue()
7241 return -ENOMEM; in bfq_init_queue()
7243 eq->elevator_data = bfqd; in bfq_init_queue()
7245 spin_lock_irq(&q->queue_lock); in bfq_init_queue()
7246 q->elevator = eq; in bfq_init_queue()
7247 spin_unlock_irq(&q->queue_lock); in bfq_init_queue()
7256 bfq_init_bfqq(bfqd, &bfqd->oom_bfqq, NULL, 1, 0, 0); in bfq_init_queue()
7257 bfqd->oom_bfqq.ref++; in bfq_init_queue()
7258 bfqd->oom_bfqq.new_ioprio = BFQ_DEFAULT_QUEUE_IOPRIO; in bfq_init_queue()
7259 bfqd->oom_bfqq.new_ioprio_class = IOPRIO_CLASS_BE; in bfq_init_queue()
7260 bfqd->oom_bfqq.entity.new_weight = in bfq_init_queue()
7261 bfq_ioprio_to_weight(bfqd->oom_bfqq.new_ioprio); in bfq_init_queue()
7264 bfq_clear_bfqq_just_created(&bfqd->oom_bfqq); in bfq_init_queue()
7271 bfqd->oom_bfqq.entity.prio_changed = 1; in bfq_init_queue()
7273 bfqd->queue = q; in bfq_init_queue()
7275 bfqd->num_actuators = 1; in bfq_init_queue()
7280 spin_lock_irq(&q->queue_lock); in bfq_init_queue()
7286 if (ia_ranges->nr_ia_ranges > BFQ_MAX_ACTUATORS) { in bfq_init_queue()
7288 ia_ranges->nr_ia_ranges, BFQ_MAX_ACTUATORS); in bfq_init_queue()
7291 bfqd->num_actuators = ia_ranges->nr_ia_ranges; in bfq_init_queue()
7293 for (i = 0; i < bfqd->num_actuators; i++) { in bfq_init_queue()
7294 bfqd->sector[i] = ia_ranges->ia_range[i].sector; in bfq_init_queue()
7295 bfqd->nr_sectors[i] = in bfq_init_queue()
7296 ia_ranges->ia_range[i].nr_sectors; in bfq_init_queue()
7301 /* Otherwise use single-actuator dev info */ in bfq_init_queue()
7302 if (bfqd->num_actuators == 1) { in bfq_init_queue()
7303 bfqd->sector[0] = 0; in bfq_init_queue()
7304 bfqd->nr_sectors[0] = get_capacity(q->disk); in bfq_init_queue()
7306 spin_unlock_irq(&q->queue_lock); in bfq_init_queue()
7308 INIT_LIST_HEAD(&bfqd->dispatch); in bfq_init_queue()
7310 hrtimer_init(&bfqd->idle_slice_timer, CLOCK_MONOTONIC, in bfq_init_queue()
7312 bfqd->idle_slice_timer.function = bfq_idle_slice_timer; in bfq_init_queue()
7314 bfqd->queue_weights_tree = RB_ROOT_CACHED; in bfq_init_queue()
7316 bfqd->num_groups_with_pending_reqs = 0; in bfq_init_queue()
7319 INIT_LIST_HEAD(&bfqd->active_list[0]); in bfq_init_queue()
7320 INIT_LIST_HEAD(&bfqd->active_list[1]); in bfq_init_queue()
7321 INIT_LIST_HEAD(&bfqd->idle_list); in bfq_init_queue()
7322 INIT_HLIST_HEAD(&bfqd->burst_list); in bfq_init_queue()
7324 bfqd->hw_tag = -1; in bfq_init_queue()
7325 bfqd->nonrot_with_queueing = blk_queue_nonrot(bfqd->queue); in bfq_init_queue()
7327 bfqd->bfq_max_budget = bfq_default_max_budget; in bfq_init_queue()
7329 bfqd->bfq_fifo_expire[0] = bfq_fifo_expire[0]; in bfq_init_queue()
7330 bfqd->bfq_fifo_expire[1] = bfq_fifo_expire[1]; in bfq_init_queue()
7331 bfqd->bfq_back_max = bfq_back_max; in bfq_init_queue()
7332 bfqd->bfq_back_penalty = bfq_back_penalty; in bfq_init_queue()
7333 bfqd->bfq_slice_idle = bfq_slice_idle; in bfq_init_queue()
7334 bfqd->bfq_timeout = bfq_timeout; in bfq_init_queue()
7336 bfqd->bfq_large_burst_thresh = 8; in bfq_init_queue()
7337 bfqd->bfq_burst_interval = msecs_to_jiffies(180); in bfq_init_queue()
7339 bfqd->low_latency = true; in bfq_init_queue()
7342 * Trade-off between responsiveness and fairness. in bfq_init_queue()
7344 bfqd->bfq_wr_coeff = 30; in bfq_init_queue()
7345 bfqd->bfq_wr_rt_max_time = msecs_to_jiffies(300); in bfq_init_queue()
7346 bfqd->bfq_wr_min_idle_time = msecs_to_jiffies(2000); in bfq_init_queue()
7347 bfqd->bfq_wr_min_inter_arr_async = msecs_to_jiffies(500); in bfq_init_queue()
7348 bfqd->bfq_wr_max_softrt_rate = 7000; /* in bfq_init_queue()
7351 * high-definition compressed in bfq_init_queue()
7354 bfqd->wr_busy_queues = 0; in bfq_init_queue()
7360 bfqd->rate_dur_prod = ref_rate[blk_queue_nonrot(bfqd->queue)] * in bfq_init_queue()
7361 ref_wr_duration[blk_queue_nonrot(bfqd->queue)]; in bfq_init_queue()
7362 bfqd->peak_rate = ref_rate[blk_queue_nonrot(bfqd->queue)] * 2 / 3; in bfq_init_queue()
7365 bfqd->actuator_load_threshold = 4; in bfq_init_queue()
7367 spin_lock_init(&bfqd->lock); in bfq_init_queue()
7372 * (bfq_create_group_hierarchy->blkcg_activate_policy-> in bfq_init_queue()
7380 * other inconsistencies, the blk-mq stack must then refrain in bfq_init_queue()
7384 bfqd->root_group = bfq_create_group_hierarchy(bfqd, q->node); in bfq_init_queue()
7385 if (!bfqd->root_group) in bfq_init_queue()
7387 bfq_init_root_group(bfqd->root_group, bfqd); in bfq_init_queue()
7388 bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group); in bfq_init_queue()
7393 set_bit(ELEVATOR_FLAG_DISABLE_WBT, &eq->flags); in bfq_init_queue()
7394 wbt_disable_default(q->disk); in bfq_init_queue()
7401 kobject_put(&eq->kobj); in bfq_init_queue()
7402 return -ENOMEM; in bfq_init_queue()
7414 return -ENOMEM; in bfq_slab_setup()
7437 struct bfq_data *bfqd = e->elevator_data; \
7445 SHOW_FUNCTION(bfq_fifo_expire_sync_show, bfqd->bfq_fifo_expire[1], 2);
7446 SHOW_FUNCTION(bfq_fifo_expire_async_show, bfqd->bfq_fifo_expire[0], 2);
7447 SHOW_FUNCTION(bfq_back_seek_max_show, bfqd->bfq_back_max, 0);
7448 SHOW_FUNCTION(bfq_back_seek_penalty_show, bfqd->bfq_back_penalty, 0);
7449 SHOW_FUNCTION(bfq_slice_idle_show, bfqd->bfq_slice_idle, 2);
7450 SHOW_FUNCTION(bfq_max_budget_show, bfqd->bfq_user_max_budget, 0);
7451 SHOW_FUNCTION(bfq_timeout_sync_show, bfqd->bfq_timeout, 1);
7452 SHOW_FUNCTION(bfq_strict_guarantees_show, bfqd->strict_guarantees, 0);
7453 SHOW_FUNCTION(bfq_low_latency_show, bfqd->low_latency, 0);
7459 struct bfq_data *bfqd = e->elevator_data; \
7464 USEC_SHOW_FUNCTION(bfq_slice_idle_us_show, bfqd->bfq_slice_idle);
7471 struct bfq_data *bfqd = e->elevator_data; \
7490 STORE_FUNCTION(bfq_fifo_expire_sync_store, &bfqd->bfq_fifo_expire[1], 1,
7492 STORE_FUNCTION(bfq_fifo_expire_async_store, &bfqd->bfq_fifo_expire[0], 1,
7494 STORE_FUNCTION(bfq_back_seek_max_store, &bfqd->bfq_back_max, 0, INT_MAX, 0);
7495 STORE_FUNCTION(bfq_back_seek_penalty_store, &bfqd->bfq_back_penalty, 1,
7497 STORE_FUNCTION(bfq_slice_idle_store, &bfqd->bfq_slice_idle, 0, INT_MAX, 2);
7503 struct bfq_data *bfqd = e->elevator_data; \
7517 USEC_STORE_FUNCTION(bfq_slice_idle_us_store, &bfqd->bfq_slice_idle, 0,
7524 struct bfq_data *bfqd = e->elevator_data; in bfq_max_budget_store()
7533 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_max_budget_store()
7537 bfqd->bfq_max_budget = __data; in bfq_max_budget_store()
7540 bfqd->bfq_user_max_budget = __data; in bfq_max_budget_store()
7552 struct bfq_data *bfqd = e->elevator_data; in bfq_timeout_sync_store()
7565 bfqd->bfq_timeout = msecs_to_jiffies(__data); in bfq_timeout_sync_store()
7566 if (bfqd->bfq_user_max_budget == 0) in bfq_timeout_sync_store()
7567 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_timeout_sync_store()
7575 struct bfq_data *bfqd = e->elevator_data; in bfq_strict_guarantees_store()
7585 if (!bfqd->strict_guarantees && __data == 1 in bfq_strict_guarantees_store()
7586 && bfqd->bfq_slice_idle < 8 * NSEC_PER_MSEC) in bfq_strict_guarantees_store()
7587 bfqd->bfq_slice_idle = 8 * NSEC_PER_MSEC; in bfq_strict_guarantees_store()
7589 bfqd->strict_guarantees = __data; in bfq_strict_guarantees_store()
7597 struct bfq_data *bfqd = e->elevator_data; in bfq_low_latency_store()
7607 if (__data == 0 && bfqd->low_latency != 0) in bfq_low_latency_store()
7609 bfqd->low_latency = __data; in bfq_low_latency_store()
7660 MODULE_ALIAS("bfq-iosched");
7672 ret = -ENOMEM; in bfq_init()
7686 * scheduler cannot rely on a peak-rate-evaluation workload to in bfq_init()