Lines Matching refs:bfqd
231 #define BFQ_RQ_SEEKY(bfqd, last_pos, rq) \ argument
234 (!blk_queue_nonrot(bfqd->queue) || \
400 static struct bfq_io_cq *bfq_bic_lookup(struct bfq_data *bfqd, in bfq_bic_lookup() argument
422 void bfq_schedule_dispatch(struct bfq_data *bfqd) in bfq_schedule_dispatch() argument
424 lockdep_assert_held(&bfqd->lock); in bfq_schedule_dispatch()
426 if (bfqd->queued != 0) { in bfq_schedule_dispatch()
427 bfq_log(bfqd, "schedule dispatch"); in bfq_schedule_dispatch()
428 blk_mq_run_hw_queues(bfqd->queue, true); in bfq_schedule_dispatch()
441 static struct request *bfq_choose_req(struct bfq_data *bfqd, in bfq_choose_req() argument
472 back_max = bfqd->bfq_back_max * 2; in bfq_choose_req()
482 d1 = (last - s1) * bfqd->bfq_back_penalty; in bfq_choose_req()
489 d2 = (last - s2) * bfqd->bfq_back_penalty; in bfq_choose_req()
539 struct bfq_data *bfqd = data->q->elevator->elevator_data; in bfq_limit_depth() local
545 bfqd->word_depths[!!bfqd->wr_busy_queues][op_is_sync(op)]; in bfq_limit_depth()
547 bfq_log(bfqd, "[%s] wr_busy %d sync %d depth %u", in bfq_limit_depth()
548 __func__, bfqd->wr_busy_queues, op_is_sync(op), in bfq_limit_depth()
553 bfq_rq_pos_tree_lookup(struct bfq_data *bfqd, struct rb_root *root, in bfq_rq_pos_tree_lookup() argument
586 bfq_log(bfqd, "rq_pos_tree_lookup %llu: returning %d", in bfq_rq_pos_tree_lookup()
609 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
620 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
637 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
679 static bool bfq_asymmetric_scenario(struct bfq_data *bfqd, in bfq_asymmetric_scenario() argument
686 rb_first_cached(&bfqd->queue_weights_tree), in bfq_asymmetric_scenario()
695 !RB_EMPTY_ROOT(&bfqd->queue_weights_tree.rb_root) && in bfq_asymmetric_scenario()
696 (bfqd->queue_weights_tree.rb_root.rb_node->rb_left || in bfq_asymmetric_scenario()
697 bfqd->queue_weights_tree.rb_root.rb_node->rb_right); in bfq_asymmetric_scenario()
700 (bfqd->busy_queues[0] && bfqd->busy_queues[1]) || in bfq_asymmetric_scenario()
701 (bfqd->busy_queues[0] && bfqd->busy_queues[2]) || in bfq_asymmetric_scenario()
702 (bfqd->busy_queues[1] && bfqd->busy_queues[2]); in bfq_asymmetric_scenario()
706 || bfqd->num_groups_with_pending_reqs > 0 in bfq_asymmetric_scenario()
724 void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_weights_tree_add() argument
798 void __bfq_weights_tree_remove(struct bfq_data *bfqd, in __bfq_weights_tree_remove() argument
821 void bfq_weights_tree_remove(struct bfq_data *bfqd, in bfq_weights_tree_remove() argument
856 bfqd->num_groups_with_pending_reqs--; in bfq_weights_tree_remove()
866 __bfq_weights_tree_remove(bfqd, bfqq, in bfq_weights_tree_remove()
867 &bfqd->queue_weights_tree); in bfq_weights_tree_remove()
888 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
892 static struct request *bfq_find_next_rq(struct bfq_data *bfqd, in bfq_find_next_rq() argument
916 return bfq_choose_req(bfqd, next, prev, blk_rq_pos(last)); in bfq_find_next_rq()
924 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
941 static void bfq_updated_next_req(struct bfq_data *bfqd, in bfq_updated_next_req() argument
951 if (bfqq == bfqd->in_service_queue) 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()
970 static unsigned int bfq_wr_duration(struct bfq_data *bfqd) in bfq_wr_duration() argument
974 if (bfqd->bfq_wr_max_time > 0) in bfq_wr_duration()
975 return bfqd->bfq_wr_max_time; in bfq_wr_duration()
977 dur = bfqd->rate_dur_prod; in bfq_wr_duration()
978 do_div(dur, bfqd->peak_rate); in bfq_wr_duration()
1005 struct bfq_data *bfqd) 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()
1013 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1039 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1042 bfq_wr_duration(bfqd))) { in bfq_bfqq_resume_state()
1043 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1046 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1058 bfqd->wr_busy_queues++; in bfq_bfqq_resume_state()
1060 bfqd->wr_busy_queues--; in bfq_bfqq_resume_state()
1070 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1075 hlist_for_each_entry_safe(item, n, &bfqd->burst_list, burst_list_node) in bfq_reset_burst_list()
1083 if (bfq_tot_busy_queues(bfqd) == 0) { in bfq_reset_burst_list()
1084 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1085 bfqd->burst_size = 1; in bfq_reset_burst_list()
1087 bfqd->burst_size = 0; 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
1096 bfqd->burst_size++; in bfq_add_to_burst()
1098 if (bfqd->burst_size == bfqd->bfq_large_burst_thresh) { in bfq_add_to_burst()
1106 bfqd->large_burst = true; in bfq_add_to_burst()
1112 hlist_for_each_entry(bfqq_item, &bfqd->burst_list, in bfq_add_to_burst()
1124 hlist_for_each_entry_safe(pos, n, &bfqd->burst_list, 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
1275 if (time_is_before_jiffies(bfqd->last_ins_in_burst + in bfq_handle_burst()
1276 bfqd->bfq_burst_interval) || in bfq_handle_burst()
1277 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1278 bfqd->large_burst = false; in bfq_handle_burst()
1279 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1288 if (bfqd->large_burst) { in bfq_handle_burst()
1298 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1308 bfqd->last_ins_in_burst = jiffies; in bfq_handle_burst()
1323 static int bfq_max_budget(struct bfq_data *bfqd) in bfq_max_budget() argument
1325 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_max_budget()
1328 return bfqd->bfq_max_budget; in bfq_max_budget()
1335 static int bfq_min_budget(struct bfq_data *bfqd) in bfq_min_budget() argument
1337 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_min_budget()
1340 return bfqd->bfq_max_budget / 32; in bfq_min_budget()
1447 static bool bfq_bfqq_update_budg_for_activation(struct bfq_data *bfqd, in bfq_bfqq_update_budg_for_activation() argument
1516 static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd, in bfq_update_bfqq_wr_on_rq_arrival() argument
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()
1544 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1547 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1561 2 * bfq_min_budget(bfqd)); 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()
1599 bfqd->bfq_wr_rt_max_time) { in bfq_update_bfqq_wr_on_rq_arrival()
1604 bfqd->bfq_wr_rt_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()
1613 static bool bfq_bfqq_idle_for_long_time(struct bfq_data *bfqd, in bfq_bfqq_idle_for_long_time() argument
1619 bfqd->bfq_wr_min_idle_time); in bfq_bfqq_idle_for_long_time()
1652 static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd, 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()
1668 bfqd->bfq_slice_idle * 3; in bfq_bfqq_handle_idle_busy_switch()
1679 soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_handle_idle_busy_switch()
1685 wr_or_deserves_wr = bfqd->low_latency && in bfq_bfqq_handle_idle_busy_switch()
1695 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1727 bfqd->bfq_requests_within_timer) in bfq_bfqq_handle_idle_busy_switch()
1733 if (bfqd->low_latency) { in bfq_bfqq_handle_idle_busy_switch()
1737 jiffies - bfqd->bfq_wr_min_idle_time - 1; in bfq_bfqq_handle_idle_busy_switch()
1740 bfqd->bfq_wr_min_idle_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()
1757 bfq_add_bfqq_busy(bfqd, bfqq); in bfq_bfqq_handle_idle_busy_switch()
1791 if (bfqd->in_service_queue && 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()
1795 next_queue_may_preempt(bfqd)) in bfq_bfqq_handle_idle_busy_switch()
1796 bfq_bfqq_expire(bfqd, bfqd->in_service_queue, in bfq_bfqq_handle_idle_busy_switch()
1800 static void bfq_reset_inject_limit(struct bfq_data *bfqd, in bfq_reset_inject_limit() argument
1810 bfqd->waited_rq = NULL; in bfq_reset_inject_limit()
1869 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request() local
1874 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
1876 bfqd->queued++; in bfq_add_request()
1933 if (bfqd->last_completed_rq_bfqq && in bfq_add_request()
1935 ktime_get_ns() - bfqd->last_completion < in bfq_add_request()
1937 if (bfqd->last_completed_rq_bfqq != bfqq && in bfq_add_request()
1938 bfqd->last_completed_rq_bfqq != in bfq_add_request()
1946 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_add_request()
1971 &bfqd->last_completed_rq_bfqq->woken_list); in bfq_add_request()
1974 } else if (bfqd->last_completed_rq_bfqq == 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()
2021 (bfqd->rq_in_driver == 0 || in bfq_add_request()
2023 bfqd->rqs_injected && bfqd->rq_in_driver > 0)) && in bfq_add_request()
2026 bfqd->last_empty_occupied_ns = ktime_get_ns(); in bfq_add_request()
2033 bfqd->wait_dispatch = true; in bfq_add_request()
2047 if (bfqd->rq_in_driver == 0) in bfq_add_request()
2048 bfqd->rqs_injected = false; in bfq_add_request()
2058 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); 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()
2069 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2072 if (bfqd->low_latency && old_wr_coeff == 1 && !rq_is_sync(rq) && in bfq_add_request()
2075 bfqd->bfq_wr_min_inter_arr_async)) { 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()
2079 bfqd->wr_busy_queues++; in bfq_add_request()
2083 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2112 if (bfqd->low_latency && in bfq_add_request()
2117 static struct request *bfq_find_rq_fmerge(struct bfq_data *bfqd, in bfq_find_rq_fmerge() argument
2121 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge()
2141 struct bfq_data *bfqd = q->elevator->elevator_data;
2143 bfqd->rq_in_driver++;
2148 struct bfq_data *bfqd = q->elevator->elevator_data;
2150 bfqd->rq_in_driver--;
2158 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request() local
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()
2169 bfqd->queued--; 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()
2206 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_remove_request()
2207 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2218 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_bio_merge() local
2227 struct bfq_io_cq *bic = bfq_bic_lookup(bfqd, current->io_context, q); in bfq_bio_merge()
2230 spin_lock_irq(&bfqd->lock); in bfq_bio_merge()
2239 bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf)); in bfq_bio_merge()
2241 bfqd->bio_bfqq = NULL; in bfq_bio_merge()
2243 bfqd->bio_bic = bic; in bfq_bio_merge()
2249 spin_unlock_irq(&bfqd->lock); in bfq_bio_merge()
2257 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_request_merge() local
2260 __rq = bfq_find_rq_fmerge(bfqd, bio, q); in bfq_request_merge()
2281 struct bfq_data *bfqd; in bfq_request_merged() local
2287 bfqd = bfqq->bfqd; in bfq_request_merged()
2295 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2296 bfqd->last_position); in bfq_request_merged()
2304 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2309 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_request_merged()
2310 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2365 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2376 void bfq_end_wr_async_queues(struct bfq_data *bfqd, in bfq_end_wr_async_queues() argument
2389 static void bfq_end_wr(struct bfq_data *bfqd) in bfq_end_wr() argument
2393 spin_lock_irq(&bfqd->lock); in bfq_end_wr()
2395 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_end_wr()
2397 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2399 bfq_end_wr_async(bfqd); in bfq_end_wr()
2401 spin_unlock_irq(&bfqd->lock); in bfq_end_wr()
2419 static struct bfq_queue *bfqq_find_close(struct bfq_data *bfqd, in bfqq_find_close() argument
2434 __bfqq = bfq_rq_pos_tree_lookup(bfqd, root, sector, &parent, NULL); in bfqq_find_close()
2461 static struct bfq_queue *bfq_find_close_cooperator(struct bfq_data *bfqd, in bfq_find_close_cooperator() argument
2474 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2520 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2607 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2653 if (likely(bfqd->nonrot_with_queueing)) in bfq_setup_cooperator()
2670 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
2674 if (bfq_tot_busy_queues(bfqd) == 1) in bfq_setup_cooperator()
2677 in_service_bfqq = bfqd->in_service_queue; in bfq_setup_cooperator()
2680 likely(in_service_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
2682 bfqd->in_serv_last_pos) && in bfq_setup_cooperator()
2694 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
2697 if (new_bfqq && likely(new_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
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()
2747 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
2761 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
2762 bfq_del_bfqq_busy(bfqd, bfqq, false); in bfq_release_process_ref()
2768 bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic, in bfq_merge_bfqqs() argument
2771 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
2796 bfqd->wr_busy_queues++; in bfq_merge_bfqqs()
2804 bfqd->wr_busy_queues--; in bfq_merge_bfqqs()
2807 bfq_log_bfqq(bfqd, new_bfqq, "merge_bfqqs: wr_busy %d", in bfq_merge_bfqqs()
2808 bfqd->wr_busy_queues); in bfq_merge_bfqqs()
2837 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
2843 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_allow_bio_merge() local
2845 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_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()
2888 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
2900 static void bfq_set_budget_timeout(struct bfq_data *bfqd, in bfq_set_budget_timeout() argument
2905 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
2910 bfqd->last_budget_start = ktime_get(); in bfq_set_budget_timeout()
2913 bfqd->bfq_timeout * timeout_coeff; in bfq_set_budget_timeout()
2916 static void __bfq_set_in_service_queue(struct bfq_data *bfqd, in __bfq_set_in_service_queue() argument
2922 bfqd->budgets_assigned = (bfqd->budgets_assigned * 7 + 256) / 8; in __bfq_set_in_service_queue()
2926 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && 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()
2966 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
2967 bfqd->in_serv_last_pos = 0; in __bfq_set_in_service_queue()
2973 static struct bfq_queue *bfq_set_in_service_queue(struct bfq_data *bfqd) in bfq_set_in_service_queue() argument
2975 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue()
2977 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
2981 static void bfq_arm_slice_timer(struct bfq_data *bfqd) in bfq_arm_slice_timer() argument
2983 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer()
2993 sl = bfqd->bfq_slice_idle; in bfq_arm_slice_timer()
3005 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
3010 bfqd->last_idling_start = ktime_get(); in bfq_arm_slice_timer()
3011 bfqd->last_idling_start_jiffies = jiffies; in bfq_arm_slice_timer()
3013 hrtimer_start(&bfqd->idle_slice_timer, ns_to_ktime(sl), in bfq_arm_slice_timer()
3025 static unsigned long bfq_calc_max_budget(struct bfq_data *bfqd) in bfq_calc_max_budget() argument
3027 return (u64)bfqd->peak_rate * USEC_PER_MSEC * in bfq_calc_max_budget()
3028 jiffies_to_msecs(bfqd->bfq_timeout)>>BFQ_RATE_SHIFT; in bfq_calc_max_budget()
3036 static void update_thr_responsiveness_params(struct bfq_data *bfqd) in update_thr_responsiveness_params() argument
3038 if (bfqd->bfq_user_max_budget == 0) { in update_thr_responsiveness_params()
3039 bfqd->bfq_max_budget = in update_thr_responsiveness_params()
3040 bfq_calc_max_budget(bfqd); in update_thr_responsiveness_params()
3041 bfq_log(bfqd, "new max_budget = %d", bfqd->bfq_max_budget); in update_thr_responsiveness_params()
3045 static void bfq_reset_rate_computation(struct bfq_data *bfqd, in bfq_reset_rate_computation() argument
3049 bfqd->last_dispatch = bfqd->first_dispatch = ktime_get_ns(); in bfq_reset_rate_computation()
3050 bfqd->peak_rate_samples = 1; in bfq_reset_rate_computation()
3051 bfqd->sequential_samples = 0; in bfq_reset_rate_computation()
3052 bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size = in bfq_reset_rate_computation()
3055 bfqd->peak_rate_samples = 0; /* full re-init on next disp. */ in bfq_reset_rate_computation()
3057 bfq_log(bfqd, in bfq_reset_rate_computation()
3059 bfqd->peak_rate_samples, bfqd->sequential_samples, in bfq_reset_rate_computation()
3060 bfqd->tot_sectors_dispatched); in bfq_reset_rate_computation()
3063 static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) in bfq_update_rate_reset() argument
3075 if (bfqd->peak_rate_samples < BFQ_RATE_MIN_SAMPLES || in bfq_update_rate_reset()
3076 bfqd->delta_from_first < BFQ_RATE_MIN_INTERVAL) in bfq_update_rate_reset()
3085 bfqd->delta_from_first = in bfq_update_rate_reset()
3086 max_t(u64, bfqd->delta_from_first, in bfq_update_rate_reset()
3087 bfqd->last_completion - bfqd->first_dispatch); in bfq_update_rate_reset()
3093 rate = div64_ul(bfqd->tot_sectors_dispatched<<BFQ_RATE_SHIFT, in bfq_update_rate_reset()
3094 div_u64(bfqd->delta_from_first, NSEC_PER_USEC)); in bfq_update_rate_reset()
3102 if ((bfqd->sequential_samples < (3 * bfqd->peak_rate_samples)>>2 && in bfq_update_rate_reset()
3103 rate <= bfqd->peak_rate) || in bfq_update_rate_reset()
3130 weight = (9 * bfqd->sequential_samples) / bfqd->peak_rate_samples; in bfq_update_rate_reset()
3137 div_u64(weight * bfqd->delta_from_first, in bfq_update_rate_reset()
3151 bfqd->peak_rate *= divisor-1; in bfq_update_rate_reset()
3152 bfqd->peak_rate /= divisor; in bfq_update_rate_reset()
3155 bfqd->peak_rate += rate; in bfq_update_rate_reset()
3164 bfqd->peak_rate = max_t(u32, 1, bfqd->peak_rate); in bfq_update_rate_reset()
3166 update_thr_responsiveness_params(bfqd); in bfq_update_rate_reset()
3169 bfq_reset_rate_computation(bfqd, rq); in bfq_update_rate_reset()
3204 static void bfq_update_peak_rate(struct bfq_data *bfqd, struct request *rq) in bfq_update_peak_rate() argument
3208 if (bfqd->peak_rate_samples == 0) { /* first dispatch */ in bfq_update_peak_rate()
3209 bfq_log(bfqd, "update_peak_rate: goto reset, samples %d", in bfq_update_peak_rate()
3210 bfqd->peak_rate_samples); in bfq_update_peak_rate()
3211 bfq_reset_rate_computation(bfqd, rq); in bfq_update_peak_rate()
3227 if (now_ns - bfqd->last_dispatch > 100*NSEC_PER_MSEC && in bfq_update_peak_rate()
3228 bfqd->rq_in_driver == 0) in bfq_update_peak_rate()
3232 bfqd->peak_rate_samples++; in bfq_update_peak_rate()
3234 if ((bfqd->rq_in_driver > 0 || in bfq_update_peak_rate()
3235 now_ns - bfqd->last_completion < BFQ_MIN_TT) in bfq_update_peak_rate()
3236 && !BFQ_RQ_SEEKY(bfqd, bfqd->last_position, rq)) in bfq_update_peak_rate()
3237 bfqd->sequential_samples++; in bfq_update_peak_rate()
3239 bfqd->tot_sectors_dispatched += blk_rq_sectors(rq); in bfq_update_peak_rate()
3242 if (likely(bfqd->peak_rate_samples % 32)) in bfq_update_peak_rate()
3243 bfqd->last_rq_max_size = in bfq_update_peak_rate()
3244 max_t(u32, blk_rq_sectors(rq), bfqd->last_rq_max_size); in bfq_update_peak_rate()
3246 bfqd->last_rq_max_size = blk_rq_sectors(rq); in bfq_update_peak_rate()
3248 bfqd->delta_from_first = now_ns - bfqd->first_dispatch; in bfq_update_peak_rate()
3251 if (bfqd->delta_from_first < BFQ_RATE_REF_INTERVAL) in bfq_update_peak_rate()
3255 bfq_update_rate_reset(bfqd, rq); in bfq_update_peak_rate()
3257 bfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_update_peak_rate()
3258 if (RQ_BFQQ(rq) == bfqd->in_service_queue) in bfq_update_peak_rate()
3259 bfqd->in_serv_last_pos = bfqd->last_position; in bfq_update_peak_rate()
3260 bfqd->last_dispatch = now_ns; in bfq_update_peak_rate()
3474 static bool idling_needed_for_service_guarantees(struct bfq_data *bfqd, in idling_needed_for_service_guarantees() argument
3482 (bfqd->wr_busy_queues < in idling_needed_for_service_guarantees()
3483 bfq_tot_busy_queues(bfqd) || in idling_needed_for_service_guarantees()
3484 bfqd->rq_in_driver >= 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
3516 idling_needed_for_service_guarantees(bfqd, bfqq))) { 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()
3533 if (unlikely(!bfqd->nonrot_with_queueing && in __bfq_bfqq_expire()
3535 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3545 return __bfq_bfqd_reset_in_service(bfqd); in __bfq_bfqq_expire()
3557 static void __bfq_bfqq_recalc_budget(struct bfq_data *bfqd, in __bfq_bfqq_recalc_budget() argument
3564 min_budget = bfq_min_budget(bfqd); in __bfq_bfqq_recalc_budget()
3576 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", 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()
3579 budget, bfq_min_budget(bfqd)); 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()
3615 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3630 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3642 budget = min(budget * 4, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3689 budget = bfqd->bfq_max_budget; in __bfq_bfqq_recalc_budget()
3694 if (bfqd->budgets_assigned >= bfq_stats_min_budgets && in __bfq_bfqq_recalc_budget()
3695 !bfqd->bfq_user_max_budget) in __bfq_bfqq_recalc_budget()
3696 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3713 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", 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
3761 delta_ktime = bfqd->last_idling_start; in bfq_bfqq_is_slow()
3764 delta_ktime = ktime_sub(delta_ktime, bfqd->last_budget_start); in bfq_bfqq_is_slow()
3769 if (blk_queue_nonrot(bfqd->queue)) 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()
3899 static unsigned long bfq_bfqq_softrt_next_start(struct bfq_data *bfqd, in bfq_bfqq_softrt_next_start() argument
3905 bfqd->bfq_wr_max_softrt_rate, in bfq_bfqq_softrt_next_start()
3906 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
3935 void bfq_bfqq_expire(struct bfq_data *bfqd, in bfq_bfqq_expire() argument
3947 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, reason, &delta); in bfq_bfqq_expire()
3968 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
3974 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
3977 if (bfqd->low_latency && bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_expire()
4006 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_bfqq_expire()
4008 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
4018 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
4027 bfqd->rqs_injected = bfqd->wait_dispatch = false; in bfq_bfqq_expire()
4028 bfqd->waited_rq = NULL; 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()
4094 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4106 static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd, in idling_boosts_thr_without_issues() argument
4110 !blk_queue_nonrot(bfqd->queue) && !bfqd->hw_tag, in idling_boosts_thr_without_issues()
4144 ((!blk_queue_nonrot(bfqd->queue) || !bfqd->hw_tag) && in idling_boosts_thr_without_issues()
4182 bfqd->wr_busy_queues == 0; in idling_boosts_thr_without_issues()
4208 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle() local
4215 if (unlikely(bfqd->strict_guarantees)) in bfq_better_to_idle()
4226 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(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()
4270 bfq_choose_bfqq_for_injection(struct bfq_data *bfqd) in bfq_choose_bfqq_for_injection() argument
4272 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection()
4300 time_is_before_eq_jiffies(bfqd->last_idling_start_jiffies + in bfq_choose_bfqq_for_injection()
4301 bfqd->bfq_slice_idle) in bfq_choose_bfqq_for_injection()
4305 if (bfqd->rq_in_driver >= limit) in bfq_choose_bfqq_for_injection()
4320 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_choose_bfqq_for_injection()
4342 if (blk_queue_nonrot(bfqd->queue) && in bfq_choose_bfqq_for_injection()
4349 if (bfqd->rq_in_driver < limit) { in bfq_choose_bfqq_for_injection()
4350 bfqd->rqs_injected = true; in bfq_choose_bfqq_for_injection()
4362 static struct bfq_queue *bfq_select_queue(struct bfq_data *bfqd) in bfq_select_queue() argument
4368 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4372 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4429 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); 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()
4539 bfqq = bfq_choose_bfqq_for_injection(bfqd); 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()
4552 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
4557 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
4559 bfq_log(bfqd, "select_queue: no queue returned"); 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
4569 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
4577 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
4588 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
4590 bfq_wr_duration(bfqd))) in bfq_update_wr_data()
4593 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
4598 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
4620 static struct request *bfq_dispatch_rq_from_bfqq(struct bfq_data *bfqd, in bfq_dispatch_rq_from_bfqq() argument
4630 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
4631 bfqd->wait_dispatch = false; in bfq_dispatch_rq_from_bfqq()
4632 bfqd->waited_rq = rq; in bfq_dispatch_rq_from_bfqq()
4635 bfq_dispatch_remove(bfqd->queue, rq); 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()
4669 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_has_work() local
4675 return !list_empty_careful(&bfqd->dispatch) || in bfq_has_work()
4676 bfq_tot_busy_queues(bfqd) > 0; in bfq_has_work()
4681 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in __bfq_dispatch_request() local
4685 if (!list_empty(&bfqd->dispatch)) { in __bfq_dispatch_request()
4686 rq = list_first_entry(&bfqd->dispatch, struct request, in __bfq_dispatch_request()
4730 bfq_log(bfqd, "dispatch requests: %d busy queues", in __bfq_dispatch_request()
4731 bfq_tot_busy_queues(bfqd)); in __bfq_dispatch_request()
4733 if (bfq_tot_busy_queues(bfqd) == 0) in __bfq_dispatch_request()
4748 if (bfqd->strict_guarantees && bfqd->rq_in_driver > 0) in __bfq_dispatch_request()
4751 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
4755 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
4759 bfqd->rq_in_driver++; in __bfq_dispatch_request()
4821 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_dispatch_request() local
4826 spin_lock_irq(&bfqd->lock); in bfq_dispatch_request()
4828 in_serv_queue = bfqd->in_service_queue; in bfq_dispatch_request()
4832 if (in_serv_queue == bfqd->in_service_queue) { in bfq_dispatch_request()
4837 spin_unlock_irq(&bfqd->lock); in bfq_dispatch_request()
4858 if (bfqq->bfqd) in bfq_put_queue()
4859 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", 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()
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()
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()
4955 bfq_schedule_dispatch(bfqd); in bfq_exit_bfqq()
4958 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
4962 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
4968 struct bfq_data *bfqd; in bfq_exit_icq_bfqq() local
4971 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
4973 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
4976 spin_lock_irqsave(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
4978 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
4980 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
5001 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data() local
5003 if (!bfqd) in bfq_set_next_ioprio_data()
5010 bdi_dev_name(bfqq->bfqd->queue->backing_dev_info), in bfq_set_next_ioprio_data()
5044 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd,
5050 struct bfq_data *bfqd = bic_to_bfqd(bic); in bfq_check_ioprio_change() local
5058 if (unlikely(!bfqd) || likely(bic->ioprio == ioprio)) 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()
5075 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5085 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5112 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5135 static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd, in bfq_async_queue_prio() argument
5154 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd, in bfq_get_queue() argument
5164 bfqg = bfq_bio_bfqg(bfqd, bio); in bfq_get_queue()
5166 async_bfqq = bfq_async_queue_prio(bfqd, bfqg, ioprio_class, in bfq_get_queue()
5175 bfqd->queue->node); in bfq_get_queue()
5178 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, 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()
5200 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5207 bfq_log_bfqq(bfqd, bfqq, "get_queue, at end: %p, %d", bfqq, bfqq->ref); in bfq_get_queue()
5211 static void bfq_update_io_thinktime(struct bfq_data *bfqd, in bfq_update_io_thinktime() argument
5217 elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle); in bfq_update_io_thinktime()
5226 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5230 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5233 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5238 static void bfq_update_has_short_ttime(struct bfq_data *bfqd, in bfq_update_has_short_ttime() argument
5250 bfqd->bfq_slice_idle == 0) in bfq_update_has_short_ttime()
5255 bfqd->bfq_wr_min_idle_time)) in bfq_update_has_short_ttime()
5264 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle)) 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
5377 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
5398 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
5410 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_rq_enqueued()
5420 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
5426 static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq) in __bfq_insert_request() argument
5429 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true); in __bfq_insert_request()
5449 bfq_merge_bfqqs(bfqd, RQ_BIC(rq), 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()
5470 rq->fifo_time = ktime_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; in __bfq_insert_request()
5473 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
5516 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_insert_request() local
5525 spin_lock_irq(&bfqd->lock); in bfq_insert_request()
5528 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
5536 list_add(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
5538 list_add_tail(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
5540 idle_timer_disabled = __bfq_insert_request(bfqd, rq); in bfq_insert_request()
5562 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
5580 static void bfq_update_hw_tag(struct bfq_data *bfqd) in bfq_update_hw_tag() argument
5582 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag()
5584 bfqd->max_rq_in_driver = max_t(int, bfqd->max_rq_in_driver, in bfq_update_hw_tag()
5585 bfqd->rq_in_driver); in bfq_update_hw_tag()
5587 if (bfqd->hw_tag == 1) in bfq_update_hw_tag()
5596 if (bfqd->rq_in_driver + bfqd->queued <= BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
5607 bfqd->rq_in_driver < BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
5610 if (bfqd->hw_tag_samples++ < BFQ_HW_QUEUE_SAMPLES) in bfq_update_hw_tag()
5613 bfqd->hw_tag = bfqd->max_rq_in_driver > BFQ_HW_QUEUE_THRESHOLD; in bfq_update_hw_tag()
5614 bfqd->max_rq_in_driver = 0; in bfq_update_hw_tag()
5615 bfqd->hw_tag_samples = 0; in bfq_update_hw_tag()
5617 bfqd->nonrot_with_queueing = in bfq_update_hw_tag()
5618 blk_queue_nonrot(bfqd->queue) && bfqd->hw_tag; in bfq_update_hw_tag()
5621 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
5626 bfq_update_hw_tag(bfqd); in bfq_completed_request()
5628 bfqd->rq_in_driver--; in bfq_completed_request()
5640 bfq_weights_tree_remove(bfqd, bfqq); in bfq_completed_request()
5651 delta_us = div_u64(now_ns - bfqd->last_completion, NSEC_PER_USEC); in bfq_completed_request()
5670 (bfqd->last_rq_max_size<<BFQ_RATE_SHIFT)/delta_us < in bfq_completed_request()
5672 bfq_update_rate_reset(bfqd, NULL); in bfq_completed_request()
5673 bfqd->last_completion = now_ns; in bfq_completed_request()
5674 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
5689 bfqq->wr_coeff != bfqd->bfq_wr_coeff) 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()
5700 bfq_arm_slice_timer(bfqd); in bfq_completed_request()
5726 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5731 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5735 if (!bfqd->rq_in_driver) in bfq_completed_request()
5736 bfq_schedule_dispatch(bfqd); in bfq_completed_request()
5850 static void bfq_update_inject_limit(struct bfq_data *bfqd, in bfq_update_inject_limit() argument
5853 u64 tot_time_ns = ktime_get_ns() - bfqd->last_empty_occupied_ns; in bfq_update_inject_limit()
5856 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
5863 old_limit <= bfqd->max_rq_in_driver) in bfq_update_inject_limit()
5879 if ((bfqq->last_serv_time_ns == 0 && bfqd->rq_in_driver == 1) || in bfq_update_inject_limit()
5889 } else if (!bfqd->rqs_injected && bfqd->rq_in_driver == 1) in bfq_update_inject_limit()
5903 bfqd->waited_rq = NULL; in bfq_update_inject_limit()
5904 bfqd->rqs_injected = false; in bfq_update_inject_limit()
5916 struct bfq_data *bfqd; in bfq_finish_requeue_request() local
5926 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
5937 spin_lock_irqsave(&bfqd->lock, flags); in bfq_finish_requeue_request()
5939 if (rq == bfqd->waited_rq) 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()
5945 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_finish_requeue_request()
5998 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6011 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6015 static struct bfq_queue *bfq_get_bfqq_handle_split(struct bfq_data *bfqd, in bfq_get_bfqq_handle_split() argument
6023 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6031 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic); in bfq_get_bfqq_handle_split()
6035 if ((bic->was_in_burst_list && bfqd->large_burst) || in bfq_get_bfqq_handle_split()
6070 &bfqd->burst_list); in bfq_get_bfqq_handle_split()
6121 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_init_rq() local
6147 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6153 bfq_log_bfqq(bfqd, bfqq, "breaking apart bfqq"); in bfq_init_rq()
6163 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6173 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6185 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6193 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6219 (bfqd->burst_size > 0 || in bfq_init_rq()
6220 bfq_tot_busy_queues(bfqd) == 0))) in bfq_init_rq()
6221 bfq_handle_burst(bfqd, 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
6232 spin_lock_irqsave(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6241 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6242 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6266 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
6269 bfq_schedule_dispatch(bfqd); in bfq_idle_slice_timer_body()
6270 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6279 struct bfq_data *bfqd = container_of(timer, struct bfq_data, in bfq_idle_slice_timer() local
6281 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer()
6292 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
6297 static void __bfq_put_async_bfqq(struct bfq_data *bfqd, in __bfq_put_async_bfqq() argument
6302 bfq_log(bfqd, "put_async_bfqq: %p", 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()
6319 void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg) in bfq_put_async_queues() argument
6325 __bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j]); in bfq_put_async_queues()
6327 __bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq); in bfq_put_async_queues()
6334 static unsigned int bfq_update_depths(struct bfq_data *bfqd, in bfq_update_depths() argument
6350 bfqd->word_depths[0][0] = max((1U << bt->sb.shift) >> 1, 1U); in bfq_update_depths()
6356 bfqd->word_depths[0][1] = max(((1U << bt->sb.shift) * 3) >> 2, 1U); in bfq_update_depths()
6366 bfqd->word_depths[1][0] = max(((1U << bt->sb.shift) * 3) >> 4, 1U); in bfq_update_depths()
6368 bfqd->word_depths[1][1] = max(((1U << bt->sb.shift) * 6) >> 4, 1U); in bfq_update_depths()
6372 min_shallow = min(min_shallow, bfqd->word_depths[i][j]); in bfq_update_depths()
6379 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_depth_updated() local
6383 min_shallow = bfq_update_depths(bfqd, tags->bitmap_tags); in bfq_depth_updated()
6395 struct bfq_data *bfqd = e->elevator_data; in bfq_exit_queue() local
6398 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
6400 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
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()
6403 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
6405 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
6408 bfqg_and_blkg_put(bfqd->root_group); in bfq_exit_queue()
6411 blkcg_deactivate_policy(bfqd->queue, &blkcg_policy_bfq); in bfq_exit_queue()
6413 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
6414 bfq_put_async_queues(bfqd, bfqd->root_group); in bfq_exit_queue()
6415 kfree(bfqd->root_group); in bfq_exit_queue()
6416 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
6419 wbt_enable_default(bfqd->queue); in bfq_exit_queue()
6421 kfree(bfqd); in bfq_exit_queue()
6425 struct bfq_data *bfqd) in bfq_init_root_group() argument
6432 root_group->bfqd = bfqd; in bfq_init_root_group()
6442 struct bfq_data *bfqd; in bfq_init_queue() local
6449 bfqd = kzalloc_node(sizeof(*bfqd), GFP_KERNEL, q->node); in bfq_init_queue()
6450 if (!bfqd) { in bfq_init_queue()
6454 eq->elevator_data = bfqd; in bfq_init_queue()
6465 bfq_init_bfqq(bfqd, &bfqd->oom_bfqq, NULL, 1, 0); in bfq_init_queue()
6466 bfqd->oom_bfqq.ref++; in bfq_init_queue()
6467 bfqd->oom_bfqq.new_ioprio = BFQ_DEFAULT_QUEUE_IOPRIO; in bfq_init_queue()
6468 bfqd->oom_bfqq.new_ioprio_class = IOPRIO_CLASS_BE; in bfq_init_queue()
6469 bfqd->oom_bfqq.entity.new_weight = in bfq_init_queue()
6470 bfq_ioprio_to_weight(bfqd->oom_bfqq.new_ioprio); in bfq_init_queue()
6473 bfq_clear_bfqq_just_created(&bfqd->oom_bfqq); in bfq_init_queue()
6480 bfqd->oom_bfqq.entity.prio_changed = 1; in bfq_init_queue()
6482 bfqd->queue = q; in bfq_init_queue()
6484 INIT_LIST_HEAD(&bfqd->dispatch); in bfq_init_queue()
6486 hrtimer_init(&bfqd->idle_slice_timer, CLOCK_MONOTONIC, in bfq_init_queue()
6488 bfqd->idle_slice_timer.function = bfq_idle_slice_timer; in bfq_init_queue()
6490 bfqd->queue_weights_tree = RB_ROOT_CACHED; in bfq_init_queue()
6491 bfqd->num_groups_with_pending_reqs = 0; in bfq_init_queue()
6493 INIT_LIST_HEAD(&bfqd->active_list); in bfq_init_queue()
6494 INIT_LIST_HEAD(&bfqd->idle_list); in bfq_init_queue()
6495 INIT_HLIST_HEAD(&bfqd->burst_list); in bfq_init_queue()
6497 bfqd->hw_tag = -1; in bfq_init_queue()
6498 bfqd->nonrot_with_queueing = blk_queue_nonrot(bfqd->queue); in bfq_init_queue()
6500 bfqd->bfq_max_budget = bfq_default_max_budget; in bfq_init_queue()
6502 bfqd->bfq_fifo_expire[0] = bfq_fifo_expire[0]; in bfq_init_queue()
6503 bfqd->bfq_fifo_expire[1] = bfq_fifo_expire[1]; in bfq_init_queue()
6504 bfqd->bfq_back_max = bfq_back_max; in bfq_init_queue()
6505 bfqd->bfq_back_penalty = bfq_back_penalty; in bfq_init_queue()
6506 bfqd->bfq_slice_idle = bfq_slice_idle; in bfq_init_queue()
6507 bfqd->bfq_timeout = bfq_timeout; in bfq_init_queue()
6509 bfqd->bfq_requests_within_timer = 120; in bfq_init_queue()
6511 bfqd->bfq_large_burst_thresh = 8; in bfq_init_queue()
6512 bfqd->bfq_burst_interval = msecs_to_jiffies(180); in bfq_init_queue()
6514 bfqd->low_latency = true; in bfq_init_queue()
6519 bfqd->bfq_wr_coeff = 30; in bfq_init_queue()
6520 bfqd->bfq_wr_rt_max_time = msecs_to_jiffies(300); in bfq_init_queue()
6521 bfqd->bfq_wr_max_time = 0; in bfq_init_queue()
6522 bfqd->bfq_wr_min_idle_time = msecs_to_jiffies(2000); in bfq_init_queue()
6523 bfqd->bfq_wr_min_inter_arr_async = msecs_to_jiffies(500); in bfq_init_queue()
6524 bfqd->bfq_wr_max_softrt_rate = 7000; /* in bfq_init_queue()
6530 bfqd->wr_busy_queues = 0; in bfq_init_queue()
6536 bfqd->rate_dur_prod = ref_rate[blk_queue_nonrot(bfqd->queue)] * in bfq_init_queue()
6537 ref_wr_duration[blk_queue_nonrot(bfqd->queue)]; in bfq_init_queue()
6538 bfqd->peak_rate = ref_rate[blk_queue_nonrot(bfqd->queue)] * 2 / 3; in bfq_init_queue()
6540 spin_lock_init(&bfqd->lock); in bfq_init_queue()
6557 bfqd->root_group = bfq_create_group_hierarchy(bfqd, q->node); in bfq_init_queue()
6558 if (!bfqd->root_group) in bfq_init_queue()
6560 bfq_init_root_group(bfqd->root_group, bfqd); in bfq_init_queue()
6561 bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group); in bfq_init_queue()
6567 kfree(bfqd); in bfq_init_queue()
6604 struct bfq_data *bfqd = e->elevator_data; \
6612 SHOW_FUNCTION(bfq_fifo_expire_sync_show, bfqd->bfq_fifo_expire[1], 2);
6613 SHOW_FUNCTION(bfq_fifo_expire_async_show, bfqd->bfq_fifo_expire[0], 2);
6614 SHOW_FUNCTION(bfq_back_seek_max_show, bfqd->bfq_back_max, 0);
6615 SHOW_FUNCTION(bfq_back_seek_penalty_show, bfqd->bfq_back_penalty, 0);
6616 SHOW_FUNCTION(bfq_slice_idle_show, bfqd->bfq_slice_idle, 2);
6617 SHOW_FUNCTION(bfq_max_budget_show, bfqd->bfq_user_max_budget, 0);
6618 SHOW_FUNCTION(bfq_timeout_sync_show, bfqd->bfq_timeout, 1);
6619 SHOW_FUNCTION(bfq_strict_guarantees_show, bfqd->strict_guarantees, 0);
6620 SHOW_FUNCTION(bfq_low_latency_show, bfqd->low_latency, 0);
6626 struct bfq_data *bfqd = e->elevator_data; \
6631 USEC_SHOW_FUNCTION(bfq_slice_idle_us_show, bfqd->bfq_slice_idle);
6638 struct bfq_data *bfqd = e->elevator_data; \
6657 STORE_FUNCTION(bfq_fifo_expire_sync_store, &bfqd->bfq_fifo_expire[1], 1,
6659 STORE_FUNCTION(bfq_fifo_expire_async_store, &bfqd->bfq_fifo_expire[0], 1,
6661 STORE_FUNCTION(bfq_back_seek_max_store, &bfqd->bfq_back_max, 0, INT_MAX, 0);
6662 STORE_FUNCTION(bfq_back_seek_penalty_store, &bfqd->bfq_back_penalty, 1,
6664 STORE_FUNCTION(bfq_slice_idle_store, &bfqd->bfq_slice_idle, 0, INT_MAX, 2);
6670 struct bfq_data *bfqd = e->elevator_data; \
6684 USEC_STORE_FUNCTION(bfq_slice_idle_us_store, &bfqd->bfq_slice_idle, 0,
6691 struct bfq_data *bfqd = e->elevator_data; in bfq_max_budget_store() local
6700 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_max_budget_store()
6704 bfqd->bfq_max_budget = __data; in bfq_max_budget_store()
6707 bfqd->bfq_user_max_budget = __data; in bfq_max_budget_store()
6719 struct bfq_data *bfqd = e->elevator_data; in bfq_timeout_sync_store() local
6732 bfqd->bfq_timeout = msecs_to_jiffies(__data); in bfq_timeout_sync_store()
6733 if (bfqd->bfq_user_max_budget == 0) in bfq_timeout_sync_store()
6734 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_timeout_sync_store()
6742 struct bfq_data *bfqd = e->elevator_data; in bfq_strict_guarantees_store() local
6752 if (!bfqd->strict_guarantees && __data == 1 in bfq_strict_guarantees_store()
6753 && bfqd->bfq_slice_idle < 8 * NSEC_PER_MSEC) in bfq_strict_guarantees_store()
6754 bfqd->bfq_slice_idle = 8 * NSEC_PER_MSEC; in bfq_strict_guarantees_store()
6756 bfqd->strict_guarantees = __data; in bfq_strict_guarantees_store()
6764 struct bfq_data *bfqd = e->elevator_data; in bfq_low_latency_store() local
6774 if (__data == 0 && bfqd->low_latency != 0) in bfq_low_latency_store()
6775 bfq_end_wr(bfqd); in bfq_low_latency_store()
6776 bfqd->low_latency = __data; in bfq_low_latency_store()