Lines Matching refs:bfqq

137 void bfq_mark_bfqq_##name(struct bfq_queue *bfqq)			\
139 __set_bit(BFQQF_##name, &(bfqq)->flags); \
141 void bfq_clear_bfqq_##name(struct bfq_queue *bfqq) \
143 __clear_bit(BFQQF_##name, &(bfqq)->flags); \
145 int bfq_bfqq_##name(const struct bfq_queue *bfqq) \
147 return test_bit(BFQQF_##name, &(bfqq)->flags); \
237 #define BFQQ_SEEKY(bfqq) (hweight32(bfqq->seek_history) > 19) argument
245 #define BFQQ_TOTALLY_SEEKY(bfqq) (bfqq->seek_history == -1) argument
383 return bic->bfqq[1][actuator_idx]; in bic_to_bfqq()
385 return bic->bfqq[0][actuator_idx]; in bic_to_bfqq()
388 static void bfq_put_stable_ref(struct bfq_queue *bfqq);
391 struct bfq_queue *bfqq, in bic_set_bfqq() argument
395 struct bfq_queue *old_bfqq = bic->bfqq[is_sync][actuator_idx]; 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()
484 #define bfq_class_idle(bfqq) ((bfqq)->ioprio_class == IOPRIO_CLASS_IDLE) argument
585 static bool bfqq_request_over_limit(struct bfq_queue *bfqq, int limit) in bfqq_request_over_limit() argument
587 struct bfq_data *bfqd = bfqq->bfqd; in bfqq_request_over_limit()
588 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_over_limit()
592 int class_idx = bfqq->ioprio_class - 1; in bfqq_request_over_limit()
603 depth = bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css.cgroup->level + 1; in bfqq_request_over_limit()
655 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfqq_request_over_limit()
669 static bool bfqq_request_over_limit(struct bfq_queue *bfqq, int limit) in bfqq_request_over_limit() argument
707 struct bfq_queue *bfqq = in bfq_limit_depth() local
716 if (bfqq && bfqq_request_over_limit(bfqq, limit)) { in bfq_limit_depth()
733 struct bfq_queue *bfqq = NULL; in bfq_rq_pos_tree_lookup() local
741 bfqq = rb_entry(parent, struct bfq_queue, pos_node); in bfq_rq_pos_tree_lookup()
747 if (sector > blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
749 else if (sector < blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
754 bfqq = NULL; in bfq_rq_pos_tree_lookup()
763 bfqq ? bfqq->pid : 0); in bfq_rq_pos_tree_lookup()
765 return bfqq; in bfq_rq_pos_tree_lookup()
768 static bool bfq_too_late_for_merging(struct bfq_queue *bfqq) in bfq_too_late_for_merging() argument
770 return bfqq->service_from_backlogged > 0 && in bfq_too_late_for_merging()
771 time_is_before_jiffies(bfqq->first_IO_time + in bfq_too_late_for_merging()
784 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
789 if (bfqq->pos_root) { in bfq_pos_tree_add_move()
790 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
791 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
795 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
803 if (bfq_too_late_for_merging(bfqq)) in bfq_pos_tree_add_move()
806 if (bfq_class_idle(bfqq)) in bfq_pos_tree_add_move()
808 if (!bfqq->next_rq) in bfq_pos_tree_add_move()
811 bfqq->pos_root = &bfqq_group(bfqq)->rq_pos_tree; in bfq_pos_tree_add_move()
812 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
813 blk_rq_pos(bfqq->next_rq), &parent, &p); in bfq_pos_tree_add_move()
815 rb_link_node(&bfqq->pos_node, parent, p); in bfq_pos_tree_add_move()
816 rb_insert_color(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
818 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
855 struct bfq_queue *bfqq) in bfq_asymmetric_scenario() argument
857 bool smallest_weight = bfqq && in bfq_asymmetric_scenario()
858 bfqq->weight_counter && in bfq_asymmetric_scenario()
859 bfqq->weight_counter == in bfq_asymmetric_scenario()
899 void bfq_weights_tree_add(struct bfq_queue *bfqq) in bfq_weights_tree_add() argument
901 struct rb_root_cached *root = &bfqq->bfqd->queue_weights_tree; in bfq_weights_tree_add()
902 struct bfq_entity *entity = &bfqq->entity; in bfq_weights_tree_add()
918 if (bfqq->weight_counter) in bfq_weights_tree_add()
928 bfqq->weight_counter = __counter; in bfq_weights_tree_add()
939 bfqq->weight_counter = kzalloc(sizeof(struct bfq_weight_counter), in bfq_weights_tree_add()
954 if (unlikely(!bfqq->weight_counter)) in bfq_weights_tree_add()
957 bfqq->weight_counter->weight = entity->weight; in bfq_weights_tree_add()
958 rb_link_node(&bfqq->weight_counter->weights_node, parent, new); in bfq_weights_tree_add()
959 rb_insert_color_cached(&bfqq->weight_counter->weights_node, root, in bfq_weights_tree_add()
963 bfqq->weight_counter->num_active++; in bfq_weights_tree_add()
964 bfqq->ref++; in bfq_weights_tree_add()
973 void bfq_weights_tree_remove(struct bfq_queue *bfqq) in bfq_weights_tree_remove() argument
977 if (!bfqq->weight_counter) in bfq_weights_tree_remove()
980 root = &bfqq->bfqd->queue_weights_tree; in bfq_weights_tree_remove()
981 bfqq->weight_counter->num_active--; in bfq_weights_tree_remove()
982 if (bfqq->weight_counter->num_active > 0) in bfq_weights_tree_remove()
985 rb_erase_cached(&bfqq->weight_counter->weights_node, root); in bfq_weights_tree_remove()
986 kfree(bfqq->weight_counter); in bfq_weights_tree_remove()
989 bfqq->weight_counter = NULL; in bfq_weights_tree_remove()
990 bfq_put_queue(bfqq); in bfq_weights_tree_remove()
996 static struct request *bfq_check_fifo(struct bfq_queue *bfqq, in bfq_check_fifo() argument
1001 if (bfq_bfqq_fifo_expire(bfqq)) in bfq_check_fifo()
1004 bfq_mark_bfqq_fifo_expire(bfqq); in bfq_check_fifo()
1006 rq = rq_entry_fifo(bfqq->fifo.next); in bfq_check_fifo()
1011 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
1016 struct bfq_queue *bfqq, in bfq_find_next_rq() argument
1024 next = bfq_check_fifo(bfqq, last); in bfq_find_next_rq()
1034 rbnext = rb_first(&bfqq->sort_list); in bfq_find_next_rq()
1044 struct bfq_queue *bfqq) in bfq_serv_to_charge() argument
1046 if (bfq_bfqq_sync(bfqq) || bfqq->wr_coeff > 1 || in bfq_serv_to_charge()
1047 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
1065 struct bfq_queue *bfqq) in bfq_updated_next_req() argument
1067 struct bfq_entity *entity = &bfqq->entity; in bfq_updated_next_req()
1068 struct request *next_rq = bfqq->next_rq; in bfq_updated_next_req()
1074 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
1082 max_t(unsigned long, bfqq->max_budget, in bfq_updated_next_req()
1083 bfq_serv_to_charge(next_rq, bfqq)), in bfq_updated_next_req()
1087 bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", in bfq_updated_next_req()
1089 bfq_requeue_bfqq(bfqd, bfqq, false); in bfq_updated_next_req()
1124 static void switch_back_to_interactive_wr(struct bfq_queue *bfqq, in switch_back_to_interactive_wr() argument
1127 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1128 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1129 bfqq->last_wr_start_finish = bfqq->wr_start_at_switch_to_srt; in switch_back_to_interactive_wr()
1133 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1137 bool busy = bfq_already_existing && bfq_bfqq_busy(bfqq); in bfq_bfqq_resume_state()
1138 unsigned int a_idx = bfqq->actuator_idx; in bfq_bfqq_resume_state()
1142 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1144 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1147 bfq_mark_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1149 bfq_clear_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1151 bfqq->last_serv_time_ns = bfqq_data->saved_last_serv_time_ns; in bfq_bfqq_resume_state()
1152 bfqq->inject_limit = bfqq_data->saved_inject_limit; in bfq_bfqq_resume_state()
1153 bfqq->decrease_time_jif = bfqq_data->saved_decrease_time_jif; in bfq_bfqq_resume_state()
1155 bfqq->entity.new_weight = bfqq_data->saved_weight; in bfq_bfqq_resume_state()
1156 bfqq->ttime = bfqq_data->saved_ttime; in bfq_bfqq_resume_state()
1157 bfqq->io_start_time = bfqq_data->saved_io_start_time; in bfq_bfqq_resume_state()
1158 bfqq->tot_idle_time = bfqq_data->saved_tot_idle_time; in bfq_bfqq_resume_state()
1163 old_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_resume_state()
1164 bfqq->wr_coeff = bfqq_data->saved_wr_coeff; in bfq_bfqq_resume_state()
1166 bfqq->service_from_wr = bfqq_data->saved_service_from_wr; in bfq_bfqq_resume_state()
1167 bfqq->wr_start_at_switch_to_srt = in bfq_bfqq_resume_state()
1169 bfqq->last_wr_start_finish = bfqq_data->saved_last_wr_start_finish; in bfq_bfqq_resume_state()
1170 bfqq->wr_cur_max_time = bfqq_data->saved_wr_cur_max_time; in bfq_bfqq_resume_state()
1172 if (bfqq->wr_coeff > 1 && (bfq_bfqq_in_large_burst(bfqq) || in bfq_bfqq_resume_state()
1173 time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_bfqq_resume_state()
1174 bfqq->wr_cur_max_time))) { in bfq_bfqq_resume_state()
1175 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1176 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_resume_state()
1177 time_is_after_eq_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_bfqq_resume_state()
1179 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1181 bfqq->wr_coeff = 1; in bfq_bfqq_resume_state()
1182 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1188 bfqq->entity.prio_changed = 1; in bfq_bfqq_resume_state()
1193 if (old_wr_coeff == 1 && bfqq->wr_coeff > 1) in bfq_bfqq_resume_state()
1195 else if (old_wr_coeff > 1 && bfqq->wr_coeff == 1) in bfq_bfqq_resume_state()
1199 static int bfqq_process_refs(struct bfq_queue *bfqq) in bfqq_process_refs() argument
1201 return bfqq->ref - bfqq->entity.allocated - in bfqq_process_refs()
1202 bfqq->entity.on_st_or_in_serv - in bfqq_process_refs()
1203 (bfqq->weight_counter != NULL) - bfqq->stable_ref; in bfqq_process_refs()
1207 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1221 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1226 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1230 static void bfq_add_to_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_add_to_burst() argument
1252 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_add_to_burst()
1270 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1382 static void bfq_handle_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_handle_burst() argument
1389 if (!hlist_unhashed(&bfqq->burst_list_node) || in bfq_handle_burst()
1390 bfq_bfqq_in_large_burst(bfqq) || in bfq_handle_burst()
1391 time_is_after_eq_jiffies(bfqq->split_time + in bfq_handle_burst()
1414 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1416 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1426 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_handle_burst()
1435 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1448 static int bfq_bfqq_budget_left(struct bfq_queue *bfqq) in bfq_bfqq_budget_left() argument
1450 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_budget_left()
1585 struct bfq_queue *bfqq, in bfq_bfqq_update_budg_for_activation() argument
1588 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_update_budg_for_activation()
1597 if (bfq_bfqq_non_blocking_wait_rq(bfqq) && arrived_in_time && in bfq_bfqq_update_budg_for_activation()
1598 bfq_bfqq_budget_left(bfqq) > 0) { in bfq_bfqq_update_budg_for_activation()
1617 bfq_bfqq_budget_left(bfqq), in bfq_bfqq_update_budg_for_activation()
1618 bfqq->max_budget); in bfq_bfqq_update_budg_for_activation()
1638 entity->budget = max_t(unsigned long, bfqq->max_budget, in bfq_bfqq_update_budg_for_activation()
1639 bfq_serv_to_charge(bfqq->next_rq, bfqq)); in bfq_bfqq_update_budg_for_activation()
1640 bfq_clear_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_update_budg_for_activation()
1654 struct bfq_queue *bfqq, in bfq_update_bfqq_wr_on_rq_arrival() argument
1664 bfqq->service_from_wr = 0; in bfq_update_bfqq_wr_on_rq_arrival()
1665 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1666 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1679 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1681 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1683 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1696 bfqq->entity.budget = min_t(unsigned long, in bfq_update_bfqq_wr_on_rq_arrival()
1697 bfqq->entity.budget, in bfq_update_bfqq_wr_on_rq_arrival()
1701 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1702 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1704 bfqq->wr_coeff = 1; in bfq_update_bfqq_wr_on_rq_arrival()
1735 if (bfqq->wr_cur_max_time != in bfq_update_bfqq_wr_on_rq_arrival()
1737 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1738 bfqq->last_wr_start_finish; in bfq_update_bfqq_wr_on_rq_arrival()
1740 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1742 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1745 bfqq->last_wr_start_finish = jiffies; in bfq_update_bfqq_wr_on_rq_arrival()
1751 struct bfq_queue *bfqq) in bfq_bfqq_idle_for_long_time() argument
1753 return bfqq->dispatched == 0 && in bfq_bfqq_idle_for_long_time()
1755 bfqq->budget_timeout + in bfq_bfqq_idle_for_long_time()
1764 static bool bfq_bfqq_higher_class_or_weight(struct bfq_queue *bfqq, in bfq_bfqq_higher_class_or_weight() argument
1769 if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class) in bfq_bfqq_higher_class_or_weight()
1772 if (in_serv_bfqq->entity.parent == bfqq->entity.parent) { in bfq_bfqq_higher_class_or_weight()
1773 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1776 if (bfqq->entity.parent) in bfq_bfqq_higher_class_or_weight()
1777 bfqq_weight = bfqq->entity.parent->weight; in bfq_bfqq_higher_class_or_weight()
1779 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1816 static bool bfq_better_to_idle(struct bfq_queue *bfqq);
1819 struct bfq_queue *bfqq, in bfq_bfqq_handle_idle_busy_switch() argument
1826 idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq), in bfq_bfqq_handle_idle_busy_switch()
1833 bfqq->ttime.last_end_request + in bfq_bfqq_handle_idle_busy_switch()
1837 bfqq->bic || RQ_BIC(rq)->bfqq_data[act_idx].stably_merged; in bfq_bfqq_handle_idle_busy_switch()
1848 in_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1850 !BFQQ_TOTALLY_SEEKY(bfqq) && in bfq_bfqq_handle_idle_busy_switch()
1852 time_is_before_jiffies(bfqq->soft_rt_next_start) && in bfq_bfqq_handle_idle_busy_switch()
1853 bfqq->dispatched == 0 && in bfq_bfqq_handle_idle_busy_switch()
1854 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1856 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1870 (bfqq->wr_coeff > 1 || in bfq_bfqq_handle_idle_busy_switch()
1871 (bfq_bfqq_sync(bfqq) && bfqq_non_merged_or_stably_merged && in bfq_bfqq_handle_idle_busy_switch()
1879 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1895 if (likely(!bfq_bfqq_just_created(bfqq)) && in bfq_bfqq_handle_idle_busy_switch()
1898 bfqq->budget_timeout + in bfq_bfqq_handle_idle_busy_switch()
1900 hlist_del_init(&bfqq->burst_list_node); in bfq_bfqq_handle_idle_busy_switch()
1901 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1904 bfq_clear_bfqq_just_created(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1907 if (unlikely(time_is_after_jiffies(bfqq->split_time))) in bfq_bfqq_handle_idle_busy_switch()
1909 bfqq->split_time = in bfq_bfqq_handle_idle_busy_switch()
1912 if (time_is_before_jiffies(bfqq->split_time + in bfq_bfqq_handle_idle_busy_switch()
1914 bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1921 if (old_wr_coeff != bfqq->wr_coeff) in bfq_bfqq_handle_idle_busy_switch()
1922 bfqq->entity.prio_changed = 1; in bfq_bfqq_handle_idle_busy_switch()
1926 bfqq->last_idle_bklogged = jiffies; in bfq_bfqq_handle_idle_busy_switch()
1927 bfqq->service_from_backlogged = 0; in bfq_bfqq_handle_idle_busy_switch()
1928 bfq_clear_bfqq_softrt_update(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1930 bfq_add_bfqq_busy(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1977 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1978 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) || in bfq_bfqq_handle_idle_busy_switch()
1986 struct bfq_queue *bfqq) in bfq_reset_inject_limit() argument
1989 bfqq->last_serv_time_ns = 0; in bfq_reset_inject_limit()
2043 if (bfq_bfqq_has_short_ttime(bfqq)) in bfq_reset_inject_limit()
2044 bfqq->inject_limit = 0; in bfq_reset_inject_limit()
2046 bfqq->inject_limit = 1; in bfq_reset_inject_limit()
2048 bfqq->decrease_time_jif = jiffies; in bfq_reset_inject_limit()
2051 static void bfq_update_io_intensity(struct bfq_queue *bfqq, u64 now_ns) in bfq_update_io_intensity() argument
2053 u64 tot_io_time = now_ns - bfqq->io_start_time; in bfq_update_io_intensity()
2055 if (RB_EMPTY_ROOT(&bfqq->sort_list) && bfqq->dispatched == 0) in bfq_update_io_intensity()
2056 bfqq->tot_idle_time += in bfq_update_io_intensity()
2057 now_ns - bfqq->ttime.last_end_request; in bfq_update_io_intensity()
2059 if (unlikely(bfq_bfqq_just_created(bfqq))) in bfq_update_io_intensity()
2066 if (bfqq->tot_idle_time * 5 > tot_io_time) in bfq_update_io_intensity()
2067 bfq_clear_bfqq_IO_bound(bfqq); in bfq_update_io_intensity()
2069 bfq_mark_bfqq_IO_bound(bfqq); in bfq_update_io_intensity()
2076 bfqq->io_start_time = now_ns - (tot_io_time>>1); in bfq_update_io_intensity()
2077 bfqq->tot_idle_time >>= 1; in bfq_update_io_intensity()
2132 static void bfq_check_waker(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_check_waker() argument
2138 bfqd->last_completed_rq_bfqq == bfqq || in bfq_check_waker()
2139 bfq_bfqq_has_short_ttime(bfqq) || in bfq_check_waker()
2142 bfqq == &bfqd->oom_bfqq) in bfq_check_waker()
2152 bfqq->tentative_waker_bfqq || in bfq_check_waker()
2153 now_ns > bfqq->waker_detection_started + in bfq_check_waker()
2160 bfqq->tentative_waker_bfqq = in bfq_check_waker()
2162 bfqq->num_waker_detections = 1; in bfq_check_waker()
2163 bfqq->waker_detection_started = now_ns; in bfq_check_waker()
2164 bfq_bfqq_name(bfqq->tentative_waker_bfqq, waker_name, in bfq_check_waker()
2166 bfq_log_bfqq(bfqd, bfqq, "set tentative waker %s", waker_name); in bfq_check_waker()
2168 bfqq->num_waker_detections++; in bfq_check_waker()
2170 if (bfqq->num_waker_detections == 3) { in bfq_check_waker()
2171 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2172 bfqq->tentative_waker_bfqq = NULL; in bfq_check_waker()
2173 bfq_bfqq_name(bfqq->waker_bfqq, waker_name, in bfq_check_waker()
2175 bfq_log_bfqq(bfqd, bfqq, "set waker %s", waker_name); in bfq_check_waker()
2197 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_check_waker()
2198 hlist_del_init(&bfqq->woken_list_node); in bfq_check_waker()
2199 hlist_add_head(&bfqq->woken_list_node, in bfq_check_waker()
2206 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_add_request() local
2207 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request()
2209 unsigned int old_wr_coeff = bfqq->wr_coeff; in bfq_add_request()
2213 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
2214 bfqq->queued[rq_is_sync(rq)]++; in bfq_add_request()
2221 if (bfq_bfqq_sync(bfqq) && RQ_BIC(rq)->requests <= 1) { in bfq_add_request()
2222 bfq_check_waker(bfqd, bfqq, now_ns); in bfq_add_request()
2230 if (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2232 bfq_reset_inject_limit(bfqd, bfqq); in bfq_add_request()
2259 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2261 (bfqq->last_serv_time_ns > 0 && in bfq_add_request()
2263 time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2291 if (bfq_bfqq_sync(bfqq)) in bfq_add_request()
2292 bfq_update_io_intensity(bfqq, now_ns); in bfq_add_request()
2294 elv_rb_add(&bfqq->sort_list, rq); in bfq_add_request()
2299 prev = bfqq->next_rq; in bfq_add_request()
2300 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2301 bfqq->next_rq = next_rq; in bfq_add_request()
2307 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2308 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_add_request()
2310 if (!bfq_bfqq_busy(bfqq)) /* switching to busy ... */ in bfq_add_request()
2311 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2316 bfqq->last_wr_start_finish + in bfq_add_request()
2318 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2319 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2322 bfqq->entity.prio_changed = 1; in bfq_add_request()
2324 if (prev != bfqq->next_rq) in bfq_add_request()
2325 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2355 (old_wr_coeff == 1 || bfqq->wr_coeff == 1 || interactive)) in bfq_add_request()
2356 bfqq->last_wr_start_finish = jiffies; in bfq_add_request()
2363 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge() local
2366 if (bfqq) in bfq_find_rq_fmerge()
2367 return elv_rb_find(&bfqq->sort_list, bio_end_sector(bio)); in bfq_find_rq_fmerge()
2383 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_remove_request() local
2384 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request()
2387 if (bfqq->next_rq == rq) { in bfq_remove_request()
2388 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2389 bfq_updated_next_req(bfqd, bfqq); in bfq_remove_request()
2394 bfqq->queued[sync]--; in bfq_remove_request()
2400 elv_rb_del(&bfqq->sort_list, rq); in bfq_remove_request()
2406 if (RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_remove_request()
2407 bfqq->next_rq = NULL; in bfq_remove_request()
2409 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2410 bfq_del_bfqq_busy(bfqq, false); in bfq_remove_request()
2424 bfqq->entity.budget = bfqq->entity.service = 0; in bfq_remove_request()
2430 if (bfqq->pos_root) { in bfq_remove_request()
2431 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_remove_request()
2432 bfqq->pos_root = NULL; in bfq_remove_request()
2437 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2441 bfqq->meta_pending--; in bfq_remove_request()
2511 struct bfq_queue *bfqq = RQ_BFQQ(req); in bfq_request_merged() local
2515 if (!bfqq) in bfq_request_merged()
2518 bfqd = bfqq->bfqd; in bfq_request_merged()
2521 elv_rb_del(&bfqq->sort_list, req); in bfq_request_merged()
2522 elv_rb_add(&bfqq->sort_list, req); in bfq_request_merged()
2525 prev = bfqq->next_rq; in bfq_request_merged()
2526 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2528 bfqq->next_rq = next_rq; in bfq_request_merged()
2534 if (prev != bfqq->next_rq) { in bfq_request_merged()
2535 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2541 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2563 struct bfq_queue *bfqq = RQ_BFQQ(rq), in bfq_requests_merged() local
2566 if (!bfqq) in bfq_requests_merged()
2578 if (bfqq == next_bfqq && in bfq_requests_merged()
2586 if (bfqq->next_rq == next) in bfq_requests_merged()
2587 bfqq->next_rq = rq; in bfq_requests_merged()
2589 bfqg_stats_update_io_merged(bfqq_group(bfqq), next->cmd_flags); in bfq_requests_merged()
2601 static void bfq_bfqq_end_wr(struct bfq_queue *bfqq) in bfq_bfqq_end_wr() argument
2617 if (bfqq->wr_cur_max_time != in bfq_bfqq_end_wr()
2618 bfqq->bfqd->bfq_wr_rt_max_time) in bfq_bfqq_end_wr()
2619 bfqq->soft_rt_next_start = jiffies; in bfq_bfqq_end_wr()
2621 if (bfq_bfqq_busy(bfqq)) in bfq_bfqq_end_wr()
2622 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2623 bfqq->wr_coeff = 1; in bfq_bfqq_end_wr()
2624 bfqq->wr_cur_max_time = 0; in bfq_bfqq_end_wr()
2625 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_end_wr()
2630 bfqq->entity.prio_changed = 1; in bfq_bfqq_end_wr()
2650 struct bfq_queue *bfqq; in bfq_end_wr() local
2656 list_for_each_entry(bfqq, &bfqd->active_list[i], bfqq_list) in bfq_end_wr()
2657 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2659 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2660 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2682 struct bfq_queue *bfqq, in bfqq_find_close()
2685 struct rb_root *root = &bfqq_group(bfqq)->rq_pos_tree; in bfqq_find_close()
2727 struct bfq_queue *bfqq; in bfq_find_close_cooperator() local
2736 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2737 if (!bfqq || bfqq == cur_bfqq) in bfq_find_close_cooperator()
2740 return bfqq; in bfq_find_close_cooperator()
2744 bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_setup_merge() argument
2760 if (__bfqq == bfqq) in bfq_setup_merge()
2765 process_refs = bfqq_process_refs(bfqq); in bfq_setup_merge()
2779 if (new_bfqq->entity.parent != bfqq->entity.parent) in bfq_setup_merge()
2782 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2805 bfqq->new_bfqq = new_bfqq; in bfq_setup_merge()
2819 static bool bfq_may_be_close_cooperator(struct bfq_queue *bfqq, in bfq_may_be_close_cooperator() argument
2825 if (bfq_class_idle(bfqq) || bfq_class_idle(new_bfqq) || in bfq_may_be_close_cooperator()
2826 (bfqq->ioprio_class != new_bfqq->ioprio_class)) in bfq_may_be_close_cooperator()
2834 if (BFQQ_SEEKY(bfqq) || BFQQ_SEEKY(new_bfqq)) in bfq_may_be_close_cooperator()
2842 if (!bfq_bfqq_sync(bfqq) || !bfq_bfqq_sync(new_bfqq)) in bfq_may_be_close_cooperator()
2849 struct bfq_queue *bfqq);
2852 bfq_setup_stable_merge(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_stable_merge() argument
2856 int proc_ref = min(bfqq_process_refs(bfqq), in bfq_setup_stable_merge()
2861 if (idling_boosts_thr_without_issues(bfqd, bfqq) || proc_ref == 0) in bfq_setup_stable_merge()
2865 new_bfqq = bfq_setup_merge(bfqq, stable_merge_bfqq); in bfq_setup_stable_merge()
2906 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2910 unsigned int a_idx = bfqq->actuator_idx; in bfq_setup_cooperator()
2914 if (bfqq->new_bfqq) in bfq_setup_cooperator()
2915 return bfqq->new_bfqq; in bfq_setup_cooperator()
2933 if (bfq_bfqq_sync(bfqq) && bfqq_data->stable_merge_bfqq && in bfq_setup_cooperator()
2934 !bfq_bfqq_just_created(bfqq) && in bfq_setup_cooperator()
2935 time_is_before_jiffies(bfqq->split_time + in bfq_setup_cooperator()
2937 time_is_before_jiffies(bfqq->creation_time + in bfq_setup_cooperator()
2942 return bfq_setup_stable_merge(bfqd, bfqq, in bfq_setup_cooperator()
2999 if (bfq_too_late_for_merging(bfqq)) in bfq_setup_cooperator()
3002 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
3011 if (in_service_bfqq && in_service_bfqq != bfqq && in bfq_setup_cooperator()
3015 bfqq->entity.parent == in_service_bfqq->entity.parent && in bfq_setup_cooperator()
3016 bfq_may_be_close_cooperator(bfqq, in_service_bfqq)) { in bfq_setup_cooperator()
3017 new_bfqq = bfq_setup_merge(bfqq, in_service_bfqq); in bfq_setup_cooperator()
3026 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
3030 bfq_may_be_close_cooperator(bfqq, new_bfqq)) in bfq_setup_cooperator()
3031 return bfq_setup_merge(bfqq, new_bfqq); in bfq_setup_cooperator()
3036 static void bfq_bfqq_save_state(struct bfq_queue *bfqq) in bfq_bfqq_save_state() argument
3038 struct bfq_io_cq *bic = bfqq->bic; in bfq_bfqq_save_state()
3039 unsigned int a_idx = bfqq->actuator_idx; in bfq_bfqq_save_state()
3050 bfqq_data->saved_last_serv_time_ns = bfqq->last_serv_time_ns; in bfq_bfqq_save_state()
3051 bfqq_data->saved_inject_limit = bfqq->inject_limit; in bfq_bfqq_save_state()
3052 bfqq_data->saved_decrease_time_jif = bfqq->decrease_time_jif; in bfq_bfqq_save_state()
3054 bfqq_data->saved_weight = bfqq->entity.orig_weight; in bfq_bfqq_save_state()
3055 bfqq_data->saved_ttime = bfqq->ttime; in bfq_bfqq_save_state()
3057 bfq_bfqq_has_short_ttime(bfqq); in bfq_bfqq_save_state()
3058 bfqq_data->saved_IO_bound = bfq_bfqq_IO_bound(bfqq); in bfq_bfqq_save_state()
3059 bfqq_data->saved_io_start_time = bfqq->io_start_time; in bfq_bfqq_save_state()
3060 bfqq_data->saved_tot_idle_time = bfqq->tot_idle_time; in bfq_bfqq_save_state()
3061 bfqq_data->saved_in_large_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_save_state()
3063 !hlist_unhashed(&bfqq->burst_list_node); in bfq_bfqq_save_state()
3065 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_bfqq_save_state()
3066 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_save_state()
3067 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
3077 bfqq_data->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
3081 bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
3084 bfqq_data->saved_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_save_state()
3086 bfqq->wr_start_at_switch_to_srt; in bfq_bfqq_save_state()
3088 bfqq->service_from_wr; in bfq_bfqq_save_state()
3090 bfqq->last_wr_start_finish; in bfq_bfqq_save_state()
3091 bfqq_data->saved_wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_bfqq_save_state()
3106 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
3119 if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_release_process_ref()
3120 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
3121 bfq_del_bfqq_busy(bfqq, false); in bfq_release_process_ref()
3123 bfq_reassign_last_bfqq(bfqq, NULL); in bfq_release_process_ref()
3125 bfq_put_queue(bfqq); in bfq_release_process_ref()
3130 struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_merge_bfqqs() argument
3132 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
3135 bfq_bfqq_save_state(bfqq); in bfq_merge_bfqqs()
3137 if (bfq_bfqq_IO_bound(bfqq)) in bfq_merge_bfqqs()
3139 bfq_clear_bfqq_IO_bound(bfqq); in bfq_merge_bfqqs()
3148 if (bfqq->waker_bfqq && !new_bfqq->waker_bfqq && in bfq_merge_bfqqs()
3149 bfqq->waker_bfqq != new_bfqq) { in bfq_merge_bfqqs()
3150 new_bfqq->waker_bfqq = bfqq->waker_bfqq; in bfq_merge_bfqqs()
3173 if (new_bfqq->wr_coeff == 1 && bfqq->wr_coeff > 1) { in bfq_merge_bfqqs()
3174 new_bfqq->wr_coeff = bfqq->wr_coeff; in bfq_merge_bfqqs()
3175 new_bfqq->wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_merge_bfqqs()
3176 new_bfqq->last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_merge_bfqqs()
3178 bfqq->wr_start_at_switch_to_srt; in bfq_merge_bfqqs()
3184 if (bfqq->wr_coeff > 1) { /* bfqq has given its wr to new_bfqq */ in bfq_merge_bfqqs()
3185 bfqq->wr_coeff = 1; in bfq_merge_bfqqs()
3186 bfqq->entity.prio_changed = 1; in bfq_merge_bfqqs()
3187 if (bfq_bfqq_busy(bfqq)) in bfq_merge_bfqqs()
3197 bic_set_bfqq(bic, new_bfqq, true, bfqq->actuator_idx); in bfq_merge_bfqqs()
3220 bfqq->bic = NULL; in bfq_merge_bfqqs()
3222 bfq_reassign_last_bfqq(bfqq, new_bfqq); in bfq_merge_bfqqs()
3224 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
3232 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge() local
3244 if (!bfqq) in bfq_allow_bio_merge()
3251 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false, bfqd->bio_bic); in bfq_allow_bio_merge()
3260 bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq, in bfq_allow_bio_merge()
3267 bfqq = new_bfqq; in bfq_allow_bio_merge()
3275 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
3278 return bfqq == RQ_BFQQ(rq); in bfq_allow_bio_merge()
3288 struct bfq_queue *bfqq) in bfq_set_budget_timeout() argument
3292 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
3295 timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight; in bfq_set_budget_timeout()
3299 bfqq->budget_timeout = jiffies + in bfq_set_budget_timeout()
3304 struct bfq_queue *bfqq) in __bfq_set_in_service_queue() argument
3306 if (bfqq) { in __bfq_set_in_service_queue()
3307 bfq_clear_bfqq_fifo_expire(bfqq); in __bfq_set_in_service_queue()
3311 if (time_is_before_jiffies(bfqq->last_wr_start_finish) && in __bfq_set_in_service_queue()
3312 bfqq->wr_coeff > 1 && in __bfq_set_in_service_queue()
3313 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
3314 time_is_before_jiffies(bfqq->budget_timeout)) { in __bfq_set_in_service_queue()
3339 if (time_after(bfqq->budget_timeout, in __bfq_set_in_service_queue()
3340 bfqq->last_wr_start_finish)) in __bfq_set_in_service_queue()
3341 bfqq->last_wr_start_finish += in __bfq_set_in_service_queue()
3342 jiffies - bfqq->budget_timeout; in __bfq_set_in_service_queue()
3344 bfqq->last_wr_start_finish = jiffies; in __bfq_set_in_service_queue()
3347 bfq_set_budget_timeout(bfqd, bfqq); in __bfq_set_in_service_queue()
3348 bfq_log_bfqq(bfqd, bfqq, in __bfq_set_in_service_queue()
3350 bfqq->entity.budget); in __bfq_set_in_service_queue()
3353 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
3362 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue() local
3364 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
3365 return bfqq; in bfq_set_in_service_queue()
3370 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer() local
3373 bfq_mark_bfqq_wait_request(bfqq); in bfq_arm_slice_timer()
3391 if (BFQQ_SEEKY(bfqq) && bfqq->wr_coeff == 1 && in bfq_arm_slice_timer()
3392 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
3394 else if (bfqq->wr_coeff > 1) in bfq_arm_slice_timer()
3402 bfqg_stats_set_start_idle_time(bfqq_group(bfqq)); in bfq_arm_slice_timer()
3655 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_dispatch_remove() local
3669 bfqq->dispatched++; in bfq_dispatch_remove()
3877 struct bfq_queue *bfqq) in idling_needed_for_service_guarantees() argument
3882 if (unlikely(!bfqq_process_refs(bfqq))) in idling_needed_for_service_guarantees()
3885 return (bfqq->wr_coeff > 1 && in idling_needed_for_service_guarantees()
3887 bfqd->tot_rq_in_driver >= bfqq->dispatched + 4)) || in idling_needed_for_service_guarantees()
3888 bfq_asymmetric_scenario(bfqd, bfqq) || in idling_needed_for_service_guarantees()
3892 static bool __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, in __bfq_bfqq_expire() argument
3901 if (bfq_bfqq_coop(bfqq) && BFQQ_SEEKY(bfqq)) in __bfq_bfqq_expire()
3902 bfq_mark_bfqq_split_coop(bfqq); in __bfq_bfqq_expire()
3917 if (RB_EMPTY_ROOT(&bfqq->sort_list) && in __bfq_bfqq_expire()
3919 idling_needed_for_service_guarantees(bfqd, bfqq))) { in __bfq_bfqq_expire()
3920 if (bfqq->dispatched == 0) in __bfq_bfqq_expire()
3927 bfqq->budget_timeout = jiffies; in __bfq_bfqq_expire()
3929 bfq_del_bfqq_busy(bfqq, true); in __bfq_bfqq_expire()
3931 bfq_requeue_bfqq(bfqd, bfqq, true); in __bfq_bfqq_expire()
3937 !RB_EMPTY_ROOT(&bfqq->sort_list))) in __bfq_bfqq_expire()
3938 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3961 struct bfq_queue *bfqq, in __bfq_bfqq_recalc_budget() argument
3969 if (bfqq->wr_coeff == 1) in __bfq_bfqq_recalc_budget()
3970 budget = bfqq->max_budget; in __bfq_bfqq_recalc_budget()
3979 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", in __bfq_bfqq_recalc_budget()
3980 bfqq->entity.budget, bfq_bfqq_budget_left(bfqq)); in __bfq_bfqq_recalc_budget()
3981 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last max_budg %d, min budg %d", in __bfq_bfqq_recalc_budget()
3983 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: sync %d, seeky %d", in __bfq_bfqq_recalc_budget()
3984 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
3986 if (bfq_bfqq_sync(bfqq) && bfqq->wr_coeff == 1) { in __bfq_bfqq_recalc_budget()
4017 if (bfqq->dispatched > 0) /* still outstanding reqs */ in __bfq_bfqq_recalc_budget()
4080 budget = max_t(int, bfqq->entity.service, min_budget); in __bfq_bfqq_recalc_budget()
4085 } else if (!bfq_bfqq_sync(bfqq)) { in __bfq_bfqq_recalc_budget()
4095 bfqq->max_budget = budget; in __bfq_bfqq_recalc_budget()
4099 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4111 next_rq = bfqq->next_rq; in __bfq_bfqq_recalc_budget()
4113 bfqq->entity.budget = max_t(unsigned long, bfqq->max_budget, in __bfq_bfqq_recalc_budget()
4114 bfq_serv_to_charge(next_rq, bfqq)); in __bfq_bfqq_recalc_budget()
4116 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", in __bfq_bfqq_recalc_budget()
4118 bfqq->entity.budget); in __bfq_bfqq_recalc_budget()
4152 static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_bfqq_is_slow() argument
4157 bool slow = BFQQ_SEEKY(bfqq); /* if delta too short, use seekyness */ in bfq_bfqq_is_slow()
4159 if (!bfq_bfqq_sync(bfqq)) in bfq_bfqq_is_slow()
4200 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
4203 bfq_log_bfqq(bfqd, bfqq, "bfq_bfqq_is_slow: slow %d", slow); in bfq_bfqq_is_slow()
4302 struct bfq_queue *bfqq) in bfq_bfqq_softrt_next_start() argument
4304 return max3(bfqq->soft_rt_next_start, in bfq_bfqq_softrt_next_start()
4305 bfqq->last_idle_bklogged + in bfq_bfqq_softrt_next_start()
4306 HZ * bfqq->service_from_backlogged / in bfq_bfqq_softrt_next_start()
4308 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
4338 struct bfq_queue *bfqq, in bfq_bfqq_expire() argument
4344 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_expire()
4349 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, &delta); in bfq_bfqq_expire()
4366 if (bfqq->wr_coeff == 1 && in bfq_bfqq_expire()
4369 bfq_bfqq_budget_left(bfqq) >= entity->budget / 3))) in bfq_bfqq_expire()
4370 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
4372 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
4373 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_expire()
4376 RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_bfqq_expire()
4389 if (bfqq->dispatched == 0) in bfq_bfqq_expire()
4390 bfqq->soft_rt_next_start = in bfq_bfqq_expire()
4391 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
4392 else if (bfqq->dispatched > 0) { in bfq_bfqq_expire()
4397 bfq_mark_bfqq_softrt_update(bfqq); in bfq_bfqq_expire()
4401 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
4403 slow, bfqq->dispatched, bfq_bfqq_has_short_ttime(bfqq)); in bfq_bfqq_expire()
4417 __bfq_bfqq_recalc_budget(bfqd, bfqq, reason); in bfq_bfqq_expire()
4418 if (__bfq_bfqq_expire(bfqd, bfqq, reason)) in bfq_bfqq_expire()
4423 if (!bfq_bfqq_busy(bfqq) && in bfq_bfqq_expire()
4426 bfq_mark_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_expire()
4462 static bool bfq_bfqq_budget_timeout(struct bfq_queue *bfqq) in bfq_bfqq_budget_timeout() argument
4464 return time_is_before_eq_jiffies(bfqq->budget_timeout); in bfq_bfqq_budget_timeout()
4475 static bool bfq_may_expire_for_budg_timeout(struct bfq_queue *bfqq) in bfq_may_expire_for_budg_timeout() argument
4477 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4479 bfq_bfqq_wait_request(bfqq), in bfq_may_expire_for_budg_timeout()
4480 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3, in bfq_may_expire_for_budg_timeout()
4481 bfq_bfqq_budget_timeout(bfqq)); in bfq_may_expire_for_budg_timeout()
4483 return (!bfq_bfqq_wait_request(bfqq) || in bfq_may_expire_for_budg_timeout()
4484 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3) in bfq_may_expire_for_budg_timeout()
4486 bfq_bfqq_budget_timeout(bfqq); in bfq_may_expire_for_budg_timeout()
4490 struct bfq_queue *bfqq) in idling_boosts_thr_without_issues() argument
4498 if (unlikely(!bfqq_process_refs(bfqq))) in idling_boosts_thr_without_issues()
4501 bfqq_sequential_and_IO_bound = !BFQQ_SEEKY(bfqq) && in idling_boosts_thr_without_issues()
4502 bfq_bfqq_IO_bound(bfqq) && bfq_bfqq_has_short_ttime(bfqq); in idling_boosts_thr_without_issues()
4589 static bool bfq_better_to_idle(struct bfq_queue *bfqq) in bfq_better_to_idle() argument
4591 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle()
4595 if (unlikely(!bfqq_process_refs(bfqq))) in bfq_better_to_idle()
4609 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4610 bfq_class_idle(bfqq)) in bfq_better_to_idle()
4614 idling_boosts_thr_without_issues(bfqd, bfqq); in bfq_better_to_idle()
4617 idling_needed_for_service_guarantees(bfqd, bfqq); in bfq_better_to_idle()
4640 static bool bfq_bfqq_must_idle(struct bfq_queue *bfqq) in bfq_bfqq_must_idle() argument
4642 return RB_EMPTY_ROOT(&bfqq->sort_list) && bfq_better_to_idle(bfqq); in bfq_bfqq_must_idle()
4655 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection() local
4706 list_for_each_entry(bfqq, &bfqd->active_list[i], bfqq_list) in bfq_choose_bfqq_for_injection()
4707 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_choose_bfqq_for_injection()
4708 (in_serv_always_inject || bfqq->wr_coeff > 1) && in bfq_choose_bfqq_for_injection()
4709 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_choose_bfqq_for_injection()
4710 bfq_bfqq_budget_left(bfqq)) { in bfq_choose_bfqq_for_injection()
4729 blk_rq_sectors(bfqq->next_rq) >= in bfq_choose_bfqq_for_injection()
4735 return bfqq; in bfq_choose_bfqq_for_injection()
4746 struct bfq_queue *bfqq; in bfq_find_active_bfqq_for_actuator() local
4752 list_for_each_entry(bfqq, &bfqd->active_list[idx], bfqq_list) { in bfq_find_active_bfqq_for_actuator()
4753 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_find_active_bfqq_for_actuator()
4754 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_find_active_bfqq_for_actuator()
4755 bfq_bfqq_budget_left(bfqq)) { in bfq_find_active_bfqq_for_actuator()
4756 return bfqq; in bfq_find_active_bfqq_for_actuator()
4785 struct bfq_queue *bfqq = in bfq_find_bfqq_for_underused_actuator() local
4788 if (bfqq) in bfq_find_bfqq_for_underused_actuator()
4789 return bfqq; in bfq_find_bfqq_for_underused_actuator()
4803 struct bfq_queue *bfqq, *inject_bfqq; in bfq_select_queue() local
4807 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4808 if (!bfqq) in bfq_select_queue()
4811 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4820 if (bfq_may_expire_for_budg_timeout(bfqq) && in bfq_select_queue()
4821 !bfq_bfqq_must_idle(bfqq)) in bfq_select_queue()
4831 if (inject_bfqq && inject_bfqq != bfqq) in bfq_select_queue()
4840 next_rq = bfqq->next_rq; in bfq_select_queue()
4846 if (bfq_serv_to_charge(next_rq, bfqq) > in bfq_select_queue()
4847 bfq_bfqq_budget_left(bfqq)) { in bfq_select_queue()
4862 if (bfq_bfqq_wait_request(bfqq)) { in bfq_select_queue()
4876 bfq_clear_bfqq_wait_request(bfqq); in bfq_select_queue()
4891 if (bfq_bfqq_wait_request(bfqq) || in bfq_select_queue()
4892 (bfqq->dispatched != 0 && bfq_better_to_idle(bfqq))) { in bfq_select_queue()
4893 unsigned int act_idx = bfqq->actuator_idx; in bfq_select_queue()
4896 !hlist_empty(&bfqq->woken_list) ? in bfq_select_queue()
4897 container_of(bfqq->woken_list.first, in bfq_select_queue()
4902 if (bfqq->bic && bfqq->bic->bfqq[0][act_idx] && in bfq_select_queue()
4903 bfq_bfqq_busy(bfqq->bic->bfqq[0][act_idx]) && in bfq_select_queue()
4904 bfqq->bic->bfqq[0][act_idx]->next_rq) in bfq_select_queue()
4905 async_bfqq = bfqq->bic->bfqq[0][act_idx]; in bfq_select_queue()
4987 icq_to_bic(async_bfqq->next_rq->elv.icq) == bfqq->bic && in bfq_select_queue()
4990 bfqq = async_bfqq; in bfq_select_queue()
4991 else if (bfqq->waker_bfqq && in bfq_select_queue()
4992 bfq_bfqq_busy(bfqq->waker_bfqq) && in bfq_select_queue()
4993 bfqq->waker_bfqq->next_rq && in bfq_select_queue()
4994 bfq_serv_to_charge(bfqq->waker_bfqq->next_rq, in bfq_select_queue()
4995 bfqq->waker_bfqq) <= in bfq_select_queue()
4996 bfq_bfqq_budget_left(bfqq->waker_bfqq) in bfq_select_queue()
4998 bfqq = bfqq->waker_bfqq; in bfq_select_queue()
5006 bfqq = blocked_bfqq; in bfq_select_queue()
5007 else if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_select_queue()
5008 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
5009 !bfq_bfqq_has_short_ttime(bfqq))) in bfq_select_queue()
5010 bfqq = bfq_choose_bfqq_for_injection(bfqd); in bfq_select_queue()
5012 bfqq = NULL; in bfq_select_queue()
5019 bfq_bfqq_expire(bfqd, bfqq, false, reason); in bfq_select_queue()
5021 bfqq = bfq_set_in_service_queue(bfqd); in bfq_select_queue()
5022 if (bfqq) { in bfq_select_queue()
5023 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
5027 if (bfqq) in bfq_select_queue()
5028 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
5032 return bfqq; in bfq_select_queue()
5035 static void bfq_update_wr_data(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_update_wr_data() argument
5037 struct bfq_entity *entity = &bfqq->entity; in bfq_update_wr_data()
5039 if (bfqq->wr_coeff > 1) { /* queue is being weight-raised */ in bfq_update_wr_data()
5040 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
5042 jiffies_to_msecs(jiffies - bfqq->last_wr_start_finish), in bfq_update_wr_data()
5043 jiffies_to_msecs(bfqq->wr_cur_max_time), in bfq_update_wr_data()
5044 bfqq->wr_coeff, in bfq_update_wr_data()
5045 bfqq->entity.weight, bfqq->entity.orig_weight); in bfq_update_wr_data()
5048 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
5055 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_update_wr_data()
5056 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
5057 else if (time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_update_wr_data()
5058 bfqq->wr_cur_max_time)) { in bfq_update_wr_data()
5059 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
5060 time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_wr_data()
5070 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
5076 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
5077 bfqq->entity.prio_changed = 1; in bfq_update_wr_data()
5080 if (bfqq->wr_coeff > 1 && in bfq_update_wr_data()
5081 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
5082 bfqq->service_from_wr > max_service_from_wr) { in bfq_update_wr_data()
5084 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
5095 if ((entity->weight > entity->orig_weight) != (bfqq->wr_coeff > 1)) in bfq_update_wr_data()
5104 struct bfq_queue *bfqq) in bfq_dispatch_rq_from_bfqq() argument
5106 struct request *rq = bfqq->next_rq; in bfq_dispatch_rq_from_bfqq()
5109 service_to_charge = bfq_serv_to_charge(rq, bfqq); in bfq_dispatch_rq_from_bfqq()
5111 bfq_bfqq_served(bfqq, service_to_charge); in bfq_dispatch_rq_from_bfqq()
5113 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
5120 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
5134 bfq_update_wr_data(bfqd, bfqq); in bfq_dispatch_rq_from_bfqq()
5141 if (bfq_tot_busy_queues(bfqd) > 1 && bfq_class_idle(bfqq)) in bfq_dispatch_rq_from_bfqq()
5142 bfq_bfqq_expire(bfqd, bfqq, false, BFQQE_BUDGET_EXHAUSTED); in bfq_dispatch_rq_from_bfqq()
5163 struct bfq_queue *bfqq = NULL; in __bfq_dispatch_request() local
5170 bfqq = RQ_BFQQ(rq); in __bfq_dispatch_request()
5172 if (bfqq) { in __bfq_dispatch_request()
5179 bfqq->dispatched++; in __bfq_dispatch_request()
5231 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
5232 if (!bfqq) in __bfq_dispatch_request()
5235 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
5239 bfqd->rq_in_driver[bfqq->actuator_idx]++; in __bfq_dispatch_request()
5254 struct bfq_queue *bfqq = rq ? RQ_BFQQ(rq) : NULL; in bfq_update_dispatch_stats() local
5256 if (!idle_timer_disabled && !bfqq) in bfq_update_dispatch_stats()
5284 if (bfqq) { in bfq_update_dispatch_stats()
5285 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_update_dispatch_stats()
5333 void bfq_put_queue(struct bfq_queue *bfqq) in bfq_put_queue() argument
5337 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_put_queue()
5339 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", bfqq, bfqq->ref); in bfq_put_queue()
5341 bfqq->ref--; in bfq_put_queue()
5342 if (bfqq->ref) in bfq_put_queue()
5345 if (!hlist_unhashed(&bfqq->burst_list_node)) { in bfq_put_queue()
5346 hlist_del_init(&bfqq->burst_list_node); in bfq_put_queue()
5373 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
5374 bfqq->bfqd->burst_size--; in bfq_put_queue()
5393 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_put_queue()
5394 hlist_del_init(&bfqq->woken_list_node); in bfq_put_queue()
5397 hlist_for_each_entry_safe(item, n, &bfqq->woken_list, in bfq_put_queue()
5403 if (bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
5404 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
5406 WARN_ON_ONCE(!list_empty(&bfqq->fifo)); in bfq_put_queue()
5407 WARN_ON_ONCE(!RB_EMPTY_ROOT(&bfqq->sort_list)); in bfq_put_queue()
5408 WARN_ON_ONCE(bfqq->dispatched); in bfq_put_queue()
5410 kmem_cache_free(bfq_pool, bfqq); in bfq_put_queue()
5414 static void bfq_put_stable_ref(struct bfq_queue *bfqq) in bfq_put_stable_ref() argument
5416 bfqq->stable_ref--; in bfq_put_stable_ref()
5417 bfq_put_queue(bfqq); in bfq_put_stable_ref()
5420 void bfq_put_cooperator(struct bfq_queue *bfqq) in bfq_put_cooperator() argument
5429 __bfqq = bfqq->new_bfqq; in bfq_put_cooperator()
5437 static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_exit_bfqq() argument
5439 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
5440 __bfq_bfqq_expire(bfqd, bfqq, BFQQE_BUDGET_TIMEOUT); in bfq_exit_bfqq()
5444 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
5446 bfq_put_cooperator(bfqq); in bfq_exit_bfqq()
5448 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
5454 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync, actuator_idx); in bfq_exit_icq_bfqq() local
5457 if (bfqq) in bfq_exit_icq_bfqq()
5458 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
5460 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
5462 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
5507 bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) in bfq_set_next_ioprio_data() argument
5511 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data()
5520 bdi_dev_name(bfqq->bfqd->queue->disk->bdi), in bfq_set_next_ioprio_data()
5527 bfqq->new_ioprio = task_nice_ioprio(tsk); in bfq_set_next_ioprio_data()
5528 bfqq->new_ioprio_class = task_nice_ioclass(tsk); in bfq_set_next_ioprio_data()
5531 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); in bfq_set_next_ioprio_data()
5532 bfqq->new_ioprio_class = IOPRIO_CLASS_RT; in bfq_set_next_ioprio_data()
5535 bfqq->new_ioprio = IOPRIO_PRIO_LEVEL(bic->ioprio); in bfq_set_next_ioprio_data()
5536 bfqq->new_ioprio_class = IOPRIO_CLASS_BE; in bfq_set_next_ioprio_data()
5539 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; in bfq_set_next_ioprio_data()
5540 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; in bfq_set_next_ioprio_data()
5544 if (bfqq->new_ioprio >= IOPRIO_NR_LEVELS) { in bfq_set_next_ioprio_data()
5546 bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5547 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; in bfq_set_next_ioprio_data()
5550 bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5551 bfq_log_bfqq(bfqd, bfqq, "new_ioprio %d new_weight %d", in bfq_set_next_ioprio_data()
5552 bfqq->new_ioprio, bfqq->entity.new_weight); in bfq_set_next_ioprio_data()
5553 bfqq->entity.prio_changed = 1; in bfq_set_next_ioprio_data()
5564 struct bfq_queue *bfqq; in bfq_check_ioprio_change() local
5576 bfqq = bic_to_bfqq(bic, false, bfq_actuator_index(bfqd, bio)); in bfq_check_ioprio_change()
5577 if (bfqq) { in bfq_check_ioprio_change()
5578 struct bfq_queue *old_bfqq = bfqq; in bfq_check_ioprio_change()
5580 bfqq = bfq_get_queue(bfqd, bio, false, bic, true); in bfq_check_ioprio_change()
5581 bic_set_bfqq(bic, bfqq, false, bfq_actuator_index(bfqd, bio)); in bfq_check_ioprio_change()
5585 bfqq = bic_to_bfqq(bic, true, bfq_actuator_index(bfqd, bio)); in bfq_check_ioprio_change()
5586 if (bfqq) in bfq_check_ioprio_change()
5587 bfq_set_next_ioprio_data(bfqq, bic); in bfq_check_ioprio_change()
5590 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5596 bfqq->actuator_idx = act_idx; in bfq_init_bfqq()
5597 RB_CLEAR_NODE(&bfqq->entity.rb_node); in bfq_init_bfqq()
5598 INIT_LIST_HEAD(&bfqq->fifo); in bfq_init_bfqq()
5599 INIT_HLIST_NODE(&bfqq->burst_list_node); in bfq_init_bfqq()
5600 INIT_HLIST_NODE(&bfqq->woken_list_node); in bfq_init_bfqq()
5601 INIT_HLIST_HEAD(&bfqq->woken_list); in bfq_init_bfqq()
5603 bfqq->ref = 0; in bfq_init_bfqq()
5604 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5607 bfq_set_next_ioprio_data(bfqq, bic); in bfq_init_bfqq()
5615 if (!bfq_class_idle(bfqq)) in bfq_init_bfqq()
5617 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_init_bfqq()
5618 bfq_mark_bfqq_sync(bfqq); in bfq_init_bfqq()
5619 bfq_mark_bfqq_just_created(bfqq); in bfq_init_bfqq()
5621 bfq_clear_bfqq_sync(bfqq); in bfq_init_bfqq()
5624 bfqq->ttime.last_end_request = now_ns + 1; in bfq_init_bfqq()
5626 bfqq->creation_time = jiffies; in bfq_init_bfqq()
5628 bfqq->io_start_time = now_ns; in bfq_init_bfqq()
5630 bfq_mark_bfqq_IO_bound(bfqq); in bfq_init_bfqq()
5632 bfqq->pid = pid; in bfq_init_bfqq()
5635 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5636 bfqq->budget_timeout = bfq_smallest_from_now(); in bfq_init_bfqq()
5638 bfqq->wr_coeff = 1; in bfq_init_bfqq()
5639 bfqq->last_wr_start_finish = jiffies; in bfq_init_bfqq()
5640 bfqq->wr_start_at_switch_to_srt = bfq_smallest_from_now(); in bfq_init_bfqq()
5641 bfqq->split_time = bfq_smallest_from_now(); in bfq_init_bfqq()
5652 bfqq->soft_rt_next_start = jiffies; in bfq_init_bfqq()
5655 bfqq->seek_history = 1; in bfq_init_bfqq()
5657 bfqq->decrease_time_jif = jiffies; in bfq_init_bfqq()
5680 bfq_do_early_stable_merge(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_do_early_stable_merge() argument
5686 bfq_setup_merge(bfqq, last_bfqq_created); in bfq_do_early_stable_merge()
5689 return bfqq; in bfq_do_early_stable_merge()
5701 bfqq->bic = bic; in bfq_do_early_stable_merge()
5702 bfq_merge_bfqqs(bfqd, bic, bfqq, new_bfqq); in bfq_do_early_stable_merge()
5754 struct bfq_queue *bfqq, in bfq_do_or_sched_stable_merge() argument
5757 struct bfq_queue **source_bfqq = bfqq->entity.parent ? in bfq_do_or_sched_stable_merge()
5758 &bfqq->entity.parent->last_bfqq_created : in bfq_do_or_sched_stable_merge()
5789 bfqq->creation_time) || in bfq_do_or_sched_stable_merge()
5790 bfqq->entity.parent != last_bfqq_created->entity.parent || in bfq_do_or_sched_stable_merge()
5791 bfqq->ioprio != last_bfqq_created->ioprio || in bfq_do_or_sched_stable_merge()
5792 bfqq->ioprio_class != last_bfqq_created->ioprio_class || in bfq_do_or_sched_stable_merge()
5793 bfqq->actuator_idx != last_bfqq_created->actuator_idx) in bfq_do_or_sched_stable_merge()
5794 *source_bfqq = bfqq; in bfq_do_or_sched_stable_merge()
5797 bfqq->creation_time)) { in bfq_do_or_sched_stable_merge()
5805 bfqq = bfq_do_early_stable_merge(bfqd, bfqq, in bfq_do_or_sched_stable_merge()
5828 return bfqq; in bfq_do_or_sched_stable_merge()
5840 struct bfq_queue *bfqq; in bfq_get_queue() local
5848 bfqq = *async_bfqq; in bfq_get_queue()
5849 if (bfqq) in bfq_get_queue()
5853 bfqq = kmem_cache_alloc_node(bfq_pool, in bfq_get_queue()
5857 if (bfqq) { in bfq_get_queue()
5858 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5860 bfq_init_entity(&bfqq->entity, bfqg); in bfq_get_queue()
5861 bfq_log_bfqq(bfqd, bfqq, "allocated"); in bfq_get_queue()
5863 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5864 bfq_log_bfqq(bfqd, bfqq, "using oom bfqq"); in bfq_get_queue()
5873 bfqq->ref++; /* in bfq_get_queue()
5880 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5881 bfqq, bfqq->ref); in bfq_get_queue()
5882 *async_bfqq = bfqq; in bfq_get_queue()
5886 bfqq->ref++; /* get a process reference to this queue */ in bfq_get_queue()
5888 if (bfqq != &bfqd->oom_bfqq && is_sync && !respawn) in bfq_get_queue()
5889 bfqq = bfq_do_or_sched_stable_merge(bfqd, bfqq, bic); in bfq_get_queue()
5890 return bfqq; in bfq_get_queue()
5894 struct bfq_queue *bfqq) in bfq_update_io_thinktime() argument
5896 struct bfq_ttime *ttime = &bfqq->ttime; in bfq_update_io_thinktime()
5904 if (bfqq->dispatched || bfq_bfqq_busy(bfqq)) in bfq_update_io_thinktime()
5906 elapsed = ktime_get_ns() - bfqq->ttime.last_end_request; in bfq_update_io_thinktime()
5916 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5919 bfqq->seek_history <<= 1; in bfq_update_io_seektime()
5920 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5922 if (bfqq->wr_coeff > 1 && in bfq_update_io_seektime()
5923 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5924 BFQQ_TOTALLY_SEEKY(bfqq)) { in bfq_update_io_seektime()
5925 if (time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_io_seektime()
5933 bfq_bfqq_end_wr(bfqq); in bfq_update_io_seektime()
5940 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_io_seektime()
5941 bfqq->entity.prio_changed = 1; in bfq_update_io_seektime()
5947 struct bfq_queue *bfqq, in bfq_update_has_short_ttime() argument
5957 if (!bfq_bfqq_sync(bfqq) || bfq_class_idle(bfqq) || in bfq_update_has_short_ttime()
5962 if (time_is_after_eq_jiffies(bfqq->split_time + in bfq_update_has_short_ttime()
5972 (bfq_sample_valid(bfqq->ttime.ttime_samples) && in bfq_update_has_short_ttime()
5973 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle>>1)) in bfq_update_has_short_ttime()
5976 state_changed = has_short_ttime != bfq_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5979 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5981 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
6067 if (state_changed && bfqq->last_serv_time_ns == 0 && in bfq_update_has_short_ttime()
6068 (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_update_has_short_ttime()
6071 bfq_reset_inject_limit(bfqd, bfqq); in bfq_update_has_short_ttime()
6078 static void bfq_rq_enqueued(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_rq_enqueued() argument
6082 bfqq->meta_pending++; in bfq_rq_enqueued()
6084 bfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_rq_enqueued()
6086 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
6087 bool small_req = bfqq->queued[rq_is_sync(rq)] == 1 && in bfq_rq_enqueued()
6089 bool budget_timeout = bfq_bfqq_budget_timeout(bfqq); in bfq_rq_enqueued()
6107 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
6118 bfq_clear_bfqq_wait_request(bfqq); in bfq_rq_enqueued()
6129 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
6134 static void bfqq_request_allocated(struct bfq_queue *bfqq) in bfqq_request_allocated() argument
6136 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_allocated()
6142 static void bfqq_request_freed(struct bfq_queue *bfqq) in bfqq_request_freed() argument
6144 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_freed()
6153 struct bfq_queue *bfqq = RQ_BFQQ(rq), in __bfq_insert_request() local
6154 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true, in __bfq_insert_request()
6164 bfqq_request_freed(bfqq); in __bfq_insert_request()
6175 bfq_actuator_index(bfqd, rq->bio)) == bfqq) in __bfq_insert_request()
6177 bfqq, new_bfqq); in __bfq_insert_request()
6179 bfq_clear_bfqq_just_created(bfqq); in __bfq_insert_request()
6184 bfq_put_queue(bfqq); in __bfq_insert_request()
6186 bfqq = new_bfqq; in __bfq_insert_request()
6189 bfq_update_io_thinktime(bfqd, bfqq); in __bfq_insert_request()
6190 bfq_update_has_short_ttime(bfqd, bfqq, RQ_BIC(rq)); in __bfq_insert_request()
6191 bfq_update_io_seektime(bfqd, bfqq, rq); in __bfq_insert_request()
6193 waiting = bfqq && bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
6195 idle_timer_disabled = waiting && !bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
6198 list_add_tail(&rq->queuelist, &bfqq->fifo); in __bfq_insert_request()
6200 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
6207 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
6211 if (!bfqq) in bfq_update_insert_stats()
6225 bfqg_stats_update_io_add(bfqq_group(bfqq), bfqq, cmd_flags); in bfq_update_insert_stats()
6227 bfqg_stats_update_idle_time(bfqq_group(bfqq)); in bfq_update_insert_stats()
6232 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
6244 struct bfq_queue *bfqq; in bfq_insert_request() local
6254 bfqq = bfq_init_rq(rq); in bfq_insert_request()
6265 } else if (!bfqq) { in bfq_insert_request()
6274 bfqq = RQ_BFQQ(rq); in bfq_insert_request()
6291 bfq_update_insert_stats(q, bfqq, idle_timer_disabled, in bfq_insert_request()
6310 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag() local
6332 if (bfqq && bfq_bfqq_has_short_ttime(bfqq) && in bfq_update_hw_tag()
6333 bfqq->dispatched + bfqq->queued[0] + bfqq->queued[1] < in bfq_update_hw_tag()
6349 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
6356 bfqd->rq_in_driver[bfqq->actuator_idx]--; in bfq_completed_request()
6358 bfqq->dispatched--; in bfq_completed_request()
6360 if (!bfqq->dispatched && !bfq_bfqq_busy(bfqq)) { in bfq_completed_request()
6367 bfqq->budget_timeout = jiffies; in bfq_completed_request()
6369 bfq_del_bfqq_in_groups_with_pending_reqs(bfqq); in bfq_completed_request()
6370 bfq_weights_tree_remove(bfqq); in bfq_completed_request()
6375 bfqq->ttime.last_end_request = now_ns; in bfq_completed_request()
6413 if (!bfq_bfqq_coop(bfqq)) in bfq_completed_request()
6414 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
6429 if (bfq_bfqq_softrt_update(bfqq) && bfqq->dispatched == 0 && in bfq_completed_request()
6430 RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6431 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
6432 bfqq->soft_rt_next_start = in bfq_completed_request()
6433 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_completed_request()
6439 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
6440 if (bfq_bfqq_must_idle(bfqq)) { in bfq_completed_request()
6441 if (bfqq->dispatched == 0) in bfq_completed_request()
6467 } else if (bfq_may_expire_for_budg_timeout(bfqq)) in bfq_completed_request()
6468 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6470 else if (RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6471 (bfqq->dispatched == 0 || in bfq_completed_request()
6472 !bfq_better_to_idle(bfqq))) in bfq_completed_request()
6473 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6586 struct bfq_queue *bfqq) in bfq_update_inject_limit() argument
6589 unsigned int old_limit = bfqq->inject_limit; in bfq_update_inject_limit()
6591 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
6592 u64 threshold = (bfqq->last_serv_time_ns * 3)>>1; in bfq_update_inject_limit()
6595 bfqq->inject_limit--; in bfq_update_inject_limit()
6596 bfqq->decrease_time_jif = jiffies; in bfq_update_inject_limit()
6599 bfqq->inject_limit++; in bfq_update_inject_limit()
6614 if ((bfqq->last_serv_time_ns == 0 && bfqd->tot_rq_in_driver == 1) || in bfq_update_inject_limit()
6615 tot_time_ns < bfqq->last_serv_time_ns) { in bfq_update_inject_limit()
6616 if (bfqq->last_serv_time_ns == 0) { in bfq_update_inject_limit()
6621 bfqq->inject_limit = max_t(unsigned int, 1, old_limit); in bfq_update_inject_limit()
6623 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6634 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6650 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_finish_requeue_request() local
6659 if (!rq->elv.icq || !bfqq) in bfq_finish_requeue_request()
6662 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
6665 bfqg_stats_update_completion(bfqq_group(bfqq), in bfq_finish_requeue_request()
6673 bfq_update_inject_limit(bfqd, bfqq); in bfq_finish_requeue_request()
6675 bfq_completed_request(bfqq, bfqd); in bfq_finish_requeue_request()
6677 bfqq_request_freed(bfqq); in bfq_finish_requeue_request()
6678 bfq_put_queue(bfqq); in bfq_finish_requeue_request()
6720 bfq_split_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq) in bfq_split_bfqq() argument
6722 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6724 if (bfqq_process_refs(bfqq) == 1) { in bfq_split_bfqq()
6725 bfqq->pid = current->pid; in bfq_split_bfqq()
6726 bfq_clear_bfqq_coop(bfqq); in bfq_split_bfqq()
6727 bfq_clear_bfqq_split_coop(bfqq); in bfq_split_bfqq()
6728 return bfqq; in bfq_split_bfqq()
6731 bic_set_bfqq(bic, NULL, true, bfqq->actuator_idx); in bfq_split_bfqq()
6733 bfq_put_cooperator(bfqq); in bfq_split_bfqq()
6735 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6746 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync, act_idx); in bfq_get_bfqq_handle_split() local
6749 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6750 return bfqq; in bfq_get_bfqq_handle_split()
6755 if (bfqq) in bfq_get_bfqq_handle_split()
6756 bfq_put_queue(bfqq); in bfq_get_bfqq_handle_split()
6757 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic, split); in bfq_get_bfqq_handle_split()
6759 bic_set_bfqq(bic, bfqq, is_sync, act_idx); in bfq_get_bfqq_handle_split()
6763 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6765 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6795 hlist_add_head(&bfqq->burst_list_node, in bfq_get_bfqq_handle_split()
6798 bfqq->split_time = jiffies; in bfq_get_bfqq_handle_split()
6801 return bfqq; in bfq_get_bfqq_handle_split()
6852 struct bfq_queue *bfqq; in bfq_init_rq() local
6876 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6881 if (bfq_bfqq_coop(bfqq) && bfq_bfqq_split_coop(bfqq) && in bfq_init_rq()
6883 struct bfq_queue *old_bfqq = bfqq; in bfq_init_rq()
6886 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_init_rq()
6890 bfqq = bfq_split_bfqq(bic, bfqq); in bfq_init_rq()
6893 if (!bfqq) { in bfq_init_rq()
6894 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6897 if (unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_init_rq()
6903 bfqq->waker_bfqq = old_bfqq->waker_bfqq; in bfq_init_rq()
6904 bfqq->tentative_waker_bfqq = NULL; in bfq_init_rq()
6913 if (bfqq->waker_bfqq) in bfq_init_rq()
6914 hlist_add_head(&bfqq->woken_list_node, in bfq_init_rq()
6915 &bfqq->waker_bfqq->woken_list); in bfq_init_rq()
6920 bfqq_request_allocated(bfqq); in bfq_init_rq()
6921 bfqq->ref++; in bfq_init_rq()
6923 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6924 rq, bfqq, bfqq->ref); in bfq_init_rq()
6927 rq->elv.priv[1] = bfqq; in bfq_init_rq()
6935 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6936 bfqq->bic = bic; in bfq_init_rq()
6943 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6968 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_init_rq()
6971 bfq_handle_burst(bfqd, bfqq); in bfq_init_rq()
6973 return bfqq; in bfq_init_rq()
6977 bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_idle_slice_timer_body() argument
6991 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6996 bfq_clear_bfqq_wait_request(bfqq); in bfq_idle_slice_timer_body()
6998 if (bfq_bfqq_budget_timeout(bfqq)) in bfq_idle_slice_timer_body()
7005 else if (bfqq->queued[0] == 0 && bfqq->queued[1] == 0) in bfq_idle_slice_timer_body()
7016 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
7031 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer() local
7041 if (bfqq) in bfq_idle_slice_timer()
7042 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
7050 struct bfq_queue *bfqq = *bfqq_ptr; in __bfq_put_async_bfqq() local
7052 bfq_log(bfqd, "put_async_bfqq: %p", bfqq); in __bfq_put_async_bfqq()
7053 if (bfqq) { in __bfq_put_async_bfqq()
7054 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
7056 bfq_log_bfqq(bfqd, bfqq, "put_async_bfqq: putting %p, %d", in __bfq_put_async_bfqq()
7057 bfqq, bfqq->ref); in __bfq_put_async_bfqq()
7058 bfq_put_queue(bfqq); in __bfq_put_async_bfqq()
7141 struct bfq_queue *bfqq, *n; in bfq_exit_queue() local
7147 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
7148 bfq_deactivate_bfqq(bfqd, bfqq, false, false); in bfq_exit_queue()