Lines Matching refs:bfqq

136 void bfq_mark_bfqq_##name(struct bfq_queue *bfqq)			\
138 __set_bit(BFQQF_##name, &(bfqq)->flags); \
140 void bfq_clear_bfqq_##name(struct bfq_queue *bfqq) \
142 __clear_bit(BFQQF_##name, &(bfqq)->flags); \
144 int bfq_bfqq_##name(const struct bfq_queue *bfqq) \
146 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
371 return bic->bfqq[is_sync]; in bic_to_bfqq()
374 void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync) in bic_set_bfqq() argument
376 bic->bfqq[is_sync] = bfqq; in bic_set_bfqq()
432 #define bfq_class_idle(bfqq) ((bfqq)->ioprio_class == IOPRIO_CLASS_IDLE) argument
558 struct bfq_queue *bfqq = NULL; in bfq_rq_pos_tree_lookup() local
566 bfqq = rb_entry(parent, struct bfq_queue, pos_node); in bfq_rq_pos_tree_lookup()
572 if (sector > blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
574 else if (sector < blk_rq_pos(bfqq->next_rq)) in bfq_rq_pos_tree_lookup()
579 bfqq = NULL; in bfq_rq_pos_tree_lookup()
588 bfqq ? bfqq->pid : 0); in bfq_rq_pos_tree_lookup()
590 return bfqq; in bfq_rq_pos_tree_lookup()
593 static bool bfq_too_late_for_merging(struct bfq_queue *bfqq) in bfq_too_late_for_merging() argument
595 return bfqq->service_from_backlogged > 0 && in bfq_too_late_for_merging()
596 time_is_before_jiffies(bfqq->first_IO_time + in bfq_too_late_for_merging()
609 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
614 if (bfqq->pos_root) { in bfq_pos_tree_add_move()
615 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
616 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
620 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
628 if (bfq_too_late_for_merging(bfqq)) in bfq_pos_tree_add_move()
631 if (bfq_class_idle(bfqq)) in bfq_pos_tree_add_move()
633 if (!bfqq->next_rq) in bfq_pos_tree_add_move()
636 bfqq->pos_root = &bfq_bfqq_to_bfqg(bfqq)->rq_pos_tree; in bfq_pos_tree_add_move()
637 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
638 blk_rq_pos(bfqq->next_rq), &parent, &p); in bfq_pos_tree_add_move()
640 rb_link_node(&bfqq->pos_node, parent, p); in bfq_pos_tree_add_move()
641 rb_insert_color(&bfqq->pos_node, bfqq->pos_root); in bfq_pos_tree_add_move()
643 bfqq->pos_root = NULL; in bfq_pos_tree_add_move()
680 struct bfq_queue *bfqq) in bfq_asymmetric_scenario() argument
682 bool smallest_weight = bfqq && in bfq_asymmetric_scenario()
683 bfqq->weight_counter && in bfq_asymmetric_scenario()
684 bfqq->weight_counter == in bfq_asymmetric_scenario()
724 void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_weights_tree_add() argument
727 struct bfq_entity *entity = &bfqq->entity; in bfq_weights_tree_add()
743 if (bfqq->weight_counter) in bfq_weights_tree_add()
753 bfqq->weight_counter = __counter; in bfq_weights_tree_add()
764 bfqq->weight_counter = kzalloc(sizeof(struct bfq_weight_counter), in bfq_weights_tree_add()
779 if (unlikely(!bfqq->weight_counter)) in bfq_weights_tree_add()
782 bfqq->weight_counter->weight = entity->weight; in bfq_weights_tree_add()
783 rb_link_node(&bfqq->weight_counter->weights_node, parent, new); in bfq_weights_tree_add()
784 rb_insert_color_cached(&bfqq->weight_counter->weights_node, root, in bfq_weights_tree_add()
788 bfqq->weight_counter->num_active++; in bfq_weights_tree_add()
789 bfqq->ref++; in bfq_weights_tree_add()
799 struct bfq_queue *bfqq, in __bfq_weights_tree_remove() argument
802 if (!bfqq->weight_counter) in __bfq_weights_tree_remove()
805 bfqq->weight_counter->num_active--; in __bfq_weights_tree_remove()
806 if (bfqq->weight_counter->num_active > 0) in __bfq_weights_tree_remove()
809 rb_erase_cached(&bfqq->weight_counter->weights_node, root); in __bfq_weights_tree_remove()
810 kfree(bfqq->weight_counter); in __bfq_weights_tree_remove()
813 bfqq->weight_counter = NULL; in __bfq_weights_tree_remove()
814 bfq_put_queue(bfqq); in __bfq_weights_tree_remove()
822 struct bfq_queue *bfqq) in bfq_weights_tree_remove() argument
824 struct bfq_entity *entity = bfqq->entity.parent; in bfq_weights_tree_remove()
866 __bfq_weights_tree_remove(bfqd, bfqq, in bfq_weights_tree_remove()
873 static struct request *bfq_check_fifo(struct bfq_queue *bfqq, in bfq_check_fifo() argument
878 if (bfq_bfqq_fifo_expire(bfqq)) in bfq_check_fifo()
881 bfq_mark_bfqq_fifo_expire(bfqq); in bfq_check_fifo()
883 rq = rq_entry_fifo(bfqq->fifo.next); in bfq_check_fifo()
888 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
893 struct bfq_queue *bfqq, in bfq_find_next_rq() argument
901 next = bfq_check_fifo(bfqq, last); in bfq_find_next_rq()
911 rbnext = rb_first(&bfqq->sort_list); in bfq_find_next_rq()
921 struct bfq_queue *bfqq) in bfq_serv_to_charge() argument
923 if (bfq_bfqq_sync(bfqq) || bfqq->wr_coeff > 1 || in bfq_serv_to_charge()
924 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
942 struct bfq_queue *bfqq) in bfq_updated_next_req() argument
944 struct bfq_entity *entity = &bfqq->entity; in bfq_updated_next_req()
945 struct request *next_rq = bfqq->next_rq; in bfq_updated_next_req()
951 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
959 max_t(unsigned long, bfqq->max_budget, in bfq_updated_next_req()
960 bfq_serv_to_charge(next_rq, bfqq)), in bfq_updated_next_req()
964 bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", in bfq_updated_next_req()
966 bfq_requeue_bfqq(bfqd, bfqq, false); in bfq_updated_next_req()
1004 static void switch_back_to_interactive_wr(struct bfq_queue *bfqq, in switch_back_to_interactive_wr() argument
1007 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1008 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1009 bfqq->last_wr_start_finish = bfqq->wr_start_at_switch_to_srt; in switch_back_to_interactive_wr()
1013 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1016 unsigned int old_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_resume_state()
1017 bool busy = bfq_already_existing && bfq_bfqq_busy(bfqq); in bfq_bfqq_resume_state()
1020 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1022 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_bfqq_resume_state()
1025 bfq_mark_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1027 bfq_clear_bfqq_IO_bound(bfqq); in bfq_bfqq_resume_state()
1029 bfqq->entity.new_weight = bic->saved_weight; in bfq_bfqq_resume_state()
1030 bfqq->ttime = bic->saved_ttime; in bfq_bfqq_resume_state()
1031 bfqq->wr_coeff = bic->saved_wr_coeff; in bfq_bfqq_resume_state()
1032 bfqq->wr_start_at_switch_to_srt = bic->saved_wr_start_at_switch_to_srt; in bfq_bfqq_resume_state()
1033 bfqq->last_wr_start_finish = bic->saved_last_wr_start_finish; in bfq_bfqq_resume_state()
1034 bfqq->wr_cur_max_time = bic->saved_wr_cur_max_time; in bfq_bfqq_resume_state()
1036 if (bfqq->wr_coeff > 1 && (bfq_bfqq_in_large_burst(bfqq) || in bfq_bfqq_resume_state()
1037 time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_bfqq_resume_state()
1038 bfqq->wr_cur_max_time))) { in bfq_bfqq_resume_state()
1039 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1040 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_resume_state()
1041 time_is_after_eq_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_bfqq_resume_state()
1043 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1045 bfqq->wr_coeff = 1; in bfq_bfqq_resume_state()
1046 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1052 bfqq->entity.prio_changed = 1; in bfq_bfqq_resume_state()
1057 if (old_wr_coeff == 1 && bfqq->wr_coeff > 1) in bfq_bfqq_resume_state()
1059 else if (old_wr_coeff > 1 && bfqq->wr_coeff == 1) in bfq_bfqq_resume_state()
1063 static int bfqq_process_refs(struct bfq_queue *bfqq) in bfqq_process_refs() argument
1065 return bfqq->ref - bfqq->allocated - bfqq->entity.on_st_or_in_serv - in bfqq_process_refs()
1066 (bfqq->weight_counter != NULL); in bfqq_process_refs()
1070 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1084 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1089 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1093 static void bfq_add_to_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_add_to_burst() argument
1115 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_add_to_burst()
1133 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1245 static void bfq_handle_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_handle_burst() argument
1252 if (!hlist_unhashed(&bfqq->burst_list_node) || in bfq_handle_burst()
1253 bfq_bfqq_in_large_burst(bfqq) || in bfq_handle_burst()
1254 time_is_after_eq_jiffies(bfqq->split_time + in bfq_handle_burst()
1277 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1279 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1289 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_handle_burst()
1298 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1311 static int bfq_bfqq_budget_left(struct bfq_queue *bfqq) in bfq_bfqq_budget_left() argument
1313 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_budget_left()
1448 struct bfq_queue *bfqq, in bfq_bfqq_update_budg_for_activation() argument
1451 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_update_budg_for_activation()
1460 if (bfq_bfqq_non_blocking_wait_rq(bfqq) && arrived_in_time && in bfq_bfqq_update_budg_for_activation()
1461 bfq_bfqq_budget_left(bfqq) > 0) { in bfq_bfqq_update_budg_for_activation()
1480 bfq_bfqq_budget_left(bfqq), in bfq_bfqq_update_budg_for_activation()
1481 bfqq->max_budget); in bfq_bfqq_update_budg_for_activation()
1501 entity->budget = max_t(unsigned long, bfqq->max_budget, in bfq_bfqq_update_budg_for_activation()
1502 bfq_serv_to_charge(bfqq->next_rq, bfqq)); in bfq_bfqq_update_budg_for_activation()
1503 bfq_clear_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_update_budg_for_activation()
1517 struct bfq_queue *bfqq, in bfq_update_bfqq_wr_on_rq_arrival() argument
1527 bfqq->service_from_wr = 0; in bfq_update_bfqq_wr_on_rq_arrival()
1528 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1529 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1542 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1544 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1546 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1559 bfqq->entity.budget = min_t(unsigned long, in bfq_update_bfqq_wr_on_rq_arrival()
1560 bfqq->entity.budget, in bfq_update_bfqq_wr_on_rq_arrival()
1564 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1565 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1567 bfqq->wr_coeff = 1; in bfq_update_bfqq_wr_on_rq_arrival()
1598 if (bfqq->wr_cur_max_time != in bfq_update_bfqq_wr_on_rq_arrival()
1600 bfqq->wr_start_at_switch_to_srt = in bfq_update_bfqq_wr_on_rq_arrival()
1601 bfqq->last_wr_start_finish; in bfq_update_bfqq_wr_on_rq_arrival()
1603 bfqq->wr_cur_max_time = in bfq_update_bfqq_wr_on_rq_arrival()
1605 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1608 bfqq->last_wr_start_finish = jiffies; in bfq_update_bfqq_wr_on_rq_arrival()
1614 struct bfq_queue *bfqq) in bfq_bfqq_idle_for_long_time() argument
1616 return bfqq->dispatched == 0 && in bfq_bfqq_idle_for_long_time()
1618 bfqq->budget_timeout + in bfq_bfqq_idle_for_long_time()
1627 static bool bfq_bfqq_higher_class_or_weight(struct bfq_queue *bfqq, in bfq_bfqq_higher_class_or_weight() argument
1632 if (bfqq->ioprio_class < in_serv_bfqq->ioprio_class) in bfq_bfqq_higher_class_or_weight()
1635 if (in_serv_bfqq->entity.parent == bfqq->entity.parent) { in bfq_bfqq_higher_class_or_weight()
1636 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1639 if (bfqq->entity.parent) in bfq_bfqq_higher_class_or_weight()
1640 bfqq_weight = bfqq->entity.parent->weight; in bfq_bfqq_higher_class_or_weight()
1642 bfqq_weight = bfqq->entity.weight; in bfq_bfqq_higher_class_or_weight()
1653 struct bfq_queue *bfqq, in bfq_bfqq_handle_idle_busy_switch() argument
1660 idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq), in bfq_bfqq_handle_idle_busy_switch()
1667 bfqq->ttime.last_end_request + in bfq_bfqq_handle_idle_busy_switch()
1678 in_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1680 !BFQQ_TOTALLY_SEEKY(bfqq) && in bfq_bfqq_handle_idle_busy_switch()
1682 time_is_before_jiffies(bfqq->soft_rt_next_start) && in bfq_bfqq_handle_idle_busy_switch()
1683 bfqq->dispatched == 0; in bfq_bfqq_handle_idle_busy_switch()
1686 (bfqq->wr_coeff > 1 || in bfq_bfqq_handle_idle_busy_switch()
1687 (bfq_bfqq_sync(bfqq) && in bfq_bfqq_handle_idle_busy_switch()
1688 bfqq->bic && (*interactive || soft_rt))); in bfq_bfqq_handle_idle_busy_switch()
1695 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1711 if (likely(!bfq_bfqq_just_created(bfqq)) && in bfq_bfqq_handle_idle_busy_switch()
1714 bfqq->budget_timeout + in bfq_bfqq_handle_idle_busy_switch()
1716 hlist_del_init(&bfqq->burst_list_node); in bfq_bfqq_handle_idle_busy_switch()
1717 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1720 bfq_clear_bfqq_just_created(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1723 if (!bfq_bfqq_IO_bound(bfqq)) { in bfq_bfqq_handle_idle_busy_switch()
1725 bfqq->requests_within_timer++; in bfq_bfqq_handle_idle_busy_switch()
1726 if (bfqq->requests_within_timer >= in bfq_bfqq_handle_idle_busy_switch()
1728 bfq_mark_bfqq_IO_bound(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1730 bfqq->requests_within_timer = 0; in bfq_bfqq_handle_idle_busy_switch()
1734 if (unlikely(time_is_after_jiffies(bfqq->split_time))) in bfq_bfqq_handle_idle_busy_switch()
1736 bfqq->split_time = in bfq_bfqq_handle_idle_busy_switch()
1739 if (time_is_before_jiffies(bfqq->split_time + in bfq_bfqq_handle_idle_busy_switch()
1741 bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1748 if (old_wr_coeff != bfqq->wr_coeff) in bfq_bfqq_handle_idle_busy_switch()
1749 bfqq->entity.prio_changed = 1; in bfq_bfqq_handle_idle_busy_switch()
1753 bfqq->last_idle_bklogged = jiffies; in bfq_bfqq_handle_idle_busy_switch()
1754 bfqq->service_from_backlogged = 0; in bfq_bfqq_handle_idle_busy_switch()
1755 bfq_clear_bfqq_softrt_update(bfqq); in bfq_bfqq_handle_idle_busy_switch()
1757 bfq_add_bfqq_busy(bfqd, bfqq); in bfq_bfqq_handle_idle_busy_switch()
1793 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1794 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue)) && in bfq_bfqq_handle_idle_busy_switch()
1801 struct bfq_queue *bfqq) in bfq_reset_inject_limit() argument
1804 bfqq->last_serv_time_ns = 0; in bfq_reset_inject_limit()
1858 if (bfq_bfqq_has_short_ttime(bfqq)) in bfq_reset_inject_limit()
1859 bfqq->inject_limit = 0; in bfq_reset_inject_limit()
1861 bfqq->inject_limit = 1; in bfq_reset_inject_limit()
1863 bfqq->decrease_time_jif = jiffies; in bfq_reset_inject_limit()
1868 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_add_request() local
1869 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request()
1871 unsigned int old_wr_coeff = bfqq->wr_coeff; in bfq_add_request()
1874 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
1875 bfqq->queued[rq_is_sync(rq)]++; in bfq_add_request()
1878 if (RB_EMPTY_ROOT(&bfqq->sort_list) && bfq_bfqq_sync(bfqq)) { in bfq_add_request()
1934 !bfq_bfqq_has_short_ttime(bfqq) && in bfq_add_request()
1937 if (bfqd->last_completed_rq_bfqq != bfqq && in bfq_add_request()
1939 bfqq->waker_bfqq) { in bfq_add_request()
1946 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_add_request()
1968 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_add_request()
1969 hlist_del_init(&bfqq->woken_list_node); in bfq_add_request()
1970 hlist_add_head(&bfqq->woken_list_node, in bfq_add_request()
1973 bfq_clear_bfqq_has_waker(bfqq); in bfq_add_request()
1975 bfqq->waker_bfqq && in bfq_add_request()
1976 !bfq_bfqq_has_waker(bfqq)) { in bfq_add_request()
1981 bfq_mark_bfqq_has_waker(bfqq); in bfq_add_request()
1991 if (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
1993 bfq_reset_inject_limit(bfqd, bfqq); in bfq_add_request()
2020 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2022 (bfqq->last_serv_time_ns > 0 && in bfq_add_request()
2024 time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_add_request()
2052 elv_rb_add(&bfqq->sort_list, rq); in bfq_add_request()
2057 prev = bfqq->next_rq; in bfq_add_request()
2058 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2059 bfqq->next_rq = next_rq; in bfq_add_request()
2065 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2066 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_add_request()
2068 if (!bfq_bfqq_busy(bfqq)) /* switching to busy ... */ in bfq_add_request()
2069 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2074 bfqq->last_wr_start_finish + in bfq_add_request()
2076 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2077 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2080 bfqq->entity.prio_changed = 1; in bfq_add_request()
2082 if (prev != bfqq->next_rq) in bfq_add_request()
2083 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2113 (old_wr_coeff == 1 || bfqq->wr_coeff == 1 || interactive)) in bfq_add_request()
2114 bfqq->last_wr_start_finish = jiffies; in bfq_add_request()
2121 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge() local
2124 if (bfqq) in bfq_find_rq_fmerge()
2125 return elv_rb_find(&bfqq->sort_list, bio_end_sector(bio)); in bfq_find_rq_fmerge()
2157 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_remove_request() local
2158 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request()
2161 if (bfqq->next_rq == rq) { in bfq_remove_request()
2162 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2163 bfq_updated_next_req(bfqd, bfqq); in bfq_remove_request()
2168 bfqq->queued[sync]--; in bfq_remove_request()
2170 elv_rb_del(&bfqq->sort_list, rq); in bfq_remove_request()
2176 if (RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_remove_request()
2177 bfqq->next_rq = NULL; in bfq_remove_request()
2179 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2180 bfq_del_bfqq_busy(bfqd, bfqq, false); in bfq_remove_request()
2194 bfqq->entity.budget = bfqq->entity.service = 0; in bfq_remove_request()
2200 if (bfqq->pos_root) { in bfq_remove_request()
2201 rb_erase(&bfqq->pos_node, bfqq->pos_root); in bfq_remove_request()
2202 bfqq->pos_root = NULL; in bfq_remove_request()
2207 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2211 bfqq->meta_pending--; in bfq_remove_request()
2280 struct bfq_queue *bfqq = RQ_BFQQ(req); in bfq_request_merged() local
2284 if (!bfqq) in bfq_request_merged()
2287 bfqd = bfqq->bfqd; in bfq_request_merged()
2290 elv_rb_del(&bfqq->sort_list, req); in bfq_request_merged()
2291 elv_rb_add(&bfqq->sort_list, req); in bfq_request_merged()
2294 prev = bfqq->next_rq; in bfq_request_merged()
2295 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2297 bfqq->next_rq = next_rq; in bfq_request_merged()
2303 if (prev != bfqq->next_rq) { in bfq_request_merged()
2304 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2310 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2332 struct bfq_queue *bfqq = RQ_BFQQ(rq), in bfq_requests_merged() local
2335 if (!bfqq) in bfq_requests_merged()
2347 if (bfqq == next_bfqq && in bfq_requests_merged()
2355 if (bfqq->next_rq == next) in bfq_requests_merged()
2356 bfqq->next_rq = rq; in bfq_requests_merged()
2358 bfqg_stats_update_io_merged(bfqq_group(bfqq), next->cmd_flags); in bfq_requests_merged()
2362 static void bfq_bfqq_end_wr(struct bfq_queue *bfqq) in bfq_bfqq_end_wr() argument
2364 if (bfq_bfqq_busy(bfqq)) in bfq_bfqq_end_wr()
2365 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2366 bfqq->wr_coeff = 1; in bfq_bfqq_end_wr()
2367 bfqq->wr_cur_max_time = 0; in bfq_bfqq_end_wr()
2368 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_end_wr()
2373 bfqq->entity.prio_changed = 1; in bfq_bfqq_end_wr()
2391 struct bfq_queue *bfqq; in bfq_end_wr() local
2395 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_end_wr()
2396 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2397 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2398 bfq_bfqq_end_wr(bfqq); in bfq_end_wr()
2420 struct bfq_queue *bfqq, in bfqq_find_close()
2423 struct rb_root *root = &bfq_bfqq_to_bfqg(bfqq)->rq_pos_tree; in bfqq_find_close()
2465 struct bfq_queue *bfqq; in bfq_find_close_cooperator() local
2474 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2475 if (!bfqq || bfqq == cur_bfqq) in bfq_find_close_cooperator()
2478 return bfqq; in bfq_find_close_cooperator()
2482 bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_setup_merge() argument
2498 if (__bfqq == bfqq) in bfq_setup_merge()
2503 process_refs = bfqq_process_refs(bfqq); in bfq_setup_merge()
2517 if (new_bfqq->entity.parent != bfqq->entity.parent) in bfq_setup_merge()
2520 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2543 bfqq->new_bfqq = new_bfqq; in bfq_setup_merge()
2557 static bool bfq_may_be_close_cooperator(struct bfq_queue *bfqq, in bfq_may_be_close_cooperator() argument
2563 if (bfq_class_idle(bfqq) || bfq_class_idle(new_bfqq) || in bfq_may_be_close_cooperator()
2564 (bfqq->ioprio_class != new_bfqq->ioprio_class)) in bfq_may_be_close_cooperator()
2572 if (BFQQ_SEEKY(bfqq) || BFQQ_SEEKY(new_bfqq)) in bfq_may_be_close_cooperator()
2580 if (!bfq_bfqq_sync(bfqq) || !bfq_bfqq_sync(new_bfqq)) in bfq_may_be_close_cooperator()
2607 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2613 if (bfqq->new_bfqq) in bfq_setup_cooperator()
2614 return bfqq->new_bfqq; in bfq_setup_cooperator()
2667 if (bfq_too_late_for_merging(bfqq)) in bfq_setup_cooperator()
2670 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
2679 if (in_service_bfqq && in_service_bfqq != bfqq && in bfq_setup_cooperator()
2683 bfqq->entity.parent == in_service_bfqq->entity.parent && in bfq_setup_cooperator()
2684 bfq_may_be_close_cooperator(bfqq, in_service_bfqq)) { in bfq_setup_cooperator()
2685 new_bfqq = bfq_setup_merge(bfqq, in_service_bfqq); in bfq_setup_cooperator()
2694 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
2698 bfq_may_be_close_cooperator(bfqq, new_bfqq)) in bfq_setup_cooperator()
2699 return bfq_setup_merge(bfqq, new_bfqq); in bfq_setup_cooperator()
2704 static void bfq_bfqq_save_state(struct bfq_queue *bfqq) in bfq_bfqq_save_state() argument
2706 struct bfq_io_cq *bic = bfqq->bic; in bfq_bfqq_save_state()
2716 bic->saved_weight = bfqq->entity.orig_weight; in bfq_bfqq_save_state()
2717 bic->saved_ttime = bfqq->ttime; in bfq_bfqq_save_state()
2718 bic->saved_has_short_ttime = bfq_bfqq_has_short_ttime(bfqq); in bfq_bfqq_save_state()
2719 bic->saved_IO_bound = bfq_bfqq_IO_bound(bfqq); in bfq_bfqq_save_state()
2720 bic->saved_in_large_burst = bfq_bfqq_in_large_burst(bfqq); in bfq_bfqq_save_state()
2721 bic->was_in_burst_list = !hlist_unhashed(&bfqq->burst_list_node); in bfq_bfqq_save_state()
2722 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_bfqq_save_state()
2723 !bfq_bfqq_in_large_burst(bfqq) && in bfq_bfqq_save_state()
2724 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
2734 bic->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
2736 bic->saved_wr_cur_max_time = bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
2739 bic->saved_wr_coeff = bfqq->wr_coeff; in bfq_bfqq_save_state()
2741 bfqq->wr_start_at_switch_to_srt; in bfq_bfqq_save_state()
2742 bic->saved_last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_bfqq_save_state()
2743 bic->saved_wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_bfqq_save_state()
2747 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
2760 if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_release_process_ref()
2761 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
2762 bfq_del_bfqq_busy(bfqd, bfqq, false); in bfq_release_process_ref()
2764 bfq_put_queue(bfqq); in bfq_release_process_ref()
2769 struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) in bfq_merge_bfqqs() argument
2771 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
2774 bfq_bfqq_save_state(bfqq); in bfq_merge_bfqqs()
2776 if (bfq_bfqq_IO_bound(bfqq)) in bfq_merge_bfqqs()
2778 bfq_clear_bfqq_IO_bound(bfqq); in bfq_merge_bfqqs()
2789 if (new_bfqq->wr_coeff == 1 && bfqq->wr_coeff > 1) { in bfq_merge_bfqqs()
2790 new_bfqq->wr_coeff = bfqq->wr_coeff; in bfq_merge_bfqqs()
2791 new_bfqq->wr_cur_max_time = bfqq->wr_cur_max_time; in bfq_merge_bfqqs()
2792 new_bfqq->last_wr_start_finish = bfqq->last_wr_start_finish; in bfq_merge_bfqqs()
2794 bfqq->wr_start_at_switch_to_srt; in bfq_merge_bfqqs()
2800 if (bfqq->wr_coeff > 1) { /* bfqq has given its wr to new_bfqq */ in bfq_merge_bfqqs()
2801 bfqq->wr_coeff = 1; in bfq_merge_bfqqs()
2802 bfqq->entity.prio_changed = 1; in bfq_merge_bfqqs()
2803 if (bfq_bfqq_busy(bfqq)) in bfq_merge_bfqqs()
2836 bfqq->bic = NULL; in bfq_merge_bfqqs()
2837 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
2845 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge() local
2857 if (!bfqq) in bfq_allow_bio_merge()
2864 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false); in bfq_allow_bio_merge()
2873 bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq, in bfq_allow_bio_merge()
2880 bfqq = new_bfqq; in bfq_allow_bio_merge()
2888 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
2891 return bfqq == RQ_BFQQ(rq); in bfq_allow_bio_merge()
2901 struct bfq_queue *bfqq) in bfq_set_budget_timeout() argument
2905 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
2908 timeout_coeff = bfqq->entity.weight / bfqq->entity.orig_weight; in bfq_set_budget_timeout()
2912 bfqq->budget_timeout = jiffies + in bfq_set_budget_timeout()
2917 struct bfq_queue *bfqq) in __bfq_set_in_service_queue() argument
2919 if (bfqq) { in __bfq_set_in_service_queue()
2920 bfq_clear_bfqq_fifo_expire(bfqq); in __bfq_set_in_service_queue()
2924 if (time_is_before_jiffies(bfqq->last_wr_start_finish) && in __bfq_set_in_service_queue()
2925 bfqq->wr_coeff > 1 && in __bfq_set_in_service_queue()
2926 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
2927 time_is_before_jiffies(bfqq->budget_timeout)) { in __bfq_set_in_service_queue()
2952 if (time_after(bfqq->budget_timeout, in __bfq_set_in_service_queue()
2953 bfqq->last_wr_start_finish)) in __bfq_set_in_service_queue()
2954 bfqq->last_wr_start_finish += in __bfq_set_in_service_queue()
2955 jiffies - bfqq->budget_timeout; in __bfq_set_in_service_queue()
2957 bfqq->last_wr_start_finish = jiffies; in __bfq_set_in_service_queue()
2960 bfq_set_budget_timeout(bfqd, bfqq); in __bfq_set_in_service_queue()
2961 bfq_log_bfqq(bfqd, bfqq, in __bfq_set_in_service_queue()
2963 bfqq->entity.budget); in __bfq_set_in_service_queue()
2966 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
2975 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue() local
2977 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
2978 return bfqq; in bfq_set_in_service_queue()
2983 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer() local
2986 bfq_mark_bfqq_wait_request(bfqq); in bfq_arm_slice_timer()
3004 if (BFQQ_SEEKY(bfqq) && bfqq->wr_coeff == 1 && in bfq_arm_slice_timer()
3005 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
3007 else if (bfqq->wr_coeff > 1) in bfq_arm_slice_timer()
3015 bfqg_stats_set_start_idle_time(bfqq_group(bfqq)); in bfq_arm_slice_timer()
3268 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_dispatch_remove() local
3282 bfqq->dispatched++; in bfq_dispatch_remove()
3475 struct bfq_queue *bfqq) in idling_needed_for_service_guarantees() argument
3478 if (unlikely(!bfqq_process_refs(bfqq))) in idling_needed_for_service_guarantees()
3481 return (bfqq->wr_coeff > 1 && in idling_needed_for_service_guarantees()
3485 bfqq->dispatched + 4)) || in idling_needed_for_service_guarantees()
3486 bfq_asymmetric_scenario(bfqd, bfqq); in idling_needed_for_service_guarantees()
3489 static bool __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, in __bfq_bfqq_expire() argument
3498 if (bfq_bfqq_coop(bfqq) && BFQQ_SEEKY(bfqq)) in __bfq_bfqq_expire()
3499 bfq_mark_bfqq_split_coop(bfqq); in __bfq_bfqq_expire()
3514 if (RB_EMPTY_ROOT(&bfqq->sort_list) && in __bfq_bfqq_expire()
3516 idling_needed_for_service_guarantees(bfqd, bfqq))) { in __bfq_bfqq_expire()
3517 if (bfqq->dispatched == 0) in __bfq_bfqq_expire()
3524 bfqq->budget_timeout = jiffies; in __bfq_bfqq_expire()
3526 bfq_del_bfqq_busy(bfqd, bfqq, true); in __bfq_bfqq_expire()
3528 bfq_requeue_bfqq(bfqd, bfqq, true); in __bfq_bfqq_expire()
3534 !RB_EMPTY_ROOT(&bfqq->sort_list))) in __bfq_bfqq_expire()
3535 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3558 struct bfq_queue *bfqq, in __bfq_bfqq_recalc_budget() argument
3566 if (bfqq->wr_coeff == 1) in __bfq_bfqq_recalc_budget()
3567 budget = bfqq->max_budget; in __bfq_bfqq_recalc_budget()
3576 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", in __bfq_bfqq_recalc_budget()
3577 bfqq->entity.budget, bfq_bfqq_budget_left(bfqq)); in __bfq_bfqq_recalc_budget()
3578 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last max_budg %d, min budg %d", in __bfq_bfqq_recalc_budget()
3580 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: sync %d, seeky %d", in __bfq_bfqq_recalc_budget()
3581 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
3583 if (bfq_bfqq_sync(bfqq) && bfqq->wr_coeff == 1) { in __bfq_bfqq_recalc_budget()
3614 if (bfqq->dispatched > 0) /* still outstanding reqs */ in __bfq_bfqq_recalc_budget()
3677 budget = max_t(int, bfqq->entity.service, min_budget); in __bfq_bfqq_recalc_budget()
3682 } else if (!bfq_bfqq_sync(bfqq)) { in __bfq_bfqq_recalc_budget()
3692 bfqq->max_budget = budget; in __bfq_bfqq_recalc_budget()
3696 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3708 next_rq = bfqq->next_rq; in __bfq_bfqq_recalc_budget()
3710 bfqq->entity.budget = max_t(unsigned long, bfqq->max_budget, in __bfq_bfqq_recalc_budget()
3711 bfq_serv_to_charge(next_rq, bfqq)); in __bfq_bfqq_recalc_budget()
3713 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", in __bfq_bfqq_recalc_budget()
3715 bfqq->entity.budget); in __bfq_bfqq_recalc_budget()
3749 static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_bfqq_is_slow() argument
3755 bool slow = BFQQ_SEEKY(bfqq); /* if delta too short, use seekyness */ in bfq_bfqq_is_slow()
3757 if (!bfq_bfqq_sync(bfqq)) in bfq_bfqq_is_slow()
3798 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
3801 bfq_log_bfqq(bfqd, bfqq, "bfq_bfqq_is_slow: slow %d", slow); in bfq_bfqq_is_slow()
3900 struct bfq_queue *bfqq) in bfq_bfqq_softrt_next_start() argument
3902 return max3(bfqq->soft_rt_next_start, in bfq_bfqq_softrt_next_start()
3903 bfqq->last_idle_bklogged + in bfq_bfqq_softrt_next_start()
3904 HZ * bfqq->service_from_backlogged / in bfq_bfqq_softrt_next_start()
3906 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
3936 struct bfq_queue *bfqq, in bfq_bfqq_expire() argument
3942 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_expire()
3947 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, reason, &delta); in bfq_bfqq_expire()
3964 if (bfqq->wr_coeff == 1 && in bfq_bfqq_expire()
3967 bfq_bfqq_budget_left(bfqq) >= entity->budget / 3))) in bfq_bfqq_expire()
3968 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
3972 bfq_clear_bfqq_IO_bound(bfqq); in bfq_bfqq_expire()
3974 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
3975 bfqq->last_wr_start_finish = jiffies; in bfq_bfqq_expire()
3978 RB_EMPTY_ROOT(&bfqq->sort_list)) { in bfq_bfqq_expire()
4005 if (bfqq->dispatched == 0 && in bfq_bfqq_expire()
4006 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_bfqq_expire()
4007 bfqq->soft_rt_next_start = in bfq_bfqq_expire()
4008 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
4009 else if (bfqq->dispatched > 0) { in bfq_bfqq_expire()
4014 bfq_mark_bfqq_softrt_update(bfqq); in bfq_bfqq_expire()
4018 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
4020 slow, bfqq->dispatched, bfq_bfqq_has_short_ttime(bfqq)); in bfq_bfqq_expire()
4034 __bfq_bfqq_recalc_budget(bfqd, bfqq, reason); in bfq_bfqq_expire()
4035 if (__bfq_bfqq_expire(bfqd, bfqq, reason)) in bfq_bfqq_expire()
4040 if (!bfq_bfqq_busy(bfqq) && in bfq_bfqq_expire()
4043 bfq_mark_bfqq_non_blocking_wait_rq(bfqq); in bfq_bfqq_expire()
4079 static bool bfq_bfqq_budget_timeout(struct bfq_queue *bfqq) in bfq_bfqq_budget_timeout() argument
4081 return time_is_before_eq_jiffies(bfqq->budget_timeout); in bfq_bfqq_budget_timeout()
4092 static bool bfq_may_expire_for_budg_timeout(struct bfq_queue *bfqq) in bfq_may_expire_for_budg_timeout() argument
4094 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4096 bfq_bfqq_wait_request(bfqq), in bfq_may_expire_for_budg_timeout()
4097 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3, in bfq_may_expire_for_budg_timeout()
4098 bfq_bfqq_budget_timeout(bfqq)); in bfq_may_expire_for_budg_timeout()
4100 return (!bfq_bfqq_wait_request(bfqq) || in bfq_may_expire_for_budg_timeout()
4101 bfq_bfqq_budget_left(bfqq) >= bfqq->entity.budget / 3) in bfq_may_expire_for_budg_timeout()
4103 bfq_bfqq_budget_timeout(bfqq); in bfq_may_expire_for_budg_timeout()
4107 struct bfq_queue *bfqq) in idling_boosts_thr_without_issues() argument
4115 if (unlikely(!bfqq_process_refs(bfqq))) in idling_boosts_thr_without_issues()
4118 bfqq_sequential_and_IO_bound = !BFQQ_SEEKY(bfqq) && in idling_boosts_thr_without_issues()
4119 bfq_bfqq_IO_bound(bfqq) && bfq_bfqq_has_short_ttime(bfqq); in idling_boosts_thr_without_issues()
4206 static bool bfq_better_to_idle(struct bfq_queue *bfqq) in bfq_better_to_idle() argument
4208 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle()
4212 if (unlikely(!bfqq_process_refs(bfqq))) in bfq_better_to_idle()
4226 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4227 bfq_class_idle(bfqq)) in bfq_better_to_idle()
4231 idling_boosts_thr_without_issues(bfqd, bfqq); in bfq_better_to_idle()
4234 idling_needed_for_service_guarantees(bfqd, bfqq); in bfq_better_to_idle()
4257 static bool bfq_bfqq_must_idle(struct bfq_queue *bfqq) in bfq_bfqq_must_idle() argument
4259 return RB_EMPTY_ROOT(&bfqq->sort_list) && bfq_better_to_idle(bfqq); in bfq_bfqq_must_idle()
4272 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection() local
4320 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_choose_bfqq_for_injection()
4321 if (!RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_choose_bfqq_for_injection()
4322 (in_serv_always_inject || bfqq->wr_coeff > 1) && in bfq_choose_bfqq_for_injection()
4323 bfq_serv_to_charge(bfqq->next_rq, bfqq) <= in bfq_choose_bfqq_for_injection()
4324 bfq_bfqq_budget_left(bfqq)) { in bfq_choose_bfqq_for_injection()
4343 blk_rq_sectors(bfqq->next_rq) >= in bfq_choose_bfqq_for_injection()
4351 return bfqq; in bfq_choose_bfqq_for_injection()
4364 struct bfq_queue *bfqq; in bfq_select_queue() local
4368 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4369 if (!bfqq) in bfq_select_queue()
4372 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4381 if (bfq_may_expire_for_budg_timeout(bfqq) && in bfq_select_queue()
4382 !bfq_bfqq_must_idle(bfqq)) in bfq_select_queue()
4392 next_rq = bfqq->next_rq; in bfq_select_queue()
4398 if (bfq_serv_to_charge(next_rq, bfqq) > in bfq_select_queue()
4399 bfq_bfqq_budget_left(bfqq)) { in bfq_select_queue()
4414 if (bfq_bfqq_wait_request(bfqq)) { in bfq_select_queue()
4428 bfq_clear_bfqq_wait_request(bfqq); in bfq_select_queue()
4443 if (bfq_bfqq_wait_request(bfqq) || in bfq_select_queue()
4444 (bfqq->dispatched != 0 && bfq_better_to_idle(bfqq))) { in bfq_select_queue()
4446 bfqq->bic && bfqq->bic->bfqq[0] && in bfq_select_queue()
4447 bfq_bfqq_busy(bfqq->bic->bfqq[0]) && in bfq_select_queue()
4448 bfqq->bic->bfqq[0]->next_rq ? in bfq_select_queue()
4449 bfqq->bic->bfqq[0] : NULL; in bfq_select_queue()
4524 icq_to_bic(async_bfqq->next_rq->elv.icq) == bfqq->bic && in bfq_select_queue()
4527 bfqq = bfqq->bic->bfqq[0]; in bfq_select_queue()
4528 else if (bfq_bfqq_has_waker(bfqq) && in bfq_select_queue()
4529 bfq_bfqq_busy(bfqq->waker_bfqq) && in bfq_select_queue()
4530 bfqq->waker_bfqq->next_rq && in bfq_select_queue()
4531 bfq_serv_to_charge(bfqq->waker_bfqq->next_rq, in bfq_select_queue()
4532 bfqq->waker_bfqq) <= in bfq_select_queue()
4533 bfq_bfqq_budget_left(bfqq->waker_bfqq) in bfq_select_queue()
4535 bfqq = bfqq->waker_bfqq; in bfq_select_queue()
4536 else if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_select_queue()
4537 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
4538 !bfq_bfqq_has_short_ttime(bfqq))) in bfq_select_queue()
4539 bfqq = bfq_choose_bfqq_for_injection(bfqd); in bfq_select_queue()
4541 bfqq = NULL; in bfq_select_queue()
4548 bfq_bfqq_expire(bfqd, bfqq, false, reason); in bfq_select_queue()
4550 bfqq = bfq_set_in_service_queue(bfqd); in bfq_select_queue()
4551 if (bfqq) { in bfq_select_queue()
4552 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
4556 if (bfqq) in bfq_select_queue()
4557 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
4561 return bfqq; in bfq_select_queue()
4564 static void bfq_update_wr_data(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_update_wr_data() argument
4566 struct bfq_entity *entity = &bfqq->entity; in bfq_update_wr_data()
4568 if (bfqq->wr_coeff > 1) { /* queue is being weight-raised */ in bfq_update_wr_data()
4569 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
4571 jiffies_to_msecs(jiffies - bfqq->last_wr_start_finish), in bfq_update_wr_data()
4572 jiffies_to_msecs(bfqq->wr_cur_max_time), in bfq_update_wr_data()
4573 bfqq->wr_coeff, in bfq_update_wr_data()
4574 bfqq->entity.weight, bfqq->entity.orig_weight); in bfq_update_wr_data()
4577 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
4584 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_update_wr_data()
4585 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
4586 else if (time_is_before_jiffies(bfqq->last_wr_start_finish + in bfq_update_wr_data()
4587 bfqq->wr_cur_max_time)) { in bfq_update_wr_data()
4588 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
4589 time_is_before_jiffies(bfqq->wr_start_at_switch_to_srt + in bfq_update_wr_data()
4591 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
4593 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
4594 bfqq->entity.prio_changed = 1; in bfq_update_wr_data()
4597 if (bfqq->wr_coeff > 1 && in bfq_update_wr_data()
4598 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
4599 bfqq->service_from_wr > max_service_from_wr) { in bfq_update_wr_data()
4601 bfq_bfqq_end_wr(bfqq); in bfq_update_wr_data()
4612 if ((entity->weight > entity->orig_weight) != (bfqq->wr_coeff > 1)) in bfq_update_wr_data()
4621 struct bfq_queue *bfqq) in bfq_dispatch_rq_from_bfqq() argument
4623 struct request *rq = bfqq->next_rq; in bfq_dispatch_rq_from_bfqq()
4626 service_to_charge = bfq_serv_to_charge(rq, bfqq); in bfq_dispatch_rq_from_bfqq()
4628 bfq_bfqq_served(bfqq, service_to_charge); in bfq_dispatch_rq_from_bfqq()
4630 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
4637 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
4651 bfq_update_wr_data(bfqd, bfqq); in bfq_dispatch_rq_from_bfqq()
4658 if (!(bfq_tot_busy_queues(bfqd) > 1 && bfq_class_idle(bfqq))) in bfq_dispatch_rq_from_bfqq()
4661 bfq_bfqq_expire(bfqd, bfqq, false, BFQQE_BUDGET_EXHAUSTED); in bfq_dispatch_rq_from_bfqq()
4683 struct bfq_queue *bfqq = NULL; in __bfq_dispatch_request() local
4690 bfqq = RQ_BFQQ(rq); in __bfq_dispatch_request()
4692 if (bfqq) { in __bfq_dispatch_request()
4699 bfqq->dispatched++; in __bfq_dispatch_request()
4751 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
4752 if (!bfqq) in __bfq_dispatch_request()
4755 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
4773 struct bfq_queue *bfqq = rq ? RQ_BFQQ(rq) : NULL; in bfq_update_dispatch_stats() local
4775 if (!idle_timer_disabled && !bfqq) in bfq_update_dispatch_stats()
4803 if (bfqq) { in bfq_update_dispatch_stats()
4804 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_update_dispatch_stats()
4852 void bfq_put_queue(struct bfq_queue *bfqq) in bfq_put_queue() argument
4856 struct bfq_group *bfqg = bfqq_group(bfqq); in bfq_put_queue()
4858 if (bfqq->bfqd) in bfq_put_queue()
4859 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", in bfq_put_queue()
4860 bfqq, bfqq->ref); in bfq_put_queue()
4862 bfqq->ref--; in bfq_put_queue()
4863 if (bfqq->ref) in bfq_put_queue()
4866 if (!hlist_unhashed(&bfqq->burst_list_node)) { in bfq_put_queue()
4867 hlist_del_init(&bfqq->burst_list_node); in bfq_put_queue()
4894 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
4895 bfqq->bfqd->burst_size--; in bfq_put_queue()
4914 if (!hlist_unhashed(&bfqq->woken_list_node)) in bfq_put_queue()
4915 hlist_del_init(&bfqq->woken_list_node); in bfq_put_queue()
4918 hlist_for_each_entry_safe(item, n, &bfqq->woken_list, in bfq_put_queue()
4925 if (bfqq->bfqd && bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
4926 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
4928 kmem_cache_free(bfq_pool, bfqq); in bfq_put_queue()
4932 void bfq_put_cooperator(struct bfq_queue *bfqq) in bfq_put_cooperator() argument
4941 __bfqq = bfqq->new_bfqq; in bfq_put_cooperator()
4943 if (__bfqq == bfqq) in bfq_put_cooperator()
4951 static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_exit_bfqq() argument
4953 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
4954 __bfq_bfqq_expire(bfqd, bfqq, BFQQE_BUDGET_TIMEOUT); in bfq_exit_bfqq()
4958 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
4960 bfq_put_cooperator(bfqq); in bfq_exit_bfqq()
4962 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
4967 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync); in bfq_exit_icq_bfqq() local
4970 if (bfqq) in bfq_exit_icq_bfqq()
4971 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
4973 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
4977 bfqq->bic = NULL; in bfq_exit_icq_bfqq()
4978 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
4997 bfq_set_next_ioprio_data(struct bfq_queue *bfqq, struct bfq_io_cq *bic) in bfq_set_next_ioprio_data() argument
5001 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data()
5010 bdi_dev_name(bfqq->bfqd->queue->backing_dev_info), in bfq_set_next_ioprio_data()
5017 bfqq->new_ioprio = task_nice_ioprio(tsk); in bfq_set_next_ioprio_data()
5018 bfqq->new_ioprio_class = task_nice_ioclass(tsk); in bfq_set_next_ioprio_data()
5021 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); in bfq_set_next_ioprio_data()
5022 bfqq->new_ioprio_class = IOPRIO_CLASS_RT; in bfq_set_next_ioprio_data()
5025 bfqq->new_ioprio = IOPRIO_PRIO_DATA(bic->ioprio); in bfq_set_next_ioprio_data()
5026 bfqq->new_ioprio_class = IOPRIO_CLASS_BE; in bfq_set_next_ioprio_data()
5029 bfqq->new_ioprio_class = IOPRIO_CLASS_IDLE; in bfq_set_next_ioprio_data()
5030 bfqq->new_ioprio = 7; in bfq_set_next_ioprio_data()
5034 if (bfqq->new_ioprio >= IOPRIO_BE_NR) { in bfq_set_next_ioprio_data()
5036 bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5037 bfqq->new_ioprio = IOPRIO_BE_NR - 1; in bfq_set_next_ioprio_data()
5040 bfqq->entity.new_weight = bfq_ioprio_to_weight(bfqq->new_ioprio); in bfq_set_next_ioprio_data()
5041 bfqq->entity.prio_changed = 1; in bfq_set_next_ioprio_data()
5051 struct bfq_queue *bfqq; in bfq_check_ioprio_change() local
5063 bfqq = bic_to_bfqq(bic, false); in bfq_check_ioprio_change()
5064 if (bfqq) { in bfq_check_ioprio_change()
5065 bfq_release_process_ref(bfqd, bfqq); in bfq_check_ioprio_change()
5066 bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic); in bfq_check_ioprio_change()
5067 bic_set_bfqq(bic, bfqq, false); in bfq_check_ioprio_change()
5070 bfqq = bic_to_bfqq(bic, true); in bfq_check_ioprio_change()
5071 if (bfqq) in bfq_check_ioprio_change()
5072 bfq_set_next_ioprio_data(bfqq, bic); in bfq_check_ioprio_change()
5075 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5078 RB_CLEAR_NODE(&bfqq->entity.rb_node); in bfq_init_bfqq()
5079 INIT_LIST_HEAD(&bfqq->fifo); in bfq_init_bfqq()
5080 INIT_HLIST_NODE(&bfqq->burst_list_node); in bfq_init_bfqq()
5081 INIT_HLIST_NODE(&bfqq->woken_list_node); in bfq_init_bfqq()
5082 INIT_HLIST_HEAD(&bfqq->woken_list); in bfq_init_bfqq()
5084 bfqq->ref = 0; in bfq_init_bfqq()
5085 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5088 bfq_set_next_ioprio_data(bfqq, bic); in bfq_init_bfqq()
5096 if (!bfq_class_idle(bfqq)) in bfq_init_bfqq()
5098 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_init_bfqq()
5099 bfq_mark_bfqq_sync(bfqq); in bfq_init_bfqq()
5100 bfq_mark_bfqq_just_created(bfqq); in bfq_init_bfqq()
5102 bfq_clear_bfqq_sync(bfqq); in bfq_init_bfqq()
5105 bfqq->ttime.last_end_request = ktime_get_ns() + 1; in bfq_init_bfqq()
5107 bfq_mark_bfqq_IO_bound(bfqq); in bfq_init_bfqq()
5109 bfqq->pid = pid; in bfq_init_bfqq()
5112 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5113 bfqq->budget_timeout = bfq_smallest_from_now(); in bfq_init_bfqq()
5115 bfqq->wr_coeff = 1; in bfq_init_bfqq()
5116 bfqq->last_wr_start_finish = jiffies; in bfq_init_bfqq()
5117 bfqq->wr_start_at_switch_to_srt = bfq_smallest_from_now(); in bfq_init_bfqq()
5118 bfqq->split_time = bfq_smallest_from_now(); in bfq_init_bfqq()
5129 bfqq->soft_rt_next_start = jiffies; in bfq_init_bfqq()
5132 bfqq->seek_history = 1; in bfq_init_bfqq()
5161 struct bfq_queue *bfqq; in bfq_get_queue() local
5168 bfqq = *async_bfqq; in bfq_get_queue()
5169 if (bfqq) in bfq_get_queue()
5173 bfqq = kmem_cache_alloc_node(bfq_pool, in bfq_get_queue()
5177 if (bfqq) { in bfq_get_queue()
5178 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5180 bfq_init_entity(&bfqq->entity, bfqg); in bfq_get_queue()
5181 bfq_log_bfqq(bfqd, bfqq, "allocated"); in bfq_get_queue()
5183 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5184 bfq_log_bfqq(bfqd, bfqq, "using oom bfqq"); in bfq_get_queue()
5193 bfqq->ref++; /* in bfq_get_queue()
5200 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5201 bfqq, bfqq->ref); in bfq_get_queue()
5202 *async_bfqq = bfqq; in bfq_get_queue()
5206 bfqq->ref++; /* get a process reference to this queue */ in bfq_get_queue()
5207 bfq_log_bfqq(bfqd, bfqq, "get_queue, at end: %p, %d", bfqq, bfqq->ref); in bfq_get_queue()
5208 return bfqq; in bfq_get_queue()
5212 struct bfq_queue *bfqq) in bfq_update_io_thinktime() argument
5214 struct bfq_ttime *ttime = &bfqq->ttime; in bfq_update_io_thinktime()
5215 u64 elapsed = ktime_get_ns() - bfqq->ttime.last_end_request; in bfq_update_io_thinktime()
5219 ttime->ttime_samples = (7*bfqq->ttime.ttime_samples + 256) / 8; in bfq_update_io_thinktime()
5226 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5229 bfqq->seek_history <<= 1; in bfq_update_io_seektime()
5230 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5232 if (bfqq->wr_coeff > 1 && in bfq_update_io_seektime()
5233 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5234 BFQQ_TOTALLY_SEEKY(bfqq)) in bfq_update_io_seektime()
5235 bfq_bfqq_end_wr(bfqq); in bfq_update_io_seektime()
5239 struct bfq_queue *bfqq, in bfq_update_has_short_ttime() argument
5249 if (!bfq_bfqq_sync(bfqq) || bfq_class_idle(bfqq) || in bfq_update_has_short_ttime()
5254 if (time_is_after_eq_jiffies(bfqq->split_time + in bfq_update_has_short_ttime()
5263 (bfq_sample_valid(bfqq->ttime.ttime_samples) && in bfq_update_has_short_ttime()
5264 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle)) in bfq_update_has_short_ttime()
5267 state_changed = has_short_ttime != bfq_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5270 bfq_mark_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5272 bfq_clear_bfqq_has_short_ttime(bfqq); in bfq_update_has_short_ttime()
5358 if (state_changed && bfqq->last_serv_time_ns == 0 && in bfq_update_has_short_ttime()
5359 (time_is_before_eq_jiffies(bfqq->decrease_time_jif + in bfq_update_has_short_ttime()
5362 bfq_reset_inject_limit(bfqd, bfqq); in bfq_update_has_short_ttime()
5369 static void bfq_rq_enqueued(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_rq_enqueued() argument
5373 bfqq->meta_pending++; in bfq_rq_enqueued()
5375 bfqq->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_rq_enqueued()
5377 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
5378 bool small_req = bfqq->queued[rq_is_sync(rq)] == 1 && in bfq_rq_enqueued()
5380 bool budget_timeout = bfq_bfqq_budget_timeout(bfqq); in bfq_rq_enqueued()
5398 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
5409 bfq_clear_bfqq_wait_request(bfqq); in bfq_rq_enqueued()
5420 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
5428 struct bfq_queue *bfqq = RQ_BFQQ(rq), in __bfq_insert_request() local
5429 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true); in __bfq_insert_request()
5438 bfqq->allocated--; in __bfq_insert_request()
5448 if (bic_to_bfqq(RQ_BIC(rq), 1) == bfqq) in __bfq_insert_request()
5450 bfqq, new_bfqq); in __bfq_insert_request()
5452 bfq_clear_bfqq_just_created(bfqq); in __bfq_insert_request()
5457 bfq_put_queue(bfqq); in __bfq_insert_request()
5459 bfqq = new_bfqq; in __bfq_insert_request()
5462 bfq_update_io_thinktime(bfqd, bfqq); in __bfq_insert_request()
5463 bfq_update_has_short_ttime(bfqd, bfqq, RQ_BIC(rq)); in __bfq_insert_request()
5464 bfq_update_io_seektime(bfqd, bfqq, rq); in __bfq_insert_request()
5466 waiting = bfqq && bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
5468 idle_timer_disabled = waiting && !bfq_bfqq_wait_request(bfqq); in __bfq_insert_request()
5471 list_add_tail(&rq->queuelist, &bfqq->fifo); in __bfq_insert_request()
5473 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
5480 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
5484 if (!bfqq) in bfq_update_insert_stats()
5498 bfqg_stats_update_io_add(bfqq_group(bfqq), bfqq, cmd_flags); in bfq_update_insert_stats()
5500 bfqg_stats_update_idle_time(bfqq_group(bfqq)); in bfq_update_insert_stats()
5505 struct bfq_queue *bfqq, in bfq_update_insert_stats() argument
5517 struct bfq_queue *bfqq; in bfq_insert_request() local
5526 bfqq = bfq_init_rq(rq); in bfq_insert_request()
5534 if (!bfqq || at_head || blk_rq_is_passthrough(rq)) { in bfq_insert_request()
5546 bfqq = RQ_BFQQ(rq); in bfq_insert_request()
5564 bfq_update_insert_stats(q, bfqq, idle_timer_disabled, in bfq_insert_request()
5582 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag() local
5604 if (bfqq && bfq_bfqq_has_short_ttime(bfqq) && in bfq_update_hw_tag()
5605 bfqq->dispatched + bfqq->queued[0] + bfqq->queued[1] < in bfq_update_hw_tag()
5621 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
5629 bfqq->dispatched--; in bfq_completed_request()
5631 if (!bfqq->dispatched && !bfq_bfqq_busy(bfqq)) { in bfq_completed_request()
5638 bfqq->budget_timeout = jiffies; in bfq_completed_request()
5640 bfq_weights_tree_remove(bfqd, bfqq); in bfq_completed_request()
5645 bfqq->ttime.last_end_request = now_ns; in bfq_completed_request()
5674 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
5687 if (bfq_bfqq_softrt_update(bfqq) && bfqq->dispatched == 0 && in bfq_completed_request()
5688 RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
5689 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
5690 bfqq->soft_rt_next_start = in bfq_completed_request()
5691 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_completed_request()
5697 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
5698 if (bfq_bfqq_must_idle(bfqq)) { in bfq_completed_request()
5699 if (bfqq->dispatched == 0) in bfq_completed_request()
5725 } else if (bfq_may_expire_for_budg_timeout(bfqq)) in bfq_completed_request()
5726 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5728 else if (RB_EMPTY_ROOT(&bfqq->sort_list) && in bfq_completed_request()
5729 (bfqq->dispatched == 0 || in bfq_completed_request()
5730 !bfq_better_to_idle(bfqq))) in bfq_completed_request()
5731 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5739 static void bfq_finish_requeue_request_body(struct bfq_queue *bfqq) in bfq_finish_requeue_request_body() argument
5741 bfqq->allocated--; in bfq_finish_requeue_request_body()
5743 bfq_put_queue(bfqq); in bfq_finish_requeue_request_body()
5851 struct bfq_queue *bfqq) in bfq_update_inject_limit() argument
5854 unsigned int old_limit = bfqq->inject_limit; in bfq_update_inject_limit()
5856 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
5857 u64 threshold = (bfqq->last_serv_time_ns * 3)>>1; in bfq_update_inject_limit()
5860 bfqq->inject_limit--; in bfq_update_inject_limit()
5861 bfqq->decrease_time_jif = jiffies; in bfq_update_inject_limit()
5864 bfqq->inject_limit++; in bfq_update_inject_limit()
5879 if ((bfqq->last_serv_time_ns == 0 && bfqd->rq_in_driver == 1) || in bfq_update_inject_limit()
5880 tot_time_ns < bfqq->last_serv_time_ns) { in bfq_update_inject_limit()
5881 if (bfqq->last_serv_time_ns == 0) { in bfq_update_inject_limit()
5886 bfqq->inject_limit = max_t(unsigned int, 1, old_limit); in bfq_update_inject_limit()
5888 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
5899 bfqq->last_serv_time_ns = tot_time_ns; in bfq_update_inject_limit()
5915 struct bfq_queue *bfqq = RQ_BFQQ(rq); in bfq_finish_requeue_request() local
5923 if (!rq->elv.icq || !bfqq) in bfq_finish_requeue_request()
5926 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
5929 bfqg_stats_update_completion(bfqq_group(bfqq), in bfq_finish_requeue_request()
5940 bfq_update_inject_limit(bfqd, bfqq); in bfq_finish_requeue_request()
5942 bfq_completed_request(bfqq, bfqd); in bfq_finish_requeue_request()
5943 bfq_finish_requeue_request_body(bfqq); in bfq_finish_requeue_request()
5962 bfqg_stats_update_io_remove(bfqq_group(bfqq), in bfq_finish_requeue_request()
5965 bfq_finish_requeue_request_body(bfqq); in bfq_finish_requeue_request()
5996 bfq_split_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq) in bfq_split_bfqq() argument
5998 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6000 if (bfqq_process_refs(bfqq) == 1) { in bfq_split_bfqq()
6001 bfqq->pid = current->pid; in bfq_split_bfqq()
6002 bfq_clear_bfqq_coop(bfqq); in bfq_split_bfqq()
6003 bfq_clear_bfqq_split_coop(bfqq); in bfq_split_bfqq()
6004 return bfqq; in bfq_split_bfqq()
6009 bfq_put_cooperator(bfqq); in bfq_split_bfqq()
6011 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6021 struct bfq_queue *bfqq = bic_to_bfqq(bic, is_sync); in bfq_get_bfqq_handle_split() local
6023 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6024 return bfqq; in bfq_get_bfqq_handle_split()
6029 if (bfqq) in bfq_get_bfqq_handle_split()
6030 bfq_put_queue(bfqq); in bfq_get_bfqq_handle_split()
6031 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic); in bfq_get_bfqq_handle_split()
6033 bic_set_bfqq(bic, bfqq, is_sync); in bfq_get_bfqq_handle_split()
6037 bfq_mark_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6039 bfq_clear_bfqq_in_large_burst(bfqq); in bfq_get_bfqq_handle_split()
6069 hlist_add_head(&bfqq->burst_list_node, in bfq_get_bfqq_handle_split()
6072 bfqq->split_time = jiffies; in bfq_get_bfqq_handle_split()
6075 return bfqq; in bfq_get_bfqq_handle_split()
6124 struct bfq_queue *bfqq; in bfq_init_rq() local
6147 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6152 if (bfq_bfqq_coop(bfqq) && bfq_bfqq_split_coop(bfqq)) { in bfq_init_rq()
6153 bfq_log_bfqq(bfqd, bfqq, "breaking apart bfqq"); in bfq_init_rq()
6156 if (bfq_bfqq_in_large_burst(bfqq)) in bfq_init_rq()
6159 bfqq = bfq_split_bfqq(bic, bfqq); in bfq_init_rq()
6162 if (!bfqq) in bfq_init_rq()
6163 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6171 bfqq->allocated++; in bfq_init_rq()
6172 bfqq->ref++; in bfq_init_rq()
6173 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6174 rq, bfqq, bfqq->ref); in bfq_init_rq()
6177 rq->elv.priv[1] = bfqq; in bfq_init_rq()
6185 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6186 bfqq->bic = bic; in bfq_init_rq()
6193 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6218 if (unlikely(bfq_bfqq_just_created(bfqq) && in bfq_init_rq()
6221 bfq_handle_burst(bfqd, bfqq); in bfq_init_rq()
6223 return bfqq; in bfq_init_rq()
6227 bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_idle_slice_timer_body() argument
6241 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6246 bfq_clear_bfqq_wait_request(bfqq); in bfq_idle_slice_timer_body()
6248 if (bfq_bfqq_budget_timeout(bfqq)) in bfq_idle_slice_timer_body()
6255 else if (bfqq->queued[0] == 0 && bfqq->queued[1] == 0) in bfq_idle_slice_timer_body()
6266 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
6281 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer() local
6291 if (bfqq) in bfq_idle_slice_timer()
6292 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
6300 struct bfq_queue *bfqq = *bfqq_ptr; in __bfq_put_async_bfqq() local
6302 bfq_log(bfqd, "put_async_bfqq: %p", bfqq); in __bfq_put_async_bfqq()
6303 if (bfqq) { in __bfq_put_async_bfqq()
6304 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
6306 bfq_log_bfqq(bfqd, bfqq, "put_async_bfqq: putting %p, %d", in __bfq_put_async_bfqq()
6307 bfqq, bfqq->ref); in __bfq_put_async_bfqq()
6308 bfq_put_queue(bfqq); in __bfq_put_async_bfqq()
6396 struct bfq_queue *bfqq, *n; in bfq_exit_queue() local
6401 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
6402 bfq_deactivate_bfqq(bfqd, bfqq, false, false); in bfq_exit_queue()