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 if (bfqd->queued != 0) { in bfq_schedule_dispatch()
425 bfq_log(bfqd, "schedule dispatch"); in bfq_schedule_dispatch()
426 blk_mq_run_hw_queues(bfqd->queue, true); in bfq_schedule_dispatch()
439 static struct request *bfq_choose_req(struct bfq_data *bfqd, in bfq_choose_req() argument
470 back_max = bfqd->bfq_back_max * 2; in bfq_choose_req()
480 d1 = (last - s1) * bfqd->bfq_back_penalty; in bfq_choose_req()
487 d2 = (last - s2) * bfqd->bfq_back_penalty; in bfq_choose_req()
537 struct bfq_data *bfqd = data->q->elevator->elevator_data; in bfq_limit_depth() local
543 bfqd->word_depths[!!bfqd->wr_busy_queues][op_is_sync(op)]; in bfq_limit_depth()
545 bfq_log(bfqd, "[%s] wr_busy %d sync %d depth %u", in bfq_limit_depth()
546 __func__, bfqd->wr_busy_queues, op_is_sync(op), in bfq_limit_depth()
551 bfq_rq_pos_tree_lookup(struct bfq_data *bfqd, struct rb_root *root, in bfq_rq_pos_tree_lookup() argument
584 bfq_log(bfqd, "rq_pos_tree_lookup %llu: returning %d", in bfq_rq_pos_tree_lookup()
607 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
618 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
635 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
677 static bool bfq_asymmetric_scenario(struct bfq_data *bfqd, in bfq_asymmetric_scenario() argument
684 rb_first_cached(&bfqd->queue_weights_tree), in bfq_asymmetric_scenario()
693 !RB_EMPTY_ROOT(&bfqd->queue_weights_tree.rb_root) && in bfq_asymmetric_scenario()
694 (bfqd->queue_weights_tree.rb_root.rb_node->rb_left || in bfq_asymmetric_scenario()
695 bfqd->queue_weights_tree.rb_root.rb_node->rb_right); in bfq_asymmetric_scenario()
698 (bfqd->busy_queues[0] && bfqd->busy_queues[1]) || in bfq_asymmetric_scenario()
699 (bfqd->busy_queues[0] && bfqd->busy_queues[2]) || in bfq_asymmetric_scenario()
700 (bfqd->busy_queues[1] && bfqd->busy_queues[2]); in bfq_asymmetric_scenario()
704 || bfqd->num_groups_with_pending_reqs > 0 in bfq_asymmetric_scenario()
722 void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_weights_tree_add() argument
796 void __bfq_weights_tree_remove(struct bfq_data *bfqd, in __bfq_weights_tree_remove() argument
819 void bfq_weights_tree_remove(struct bfq_data *bfqd, in bfq_weights_tree_remove() argument
854 bfqd->num_groups_with_pending_reqs--; in bfq_weights_tree_remove()
864 __bfq_weights_tree_remove(bfqd, bfqq, in bfq_weights_tree_remove()
865 &bfqd->queue_weights_tree); in bfq_weights_tree_remove()
886 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
890 static struct request *bfq_find_next_rq(struct bfq_data *bfqd, in bfq_find_next_rq() argument
914 return bfq_choose_req(bfqd, next, prev, blk_rq_pos(last)); in bfq_find_next_rq()
922 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
939 static void bfq_updated_next_req(struct bfq_data *bfqd, in bfq_updated_next_req() argument
949 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
962 bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", in bfq_updated_next_req()
964 bfq_requeue_bfqq(bfqd, bfqq, false); in bfq_updated_next_req()
968 static unsigned int bfq_wr_duration(struct bfq_data *bfqd) in bfq_wr_duration() argument
972 if (bfqd->bfq_wr_max_time > 0) in bfq_wr_duration()
973 return bfqd->bfq_wr_max_time; in bfq_wr_duration()
975 dur = bfqd->rate_dur_prod; in bfq_wr_duration()
976 do_div(dur, bfqd->peak_rate); in bfq_wr_duration()
1003 struct bfq_data *bfqd) in switch_back_to_interactive_wr() argument
1005 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1006 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1011 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1037 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1040 bfq_wr_duration(bfqd))) { in bfq_bfqq_resume_state()
1041 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1044 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1056 bfqd->wr_busy_queues++; in bfq_bfqq_resume_state()
1058 bfqd->wr_busy_queues--; in bfq_bfqq_resume_state()
1068 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1073 hlist_for_each_entry_safe(item, n, &bfqd->burst_list, burst_list_node) in bfq_reset_burst_list()
1081 if (bfq_tot_busy_queues(bfqd) == 0) { in bfq_reset_burst_list()
1082 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1083 bfqd->burst_size = 1; in bfq_reset_burst_list()
1085 bfqd->burst_size = 0; in bfq_reset_burst_list()
1087 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1091 static void bfq_add_to_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_add_to_burst() argument
1094 bfqd->burst_size++; in bfq_add_to_burst()
1096 if (bfqd->burst_size == bfqd->bfq_large_burst_thresh) { in bfq_add_to_burst()
1104 bfqd->large_burst = true; in bfq_add_to_burst()
1110 hlist_for_each_entry(bfqq_item, &bfqd->burst_list, in bfq_add_to_burst()
1122 hlist_for_each_entry_safe(pos, n, &bfqd->burst_list, in bfq_add_to_burst()
1131 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1243 static void bfq_handle_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_handle_burst() argument
1273 if (time_is_before_jiffies(bfqd->last_ins_in_burst + in bfq_handle_burst()
1274 bfqd->bfq_burst_interval) || in bfq_handle_burst()
1275 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1276 bfqd->large_burst = false; in bfq_handle_burst()
1277 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1286 if (bfqd->large_burst) { in bfq_handle_burst()
1296 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1306 bfqd->last_ins_in_burst = jiffies; in bfq_handle_burst()
1321 static int bfq_max_budget(struct bfq_data *bfqd) in bfq_max_budget() argument
1323 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_max_budget()
1326 return bfqd->bfq_max_budget; in bfq_max_budget()
1333 static int bfq_min_budget(struct bfq_data *bfqd) in bfq_min_budget() argument
1335 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_min_budget()
1338 return bfqd->bfq_max_budget / 32; in bfq_min_budget()
1445 static bool bfq_bfqq_update_budg_for_activation(struct bfq_data *bfqd, in bfq_bfqq_update_budg_for_activation() argument
1514 static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd, in bfq_update_bfqq_wr_on_rq_arrival() argument
1526 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1527 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1542 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1545 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1559 2 * bfq_min_budget(bfqd)); in bfq_update_bfqq_wr_on_rq_arrival()
1562 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1563 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1597 bfqd->bfq_wr_rt_max_time) { in bfq_update_bfqq_wr_on_rq_arrival()
1602 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1603 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1611 static bool bfq_bfqq_idle_for_long_time(struct bfq_data *bfqd, in bfq_bfqq_idle_for_long_time() argument
1617 bfqd->bfq_wr_min_idle_time); in bfq_bfqq_idle_for_long_time()
1650 static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd, in bfq_bfqq_handle_idle_busy_switch() argument
1658 idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq), in bfq_bfqq_handle_idle_busy_switch()
1666 bfqd->bfq_slice_idle * 3; in bfq_bfqq_handle_idle_busy_switch()
1677 soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_handle_idle_busy_switch()
1683 wr_or_deserves_wr = bfqd->low_latency && in bfq_bfqq_handle_idle_busy_switch()
1693 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1725 bfqd->bfq_requests_within_timer) in bfq_bfqq_handle_idle_busy_switch()
1731 if (bfqd->low_latency) { in bfq_bfqq_handle_idle_busy_switch()
1735 jiffies - bfqd->bfq_wr_min_idle_time - 1; in bfq_bfqq_handle_idle_busy_switch()
1738 bfqd->bfq_wr_min_idle_time)) { in bfq_bfqq_handle_idle_busy_switch()
1739 bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1755 bfq_add_bfqq_busy(bfqd, bfqq); in bfq_bfqq_handle_idle_busy_switch()
1789 if (bfqd->in_service_queue && in bfq_bfqq_handle_idle_busy_switch()
1791 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1792 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue)) && in bfq_bfqq_handle_idle_busy_switch()
1793 next_queue_may_preempt(bfqd)) in bfq_bfqq_handle_idle_busy_switch()
1794 bfq_bfqq_expire(bfqd, bfqd->in_service_queue, in bfq_bfqq_handle_idle_busy_switch()
1798 static void bfq_reset_inject_limit(struct bfq_data *bfqd, in bfq_reset_inject_limit() argument
1808 bfqd->waited_rq = NULL; in bfq_reset_inject_limit()
1867 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request() local
1872 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
1874 bfqd->queued++; in bfq_add_request()
1931 if (bfqd->last_completed_rq_bfqq && in bfq_add_request()
1933 ktime_get_ns() - bfqd->last_completion < in bfq_add_request()
1935 if (bfqd->last_completed_rq_bfqq != bfqq && in bfq_add_request()
1936 bfqd->last_completed_rq_bfqq != in bfq_add_request()
1944 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_add_request()
1969 &bfqd->last_completed_rq_bfqq->woken_list); in bfq_add_request()
1972 } else if (bfqd->last_completed_rq_bfqq == in bfq_add_request()
1991 bfq_reset_inject_limit(bfqd, bfqq); in bfq_add_request()
2018 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2019 (bfqd->rq_in_driver == 0 || in bfq_add_request()
2021 bfqd->rqs_injected && bfqd->rq_in_driver > 0)) && in bfq_add_request()
2024 bfqd->last_empty_occupied_ns = ktime_get_ns(); in bfq_add_request()
2031 bfqd->wait_dispatch = true; in bfq_add_request()
2045 if (bfqd->rq_in_driver == 0) in bfq_add_request()
2046 bfqd->rqs_injected = false; in bfq_add_request()
2056 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2063 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2064 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_add_request()
2067 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2070 if (bfqd->low_latency && old_wr_coeff == 1 && !rq_is_sync(rq) && in bfq_add_request()
2073 bfqd->bfq_wr_min_inter_arr_async)) { in bfq_add_request()
2074 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2075 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2077 bfqd->wr_busy_queues++; in bfq_add_request()
2081 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2110 if (bfqd->low_latency && in bfq_add_request()
2115 static struct request *bfq_find_rq_fmerge(struct bfq_data *bfqd, in bfq_find_rq_fmerge() argument
2119 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge()
2139 struct bfq_data *bfqd = q->elevator->elevator_data;
2141 bfqd->rq_in_driver++;
2146 struct bfq_data *bfqd = q->elevator->elevator_data;
2148 bfqd->rq_in_driver--;
2156 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request() local
2160 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2161 bfq_updated_next_req(bfqd, bfqq); in bfq_remove_request()
2167 bfqd->queued--; in bfq_remove_request()
2177 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2178 bfq_del_bfqq_busy(bfqd, bfqq, false); in bfq_remove_request()
2204 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_remove_request()
2205 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2217 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_bio_merge() local
2226 struct bfq_io_cq *bic = bfq_bic_lookup(bfqd, current->io_context, q); in bfq_bio_merge()
2229 spin_lock_irq(&bfqd->lock); in bfq_bio_merge()
2232 bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf)); in bfq_bio_merge()
2234 bfqd->bio_bfqq = NULL; in bfq_bio_merge()
2235 bfqd->bio_bic = bic; in bfq_bio_merge()
2241 spin_unlock_irq(&bfqd->lock); in bfq_bio_merge()
2249 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_request_merge() local
2252 __rq = bfq_find_rq_fmerge(bfqd, bio, q); in bfq_request_merge()
2272 struct bfq_data *bfqd; in bfq_request_merged() local
2278 bfqd = bfqq->bfqd; in bfq_request_merged()
2286 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2287 bfqd->last_position); in bfq_request_merged()
2295 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2300 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_request_merged()
2301 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2356 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2367 void bfq_end_wr_async_queues(struct bfq_data *bfqd, in bfq_end_wr_async_queues() argument
2380 static void bfq_end_wr(struct bfq_data *bfqd) in bfq_end_wr() argument
2384 spin_lock_irq(&bfqd->lock); in bfq_end_wr()
2386 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_end_wr()
2388 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2390 bfq_end_wr_async(bfqd); in bfq_end_wr()
2392 spin_unlock_irq(&bfqd->lock); in bfq_end_wr()
2410 static struct bfq_queue *bfqq_find_close(struct bfq_data *bfqd, in bfqq_find_close() argument
2425 __bfqq = bfq_rq_pos_tree_lookup(bfqd, root, sector, &parent, NULL); in bfqq_find_close()
2452 static struct bfq_queue *bfq_find_close_cooperator(struct bfq_data *bfqd, in bfq_find_close_cooperator() argument
2465 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2503 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2581 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2623 if (likely(bfqd->nonrot_with_queueing)) in bfq_setup_cooperator()
2643 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
2647 if (bfq_tot_busy_queues(bfqd) == 1) in bfq_setup_cooperator()
2650 in_service_bfqq = bfqd->in_service_queue; in bfq_setup_cooperator()
2653 likely(in_service_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
2655 bfqd->in_serv_last_pos) && in bfq_setup_cooperator()
2667 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
2670 if (new_bfqq && likely(new_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
2697 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
2707 bic->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
2709 bic->saved_wr_cur_max_time = bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
2720 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
2734 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
2735 bfq_del_bfqq_busy(bfqd, bfqq, false); in bfq_release_process_ref()
2741 bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic, in bfq_merge_bfqqs() argument
2744 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
2769 bfqd->wr_busy_queues++; in bfq_merge_bfqqs()
2777 bfqd->wr_busy_queues--; in bfq_merge_bfqqs()
2780 bfq_log_bfqq(bfqd, new_bfqq, "merge_bfqqs: wr_busy %d", in bfq_merge_bfqqs()
2781 bfqd->wr_busy_queues); in bfq_merge_bfqqs()
2810 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
2816 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_allow_bio_merge() local
2818 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge()
2837 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false); in bfq_allow_bio_merge()
2846 bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq, in bfq_allow_bio_merge()
2861 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
2873 static void bfq_set_budget_timeout(struct bfq_data *bfqd, in bfq_set_budget_timeout() argument
2878 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
2883 bfqd->last_budget_start = ktime_get(); in bfq_set_budget_timeout()
2886 bfqd->bfq_timeout * timeout_coeff; in bfq_set_budget_timeout()
2889 static void __bfq_set_in_service_queue(struct bfq_data *bfqd, in __bfq_set_in_service_queue() argument
2895 bfqd->budgets_assigned = (bfqd->budgets_assigned * 7 + 256) / 8; in __bfq_set_in_service_queue()
2899 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
2933 bfq_set_budget_timeout(bfqd, bfqq); in __bfq_set_in_service_queue()
2934 bfq_log_bfqq(bfqd, bfqq, in __bfq_set_in_service_queue()
2939 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
2945 static struct bfq_queue *bfq_set_in_service_queue(struct bfq_data *bfqd) in bfq_set_in_service_queue() argument
2947 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue()
2949 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
2953 static void bfq_arm_slice_timer(struct bfq_data *bfqd) in bfq_arm_slice_timer() argument
2955 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer()
2965 sl = bfqd->bfq_slice_idle; in bfq_arm_slice_timer()
2977 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
2982 bfqd->last_idling_start = ktime_get(); in bfq_arm_slice_timer()
2983 bfqd->last_idling_start_jiffies = jiffies; in bfq_arm_slice_timer()
2985 hrtimer_start(&bfqd->idle_slice_timer, ns_to_ktime(sl), in bfq_arm_slice_timer()
2997 static unsigned long bfq_calc_max_budget(struct bfq_data *bfqd) in bfq_calc_max_budget() argument
2999 return (u64)bfqd->peak_rate * USEC_PER_MSEC * in bfq_calc_max_budget()
3000 jiffies_to_msecs(bfqd->bfq_timeout)>>BFQ_RATE_SHIFT; in bfq_calc_max_budget()
3008 static void update_thr_responsiveness_params(struct bfq_data *bfqd) in update_thr_responsiveness_params() argument
3010 if (bfqd->bfq_user_max_budget == 0) { in update_thr_responsiveness_params()
3011 bfqd->bfq_max_budget = in update_thr_responsiveness_params()
3012 bfq_calc_max_budget(bfqd); in update_thr_responsiveness_params()
3013 bfq_log(bfqd, "new max_budget = %d", bfqd->bfq_max_budget); in update_thr_responsiveness_params()
3017 static void bfq_reset_rate_computation(struct bfq_data *bfqd, in bfq_reset_rate_computation() argument
3021 bfqd->last_dispatch = bfqd->first_dispatch = ktime_get_ns(); in bfq_reset_rate_computation()
3022 bfqd->peak_rate_samples = 1; in bfq_reset_rate_computation()
3023 bfqd->sequential_samples = 0; in bfq_reset_rate_computation()
3024 bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size = in bfq_reset_rate_computation()
3027 bfqd->peak_rate_samples = 0; /* full re-init on next disp. */ in bfq_reset_rate_computation()
3029 bfq_log(bfqd, in bfq_reset_rate_computation()
3031 bfqd->peak_rate_samples, bfqd->sequential_samples, in bfq_reset_rate_computation()
3032 bfqd->tot_sectors_dispatched); in bfq_reset_rate_computation()
3035 static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) in bfq_update_rate_reset() argument
3047 if (bfqd->peak_rate_samples < BFQ_RATE_MIN_SAMPLES || in bfq_update_rate_reset()
3048 bfqd->delta_from_first < BFQ_RATE_MIN_INTERVAL) in bfq_update_rate_reset()
3057 bfqd->delta_from_first = in bfq_update_rate_reset()
3058 max_t(u64, bfqd->delta_from_first, in bfq_update_rate_reset()
3059 bfqd->last_completion - bfqd->first_dispatch); in bfq_update_rate_reset()
3065 rate = div64_ul(bfqd->tot_sectors_dispatched<<BFQ_RATE_SHIFT, in bfq_update_rate_reset()
3066 div_u64(bfqd->delta_from_first, NSEC_PER_USEC)); in bfq_update_rate_reset()
3074 if ((bfqd->sequential_samples < (3 * bfqd->peak_rate_samples)>>2 && in bfq_update_rate_reset()
3075 rate <= bfqd->peak_rate) || in bfq_update_rate_reset()
3102 weight = (9 * bfqd->sequential_samples) / bfqd->peak_rate_samples; in bfq_update_rate_reset()
3109 div_u64(weight * bfqd->delta_from_first, in bfq_update_rate_reset()
3123 bfqd->peak_rate *= divisor-1; in bfq_update_rate_reset()
3124 bfqd->peak_rate /= divisor; in bfq_update_rate_reset()
3127 bfqd->peak_rate += rate; in bfq_update_rate_reset()
3136 bfqd->peak_rate = max_t(u32, 1, bfqd->peak_rate); in bfq_update_rate_reset()
3138 update_thr_responsiveness_params(bfqd); in bfq_update_rate_reset()
3141 bfq_reset_rate_computation(bfqd, rq); in bfq_update_rate_reset()
3176 static void bfq_update_peak_rate(struct bfq_data *bfqd, struct request *rq) in bfq_update_peak_rate() argument
3180 if (bfqd->peak_rate_samples == 0) { /* first dispatch */ in bfq_update_peak_rate()
3181 bfq_log(bfqd, "update_peak_rate: goto reset, samples %d", in bfq_update_peak_rate()
3182 bfqd->peak_rate_samples); in bfq_update_peak_rate()
3183 bfq_reset_rate_computation(bfqd, rq); in bfq_update_peak_rate()
3199 if (now_ns - bfqd->last_dispatch > 100*NSEC_PER_MSEC && in bfq_update_peak_rate()
3200 bfqd->rq_in_driver == 0) in bfq_update_peak_rate()
3204 bfqd->peak_rate_samples++; in bfq_update_peak_rate()
3206 if ((bfqd->rq_in_driver > 0 || in bfq_update_peak_rate()
3207 now_ns - bfqd->last_completion < BFQ_MIN_TT) in bfq_update_peak_rate()
3208 && !BFQ_RQ_SEEKY(bfqd, bfqd->last_position, rq)) in bfq_update_peak_rate()
3209 bfqd->sequential_samples++; in bfq_update_peak_rate()
3211 bfqd->tot_sectors_dispatched += blk_rq_sectors(rq); in bfq_update_peak_rate()
3214 if (likely(bfqd->peak_rate_samples % 32)) in bfq_update_peak_rate()
3215 bfqd->last_rq_max_size = in bfq_update_peak_rate()
3216 max_t(u32, blk_rq_sectors(rq), bfqd->last_rq_max_size); in bfq_update_peak_rate()
3218 bfqd->last_rq_max_size = blk_rq_sectors(rq); in bfq_update_peak_rate()
3220 bfqd->delta_from_first = now_ns - bfqd->first_dispatch; in bfq_update_peak_rate()
3223 if (bfqd->delta_from_first < BFQ_RATE_REF_INTERVAL) in bfq_update_peak_rate()
3227 bfq_update_rate_reset(bfqd, rq); in bfq_update_peak_rate()
3229 bfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_update_peak_rate()
3230 if (RQ_BFQQ(rq) == bfqd->in_service_queue) in bfq_update_peak_rate()
3231 bfqd->in_serv_last_pos = bfqd->last_position; in bfq_update_peak_rate()
3232 bfqd->last_dispatch = now_ns; in bfq_update_peak_rate()
3446 static bool idling_needed_for_service_guarantees(struct bfq_data *bfqd, in idling_needed_for_service_guarantees() argument
3454 (bfqd->wr_busy_queues < in idling_needed_for_service_guarantees()
3455 bfq_tot_busy_queues(bfqd) || in idling_needed_for_service_guarantees()
3456 bfqd->rq_in_driver >= in idling_needed_for_service_guarantees()
3458 bfq_asymmetric_scenario(bfqd, bfqq); in idling_needed_for_service_guarantees()
3461 static bool __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, in __bfq_bfqq_expire() argument
3488 idling_needed_for_service_guarantees(bfqd, bfqq))) { in __bfq_bfqq_expire()
3498 bfq_del_bfqq_busy(bfqd, bfqq, true); in __bfq_bfqq_expire()
3500 bfq_requeue_bfqq(bfqd, bfqq, true); in __bfq_bfqq_expire()
3505 if (unlikely(!bfqd->nonrot_with_queueing && in __bfq_bfqq_expire()
3507 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3517 return __bfq_bfqd_reset_in_service(bfqd); in __bfq_bfqq_expire()
3529 static void __bfq_bfqq_recalc_budget(struct bfq_data *bfqd, in __bfq_bfqq_recalc_budget() argument
3536 min_budget = bfq_min_budget(bfqd); in __bfq_bfqq_recalc_budget()
3548 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", in __bfq_bfqq_recalc_budget()
3550 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last max_budg %d, min budg %d", in __bfq_bfqq_recalc_budget()
3551 budget, bfq_min_budget(bfqd)); in __bfq_bfqq_recalc_budget()
3552 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: sync %d, seeky %d", in __bfq_bfqq_recalc_budget()
3553 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
3587 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3602 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3614 budget = min(budget * 4, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3661 budget = bfqd->bfq_max_budget; in __bfq_bfqq_recalc_budget()
3666 if (bfqd->budgets_assigned >= bfq_stats_min_budgets && in __bfq_bfqq_recalc_budget()
3667 !bfqd->bfq_user_max_budget) in __bfq_bfqq_recalc_budget()
3668 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
3685 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", in __bfq_bfqq_recalc_budget()
3721 static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_bfqq_is_slow() argument
3733 delta_ktime = bfqd->last_idling_start; in bfq_bfqq_is_slow()
3736 delta_ktime = ktime_sub(delta_ktime, bfqd->last_budget_start); in bfq_bfqq_is_slow()
3741 if (blk_queue_nonrot(bfqd->queue)) in bfq_bfqq_is_slow()
3770 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
3773 bfq_log_bfqq(bfqd, bfqq, "bfq_bfqq_is_slow: slow %d", slow); in bfq_bfqq_is_slow()
3871 static unsigned long bfq_bfqq_softrt_next_start(struct bfq_data *bfqd, in bfq_bfqq_softrt_next_start() argument
3877 bfqd->bfq_wr_max_softrt_rate, in bfq_bfqq_softrt_next_start()
3878 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
3907 void bfq_bfqq_expire(struct bfq_data *bfqd, in bfq_bfqq_expire() argument
3919 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, reason, &delta); in bfq_bfqq_expire()
3940 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
3946 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
3949 if (bfqd->low_latency && bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_expire()
3978 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_bfqq_expire()
3980 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
3990 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
3999 bfqd->rqs_injected = bfqd->wait_dispatch = false; in bfq_bfqq_expire()
4000 bfqd->waited_rq = NULL; in bfq_bfqq_expire()
4006 __bfq_bfqq_recalc_budget(bfqd, bfqq, reason); in bfq_bfqq_expire()
4007 if (__bfq_bfqq_expire(bfqd, bfqq, reason)) in bfq_bfqq_expire()
4066 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4078 static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd, in idling_boosts_thr_without_issues() argument
4082 !blk_queue_nonrot(bfqd->queue) && !bfqd->hw_tag, in idling_boosts_thr_without_issues()
4116 ((!blk_queue_nonrot(bfqd->queue) || !bfqd->hw_tag) && in idling_boosts_thr_without_issues()
4154 bfqd->wr_busy_queues == 0; in idling_boosts_thr_without_issues()
4180 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle() local
4187 if (unlikely(bfqd->strict_guarantees)) in bfq_better_to_idle()
4198 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4203 idling_boosts_thr_without_issues(bfqd, bfqq); in bfq_better_to_idle()
4206 idling_needed_for_service_guarantees(bfqd, bfqq); in bfq_better_to_idle()
4242 bfq_choose_bfqq_for_injection(struct bfq_data *bfqd) in bfq_choose_bfqq_for_injection() argument
4244 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection()
4272 time_is_before_eq_jiffies(bfqd->last_idling_start_jiffies + in bfq_choose_bfqq_for_injection()
4273 bfqd->bfq_slice_idle) in bfq_choose_bfqq_for_injection()
4277 if (bfqd->rq_in_driver >= limit) in bfq_choose_bfqq_for_injection()
4292 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_choose_bfqq_for_injection()
4314 if (blk_queue_nonrot(bfqd->queue) && in bfq_choose_bfqq_for_injection()
4321 if (bfqd->rq_in_driver < limit) { in bfq_choose_bfqq_for_injection()
4322 bfqd->rqs_injected = true; in bfq_choose_bfqq_for_injection()
4334 static struct bfq_queue *bfq_select_queue(struct bfq_data *bfqd) in bfq_select_queue() argument
4340 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4344 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4401 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_select_queue()
4508 else if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_select_queue()
4509 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
4511 bfqq = bfq_choose_bfqq_for_injection(bfqd); in bfq_select_queue()
4520 bfq_bfqq_expire(bfqd, bfqq, false, reason); in bfq_select_queue()
4522 bfqq = bfq_set_in_service_queue(bfqd); in bfq_select_queue()
4524 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
4529 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
4531 bfq_log(bfqd, "select_queue: no queue returned"); in bfq_select_queue()
4536 static void bfq_update_wr_data(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_update_wr_data() argument
4541 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
4549 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
4560 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
4562 bfq_wr_duration(bfqd))) in bfq_update_wr_data()
4565 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
4570 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
4592 static struct request *bfq_dispatch_rq_from_bfqq(struct bfq_data *bfqd, in bfq_dispatch_rq_from_bfqq() argument
4602 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
4603 bfqd->wait_dispatch = false; in bfq_dispatch_rq_from_bfqq()
4604 bfqd->waited_rq = rq; in bfq_dispatch_rq_from_bfqq()
4607 bfq_dispatch_remove(bfqd->queue, rq); in bfq_dispatch_rq_from_bfqq()
4609 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
4623 bfq_update_wr_data(bfqd, bfqq); in bfq_dispatch_rq_from_bfqq()
4630 if (!(bfq_tot_busy_queues(bfqd) > 1 && bfq_class_idle(bfqq))) in bfq_dispatch_rq_from_bfqq()
4633 bfq_bfqq_expire(bfqd, bfqq, false, BFQQE_BUDGET_EXHAUSTED); in bfq_dispatch_rq_from_bfqq()
4641 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_has_work() local
4650 return !list_empty_careful(&bfqd->dispatch) || in bfq_has_work()
4651 bfq_tot_busy_queues(bfqd) > 0; in bfq_has_work()
4656 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in __bfq_dispatch_request() local
4660 if (!list_empty(&bfqd->dispatch)) { in __bfq_dispatch_request()
4661 rq = list_first_entry(&bfqd->dispatch, struct request, in __bfq_dispatch_request()
4705 bfq_log(bfqd, "dispatch requests: %d busy queues", in __bfq_dispatch_request()
4706 bfq_tot_busy_queues(bfqd)); in __bfq_dispatch_request()
4708 if (bfq_tot_busy_queues(bfqd) == 0) in __bfq_dispatch_request()
4723 if (bfqd->strict_guarantees && bfqd->rq_in_driver > 0) in __bfq_dispatch_request()
4726 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
4730 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
4734 bfqd->rq_in_driver++; in __bfq_dispatch_request()
4796 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_dispatch_request() local
4801 spin_lock_irq(&bfqd->lock); in bfq_dispatch_request()
4803 in_serv_queue = bfqd->in_service_queue; in bfq_dispatch_request()
4811 spin_unlock_irq(&bfqd->lock); in bfq_dispatch_request()
4832 if (bfqq->bfqd) in bfq_put_queue()
4833 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", in bfq_put_queue()
4868 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
4869 bfqq->bfqd->burst_size--; in bfq_put_queue()
4899 if (bfqq->bfqd && bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
4900 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
4925 static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_exit_bfqq() argument
4927 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
4928 __bfq_bfqq_expire(bfqd, bfqq, BFQQE_BUDGET_TIMEOUT); in bfq_exit_bfqq()
4929 bfq_schedule_dispatch(bfqd); in bfq_exit_bfqq()
4932 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
4936 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
4942 struct bfq_data *bfqd; in bfq_exit_icq_bfqq() local
4945 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
4947 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
4950 spin_lock_irqsave(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
4952 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
4954 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
4975 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data() local
4977 if (!bfqd) in bfq_set_next_ioprio_data()
4984 bdi_dev_name(bfqq->bfqd->queue->backing_dev_info), in bfq_set_next_ioprio_data()
5018 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd,
5024 struct bfq_data *bfqd = bic_to_bfqd(bic); in bfq_check_ioprio_change() local
5032 if (unlikely(!bfqd) || likely(bic->ioprio == ioprio)) in bfq_check_ioprio_change()
5039 bfq_release_process_ref(bfqd, bfqq); in bfq_check_ioprio_change()
5040 bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic); in bfq_check_ioprio_change()
5049 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5059 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5086 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5109 static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd, in bfq_async_queue_prio() argument
5128 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd, in bfq_get_queue() argument
5140 bfqg = bfq_find_set_group(bfqd, __bio_blkcg(bio)); in bfq_get_queue()
5142 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5147 async_bfqq = bfq_async_queue_prio(bfqd, bfqg, ioprio_class, in bfq_get_queue()
5156 bfqd->queue->node); in bfq_get_queue()
5159 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5162 bfq_log_bfqq(bfqd, bfqq, "allocated"); in bfq_get_queue()
5164 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5165 bfq_log_bfqq(bfqd, bfqq, "using oom bfqq"); in bfq_get_queue()
5181 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5188 bfq_log_bfqq(bfqd, bfqq, "get_queue, at end: %p, %d", bfqq, bfqq->ref); in bfq_get_queue()
5193 static void bfq_update_io_thinktime(struct bfq_data *bfqd, in bfq_update_io_thinktime() argument
5199 elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle); in bfq_update_io_thinktime()
5208 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5212 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5215 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5220 static void bfq_update_has_short_ttime(struct bfq_data *bfqd, in bfq_update_has_short_ttime() argument
5232 bfqd->bfq_slice_idle == 0) in bfq_update_has_short_ttime()
5237 bfqd->bfq_wr_min_idle_time)) in bfq_update_has_short_ttime()
5246 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle)) in bfq_update_has_short_ttime()
5344 bfq_reset_inject_limit(bfqd, bfqq); in bfq_update_has_short_ttime()
5351 static void bfq_rq_enqueued(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_rq_enqueued() argument
5359 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
5380 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
5392 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_rq_enqueued()
5402 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
5408 static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq) in __bfq_insert_request() argument
5411 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true); in __bfq_insert_request()
5431 bfq_merge_bfqqs(bfqd, RQ_BIC(rq), in __bfq_insert_request()
5444 bfq_update_io_thinktime(bfqd, bfqq); in __bfq_insert_request()
5445 bfq_update_has_short_ttime(bfqd, bfqq, RQ_BIC(rq)); in __bfq_insert_request()
5446 bfq_update_io_seektime(bfqd, bfqq, rq); in __bfq_insert_request()
5452 rq->fifo_time = ktime_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; in __bfq_insert_request()
5455 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
5496 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_insert_request() local
5505 spin_lock_irq(&bfqd->lock); in bfq_insert_request()
5507 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
5511 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
5515 spin_lock_irq(&bfqd->lock); in bfq_insert_request()
5519 list_add(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
5521 list_add_tail(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
5523 idle_timer_disabled = __bfq_insert_request(bfqd, rq); in bfq_insert_request()
5545 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
5564 static void bfq_update_hw_tag(struct bfq_data *bfqd) in bfq_update_hw_tag() argument
5566 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag()
5568 bfqd->max_rq_in_driver = max_t(int, bfqd->max_rq_in_driver, in bfq_update_hw_tag()
5569 bfqd->rq_in_driver); in bfq_update_hw_tag()
5571 if (bfqd->hw_tag == 1) in bfq_update_hw_tag()
5580 if (bfqd->rq_in_driver + bfqd->queued <= BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
5591 bfqd->rq_in_driver < BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
5594 if (bfqd->hw_tag_samples++ < BFQ_HW_QUEUE_SAMPLES) in bfq_update_hw_tag()
5597 bfqd->hw_tag = bfqd->max_rq_in_driver > BFQ_HW_QUEUE_THRESHOLD; in bfq_update_hw_tag()
5598 bfqd->max_rq_in_driver = 0; in bfq_update_hw_tag()
5599 bfqd->hw_tag_samples = 0; in bfq_update_hw_tag()
5601 bfqd->nonrot_with_queueing = in bfq_update_hw_tag()
5602 blk_queue_nonrot(bfqd->queue) && bfqd->hw_tag; in bfq_update_hw_tag()
5605 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
5610 bfq_update_hw_tag(bfqd); in bfq_completed_request()
5612 bfqd->rq_in_driver--; in bfq_completed_request()
5624 bfq_weights_tree_remove(bfqd, bfqq); in bfq_completed_request()
5635 delta_us = div_u64(now_ns - bfqd->last_completion, NSEC_PER_USEC); in bfq_completed_request()
5654 (bfqd->last_rq_max_size<<BFQ_RATE_SHIFT)/delta_us < in bfq_completed_request()
5656 bfq_update_rate_reset(bfqd, NULL); in bfq_completed_request()
5657 bfqd->last_completion = now_ns; in bfq_completed_request()
5658 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
5673 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
5675 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_completed_request()
5681 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
5684 bfq_arm_slice_timer(bfqd); in bfq_completed_request()
5710 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5715 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
5719 if (!bfqd->rq_in_driver) in bfq_completed_request()
5720 bfq_schedule_dispatch(bfqd); in bfq_completed_request()
5834 static void bfq_update_inject_limit(struct bfq_data *bfqd, in bfq_update_inject_limit() argument
5837 u64 tot_time_ns = ktime_get_ns() - bfqd->last_empty_occupied_ns; in bfq_update_inject_limit()
5840 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
5847 old_limit <= bfqd->max_rq_in_driver) in bfq_update_inject_limit()
5863 if ((bfqq->last_serv_time_ns == 0 && bfqd->rq_in_driver == 1) || in bfq_update_inject_limit()
5873 } else if (!bfqd->rqs_injected && bfqd->rq_in_driver == 1) in bfq_update_inject_limit()
5887 bfqd->waited_rq = NULL; in bfq_update_inject_limit()
5888 bfqd->rqs_injected = false; in bfq_update_inject_limit()
5900 struct bfq_data *bfqd; in bfq_finish_requeue_request() local
5910 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
5921 spin_lock_irqsave(&bfqd->lock, flags); in bfq_finish_requeue_request()
5923 if (rq == bfqd->waited_rq) in bfq_finish_requeue_request()
5924 bfq_update_inject_limit(bfqd, bfqq); in bfq_finish_requeue_request()
5926 bfq_completed_request(bfqq, bfqd); in bfq_finish_requeue_request()
5930 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_finish_requeue_request()
5983 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
5996 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6000 static struct bfq_queue *bfq_get_bfqq_handle_split(struct bfq_data *bfqd, in bfq_get_bfqq_handle_split() argument
6008 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6016 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic); in bfq_get_bfqq_handle_split()
6020 if ((bic->was_in_burst_list && bfqd->large_burst) || in bfq_get_bfqq_handle_split()
6055 &bfqd->burst_list); in bfq_get_bfqq_handle_split()
6106 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_init_rq() local
6132 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6138 bfq_log_bfqq(bfqd, bfqq, "breaking apart bfqq"); in bfq_init_rq()
6148 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6158 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6170 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6178 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6204 (bfqd->burst_size > 0 || in bfq_init_rq()
6205 bfq_tot_busy_queues(bfqd) == 0))) in bfq_init_rq()
6206 bfq_handle_burst(bfqd, bfqq); in bfq_init_rq()
6212 bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_idle_slice_timer_body() argument
6217 spin_lock_irqsave(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6226 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6227 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6251 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
6254 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6255 bfq_schedule_dispatch(bfqd); in bfq_idle_slice_timer_body()
6264 struct bfq_data *bfqd = container_of(timer, struct bfq_data, in bfq_idle_slice_timer() local
6266 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer()
6277 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
6282 static void __bfq_put_async_bfqq(struct bfq_data *bfqd, in __bfq_put_async_bfqq() argument
6287 bfq_log(bfqd, "put_async_bfqq: %p", bfqq); in __bfq_put_async_bfqq()
6289 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
6291 bfq_log_bfqq(bfqd, bfqq, "put_async_bfqq: putting %p, %d", in __bfq_put_async_bfqq()
6304 void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg) in bfq_put_async_queues() argument
6310 __bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j]); in bfq_put_async_queues()
6312 __bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq); in bfq_put_async_queues()
6319 static unsigned int bfq_update_depths(struct bfq_data *bfqd, in bfq_update_depths() argument
6335 bfqd->word_depths[0][0] = max((1U << bt->sb.shift) >> 1, 1U); in bfq_update_depths()
6341 bfqd->word_depths[0][1] = max(((1U << bt->sb.shift) * 3) >> 2, 1U); in bfq_update_depths()
6351 bfqd->word_depths[1][0] = max(((1U << bt->sb.shift) * 3) >> 4, 1U); in bfq_update_depths()
6353 bfqd->word_depths[1][1] = max(((1U << bt->sb.shift) * 6) >> 4, 1U); in bfq_update_depths()
6357 min_shallow = min(min_shallow, bfqd->word_depths[i][j]); in bfq_update_depths()
6364 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_depth_updated() local
6368 min_shallow = bfq_update_depths(bfqd, tags->bitmap_tags); in bfq_depth_updated()
6380 struct bfq_data *bfqd = e->elevator_data; in bfq_exit_queue() local
6383 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
6385 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
6386 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
6387 bfq_deactivate_bfqq(bfqd, bfqq, false, false); in bfq_exit_queue()
6388 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
6390 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
6393 bfqg_and_blkg_put(bfqd->root_group); in bfq_exit_queue()
6396 blkcg_deactivate_policy(bfqd->queue, &blkcg_policy_bfq); in bfq_exit_queue()
6398 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
6399 bfq_put_async_queues(bfqd, bfqd->root_group); in bfq_exit_queue()
6400 kfree(bfqd->root_group); in bfq_exit_queue()
6401 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
6404 kfree(bfqd); in bfq_exit_queue()
6408 struct bfq_data *bfqd) in bfq_init_root_group() argument
6415 root_group->bfqd = bfqd; in bfq_init_root_group()
6425 struct bfq_data *bfqd; in bfq_init_queue() local
6432 bfqd = kzalloc_node(sizeof(*bfqd), GFP_KERNEL, q->node); in bfq_init_queue()
6433 if (!bfqd) { in bfq_init_queue()
6437 eq->elevator_data = bfqd; in bfq_init_queue()
6448 bfq_init_bfqq(bfqd, &bfqd->oom_bfqq, NULL, 1, 0); in bfq_init_queue()
6449 bfqd->oom_bfqq.ref++; in bfq_init_queue()
6450 bfqd->oom_bfqq.new_ioprio = BFQ_DEFAULT_QUEUE_IOPRIO; in bfq_init_queue()
6451 bfqd->oom_bfqq.new_ioprio_class = IOPRIO_CLASS_BE; in bfq_init_queue()
6452 bfqd->oom_bfqq.entity.new_weight = in bfq_init_queue()
6453 bfq_ioprio_to_weight(bfqd->oom_bfqq.new_ioprio); in bfq_init_queue()
6456 bfq_clear_bfqq_just_created(&bfqd->oom_bfqq); in bfq_init_queue()
6463 bfqd->oom_bfqq.entity.prio_changed = 1; in bfq_init_queue()
6465 bfqd->queue = q; in bfq_init_queue()
6467 INIT_LIST_HEAD(&bfqd->dispatch); in bfq_init_queue()
6469 hrtimer_init(&bfqd->idle_slice_timer, CLOCK_MONOTONIC, in bfq_init_queue()
6471 bfqd->idle_slice_timer.function = bfq_idle_slice_timer; in bfq_init_queue()
6473 bfqd->queue_weights_tree = RB_ROOT_CACHED; in bfq_init_queue()
6474 bfqd->num_groups_with_pending_reqs = 0; in bfq_init_queue()
6476 INIT_LIST_HEAD(&bfqd->active_list); in bfq_init_queue()
6477 INIT_LIST_HEAD(&bfqd->idle_list); in bfq_init_queue()
6478 INIT_HLIST_HEAD(&bfqd->burst_list); in bfq_init_queue()
6480 bfqd->hw_tag = -1; in bfq_init_queue()
6481 bfqd->nonrot_with_queueing = blk_queue_nonrot(bfqd->queue); in bfq_init_queue()
6483 bfqd->bfq_max_budget = bfq_default_max_budget; in bfq_init_queue()
6485 bfqd->bfq_fifo_expire[0] = bfq_fifo_expire[0]; in bfq_init_queue()
6486 bfqd->bfq_fifo_expire[1] = bfq_fifo_expire[1]; in bfq_init_queue()
6487 bfqd->bfq_back_max = bfq_back_max; in bfq_init_queue()
6488 bfqd->bfq_back_penalty = bfq_back_penalty; in bfq_init_queue()
6489 bfqd->bfq_slice_idle = bfq_slice_idle; in bfq_init_queue()
6490 bfqd->bfq_timeout = bfq_timeout; in bfq_init_queue()
6492 bfqd->bfq_requests_within_timer = 120; in bfq_init_queue()
6494 bfqd->bfq_large_burst_thresh = 8; in bfq_init_queue()
6495 bfqd->bfq_burst_interval = msecs_to_jiffies(180); in bfq_init_queue()
6497 bfqd->low_latency = true; in bfq_init_queue()
6502 bfqd->bfq_wr_coeff = 30; in bfq_init_queue()
6503 bfqd->bfq_wr_rt_max_time = msecs_to_jiffies(300); in bfq_init_queue()
6504 bfqd->bfq_wr_max_time = 0; in bfq_init_queue()
6505 bfqd->bfq_wr_min_idle_time = msecs_to_jiffies(2000); in bfq_init_queue()
6506 bfqd->bfq_wr_min_inter_arr_async = msecs_to_jiffies(500); in bfq_init_queue()
6507 bfqd->bfq_wr_max_softrt_rate = 7000; /* in bfq_init_queue()
6513 bfqd->wr_busy_queues = 0; in bfq_init_queue()
6519 bfqd->rate_dur_prod = ref_rate[blk_queue_nonrot(bfqd->queue)] * in bfq_init_queue()
6520 ref_wr_duration[blk_queue_nonrot(bfqd->queue)]; in bfq_init_queue()
6521 bfqd->peak_rate = ref_rate[blk_queue_nonrot(bfqd->queue)] * 2 / 3; in bfq_init_queue()
6523 spin_lock_init(&bfqd->lock); in bfq_init_queue()
6540 bfqd->root_group = bfq_create_group_hierarchy(bfqd, q->node); in bfq_init_queue()
6541 if (!bfqd->root_group) in bfq_init_queue()
6543 bfq_init_root_group(bfqd->root_group, bfqd); in bfq_init_queue()
6544 bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group); in bfq_init_queue()
6550 kfree(bfqd); in bfq_init_queue()
6587 struct bfq_data *bfqd = e->elevator_data; \
6595 SHOW_FUNCTION(bfq_fifo_expire_sync_show, bfqd->bfq_fifo_expire[1], 2);
6596 SHOW_FUNCTION(bfq_fifo_expire_async_show, bfqd->bfq_fifo_expire[0], 2);
6597 SHOW_FUNCTION(bfq_back_seek_max_show, bfqd->bfq_back_max, 0);
6598 SHOW_FUNCTION(bfq_back_seek_penalty_show, bfqd->bfq_back_penalty, 0);
6599 SHOW_FUNCTION(bfq_slice_idle_show, bfqd->bfq_slice_idle, 2);
6600 SHOW_FUNCTION(bfq_max_budget_show, bfqd->bfq_user_max_budget, 0);
6601 SHOW_FUNCTION(bfq_timeout_sync_show, bfqd->bfq_timeout, 1);
6602 SHOW_FUNCTION(bfq_strict_guarantees_show, bfqd->strict_guarantees, 0);
6603 SHOW_FUNCTION(bfq_low_latency_show, bfqd->low_latency, 0);
6609 struct bfq_data *bfqd = e->elevator_data; \
6614 USEC_SHOW_FUNCTION(bfq_slice_idle_us_show, bfqd->bfq_slice_idle);
6621 struct bfq_data *bfqd = e->elevator_data; \
6640 STORE_FUNCTION(bfq_fifo_expire_sync_store, &bfqd->bfq_fifo_expire[1], 1,
6642 STORE_FUNCTION(bfq_fifo_expire_async_store, &bfqd->bfq_fifo_expire[0], 1,
6644 STORE_FUNCTION(bfq_back_seek_max_store, &bfqd->bfq_back_max, 0, INT_MAX, 0);
6645 STORE_FUNCTION(bfq_back_seek_penalty_store, &bfqd->bfq_back_penalty, 1,
6647 STORE_FUNCTION(bfq_slice_idle_store, &bfqd->bfq_slice_idle, 0, INT_MAX, 2);
6653 struct bfq_data *bfqd = e->elevator_data; \
6667 USEC_STORE_FUNCTION(bfq_slice_idle_us_store, &bfqd->bfq_slice_idle, 0,
6674 struct bfq_data *bfqd = e->elevator_data; in bfq_max_budget_store() local
6683 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_max_budget_store()
6687 bfqd->bfq_max_budget = __data; in bfq_max_budget_store()
6690 bfqd->bfq_user_max_budget = __data; in bfq_max_budget_store()
6702 struct bfq_data *bfqd = e->elevator_data; in bfq_timeout_sync_store() local
6715 bfqd->bfq_timeout = msecs_to_jiffies(__data); in bfq_timeout_sync_store()
6716 if (bfqd->bfq_user_max_budget == 0) in bfq_timeout_sync_store()
6717 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_timeout_sync_store()
6725 struct bfq_data *bfqd = e->elevator_data; in bfq_strict_guarantees_store() local
6735 if (!bfqd->strict_guarantees && __data == 1 in bfq_strict_guarantees_store()
6736 && bfqd->bfq_slice_idle < 8 * NSEC_PER_MSEC) in bfq_strict_guarantees_store()
6737 bfqd->bfq_slice_idle = 8 * NSEC_PER_MSEC; in bfq_strict_guarantees_store()
6739 bfqd->strict_guarantees = __data; in bfq_strict_guarantees_store()
6747 struct bfq_data *bfqd = e->elevator_data; in bfq_low_latency_store() local
6757 if (__data == 0 && bfqd->low_latency != 0) in bfq_low_latency_store()
6758 bfq_end_wr(bfqd); in bfq_low_latency_store()
6759 bfqd->low_latency = __data; in bfq_low_latency_store()