Lines Matching refs:bfqq

138 void bfq_mark_bfqq_##name(struct bfq_queue *bfqq)			\
140 __set_bit(BFQQF_##name, &(bfqq)->flags); \
142 void bfq_clear_bfqq_##name(struct bfq_queue *bfqq) \
144 __clear_bit(BFQQF_##name, &(bfqq)->flags); \
146 int bfq_bfqq_##name(const struct bfq_queue *bfqq) \
148 return test_bit(BFQQF_##name, &(bfqq)->flags); \
238 #define BFQQ_SEEKY(bfqq) (hweight32(bfqq->seek_history) > 19) argument
246 #define BFQQ_TOTALLY_SEEKY(bfqq) (bfqq->seek_history == -1) argument
382 return bic->bfqq[is_sync]; in bic_to_bfqq()
385 static void bfq_put_stable_ref(struct bfq_queue *bfqq);
387 void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync) in bic_set_bfqq() argument
389 struct bfq_queue *old_bfqq = bic->bfqq[is_sync]; in bic_set_bfqq()
408 bic->bfqq[is_sync] = bfqq; in bic_set_bfqq()
410 if (bfqq && bic->stable_merge_bfqq == bfqq) { in bic_set_bfqq()
473 #define bfq_class_idle(bfqq) ((bfqq)->ioprio_class == IOPRIO_CLASS_IDLE) argument
574 static bool bfqq_request_over_limit(struct bfq_queue *bfqq, int limit) in bfqq_request_over_limit() argument
576 struct bfq_data *bfqd = bfqq->bfqd; in bfqq_request_over_limit()
577 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_over_limit()
581 int class_idx = bfqq->ioprio_class - 1; in bfqq_request_over_limit()
592 depth = bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css.cgroup->level + 1; in bfqq_request_over_limit()
642 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfqq_request_over_limit()
656 static bool bfqq_request_over_limit(struct bfq_queue *bfqq, int limit) in bfqq_request_over_limit() argument
681 struct bfq_queue *bfqq = bic ? bic_to_bfqq(bic, op_is_sync(opf)) : NULL; in bfq_limit_depth() local
698 if (bfqq && bfqq_request_over_limit(bfqq, limit)) in bfq_limit_depth()
713 struct bfq_queue *bfqq = NULL; in bfq_rq_pos_tree_lookup() local
721 bfqq = rb_entry(parent, struct bfq_queue, pos_node); in bfq_rq_pos_tree_lookup()
727 if (sector > blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
729 else if (sector < blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
734 bfqq = NULL; in bfq_rq_pos_tree_lookup()
743 bfqq ? bfqq->pid : 0); in bfq_rq_pos_tree_lookup()
745 return bfqq; in bfq_rq_pos_tree_lookup()
748 static bool bfq_too_late_for_merging(struct bfq_queue *bfqq) in bfq_too_late_for_merging() argument
750 return bfqq->service_from_backlogged > 0 && in bfq_too_late_for_merging()
751 time_is_before_jiffies(bfqq->first_IO_time + in bfq_too_late_for_merging()
764 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
769 if (bfqq->pos_root) { in bfq_pos_tree_add_move()
770 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
771 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
775 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
783 if (bfq_too_late_for_merging(bfqq)) in bfq_pos_tree_add_move()
786 if (bfq_class_idle(bfqq)) in bfq_pos_tree_add_move()
788 if (!bfqq->next_rq) in bfq_pos_tree_add_move()
791 bfqq->pos_root = &bfqq_group(bfqq)->rq_pos_tree; in bfq_pos_tree_add_move()
792 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
793 blk_rq_pos(bfqq->next_rq), &parent, &p); in bfq_pos_tree_add_move()
795 rb_link_node(&bfqq->pos_node, parent, p); in bfq_pos_tree_add_move()
796 rb_insert_color(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
798 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
835 struct bfq_queue *bfqq) in bfq_asymmetric_scenario() argument
837 bool smallest_weight = bfqq && in bfq_asymmetric_scenario()
838 bfqq->weight_counter && in bfq_asymmetric_scenario()
839 bfqq->weight_counter == in bfq_asymmetric_scenario()
879 void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_weights_tree_add() argument
882 struct bfq_entity *entity = &bfqq->entity; in bfq_weights_tree_add()
898 if (bfqq->weight_counter) in bfq_weights_tree_add()
908 bfqq->weight_counter = __counter; in bfq_weights_tree_add()
919 bfqq->weight_counter = kzalloc(sizeof(struct bfq_weight_counter), in bfq_weights_tree_add()
934 if (unlikely(!bfqq->weight_counter)) in bfq_weights_tree_add()
937 bfqq->weight_counter->weight = entity->weight; in bfq_weights_tree_add()
938 rb_link_node(&bfqq->weight_counter->weights_node, parent, new); in bfq_weights_tree_add()
939 rb_insert_color_cached(&bfqq->weight_counter->weights_node, root, in bfq_weights_tree_add()
943 bfqq->weight_counter->num_active++; in bfq_weights_tree_add()
944 bfqq->ref++; in bfq_weights_tree_add()
954 struct bfq_queue *bfqq, in __bfq_weights_tree_remove() argument
957 if (!bfqq->weight_counter) in __bfq_weights_tree_remove()
960 bfqq->weight_counter->num_active--; in __bfq_weights_tree_remove()
961 if (bfqq->weight_counter->num_active > 0) in __bfq_weights_tree_remove()
964 rb_erase_cached(&bfqq->weight_counter->weights_node, root); in __bfq_weights_tree_remove()
965 kfree(bfqq->weight_counter); in __bfq_weights_tree_remove()
968 bfqq->weight_counter = NULL; in __bfq_weights_tree_remove()
969 bfq_put_queue(bfqq); in __bfq_weights_tree_remove()
977 struct bfq_queue *bfqq) in bfq_weights_tree_remove() argument
979 struct bfq_entity *entity = bfqq->entity.parent; in bfq_weights_tree_remove()
1021 __bfq_weights_tree_remove(bfqd, bfqq, in bfq_weights_tree_remove()
1028 static struct request *bfq_check_fifo(struct bfq_queue *bfqq, in bfq_check_fifo() argument
1033 if (bfq_bfqq_fifo_expire(bfqq)) in bfq_check_fifo()
1036 bfq_mark_bfqq_fifo_expire(bfqq); in bfq_check_fifo()
1038 rq = rq_entry_fifo(bfqq->fifo.next); in bfq_check_fifo()
1043 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
1048 struct bfq_queue *bfqq, in bfq_find_next_rq() argument
1056 next = bfq_check_fifo(bfqq, last); in bfq_find_next_rq()
1066 rbnext = rb_first(&bfqq->sort_list); in bfq_find_next_rq()
1076 struct bfq_queue *bfqq) in bfq_serv_to_charge() argument
1078 if (bfq_bfqq_sync(bfqq) || bfqq->wr_coeff > 1 || in bfq_serv_to_charge()
1079 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
1097 struct bfq_queue *bfqq) in bfq_updated_next_req() argument
1099 struct bfq_entity *entity = &bfqq->entity; in bfq_updated_next_req()
1100 struct request *next_rq = bfqq->next_rq; in bfq_updated_next_req()
1106 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
1114 max_t(unsigned long, bfqq->max_budget, in bfq_updated_next_req()
1115 bfq_serv_to_charge(next_rq, bfqq)), in bfq_updated_next_req()
1119 bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", in bfq_updated_next_req()
1121 bfq_requeue_bfqq(bfqd, bfqq, false); in bfq_updated_next_req()
1159 static void switch_back_to_interactive_wr(struct bfq_queue *bfqq, in switch_back_to_interactive_wr() argument
1162 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1163 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1164 bfqq->last_wr_start_finish = bfqq->wr_start_at_switch_to_srt; in switch_back_to_interactive_wr()
1168 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1172 bool busy = bfq_already_existing && bfq_bfqq_busy(bfqq); in bfq_bfqq_resume_state()
1175 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1177 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1180 bfq_mark_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1182 bfq_clear_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1184 bfqq->last_serv_time_ns = bic->saved_last_serv_time_ns; in bfq_bfqq_resume_state()
1185 bfqq->inject_limit = bic->saved_inject_limit; in bfq_bfqq_resume_state()
1186 bfqq->decrease_time_jif = bic->saved_decrease_time_jif; in bfq_bfqq_resume_state()
1188 bfqq->entity.new_weight = bic->saved_weight; in bfq_bfqq_resume_state()
1189 bfqq->ttime = bic->saved_ttime; in bfq_bfqq_resume_state()
1190 bfqq->io_start_time = bic->saved_io_start_time; in bfq_bfqq_resume_state()
1191 bfqq->tot_idle_time = bic->saved_tot_idle_time; in bfq_bfqq_resume_state()
1196 old_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_resume_state()
1197 bfqq->wr_coeff = bic->saved_wr_coeff; in bfq_bfqq_resume_state()
1199 bfqq->service_from_wr = bic->saved_service_from_wr; in bfq_bfqq_resume_state()
1200 bfqq->wr_start_at_switch_to_srt = bic->saved_wr_start_at_switch_to_srt; in bfq_bfqq_resume_state()
1201 bfqq->last_wr_start_finish = bic->saved_last_wr_start_finish; in bfq_bfqq_resume_state()
1202 bfqq->wr_cur_max_time = bic->saved_wr_cur_max_time; in bfq_bfqq_resume_state()
1204 if (bfqq->wr_coeff > 1 && (bfq_bfqq_in_large_burst(bfqq) || in bfq_bfqq_resume_state()
1205 time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_bfqq_resume_state()
1206 bfqq->wr_cur_max_time))) { in bfq_bfqq_resume_state()
1207 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1208 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_resume_state()
1209 time_is_after_eq_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_bfqq_resume_state()
1211 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1213 bfqq->wr_coeff = 1; in bfq_bfqq_resume_state()
1214 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1220 bfqq->entity.prio_changed = 1; in bfq_bfqq_resume_state()
1225 if (old_wr_coeff == 1 && bfqq->wr_coeff > 1) in bfq_bfqq_resume_state()
1227 else if (old_wr_coeff > 1 && bfqq->wr_coeff == 1) in bfq_bfqq_resume_state()
1231 static int bfqq_process_refs(struct bfq_queue *bfqq) in bfqq_process_refs() argument
1233 return bfqq->ref - bfqq->entity.allocated - in bfqq_process_refs()
1234 bfqq->entity.on_st_or_in_serv - in bfqq_process_refs()
1235 (bfqq->weight_counter != NULL) - bfqq->stable_ref; in bfqq_process_refs()
1239 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1253 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1258 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1262 static void bfq_add_to_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_add_to_burst() argument
1284 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_add_to_burst()
1302 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1414 static void bfq_handle_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_handle_burst() argument
1421 if (!hlist_unhashed(&bfqq->burst_list_node) || in bfq_handle_burst()
1422 bfq_bfqq_in_large_burst(bfqq) || in bfq_handle_burst()
1423 time_is_after_eq_jiffies(bfqq->split_time + in bfq_handle_burst()
1446 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1448 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1458 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_handle_burst()
1467 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1480 static int bfq_bfqq_budget_left(struct bfq_queue *bfqq) in bfq_bfqq_budget_left() argument
1482 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_budget_left()
1617 struct bfq_queue *bfqq, in bfq_bfqq_update_budg_for_activation() argument
1620 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_update_budg_for_activation()
1629 if (bfq_bfqq_non_blocking_wait_rq(bfqq) && arrived_in_time && in bfq_bfqq_update_budg_for_activation()
1630 bfq_bfqq_budget_left(bfqq) > 0) { in bfq_bfqq_update_budg_for_activation()
1649 bfq_bfqq_budget_left(bfqq), in bfq_bfqq_update_budg_for_activation()
1650 bfqq->max_budget); in bfq_bfqq_update_budg_for_activation()
1670 entity->budget = max_t(unsigned long, bfqq->max_budget, in bfq_bfqq_update_budg_for_activation()
1671 bfq_serv_to_charge(bfqq->next_rq, bfqq)); in bfq_bfqq_update_budg_for_activation()
1672 bfq_clear_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_update_budg_for_activation()
1686 struct bfq_queue *bfqq, in bfq_update_bfqq_wr_on_rq_arrival() argument
1696 bfqq->service_from_wr = 0; in bfq_update_bfqq_wr_on_rq_arrival()
1697 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1698 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1711 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1713 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1715 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1728 bfqq->entity.budget = min_t(unsigned long, in bfq_update_bfqq_wr_on_rq_arrival()
1729 bfqq->entity.budget, in bfq_update_bfqq_wr_on_rq_arrival()
1733 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1734 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1736 bfqq->wr_coeff = 1; in bfq_update_bfqq_wr_on_rq_arrival()
1767 if (bfqq->wr_cur_max_time != in bfq_update_bfqq_wr_on_rq_arrival()
1769 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1770 bfqq->last_wr_start_finish; in bfq_update_bfqq_wr_on_rq_arrival()
1772 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1774 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1777 bfqq->last_wr_start_finish = jiffies; in bfq_update_bfqq_wr_on_rq_arrival()
1783 struct bfq_queue *bfqq) in bfq_bfqq_idle_for_long_time() argument
1785 return bfqq->dispatched == 0 && in bfq_bfqq_idle_for_long_time()
1787 bfqq->budget_timeout + in bfq_bfqq_idle_for_long_time()
1796 static bool bfq_bfqq_higher_class_or_weight(struct bfq_queue *bfqq, in bfq_bfqq_higher_class_or_weight() argument
1801 if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class) in bfq_bfqq_higher_class_or_weight()
1804 if (in_serv_bfqq->entity.parent == bfqq->entity.parent) { in bfq_bfqq_higher_class_or_weight()
1805 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1808 if (bfqq->entity.parent) in bfq_bfqq_higher_class_or_weight()
1809 bfqq_weight = bfqq->entity.parent->weight; in bfq_bfqq_higher_class_or_weight()
1811 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1821 static bool bfq_better_to_idle(struct bfq_queue *bfqq);
1824 struct bfq_queue *bfqq, in bfq_bfqq_handle_idle_busy_switch() argument
1831 idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq), in bfq_bfqq_handle_idle_busy_switch()
1838 bfqq->ttime.last_end_request + in bfq_bfqq_handle_idle_busy_switch()
1851 in_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1853 !BFQQ_TOTALLY_SEEKY(bfqq) && in bfq_bfqq_handle_idle_busy_switch()
1855 time_is_before_jiffies(bfqq->soft_rt_next_start) && in bfq_bfqq_handle_idle_busy_switch()
1856 bfqq->dispatched == 0 && in bfq_bfqq_handle_idle_busy_switch()
1857 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1859 bfqq->entity.new_weight == 40; in bfq_bfqq_handle_idle_busy_switch()
1873 (bfqq->wr_coeff > 1 || in bfq_bfqq_handle_idle_busy_switch()
1874 (bfq_bfqq_sync(bfqq) && in bfq_bfqq_handle_idle_busy_switch()
1875 (bfqq->bic || RQ_BIC(rq)->stably_merged) && in bfq_bfqq_handle_idle_busy_switch()
1883 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1899 if (likely(!bfq_bfqq_just_created(bfqq)) && in bfq_bfqq_handle_idle_busy_switch()
1902 bfqq->budget_timeout + in bfq_bfqq_handle_idle_busy_switch()
1904 hlist_del_init(&bfqq->burst_list_node); in bfq_bfqq_handle_idle_busy_switch()
1905 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1908 bfq_clear_bfqq_just_created(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1911 if (unlikely(time_is_after_jiffies(bfqq->split_time))) in bfq_bfqq_handle_idle_busy_switch()
1913 bfqq->split_time = in bfq_bfqq_handle_idle_busy_switch()
1916 if (time_is_before_jiffies(bfqq->split_time + in bfq_bfqq_handle_idle_busy_switch()
1918 bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1925 if (old_wr_coeff != bfqq->wr_coeff) in bfq_bfqq_handle_idle_busy_switch()
1926 bfqq->entity.prio_changed = 1; in bfq_bfqq_handle_idle_busy_switch()
1930 bfqq->last_idle_bklogged = jiffies; in bfq_bfqq_handle_idle_busy_switch()
1931 bfqq->service_from_backlogged = 0; in bfq_bfqq_handle_idle_busy_switch()
1932 bfq_clear_bfqq_softrt_update(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1934 bfq_add_bfqq_busy(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1981 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1982 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) || in bfq_bfqq_handle_idle_busy_switch()
1990 struct bfq_queue *bfqq) in bfq_reset_inject_limit() argument
1993 bfqq->last_serv_time_ns = 0; in bfq_reset_inject_limit()
2047 if (bfq_bfqq_has_short_ttime(bfqq)) in bfq_reset_inject_limit()
2048 bfqq->inject_limit = 0; in bfq_reset_inject_limit()
2050 bfqq->inject_limit = 1; in bfq_reset_inject_limit()
2052 bfqq->decrease_time_jif = jiffies; in bfq_reset_inject_limit()
2055 static void bfq_update_io_intensity(struct bfq_queue *bfqq, u64 now_ns) in bfq_update_io_intensity() argument
2057 u64 tot_io_time = now_ns - bfqq->io_start_time; in bfq_update_io_intensity()
2059 if (RB_EMPTY_ROOT(&bfqq->sort_list) && bfqq->dispatched == 0) in bfq_update_io_intensity()
2060 bfqq->tot_idle_time += in bfq_update_io_intensity()
2061 now_ns - bfqq->ttime.last_end_request; in bfq_update_io_intensity()
2063 if (unlikely(bfq_bfqq_just_created(bfqq))) in bfq_update_io_intensity()
2070 if (bfqq->tot_idle_time * 5 > tot_io_time) in bfq_update_io_intensity()
2071 bfq_clear_bfqq_IO_bound(bfqq); in bfq_update_io_intensity()
2073 bfq_mark_bfqq_IO_bound(bfqq); in bfq_update_io_intensity()
2080 bfqq->io_start_time = now_ns - (tot_io_time>>1); in bfq_update_io_intensity()
2081 bfqq->tot_idle_time >>= 1; in bfq_update_io_intensity()
2136 static void bfq_check_waker(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_check_waker() argument
2142 bfqd->last_completed_rq_bfqq == bfqq || in bfq_check_waker()
2143 bfq_bfqq_has_short_ttime(bfqq) || in bfq_check_waker()
2154 bfqq->tentative_waker_bfqq || in bfq_check_waker()
2155 now_ns > bfqq->waker_detection_started + in bfq_check_waker()
2162 bfqq->tentative_waker_bfqq = in bfq_check_waker()
2164 bfqq->num_waker_detections = 1; in bfq_check_waker()
2165 bfqq->waker_detection_started = now_ns; in bfq_check_waker()
2166 bfq_bfqq_name(bfqq->tentative_waker_bfqq, waker_name, in bfq_check_waker()
2168 bfq_log_bfqq(bfqd, bfqq, "set tentative waker %s", waker_name); in bfq_check_waker()
2170 bfqq->num_waker_detections++; in bfq_check_waker()
2172 if (bfqq->num_waker_detections == 3) { in bfq_check_waker()
2173 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2174 bfqq->tentative_waker_bfqq = NULL; in bfq_check_waker()
2175 bfq_bfqq_name(bfqq->waker_bfqq, waker_name, in bfq_check_waker()
2177 bfq_log_bfqq(bfqd, bfqq, "set waker %s", waker_name); in bfq_check_waker()
2199 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_check_waker()
2200 hlist_del_init(&bfqq->woken_list_node); in bfq_check_waker()
2201 hlist_add_head(&bfqq->woken_list_node, in bfq_check_waker()
2208 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_add_request() local
2209 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request()
2211 unsigned int old_wr_coeff = bfqq->wr_coeff; in bfq_add_request()
2215 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
2216 bfqq->queued[rq_is_sync(rq)]++; in bfq_add_request()
2223 if (bfq_bfqq_sync(bfqq) && RQ_BIC(rq)->requests <= 1) { in bfq_add_request()
2224 bfq_check_waker(bfqd, bfqq, now_ns); in bfq_add_request()
2232 if (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2234 bfq_reset_inject_limit(bfqd, bfqq); in bfq_add_request()
2261 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2263 (bfqq->last_serv_time_ns > 0 && in bfq_add_request()
2265 time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2293 if (bfq_bfqq_sync(bfqq)) in bfq_add_request()
2294 bfq_update_io_intensity(bfqq, now_ns); in bfq_add_request()
2296 elv_rb_add(&bfqq->sort_list, rq); in bfq_add_request()
2301 prev = bfqq->next_rq; in bfq_add_request()
2302 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2303 bfqq->next_rq = next_rq; in bfq_add_request()
2309 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2310 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_add_request()
2312 if (!bfq_bfqq_busy(bfqq)) /* switching to busy ... */ in bfq_add_request()
2313 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2318 bfqq->last_wr_start_finish + in bfq_add_request()
2320 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2321 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2324 bfqq->entity.prio_changed = 1; in bfq_add_request()
2326 if (prev != bfqq->next_rq) in bfq_add_request()
2327 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2357 (old_wr_coeff == 1 || bfqq->wr_coeff == 1 || interactive)) in bfq_add_request()
2358 bfqq->last_wr_start_finish = jiffies; in bfq_add_request()
2365 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge() local
2368 if (bfqq) in bfq_find_rq_fmerge()
2369 return elv_rb_find(&bfqq->sort_list, bio_end_sector(bio)); in bfq_find_rq_fmerge()
2401 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_remove_request() local
2402 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request()
2405 if (bfqq->next_rq == rq) { in bfq_remove_request()
2406 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2407 bfq_updated_next_req(bfqd, bfqq); in bfq_remove_request()
2412 bfqq->queued[sync]--; in bfq_remove_request()
2418 elv_rb_del(&bfqq->sort_list, rq); in bfq_remove_request()
2424 if (RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_remove_request()
2425 bfqq->next_rq = NULL; in bfq_remove_request()
2427 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2428 bfq_del_bfqq_busy(bfqq, false); in bfq_remove_request()
2442 bfqq->entity.budget = bfqq->entity.service = 0; in bfq_remove_request()
2448 if (bfqq->pos_root) { in bfq_remove_request()
2449 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_remove_request()
2450 bfqq->pos_root = NULL; in bfq_remove_request()
2455 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2459 bfqq->meta_pending--; in bfq_remove_request()
2528 struct bfq_queue *bfqq = RQ_BFQQ(req); in bfq_request_merged() local
2532 if (!bfqq) in bfq_request_merged()
2535 bfqd = bfqq->bfqd; in bfq_request_merged()
2538 elv_rb_del(&bfqq->sort_list, req); in bfq_request_merged()
2539 elv_rb_add(&bfqq->sort_list, req); in bfq_request_merged()
2542 prev = bfqq->next_rq; in bfq_request_merged()
2543 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2545 bfqq->next_rq = next_rq; in bfq_request_merged()
2551 if (prev != bfqq->next_rq) { in bfq_request_merged()
2552 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2558 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2580 struct bfq_queue *bfqq = RQ_BFQQ(rq), in bfq_requests_merged() local
2583 if (!bfqq) in bfq_requests_merged()
2595 if (bfqq == next_bfqq && in bfq_requests_merged()
2603 if (bfqq->next_rq == next) in bfq_requests_merged()
2604 bfqq->next_rq = rq; in bfq_requests_merged()
2606 bfqg_stats_update_io_merged(bfqq_group(bfqq), next->cmd_flags); in bfq_requests_merged()
2618 static void bfq_bfqq_end_wr(struct bfq_queue *bfqq) in bfq_bfqq_end_wr() argument
2634 if (bfqq->wr_cur_max_time != in bfq_bfqq_end_wr()
2635 bfqq->bfqd->bfq_wr_rt_max_time) in bfq_bfqq_end_wr()
2636 bfqq->soft_rt_next_start = jiffies; in bfq_bfqq_end_wr()
2638 if (bfq_bfqq_busy(bfqq)) in bfq_bfqq_end_wr()
2639 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2640 bfqq->wr_coeff = 1; in bfq_bfqq_end_wr()
2641 bfqq->wr_cur_max_time = 0; in bfq_bfqq_end_wr()
2642 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_end_wr()
2647 bfqq->entity.prio_changed = 1; in bfq_bfqq_end_wr()
2665 struct bfq_queue *bfqq; in bfq_end_wr() local
2669 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_end_wr()
2670 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2671 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2672 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2694 struct bfq_queue *bfqq, in bfqq_find_close()
2697 struct rb_root *root = &bfqq_group(bfqq)->rq_pos_tree; in bfqq_find_close()
2739 struct bfq_queue *bfqq; in bfq_find_close_cooperator() local
2748 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2749 if (!bfqq || bfqq == cur_bfqq) in bfq_find_close_cooperator()
2752 return bfqq; in bfq_find_close_cooperator()
2756 bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_setup_merge() argument
2772 if (__bfqq == bfqq) in bfq_setup_merge()
2777 process_refs = bfqq_process_refs(bfqq); in bfq_setup_merge()
2791 if (new_bfqq->entity.parent != bfqq->entity.parent) in bfq_setup_merge()
2794 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2817 bfqq->new_bfqq = new_bfqq; in bfq_setup_merge()
2831 static bool bfq_may_be_close_cooperator(struct bfq_queue *bfqq, in bfq_may_be_close_cooperator() argument
2837 if (bfq_class_idle(bfqq) || bfq_class_idle(new_bfqq) || in bfq_may_be_close_cooperator()
2838 (bfqq->ioprio_class != new_bfqq->ioprio_class)) in bfq_may_be_close_cooperator()
2846 if (BFQQ_SEEKY(bfqq) || BFQQ_SEEKY(new_bfqq)) in bfq_may_be_close_cooperator()
2854 if (!bfq_bfqq_sync(bfqq) || !bfq_bfqq_sync(new_bfqq)) in bfq_may_be_close_cooperator()
2861 struct bfq_queue *bfqq);
2884 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2890 if (bfqq->new_bfqq) in bfq_setup_cooperator()
2891 return bfqq->new_bfqq; in bfq_setup_cooperator()
2909 if (bfq_bfqq_sync(bfqq) && bic->stable_merge_bfqq && in bfq_setup_cooperator()
2910 !bfq_bfqq_just_created(bfqq) && in bfq_setup_cooperator()
2911 time_is_before_jiffies(bfqq->split_time + in bfq_setup_cooperator()
2913 time_is_before_jiffies(bfqq->creation_time + in bfq_setup_cooperator()
2917 int proc_ref = min(bfqq_process_refs(bfqq), in bfq_setup_cooperator()
2925 if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_setup_cooperator()
2929 bfq_setup_merge(bfqq, stable_merge_bfqq); in bfq_setup_cooperator()
2994 if (bfq_too_late_for_merging(bfqq)) in bfq_setup_cooperator()
2997 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
3006 if (in_service_bfqq && in_service_bfqq != bfqq && in bfq_setup_cooperator()
3010 bfqq->entity.parent == in_service_bfqq->entity.parent && in bfq_setup_cooperator()
3011 bfq_may_be_close_cooperator(bfqq, in_service_bfqq)) { in bfq_setup_cooperator()
3012 new_bfqq = bfq_setup_merge(bfqq, in_service_bfqq); in bfq_setup_cooperator()
3021 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
3025 bfq_may_be_close_cooperator(bfqq, new_bfqq)) in bfq_setup_cooperator()
3026 return bfq_setup_merge(bfqq, new_bfqq); in bfq_setup_cooperator()
3031 static void bfq_bfqq_save_state(struct bfq_queue *bfqq) in bfq_bfqq_save_state() argument
3033 struct bfq_io_cq *bic = bfqq->bic; in bfq_bfqq_save_state()
3043 bic->saved_last_serv_time_ns = bfqq->last_serv_time_ns; in bfq_bfqq_save_state()
3044 bic->saved_inject_limit = bfqq->inject_limit; in bfq_bfqq_save_state()
3045 bic->saved_decrease_time_jif = bfqq->decrease_time_jif; in bfq_bfqq_save_state()
3047 bic->saved_weight = bfqq->entity.orig_weight; in bfq_bfqq_save_state()
3048 bic->saved_ttime = bfqq->ttime; in bfq_bfqq_save_state()
3049 bic->saved_has_short_ttime = bfq_bfqq_has_short_ttime(bfqq); in bfq_bfqq_save_state()
3050 bic->saved_IO_bound = bfq_bfqq_IO_bound(bfqq); in bfq_bfqq_save_state()
3051 bic->saved_io_start_time = bfqq->io_start_time; in bfq_bfqq_save_state()
3052 bic->saved_tot_idle_time = bfqq->tot_idle_time; in bfq_bfqq_save_state()
3053 bic->saved_in_large_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_save_state()
3054 bic->was_in_burst_list = !hlist_unhashed(&bfqq->burst_list_node); in bfq_bfqq_save_state()
3055 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_bfqq_save_state()
3056 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_save_state()
3057 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
3067 bic->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
3069 bic->saved_wr_cur_max_time = bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
3072 bic->saved_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_save_state()
3074 bfqq->wr_start_at_switch_to_srt; in bfq_bfqq_save_state()
3075 bic->saved_service_from_wr = bfqq->service_from_wr; in bfq_bfqq_save_state()
3076 bic->saved_last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_bfqq_save_state()
3077 bic->saved_wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_bfqq_save_state()
3092 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
3105 if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_release_process_ref()
3106 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
3107 bfq_del_bfqq_busy(bfqq, false); in bfq_release_process_ref()
3109 bfq_reassign_last_bfqq(bfqq, NULL); in bfq_release_process_ref()
3111 bfq_put_queue(bfqq); in bfq_release_process_ref()
3116 struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_merge_bfqqs() argument
3118 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
3121 bfq_bfqq_save_state(bfqq); in bfq_merge_bfqqs()
3123 if (bfq_bfqq_IO_bound(bfqq)) in bfq_merge_bfqqs()
3125 bfq_clear_bfqq_IO_bound(bfqq); in bfq_merge_bfqqs()
3134 if (bfqq->waker_bfqq && !new_bfqq->waker_bfqq && in bfq_merge_bfqqs()
3135 bfqq->waker_bfqq != new_bfqq) { in bfq_merge_bfqqs()
3136 new_bfqq->waker_bfqq = bfqq->waker_bfqq; in bfq_merge_bfqqs()
3159 if (new_bfqq->wr_coeff == 1 && bfqq->wr_coeff > 1) { in bfq_merge_bfqqs()
3160 new_bfqq->wr_coeff = bfqq->wr_coeff; in bfq_merge_bfqqs()
3161 new_bfqq->wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_merge_bfqqs()
3162 new_bfqq->last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_merge_bfqqs()
3164 bfqq->wr_start_at_switch_to_srt; in bfq_merge_bfqqs()
3170 if (bfqq->wr_coeff > 1) { /* bfqq has given its wr to new_bfqq */ in bfq_merge_bfqqs()
3171 bfqq->wr_coeff = 1; in bfq_merge_bfqqs()
3172 bfqq->entity.prio_changed = 1; in bfq_merge_bfqqs()
3173 if (bfq_bfqq_busy(bfqq)) in bfq_merge_bfqqs()
3206 bfqq->bic = NULL; in bfq_merge_bfqqs()
3208 bfq_reassign_last_bfqq(bfqq, new_bfqq); in bfq_merge_bfqqs()
3210 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
3218 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge() local
3230 if (!bfqq) in bfq_allow_bio_merge()
3237 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false, bfqd->bio_bic); in bfq_allow_bio_merge()
3246 bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq, in bfq_allow_bio_merge()
3253 bfqq = new_bfqq; in bfq_allow_bio_merge()
3261 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
3264 return bfqq == RQ_BFQQ(rq); in bfq_allow_bio_merge()
3274 struct bfq_queue *bfqq) in bfq_set_budget_timeout() argument
3278 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
3281 timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight; in bfq_set_budget_timeout()
3285 bfqq->budget_timeout = jiffies + in bfq_set_budget_timeout()
3290 struct bfq_queue *bfqq) in __bfq_set_in_service_queue() argument
3292 if (bfqq) { in __bfq_set_in_service_queue()
3293 bfq_clear_bfqq_fifo_expire(bfqq); in __bfq_set_in_service_queue()
3297 if (time_is_before_jiffies(bfqq->last_wr_start_finish) && in __bfq_set_in_service_queue()
3298 bfqq->wr_coeff > 1 && in __bfq_set_in_service_queue()
3299 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
3300 time_is_before_jiffies(bfqq->budget_timeout)) { in __bfq_set_in_service_queue()
3325 if (time_after(bfqq->budget_timeout, in __bfq_set_in_service_queue()
3326 bfqq->last_wr_start_finish)) in __bfq_set_in_service_queue()
3327 bfqq->last_wr_start_finish += in __bfq_set_in_service_queue()
3328 jiffies - bfqq->budget_timeout; in __bfq_set_in_service_queue()
3330 bfqq->last_wr_start_finish = jiffies; in __bfq_set_in_service_queue()
3333 bfq_set_budget_timeout(bfqd, bfqq); in __bfq_set_in_service_queue()
3334 bfq_log_bfqq(bfqd, bfqq, in __bfq_set_in_service_queue()
3336 bfqq->entity.budget); in __bfq_set_in_service_queue()
3339 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
3348 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue() local
3350 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
3351 return bfqq; in bfq_set_in_service_queue()
3356 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer() local
3359 bfq_mark_bfqq_wait_request(bfqq); in bfq_arm_slice_timer()
3377 if (BFQQ_SEEKY(bfqq) && bfqq->wr_coeff == 1 && in bfq_arm_slice_timer()
3378 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
3380 else if (bfqq->wr_coeff > 1) in bfq_arm_slice_timer()
3388 bfqg_stats_set_start_idle_time(bfqq_group(bfqq)); in bfq_arm_slice_timer()
3641 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_dispatch_remove() local
3655 bfqq->dispatched++; in bfq_dispatch_remove()
3863 struct bfq_queue *bfqq) in idling_needed_for_service_guarantees() argument
3868 if (unlikely(!bfqq_process_refs(bfqq))) in idling_needed_for_service_guarantees()
3871 return (bfqq->wr_coeff > 1 && in idling_needed_for_service_guarantees()
3875 bfqq->dispatched + 4)) || in idling_needed_for_service_guarantees()
3876 bfq_asymmetric_scenario(bfqd, bfqq) || in idling_needed_for_service_guarantees()
3880 static bool __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, in __bfq_bfqq_expire() argument
3889 if (bfq_bfqq_coop(bfqq) && BFQQ_SEEKY(bfqq)) in __bfq_bfqq_expire()
3890 bfq_mark_bfqq_split_coop(bfqq); in __bfq_bfqq_expire()
3905 if (RB_EMPTY_ROOT(&bfqq->sort_list) && in __bfq_bfqq_expire()
3907 idling_needed_for_service_guarantees(bfqd, bfqq))) { in __bfq_bfqq_expire()
3908 if (bfqq->dispatched == 0) in __bfq_bfqq_expire()
3915 bfqq->budget_timeout = jiffies; in __bfq_bfqq_expire()
3917 bfq_del_bfqq_busy(bfqq, true); in __bfq_bfqq_expire()
3919 bfq_requeue_bfqq(bfqd, bfqq, true); in __bfq_bfqq_expire()
3925 !RB_EMPTY_ROOT(&bfqq->sort_list))) in __bfq_bfqq_expire()
3926 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3949 struct bfq_queue *bfqq, in __bfq_bfqq_recalc_budget() argument
3957 if (bfqq->wr_coeff == 1) in __bfq_bfqq_recalc_budget()
3958 budget = bfqq->max_budget; in __bfq_bfqq_recalc_budget()
3967 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", in __bfq_bfqq_recalc_budget()
3968 bfqq->entity.budget, bfq_bfqq_budget_left(bfqq)); in __bfq_bfqq_recalc_budget()
3969 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last max_budg %d, min budg %d", in __bfq_bfqq_recalc_budget()
3971 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: sync %d, seeky %d", in __bfq_bfqq_recalc_budget()
3972 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
3974 if (bfq_bfqq_sync(bfqq) && bfqq->wr_coeff == 1) { in __bfq_bfqq_recalc_budget()
4005 if (bfqq->dispatched > 0) /* still outstanding reqs */ in __bfq_bfqq_recalc_budget()
4068 budget = max_t(int, bfqq->entity.service, min_budget); in __bfq_bfqq_recalc_budget()
4073 } else if (!bfq_bfqq_sync(bfqq)) { in __bfq_bfqq_recalc_budget()
4083 bfqq->max_budget = budget; in __bfq_bfqq_recalc_budget()
4087 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4099 next_rq = bfqq->next_rq; in __bfq_bfqq_recalc_budget()
4101 bfqq->entity.budget = max_t(unsigned long, bfqq->max_budget, in __bfq_bfqq_recalc_budget()
4102 bfq_serv_to_charge(next_rq, bfqq)); in __bfq_bfqq_recalc_budget()
4104 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", in __bfq_bfqq_recalc_budget()
4106 bfqq->entity.budget); in __bfq_bfqq_recalc_budget()
4140 static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_bfqq_is_slow() argument
4146 bool slow = BFQQ_SEEKY(bfqq); /* if delta too short, use seekyness */ in bfq_bfqq_is_slow()
4148 if (!bfq_bfqq_sync(bfqq)) in bfq_bfqq_is_slow()
4189 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
4192 bfq_log_bfqq(bfqd, bfqq, "bfq_bfqq_is_slow: slow %d", slow); in bfq_bfqq_is_slow()
4291 struct bfq_queue *bfqq) in bfq_bfqq_softrt_next_start() argument
4293 return max3(bfqq->soft_rt_next_start, in bfq_bfqq_softrt_next_start()
4294 bfqq->last_idle_bklogged + in bfq_bfqq_softrt_next_start()
4295 HZ * bfqq->service_from_backlogged / in bfq_bfqq_softrt_next_start()
4297 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
4327 struct bfq_queue *bfqq, in bfq_bfqq_expire() argument
4333 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_expire()
4338 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, reason, &delta); in bfq_bfqq_expire()
4355 if (bfqq->wr_coeff == 1 && in bfq_bfqq_expire()
4358 bfq_bfqq_budget_left(bfqq) >= entity->budget / 3))) in bfq_bfqq_expire()
4359 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
4361 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
4362 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_expire()
4365 RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_bfqq_expire()
4378 if (bfqq->dispatched == 0) in bfq_bfqq_expire()
4379 bfqq->soft_rt_next_start = in bfq_bfqq_expire()
4380 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
4381 else if (bfqq->dispatched > 0) { in bfq_bfqq_expire()
4386 bfq_mark_bfqq_softrt_update(bfqq); in bfq_bfqq_expire()
4390 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
4392 slow, bfqq->dispatched, bfq_bfqq_has_short_ttime(bfqq)); in bfq_bfqq_expire()
4406 __bfq_bfqq_recalc_budget(bfqd, bfqq, reason); in bfq_bfqq_expire()
4407 if (__bfq_bfqq_expire(bfqd, bfqq, reason)) in bfq_bfqq_expire()
4412 if (!bfq_bfqq_busy(bfqq) && in bfq_bfqq_expire()
4415 bfq_mark_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_expire()
4451 static bool bfq_bfqq_budget_timeout(struct bfq_queue *bfqq) in bfq_bfqq_budget_timeout() argument
4453 return time_is_before_eq_jiffies(bfqq->budget_timeout); in bfq_bfqq_budget_timeout()
4464 static bool bfq_may_expire_for_budg_timeout(struct bfq_queue *bfqq) in bfq_may_expire_for_budg_timeout() argument
4466 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4468 bfq_bfqq_wait_request(bfqq), in bfq_may_expire_for_budg_timeout()
4469 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3, in bfq_may_expire_for_budg_timeout()
4470 bfq_bfqq_budget_timeout(bfqq)); in bfq_may_expire_for_budg_timeout()
4472 return (!bfq_bfqq_wait_request(bfqq) || in bfq_may_expire_for_budg_timeout()
4473 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3) in bfq_may_expire_for_budg_timeout()
4475 bfq_bfqq_budget_timeout(bfqq); in bfq_may_expire_for_budg_timeout()
4479 struct bfq_queue *bfqq) in idling_boosts_thr_without_issues() argument
4487 if (unlikely(!bfqq_process_refs(bfqq))) in idling_boosts_thr_without_issues()
4490 bfqq_sequential_and_IO_bound = !BFQQ_SEEKY(bfqq) && in idling_boosts_thr_without_issues()
4491 bfq_bfqq_IO_bound(bfqq) && bfq_bfqq_has_short_ttime(bfqq); in idling_boosts_thr_without_issues()
4578 static bool bfq_better_to_idle(struct bfq_queue *bfqq) in bfq_better_to_idle() argument
4580 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle()
4584 if (unlikely(!bfqq_process_refs(bfqq))) in bfq_better_to_idle()
4598 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4599 bfq_class_idle(bfqq)) in bfq_better_to_idle()
4603 idling_boosts_thr_without_issues(bfqd, bfqq); in bfq_better_to_idle()
4606 idling_needed_for_service_guarantees(bfqd, bfqq); in bfq_better_to_idle()
4629 static bool bfq_bfqq_must_idle(struct bfq_queue *bfqq) in bfq_bfqq_must_idle() argument
4631 return RB_EMPTY_ROOT(&bfqq->sort_list) && bfq_better_to_idle(bfqq); in bfq_bfqq_must_idle()
4644 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection() local
4692 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_choose_bfqq_for_injection()
4693 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_choose_bfqq_for_injection()
4694 (in_serv_always_inject || bfqq->wr_coeff > 1) && in bfq_choose_bfqq_for_injection()
4695 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_choose_bfqq_for_injection()
4696 bfq_bfqq_budget_left(bfqq)) { in bfq_choose_bfqq_for_injection()
4715 blk_rq_sectors(bfqq->next_rq) >= in bfq_choose_bfqq_for_injection()
4723 return bfqq; in bfq_choose_bfqq_for_injection()
4736 struct bfq_queue *bfqq; in bfq_select_queue() local
4740 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4741 if (!bfqq) in bfq_select_queue()
4744 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4753 if (bfq_may_expire_for_budg_timeout(bfqq) && in bfq_select_queue()
4754 !bfq_bfqq_must_idle(bfqq)) in bfq_select_queue()
4764 next_rq = bfqq->next_rq; in bfq_select_queue()
4770 if (bfq_serv_to_charge(next_rq, bfqq) > in bfq_select_queue()
4771 bfq_bfqq_budget_left(bfqq)) { in bfq_select_queue()
4786 if (bfq_bfqq_wait_request(bfqq)) { in bfq_select_queue()
4800 bfq_clear_bfqq_wait_request(bfqq); in bfq_select_queue()
4815 if (bfq_bfqq_wait_request(bfqq) || in bfq_select_queue()
4816 (bfqq->dispatched != 0 && bfq_better_to_idle(bfqq))) { in bfq_select_queue()
4818 bfqq->bic && bfqq->bic->bfqq[0] && in bfq_select_queue()
4819 bfq_bfqq_busy(bfqq->bic->bfqq[0]) && in bfq_select_queue()
4820 bfqq->bic->bfqq[0]->next_rq ? in bfq_select_queue()
4821 bfqq->bic->bfqq[0] : NULL; in bfq_select_queue()
4823 !hlist_empty(&bfqq->woken_list) ? in bfq_select_queue()
4824 container_of(bfqq->woken_list.first, in bfq_select_queue()
4910 icq_to_bic(async_bfqq->next_rq->elv.icq) == bfqq->bic && in bfq_select_queue()
4913 bfqq = bfqq->bic->bfqq[0]; in bfq_select_queue()
4914 else if (bfqq->waker_bfqq && in bfq_select_queue()
4915 bfq_bfqq_busy(bfqq->waker_bfqq) && in bfq_select_queue()
4916 bfqq->waker_bfqq->next_rq && in bfq_select_queue()
4917 bfq_serv_to_charge(bfqq->waker_bfqq->next_rq, in bfq_select_queue()
4918 bfqq->waker_bfqq) <= in bfq_select_queue()
4919 bfq_bfqq_budget_left(bfqq->waker_bfqq) in bfq_select_queue()
4921 bfqq = bfqq->waker_bfqq; in bfq_select_queue()
4929 bfqq = blocked_bfqq; in bfq_select_queue()
4930 else if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_select_queue()
4931 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
4932 !bfq_bfqq_has_short_ttime(bfqq))) in bfq_select_queue()
4933 bfqq = bfq_choose_bfqq_for_injection(bfqd); in bfq_select_queue()
4935 bfqq = NULL; in bfq_select_queue()
4942 bfq_bfqq_expire(bfqd, bfqq, false, reason); in bfq_select_queue()
4944 bfqq = bfq_set_in_service_queue(bfqd); in bfq_select_queue()
4945 if (bfqq) { in bfq_select_queue()
4946 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
4950 if (bfqq) in bfq_select_queue()
4951 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
4955 return bfqq; in bfq_select_queue()
4958 static void bfq_update_wr_data(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_update_wr_data() argument
4960 struct bfq_entity *entity = &bfqq->entity; in bfq_update_wr_data()
4962 if (bfqq->wr_coeff > 1) { /* queue is being weight-raised */ in bfq_update_wr_data()
4963 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
4965 jiffies_to_msecs(jiffies - bfqq->last_wr_start_finish), in bfq_update_wr_data()
4966 jiffies_to_msecs(bfqq->wr_cur_max_time), in bfq_update_wr_data()
4967 bfqq->wr_coeff, in bfq_update_wr_data()
4968 bfqq->entity.weight, bfqq->entity.orig_weight); in bfq_update_wr_data()
4971 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
4978 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_update_wr_data()
4979 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
4980 else if (time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_update_wr_data()
4981 bfqq->wr_cur_max_time)) { in bfq_update_wr_data()
4982 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
4983 time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_wr_data()
4993 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
4999 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
5000 bfqq->entity.prio_changed = 1; in bfq_update_wr_data()
5003 if (bfqq->wr_coeff > 1 && in bfq_update_wr_data()
5004 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
5005 bfqq->service_from_wr > max_service_from_wr) { in bfq_update_wr_data()
5007 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
5018 if ((entity->weight > entity->orig_weight) != (bfqq->wr_coeff > 1)) in bfq_update_wr_data()
5027 struct bfq_queue *bfqq) in bfq_dispatch_rq_from_bfqq() argument
5029 struct request *rq = bfqq->next_rq; in bfq_dispatch_rq_from_bfqq()
5032 service_to_charge = bfq_serv_to_charge(rq, bfqq); in bfq_dispatch_rq_from_bfqq()
5034 bfq_bfqq_served(bfqq, service_to_charge); in bfq_dispatch_rq_from_bfqq()
5036 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
5043 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
5057 bfq_update_wr_data(bfqd, bfqq); in bfq_dispatch_rq_from_bfqq()
5064 if (!(bfq_tot_busy_queues(bfqd) > 1 && bfq_class_idle(bfqq))) in bfq_dispatch_rq_from_bfqq()
5067 bfq_bfqq_expire(bfqd, bfqq, false, BFQQE_BUDGET_EXHAUSTED); in bfq_dispatch_rq_from_bfqq()
5089 struct bfq_queue *bfqq = NULL; in __bfq_dispatch_request() local
5096 bfqq = RQ_BFQQ(rq); in __bfq_dispatch_request()
5098 if (bfqq) { in __bfq_dispatch_request()
5105 bfqq->dispatched++; in __bfq_dispatch_request()
5157 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
5158 if (!bfqq) in __bfq_dispatch_request()
5161 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
5179 struct bfq_queue *bfqq = rq ? RQ_BFQQ(rq) : NULL; in bfq_update_dispatch_stats() local
5181 if (!idle_timer_disabled && !bfqq) in bfq_update_dispatch_stats()
5209 if (bfqq) { in bfq_update_dispatch_stats()
5210 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_update_dispatch_stats()
5258 void bfq_put_queue(struct bfq_queue *bfqq) in bfq_put_queue() argument
5262 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_put_queue()
5264 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", bfqq, bfqq->ref); in bfq_put_queue()
5266 bfqq->ref--; in bfq_put_queue()
5267 if (bfqq->ref) in bfq_put_queue()
5270 if (!hlist_unhashed(&bfqq->burst_list_node)) { in bfq_put_queue()
5271 hlist_del_init(&bfqq->burst_list_node); in bfq_put_queue()
5298 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
5299 bfqq->bfqd->burst_size--; in bfq_put_queue()
5318 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_put_queue()
5319 hlist_del_init(&bfqq->woken_list_node); in bfq_put_queue()
5322 hlist_for_each_entry_safe(item, n, &bfqq->woken_list, in bfq_put_queue()
5328 if (bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
5329 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
5331 kmem_cache_free(bfq_pool, bfqq); in bfq_put_queue()
5335 static void bfq_put_stable_ref(struct bfq_queue *bfqq) in bfq_put_stable_ref() argument
5337 bfqq->stable_ref--; in bfq_put_stable_ref()
5338 bfq_put_queue(bfqq); in bfq_put_stable_ref()
5341 void bfq_put_cooperator(struct bfq_queue *bfqq) in bfq_put_cooperator() argument
5350 __bfqq = bfqq->new_bfqq; in bfq_put_cooperator()
5352 if (__bfqq == bfqq) in bfq_put_cooperator()
5360 static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_exit_bfqq() argument
5362 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
5363 __bfq_bfqq_expire(bfqd, bfqq, BFQQE_BUDGET_TIMEOUT); in bfq_exit_bfqq()
5367 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
5369 bfq_put_cooperator(bfqq); in bfq_exit_bfqq()
5371 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
5376 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync); in bfq_exit_icq_bfqq() local
5379 if (bfqq) in bfq_exit_icq_bfqq()
5380 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
5382 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
5387 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
5423 bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) in bfq_set_next_ioprio_data() argument
5427 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data()
5436 bdi_dev_name(bfqq->bfqd->queue->disk->bdi), in bfq_set_next_ioprio_data()
5443 bfqq->new_ioprio = task_nice_ioprio(tsk); in bfq_set_next_ioprio_data()
5444 bfqq->new_ioprio_class = task_nice_ioclass(tsk); in bfq_set_next_ioprio_data()
5447 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); in bfq_set_next_ioprio_data()
5448 bfqq->new_ioprio_class = IOPRIO_CLASS_RT; in bfq_set_next_ioprio_data()
5451 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); in bfq_set_next_ioprio_data()
5452 bfqq->new_ioprio_class = IOPRIO_CLASS_BE; in bfq_set_next_ioprio_data()
5455 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; in bfq_set_next_ioprio_data()
5456 bfqq->new_ioprio = 7; in bfq_set_next_ioprio_data()
5460 if (bfqq->new_ioprio >= IOPRIO_NR_LEVELS) { in bfq_set_next_ioprio_data()
5462 bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5463 bfqq->new_ioprio = IOPRIO_NR_LEVELS - 1; in bfq_set_next_ioprio_data()
5466 bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5467 bfq_log_bfqq(bfqd, bfqq, "new_ioprio %d new_weight %d", in bfq_set_next_ioprio_data()
5468 bfqq->new_ioprio, bfqq->entity.new_weight); in bfq_set_next_ioprio_data()
5469 bfqq->entity.prio_changed = 1; in bfq_set_next_ioprio_data()
5480 struct bfq_queue *bfqq; in bfq_check_ioprio_change() local
5492 bfqq = bic_to_bfqq(bic, false); in bfq_check_ioprio_change()
5493 if (bfqq) { in bfq_check_ioprio_change()
5494 bfq_release_process_ref(bfqd, bfqq); in bfq_check_ioprio_change()
5495 bfqq = bfq_get_queue(bfqd, bio, false, bic, true); in bfq_check_ioprio_change()
5496 bic_set_bfqq(bic, bfqq, false); in bfq_check_ioprio_change()
5499 bfqq = bic_to_bfqq(bic, true); in bfq_check_ioprio_change()
5500 if (bfqq) in bfq_check_ioprio_change()
5501 bfq_set_next_ioprio_data(bfqq, bic); in bfq_check_ioprio_change()
5504 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5509 RB_CLEAR_NODE(&bfqq->entity.rb_node); in bfq_init_bfqq()
5510 INIT_LIST_HEAD(&bfqq->fifo); in bfq_init_bfqq()
5511 INIT_HLIST_NODE(&bfqq->burst_list_node); in bfq_init_bfqq()
5512 INIT_HLIST_NODE(&bfqq->woken_list_node); in bfq_init_bfqq()
5513 INIT_HLIST_HEAD(&bfqq->woken_list); in bfq_init_bfqq()
5515 bfqq->ref = 0; in bfq_init_bfqq()
5516 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5519 bfq_set_next_ioprio_data(bfqq, bic); in bfq_init_bfqq()
5527 if (!bfq_class_idle(bfqq)) in bfq_init_bfqq()
5529 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_init_bfqq()
5530 bfq_mark_bfqq_sync(bfqq); in bfq_init_bfqq()
5531 bfq_mark_bfqq_just_created(bfqq); in bfq_init_bfqq()
5533 bfq_clear_bfqq_sync(bfqq); in bfq_init_bfqq()
5536 bfqq->ttime.last_end_request = now_ns + 1; in bfq_init_bfqq()
5538 bfqq->creation_time = jiffies; in bfq_init_bfqq()
5540 bfqq->io_start_time = now_ns; in bfq_init_bfqq()
5542 bfq_mark_bfqq_IO_bound(bfqq); in bfq_init_bfqq()
5544 bfqq->pid = pid; in bfq_init_bfqq()
5547 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5548 bfqq->budget_timeout = bfq_smallest_from_now(); in bfq_init_bfqq()
5550 bfqq->wr_coeff = 1; in bfq_init_bfqq()
5551 bfqq->last_wr_start_finish = jiffies; in bfq_init_bfqq()
5552 bfqq->wr_start_at_switch_to_srt = bfq_smallest_from_now(); in bfq_init_bfqq()
5553 bfqq->split_time = bfq_smallest_from_now(); in bfq_init_bfqq()
5564 bfqq->soft_rt_next_start = jiffies; in bfq_init_bfqq()
5567 bfqq->seek_history = 1; in bfq_init_bfqq()
5590 bfq_do_early_stable_merge(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_do_early_stable_merge() argument
5595 bfq_setup_merge(bfqq, last_bfqq_created); in bfq_do_early_stable_merge()
5598 return bfqq; in bfq_do_early_stable_merge()
5610 bfqq->bic = bic; in bfq_do_early_stable_merge()
5611 bfq_merge_bfqqs(bfqd, bic, bfqq, new_bfqq); in bfq_do_early_stable_merge()
5663 struct bfq_queue *bfqq, in bfq_do_or_sched_stable_merge() argument
5666 struct bfq_queue **source_bfqq = bfqq->entity.parent ? in bfq_do_or_sched_stable_merge()
5667 &bfqq->entity.parent->last_bfqq_created : in bfq_do_or_sched_stable_merge()
5694 bfqq->creation_time) || in bfq_do_or_sched_stable_merge()
5695 bfqq->entity.parent != last_bfqq_created->entity.parent || in bfq_do_or_sched_stable_merge()
5696 bfqq->ioprio != last_bfqq_created->ioprio || in bfq_do_or_sched_stable_merge()
5697 bfqq->ioprio_class != last_bfqq_created->ioprio_class) in bfq_do_or_sched_stable_merge()
5698 *source_bfqq = bfqq; in bfq_do_or_sched_stable_merge()
5701 bfqq->creation_time)) { in bfq_do_or_sched_stable_merge()
5709 bfqq = bfq_do_early_stable_merge(bfqd, bfqq, in bfq_do_or_sched_stable_merge()
5731 return bfqq; in bfq_do_or_sched_stable_merge()
5743 struct bfq_queue *bfqq; in bfq_get_queue() local
5750 bfqq = *async_bfqq; in bfq_get_queue()
5751 if (bfqq) in bfq_get_queue()
5755 bfqq = kmem_cache_alloc_node(bfq_pool, in bfq_get_queue()
5759 if (bfqq) { in bfq_get_queue()
5760 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5762 bfq_init_entity(&bfqq->entity, bfqg); in bfq_get_queue()
5763 bfq_log_bfqq(bfqd, bfqq, "allocated"); in bfq_get_queue()
5765 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5766 bfq_log_bfqq(bfqd, bfqq, "using oom bfqq"); in bfq_get_queue()
5775 bfqq->ref++; /* in bfq_get_queue()
5782 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5783 bfqq, bfqq->ref); in bfq_get_queue()
5784 *async_bfqq = bfqq; in bfq_get_queue()
5788 bfqq->ref++; /* get a process reference to this queue */ in bfq_get_queue()
5790 if (bfqq != &bfqd->oom_bfqq && is_sync && !respawn) in bfq_get_queue()
5791 bfqq = bfq_do_or_sched_stable_merge(bfqd, bfqq, bic); in bfq_get_queue()
5792 return bfqq; in bfq_get_queue()
5796 struct bfq_queue *bfqq) in bfq_update_io_thinktime() argument
5798 struct bfq_ttime *ttime = &bfqq->ttime; in bfq_update_io_thinktime()
5806 if (bfqq->dispatched || bfq_bfqq_busy(bfqq)) in bfq_update_io_thinktime()
5808 elapsed = ktime_get_ns() - bfqq->ttime.last_end_request; in bfq_update_io_thinktime()
5818 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5821 bfqq->seek_history <<= 1; in bfq_update_io_seektime()
5822 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5824 if (bfqq->wr_coeff > 1 && in bfq_update_io_seektime()
5825 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5826 BFQQ_TOTALLY_SEEKY(bfqq)) { in bfq_update_io_seektime()
5827 if (time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_io_seektime()
5835 bfq_bfqq_end_wr(bfqq); in bfq_update_io_seektime()
5842 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_io_seektime()
5843 bfqq->entity.prio_changed = 1; in bfq_update_io_seektime()
5849 struct bfq_queue *bfqq, in bfq_update_has_short_ttime() argument
5859 if (!bfq_bfqq_sync(bfqq) || bfq_class_idle(bfqq) || in bfq_update_has_short_ttime()
5864 if (time_is_after_eq_jiffies(bfqq->split_time + in bfq_update_has_short_ttime()
5874 (bfq_sample_valid(bfqq->ttime.ttime_samples) && in bfq_update_has_short_ttime()
5875 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle>>1)) in bfq_update_has_short_ttime()
5878 state_changed = has_short_ttime != bfq_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5881 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5883 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5969 if (state_changed && bfqq->last_serv_time_ns == 0 && in bfq_update_has_short_ttime()
5970 (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_update_has_short_ttime()
5973 bfq_reset_inject_limit(bfqd, bfqq); in bfq_update_has_short_ttime()
5980 static void bfq_rq_enqueued(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_rq_enqueued() argument
5984 bfqq->meta_pending++; in bfq_rq_enqueued()
5986 bfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_rq_enqueued()
5988 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
5989 bool small_req = bfqq->queued[rq_is_sync(rq)] == 1 && in bfq_rq_enqueued()
5991 bool budget_timeout = bfq_bfqq_budget_timeout(bfqq); in bfq_rq_enqueued()
6009 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
6020 bfq_clear_bfqq_wait_request(bfqq); in bfq_rq_enqueued()
6031 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
6036 static void bfqq_request_allocated(struct bfq_queue *bfqq) in bfqq_request_allocated() argument
6038 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_allocated()
6044 static void bfqq_request_freed(struct bfq_queue *bfqq) in bfqq_request_freed() argument
6046 struct bfq_entity *entity = &bfqq->entity; in bfqq_request_freed()
6055 struct bfq_queue *bfqq = RQ_BFQQ(rq), in __bfq_insert_request() local
6056 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true, in __bfq_insert_request()
6066 bfqq_request_freed(bfqq); in __bfq_insert_request()
6076 if (bic_to_bfqq(RQ_BIC(rq), 1) == bfqq) in __bfq_insert_request()
6078 bfqq, new_bfqq); in __bfq_insert_request()
6080 bfq_clear_bfqq_just_created(bfqq); in __bfq_insert_request()
6085 bfq_put_queue(bfqq); in __bfq_insert_request()
6087 bfqq = new_bfqq; in __bfq_insert_request()
6090 bfq_update_io_thinktime(bfqd, bfqq); in __bfq_insert_request()
6091 bfq_update_has_short_ttime(bfqd, bfqq, RQ_BIC(rq)); in __bfq_insert_request()
6092 bfq_update_io_seektime(bfqd, bfqq, rq); in __bfq_insert_request()
6094 waiting = bfqq && bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
6096 idle_timer_disabled = waiting && !bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
6099 list_add_tail(&rq->queuelist, &bfqq->fifo); in __bfq_insert_request()
6101 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
6108 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
6112 if (!bfqq) in bfq_update_insert_stats()
6126 bfqg_stats_update_io_add(bfqq_group(bfqq), bfqq, cmd_flags); in bfq_update_insert_stats()
6128 bfqg_stats_update_idle_time(bfqq_group(bfqq)); in bfq_update_insert_stats()
6133 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
6145 struct bfq_queue *bfqq; in bfq_insert_request() local
6155 bfqq = bfq_init_rq(rq); in bfq_insert_request()
6164 if (!bfqq || at_head) { in bfq_insert_request()
6176 bfqq = RQ_BFQQ(rq); in bfq_insert_request()
6193 bfq_update_insert_stats(q, bfqq, idle_timer_disabled, in bfq_insert_request()
6211 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag() local
6233 if (bfqq && bfq_bfqq_has_short_ttime(bfqq) && in bfq_update_hw_tag()
6234 bfqq->dispatched + bfqq->queued[0] + bfqq->queued[1] < in bfq_update_hw_tag()
6250 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
6258 bfqq->dispatched--; in bfq_completed_request()
6260 if (!bfqq->dispatched && !bfq_bfqq_busy(bfqq)) { in bfq_completed_request()
6267 bfqq->budget_timeout = jiffies; in bfq_completed_request()
6269 bfq_weights_tree_remove(bfqd, bfqq); in bfq_completed_request()
6274 bfqq->ttime.last_end_request = now_ns; in bfq_completed_request()
6312 if (!bfq_bfqq_coop(bfqq)) in bfq_completed_request()
6313 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
6328 if (bfq_bfqq_softrt_update(bfqq) && bfqq->dispatched == 0 && in bfq_completed_request()
6329 RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6330 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
6331 bfqq->soft_rt_next_start = in bfq_completed_request()
6332 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_completed_request()
6338 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
6339 if (bfq_bfqq_must_idle(bfqq)) { in bfq_completed_request()
6340 if (bfqq->dispatched == 0) in bfq_completed_request()
6366 } else if (bfq_may_expire_for_budg_timeout(bfqq)) in bfq_completed_request()
6367 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6369 else if (RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
6370 (bfqq->dispatched == 0 || in bfq_completed_request()
6371 !bfq_better_to_idle(bfqq))) in bfq_completed_request()
6372 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6485 struct bfq_queue *bfqq) in bfq_update_inject_limit() argument
6488 unsigned int old_limit = bfqq->inject_limit; in bfq_update_inject_limit()
6490 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
6491 u64 threshold = (bfqq->last_serv_time_ns * 3)>>1; in bfq_update_inject_limit()
6494 bfqq->inject_limit--; in bfq_update_inject_limit()
6495 bfqq->decrease_time_jif = jiffies; in bfq_update_inject_limit()
6498 bfqq->inject_limit++; in bfq_update_inject_limit()
6513 if ((bfqq->last_serv_time_ns == 0 && bfqd->rq_in_driver == 1) || in bfq_update_inject_limit()
6514 tot_time_ns < bfqq->last_serv_time_ns) { in bfq_update_inject_limit()
6515 if (bfqq->last_serv_time_ns == 0) { in bfq_update_inject_limit()
6520 bfqq->inject_limit = max_t(unsigned int, 1, old_limit); in bfq_update_inject_limit()
6522 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6533 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
6549 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_finish_requeue_request() local
6558 if (!rq->elv.icq || !bfqq) in bfq_finish_requeue_request()
6561 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
6564 bfqg_stats_update_completion(bfqq_group(bfqq), in bfq_finish_requeue_request()
6572 bfq_update_inject_limit(bfqd, bfqq); in bfq_finish_requeue_request()
6574 bfq_completed_request(bfqq, bfqd); in bfq_finish_requeue_request()
6576 bfqq_request_freed(bfqq); in bfq_finish_requeue_request()
6577 bfq_put_queue(bfqq); in bfq_finish_requeue_request()
6619 bfq_split_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq) in bfq_split_bfqq() argument
6621 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6623 if (bfqq_process_refs(bfqq) == 1) { in bfq_split_bfqq()
6624 bfqq->pid = current->pid; in bfq_split_bfqq()
6625 bfq_clear_bfqq_coop(bfqq); in bfq_split_bfqq()
6626 bfq_clear_bfqq_split_coop(bfqq); in bfq_split_bfqq()
6627 return bfqq; in bfq_split_bfqq()
6632 bfq_put_cooperator(bfqq); in bfq_split_bfqq()
6634 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6644 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync); in bfq_get_bfqq_handle_split() local
6646 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6647 return bfqq; in bfq_get_bfqq_handle_split()
6652 if (bfqq) in bfq_get_bfqq_handle_split()
6653 bfq_put_queue(bfqq); in bfq_get_bfqq_handle_split()
6654 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic, split); in bfq_get_bfqq_handle_split()
6656 bic_set_bfqq(bic, bfqq, is_sync); in bfq_get_bfqq_handle_split()
6660 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6662 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6692 hlist_add_head(&bfqq->burst_list_node, in bfq_get_bfqq_handle_split()
6695 bfqq->split_time = jiffies; in bfq_get_bfqq_handle_split()
6698 return bfqq; in bfq_get_bfqq_handle_split()
6749 struct bfq_queue *bfqq; in bfq_init_rq() local
6772 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6777 if (bfq_bfqq_coop(bfqq) && bfq_bfqq_split_coop(bfqq) && in bfq_init_rq()
6779 struct bfq_queue *old_bfqq = bfqq; in bfq_init_rq()
6782 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_init_rq()
6785 bfqq = bfq_split_bfqq(bic, bfqq); in bfq_init_rq()
6788 if (!bfqq) { in bfq_init_rq()
6789 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6792 if (unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_init_rq()
6798 bfqq->waker_bfqq = old_bfqq->waker_bfqq; in bfq_init_rq()
6799 bfqq->tentative_waker_bfqq = NULL; in bfq_init_rq()
6808 if (bfqq->waker_bfqq) in bfq_init_rq()
6809 hlist_add_head(&bfqq->woken_list_node, in bfq_init_rq()
6810 &bfqq->waker_bfqq->woken_list); in bfq_init_rq()
6815 bfqq_request_allocated(bfqq); in bfq_init_rq()
6816 bfqq->ref++; in bfq_init_rq()
6818 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6819 rq, bfqq, bfqq->ref); in bfq_init_rq()
6822 rq->elv.priv[1] = bfqq; in bfq_init_rq()
6830 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6831 bfqq->bic = bic; in bfq_init_rq()
6838 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6863 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_init_rq()
6866 bfq_handle_burst(bfqd, bfqq); in bfq_init_rq()
6868 return bfqq; in bfq_init_rq()
6872 bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_idle_slice_timer_body() argument
6886 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6891 bfq_clear_bfqq_wait_request(bfqq); in bfq_idle_slice_timer_body()
6893 if (bfq_bfqq_budget_timeout(bfqq)) in bfq_idle_slice_timer_body()
6900 else if (bfqq->queued[0] == 0 && bfqq->queued[1] == 0) in bfq_idle_slice_timer_body()
6911 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
6926 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer() local
6936 if (bfqq) in bfq_idle_slice_timer()
6937 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
6945 struct bfq_queue *bfqq = *bfqq_ptr; in __bfq_put_async_bfqq() local
6947 bfq_log(bfqd, "put_async_bfqq: %p", bfqq); in __bfq_put_async_bfqq()
6948 if (bfqq) { in __bfq_put_async_bfqq()
6949 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
6951 bfq_log_bfqq(bfqd, bfqq, "put_async_bfqq: putting %p, %d", in __bfq_put_async_bfqq()
6952 bfqq, bfqq->ref); in __bfq_put_async_bfqq()
6953 bfq_put_queue(bfqq); in __bfq_put_async_bfqq()
7034 struct bfq_queue *bfqq, *n; in bfq_exit_queue() local
7039 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
7040 bfq_deactivate_bfqq(bfqd, bfqq, false, false); in bfq_exit_queue()