Lines Matching refs:bfqd

232 #define BFQ_RQ_SEEKY(bfqd, last_pos, rq) \  argument
235 (!blk_queue_nonrot(bfqd->queue) || \
457 void bfq_schedule_dispatch(struct bfq_data *bfqd) in bfq_schedule_dispatch() argument
459 lockdep_assert_held(&bfqd->lock); in bfq_schedule_dispatch()
461 if (bfqd->queued != 0) { in bfq_schedule_dispatch()
462 bfq_log(bfqd, "schedule dispatch"); in bfq_schedule_dispatch()
463 blk_mq_run_hw_queues(bfqd->queue, true); in bfq_schedule_dispatch()
476 static struct request *bfq_choose_req(struct bfq_data *bfqd, in bfq_choose_req() argument
507 back_max = bfqd->bfq_back_max * 2; in bfq_choose_req()
517 d1 = (last - s1) * bfqd->bfq_back_penalty; in bfq_choose_req()
524 d2 = (last - s2) * bfqd->bfq_back_penalty; in bfq_choose_req()
570 struct bfq_data *bfqd = bfqq->bfqd; in bfqq_request_over_limit() local
584 spin_lock_irq(&bfqd->lock); in bfqq_request_over_limit()
588 spin_unlock_irq(&bfqd->lock); in bfqq_request_over_limit()
636 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfqq_request_over_limit()
644 spin_unlock_irq(&bfqd->lock); in bfqq_request_over_limit()
673 struct bfq_data *bfqd = data->q->elevator->elevator_data; in bfq_limit_depth() local
683 depth = bfqd->word_depths[!!bfqd->wr_busy_queues][op_is_sync(opf)]; in bfq_limit_depth()
684 limit = (limit * depth) >> bfqd->full_depth_shift; in bfq_limit_depth()
695 bfq_log(bfqd, "[%s] wr_busy %d sync %d depth %u", in bfq_limit_depth()
696 __func__, bfqd->wr_busy_queues, op_is_sync(opf), depth); in bfq_limit_depth()
702 bfq_rq_pos_tree_lookup(struct bfq_data *bfqd, struct rb_root *root, in bfq_rq_pos_tree_lookup() argument
735 bfq_log(bfqd, "rq_pos_tree_lookup %llu: returning %d", in bfq_rq_pos_tree_lookup()
758 bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_pos_tree_add_move() argument
769 if (bfqq == &bfqd->oom_bfqq) in bfq_pos_tree_add_move()
786 __bfqq = bfq_rq_pos_tree_lookup(bfqd, bfqq->pos_root, in bfq_pos_tree_add_move()
828 static bool bfq_asymmetric_scenario(struct bfq_data *bfqd, in bfq_asymmetric_scenario() argument
835 rb_first_cached(&bfqd->queue_weights_tree), in bfq_asymmetric_scenario()
844 !RB_EMPTY_ROOT(&bfqd->queue_weights_tree.rb_root) && in bfq_asymmetric_scenario()
845 (bfqd->queue_weights_tree.rb_root.rb_node->rb_left || in bfq_asymmetric_scenario()
846 bfqd->queue_weights_tree.rb_root.rb_node->rb_right); in bfq_asymmetric_scenario()
849 (bfqd->busy_queues[0] && bfqd->busy_queues[1]) || in bfq_asymmetric_scenario()
850 (bfqd->busy_queues[0] && bfqd->busy_queues[2]) || in bfq_asymmetric_scenario()
851 (bfqd->busy_queues[1] && bfqd->busy_queues[2]); in bfq_asymmetric_scenario()
855 || bfqd->num_groups_with_pending_reqs > 0 in bfq_asymmetric_scenario()
873 void bfq_weights_tree_add(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_weights_tree_add() argument
947 void __bfq_weights_tree_remove(struct bfq_data *bfqd, in __bfq_weights_tree_remove() argument
970 void bfq_weights_tree_remove(struct bfq_data *bfqd, in bfq_weights_tree_remove() argument
1005 bfqd->num_groups_with_pending_reqs--; in bfq_weights_tree_remove()
1015 __bfq_weights_tree_remove(bfqd, bfqq, in bfq_weights_tree_remove()
1016 &bfqd->queue_weights_tree); in bfq_weights_tree_remove()
1037 bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); in bfq_check_fifo()
1041 static struct request *bfq_find_next_rq(struct bfq_data *bfqd, in bfq_find_next_rq() argument
1065 return bfq_choose_req(bfqd, next, prev, blk_rq_pos(last)); in bfq_find_next_rq()
1073 bfq_asymmetric_scenario(bfqq->bfqd, bfqq)) in bfq_serv_to_charge()
1090 static void bfq_updated_next_req(struct bfq_data *bfqd, in bfq_updated_next_req() argument
1100 if (bfqq == bfqd->in_service_queue) in bfq_updated_next_req()
1113 bfq_log_bfqq(bfqd, bfqq, "updated next rq: new budget %lu", in bfq_updated_next_req()
1115 bfq_requeue_bfqq(bfqd, bfqq, false); in bfq_updated_next_req()
1119 static unsigned int bfq_wr_duration(struct bfq_data *bfqd) in bfq_wr_duration() argument
1123 if (bfqd->bfq_wr_max_time > 0) in bfq_wr_duration()
1124 return bfqd->bfq_wr_max_time; in bfq_wr_duration()
1126 dur = bfqd->rate_dur_prod; in bfq_wr_duration()
1127 do_div(dur, bfqd->peak_rate); in bfq_wr_duration()
1154 struct bfq_data *bfqd) in switch_back_to_interactive_wr() argument
1156 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in switch_back_to_interactive_wr()
1157 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in switch_back_to_interactive_wr()
1162 bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, in bfq_bfqq_resume_state() argument
1189 if (bfqd->low_latency) { in bfq_bfqq_resume_state()
1201 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_bfqq_resume_state()
1204 bfq_wr_duration(bfqd))) { in bfq_bfqq_resume_state()
1205 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_bfqq_resume_state()
1208 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_bfqq_resume_state()
1220 bfqd->wr_busy_queues++; in bfq_bfqq_resume_state()
1222 bfqd->wr_busy_queues--; in bfq_bfqq_resume_state()
1233 static void bfq_reset_burst_list(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_reset_burst_list() argument
1238 hlist_for_each_entry_safe(item, n, &bfqd->burst_list, burst_list_node) in bfq_reset_burst_list()
1246 if (bfq_tot_busy_queues(bfqd) == 0) { in bfq_reset_burst_list()
1247 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_reset_burst_list()
1248 bfqd->burst_size = 1; in bfq_reset_burst_list()
1250 bfqd->burst_size = 0; in bfq_reset_burst_list()
1252 bfqd->burst_parent_entity = bfqq->entity.parent; in bfq_reset_burst_list()
1256 static void bfq_add_to_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_add_to_burst() argument
1259 bfqd->burst_size++; in bfq_add_to_burst()
1261 if (bfqd->burst_size == bfqd->bfq_large_burst_thresh) { in bfq_add_to_burst()
1269 bfqd->large_burst = true; in bfq_add_to_burst()
1275 hlist_for_each_entry(bfqq_item, &bfqd->burst_list, in bfq_add_to_burst()
1287 hlist_for_each_entry_safe(pos, n, &bfqd->burst_list, in bfq_add_to_burst()
1296 hlist_add_head(&bfqq->burst_list_node, &bfqd->burst_list); in bfq_add_to_burst()
1408 static void bfq_handle_burst(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_handle_burst() argument
1438 if (time_is_before_jiffies(bfqd->last_ins_in_burst + in bfq_handle_burst()
1439 bfqd->bfq_burst_interval) || in bfq_handle_burst()
1440 bfqq->entity.parent != bfqd->burst_parent_entity) { in bfq_handle_burst()
1441 bfqd->large_burst = false; in bfq_handle_burst()
1442 bfq_reset_burst_list(bfqd, bfqq); in bfq_handle_burst()
1451 if (bfqd->large_burst) { in bfq_handle_burst()
1461 bfq_add_to_burst(bfqd, bfqq); in bfq_handle_burst()
1471 bfqd->last_ins_in_burst = jiffies; in bfq_handle_burst()
1486 static int bfq_max_budget(struct bfq_data *bfqd) in bfq_max_budget() argument
1488 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_max_budget()
1491 return bfqd->bfq_max_budget; in bfq_max_budget()
1498 static int bfq_min_budget(struct bfq_data *bfqd) in bfq_min_budget() argument
1500 if (bfqd->budgets_assigned < bfq_stats_min_budgets) in bfq_min_budget()
1503 return bfqd->bfq_max_budget / 32; in bfq_min_budget()
1610 static bool bfq_bfqq_update_budg_for_activation(struct bfq_data *bfqd, in bfq_bfqq_update_budg_for_activation() argument
1679 static void bfq_update_bfqq_wr_on_rq_arrival(struct bfq_data *bfqd, in bfq_update_bfqq_wr_on_rq_arrival() argument
1691 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1692 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1707 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1710 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1724 2 * bfq_min_budget(bfqd)); in bfq_update_bfqq_wr_on_rq_arrival()
1727 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_update_bfqq_wr_on_rq_arrival()
1728 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_update_bfqq_wr_on_rq_arrival()
1762 bfqd->bfq_wr_rt_max_time) { in bfq_update_bfqq_wr_on_rq_arrival()
1767 bfqd->bfq_wr_rt_max_time; in bfq_update_bfqq_wr_on_rq_arrival()
1768 bfqq->wr_coeff = bfqd->bfq_wr_coeff * in bfq_update_bfqq_wr_on_rq_arrival()
1776 static bool bfq_bfqq_idle_for_long_time(struct bfq_data *bfqd, in bfq_bfqq_idle_for_long_time() argument
1782 bfqd->bfq_wr_min_idle_time); in bfq_bfqq_idle_for_long_time()
1817 static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd, in bfq_bfqq_handle_idle_busy_switch() argument
1825 idle_for_long_time = bfq_bfqq_idle_for_long_time(bfqd, bfqq), in bfq_bfqq_handle_idle_busy_switch()
1833 bfqd->bfq_slice_idle * 3; in bfq_bfqq_handle_idle_busy_switch()
1846 soft_rt = bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_handle_idle_busy_switch()
1866 wr_or_deserves_wr = bfqd->low_latency && in bfq_bfqq_handle_idle_busy_switch()
1877 bfq_bfqq_update_budg_for_activation(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1904 if (bfqd->low_latency) { in bfq_bfqq_handle_idle_busy_switch()
1908 jiffies - bfqd->bfq_wr_min_idle_time - 1; in bfq_bfqq_handle_idle_busy_switch()
1911 bfqd->bfq_wr_min_idle_time)) { in bfq_bfqq_handle_idle_busy_switch()
1912 bfq_update_bfqq_wr_on_rq_arrival(bfqd, bfqq, in bfq_bfqq_handle_idle_busy_switch()
1973 if (bfqd->in_service_queue && in bfq_bfqq_handle_idle_busy_switch()
1975 bfqq->wr_coeff >= bfqd->in_service_queue->wr_coeff) || in bfq_bfqq_handle_idle_busy_switch()
1976 bfq_bfqq_higher_class_or_weight(bfqq, bfqd->in_service_queue) || in bfq_bfqq_handle_idle_busy_switch()
1977 !bfq_better_to_idle(bfqd->in_service_queue)) && in bfq_bfqq_handle_idle_busy_switch()
1978 next_queue_may_preempt(bfqd)) in bfq_bfqq_handle_idle_busy_switch()
1979 bfq_bfqq_expire(bfqd, bfqd->in_service_queue, in bfq_bfqq_handle_idle_busy_switch()
1983 static void bfq_reset_inject_limit(struct bfq_data *bfqd, in bfq_reset_inject_limit() argument
1993 bfqd->waited_rq = NULL; in bfq_reset_inject_limit()
2130 static void bfq_check_waker(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_check_waker() argument
2135 if (!bfqd->last_completed_rq_bfqq || in bfq_check_waker()
2136 bfqd->last_completed_rq_bfqq == bfqq || in bfq_check_waker()
2138 now_ns - bfqd->last_completion >= 4 * NSEC_PER_MSEC) in bfq_check_waker()
2147 if (bfqd->last_completed_rq_bfqq != in bfq_check_waker()
2150 128 * (u64)bfqd->bfq_slice_idle) { in bfq_check_waker()
2157 bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2162 bfq_log_bfqq(bfqd, bfqq, "set tentative waker %s", waker_name); in bfq_check_waker()
2167 bfqq->waker_bfqq = bfqd->last_completed_rq_bfqq; in bfq_check_waker()
2171 bfq_log_bfqq(bfqd, bfqq, "set waker %s", waker_name); in bfq_check_waker()
2196 &bfqd->last_completed_rq_bfqq->woken_list); in bfq_check_waker()
2203 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_request() local
2209 bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); in bfq_add_request()
2215 WRITE_ONCE(bfqd->queued, bfqd->queued + 1); in bfq_add_request()
2218 bfq_check_waker(bfqd, bfqq, now_ns); in bfq_add_request()
2228 bfq_reset_inject_limit(bfqd, bfqq); in bfq_add_request()
2255 if (bfqq == bfqd->in_service_queue && in bfq_add_request()
2256 (bfqd->rq_in_driver == 0 || in bfq_add_request()
2258 bfqd->rqs_injected && bfqd->rq_in_driver > 0)) && in bfq_add_request()
2261 bfqd->last_empty_occupied_ns = ktime_get_ns(); in bfq_add_request()
2268 bfqd->wait_dispatch = true; in bfq_add_request()
2282 if (bfqd->rq_in_driver == 0) in bfq_add_request()
2283 bfqd->rqs_injected = false; in bfq_add_request()
2296 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, rq, bfqd->last_position); in bfq_add_request()
2303 if (unlikely(!bfqd->nonrot_with_queueing && prev != bfqq->next_rq)) in bfq_add_request()
2304 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_add_request()
2307 bfq_bfqq_handle_idle_busy_switch(bfqd, bfqq, old_wr_coeff, in bfq_add_request()
2310 if (bfqd->low_latency && old_wr_coeff == 1 && !rq_is_sync(rq) && in bfq_add_request()
2313 bfqd->bfq_wr_min_inter_arr_async)) { in bfq_add_request()
2314 bfqq->wr_coeff = bfqd->bfq_wr_coeff; in bfq_add_request()
2315 bfqq->wr_cur_max_time = bfq_wr_duration(bfqd); in bfq_add_request()
2317 bfqd->wr_busy_queues++; in bfq_add_request()
2321 bfq_updated_next_req(bfqd, bfqq); in bfq_add_request()
2350 if (bfqd->low_latency && in bfq_add_request()
2355 static struct request *bfq_find_rq_fmerge(struct bfq_data *bfqd, in bfq_find_rq_fmerge() argument
2359 struct bfq_queue *bfqq = bfqd->bio_bfqq; in bfq_find_rq_fmerge()
2379 struct bfq_data *bfqd = q->elevator->elevator_data;
2381 bfqd->rq_in_driver++;
2386 struct bfq_data *bfqd = q->elevator->elevator_data;
2388 bfqd->rq_in_driver--;
2396 struct bfq_data *bfqd = bfqq->bfqd; in bfq_remove_request() local
2400 bfqq->next_rq = bfq_find_next_rq(bfqd, bfqq, rq); in bfq_remove_request()
2401 bfq_updated_next_req(bfqd, bfqq); in bfq_remove_request()
2411 WRITE_ONCE(bfqd->queued, bfqd->queued - 1); in bfq_remove_request()
2421 if (bfq_bfqq_busy(bfqq) && bfqq != bfqd->in_service_queue) { in bfq_remove_request()
2448 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_remove_request()
2449 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_remove_request()
2460 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_bio_merge() local
2472 spin_lock_irq(&bfqd->lock); in bfq_bio_merge()
2481 bfqd->bio_bfqq = bic_to_bfqq(bic, op_is_sync(bio->bi_opf)); in bfq_bio_merge()
2483 bfqd->bio_bfqq = NULL; in bfq_bio_merge()
2485 bfqd->bio_bic = bic; in bfq_bio_merge()
2489 spin_unlock_irq(&bfqd->lock); in bfq_bio_merge()
2499 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_request_merge() local
2502 __rq = bfq_find_rq_fmerge(bfqd, bio, q); in bfq_request_merge()
2523 struct bfq_data *bfqd; in bfq_request_merged() local
2529 bfqd = bfqq->bfqd; in bfq_request_merged()
2537 next_rq = bfq_choose_req(bfqd, bfqq->next_rq, req, in bfq_request_merged()
2538 bfqd->last_position); in bfq_request_merged()
2546 bfq_updated_next_req(bfqd, bfqq); in bfq_request_merged()
2551 if (unlikely(!bfqd->nonrot_with_queueing)) in bfq_request_merged()
2552 bfq_pos_tree_add_move(bfqd, bfqq); in bfq_request_merged()
2629 bfqq->bfqd->bfq_wr_rt_max_time) in bfq_bfqq_end_wr()
2633 bfqq->bfqd->wr_busy_queues--; in bfq_bfqq_end_wr()
2644 void bfq_end_wr_async_queues(struct bfq_data *bfqd, in bfq_end_wr_async_queues() argument
2657 static void bfq_end_wr(struct bfq_data *bfqd) in bfq_end_wr() argument
2661 spin_lock_irq(&bfqd->lock); in bfq_end_wr()
2663 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_end_wr()
2665 list_for_each_entry(bfqq, &bfqd->idle_list, bfqq_list) in bfq_end_wr()
2667 bfq_end_wr_async(bfqd); in bfq_end_wr()
2669 spin_unlock_irq(&bfqd->lock); in bfq_end_wr()
2687 static struct bfq_queue *bfqq_find_close(struct bfq_data *bfqd, in bfqq_find_close() argument
2702 __bfqq = bfq_rq_pos_tree_lookup(bfqd, root, sector, &parent, NULL); in bfqq_find_close()
2729 static struct bfq_queue *bfq_find_close_cooperator(struct bfq_data *bfqd, in bfq_find_close_cooperator() argument
2742 bfqq = bfqq_find_close(bfqd, cur_bfqq, sector); in bfq_find_close_cooperator()
2788 bfq_log_bfqq(bfqq->bfqd, bfqq, "scheduling merge with queue %d", in bfq_setup_merge()
2854 static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd,
2878 bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_setup_cooperator() argument
2896 if (unlikely(!bfqd->nonrot_with_queueing)) { in bfq_setup_cooperator()
2919 if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_setup_cooperator()
2974 if (likely(bfqd->nonrot_with_queueing)) in bfq_setup_cooperator()
2991 if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) in bfq_setup_cooperator()
2995 if (bfq_tot_busy_queues(bfqd) == 1) in bfq_setup_cooperator()
2998 in_service_bfqq = bfqd->in_service_queue; in bfq_setup_cooperator()
3001 likely(in_service_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
3003 bfqd->in_serv_last_pos) && in bfq_setup_cooperator()
3015 new_bfqq = bfq_find_close_cooperator(bfqd, bfqq, in bfq_setup_cooperator()
3018 if (new_bfqq && likely(new_bfqq != &bfqd->oom_bfqq) && in bfq_setup_cooperator()
3051 bfqq->bfqd->low_latency)) { in bfq_bfqq_save_state()
3061 bic->saved_wr_coeff = bfqq->bfqd->bfq_wr_coeff; in bfq_bfqq_save_state()
3063 bic->saved_wr_cur_max_time = bfq_wr_duration(bfqq->bfqd); in bfq_bfqq_save_state()
3082 else if (cur_bfqq->bfqd && cur_bfqq->bfqd->last_bfqq_created == cur_bfqq) in bfq_reassign_last_bfqq()
3083 cur_bfqq->bfqd->last_bfqq_created = new_bfqq; in bfq_reassign_last_bfqq()
3086 void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_release_process_ref() argument
3100 bfqq != bfqd->in_service_queue) in bfq_release_process_ref()
3109 bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic, in bfq_merge_bfqqs() argument
3112 bfq_log_bfqq(bfqd, bfqq, "merging with queue %lu", in bfq_merge_bfqqs()
3160 bfqd->wr_busy_queues++; in bfq_merge_bfqqs()
3168 bfqd->wr_busy_queues--; in bfq_merge_bfqqs()
3171 bfq_log_bfqq(bfqd, new_bfqq, "merge_bfqqs: wr_busy %d", in bfq_merge_bfqqs()
3172 bfqd->wr_busy_queues); in bfq_merge_bfqqs()
3204 bfq_release_process_ref(bfqd, bfqq); in bfq_merge_bfqqs()
3210 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_allow_bio_merge() local
3212 struct bfq_queue *bfqq = bfqd->bio_bfqq, *new_bfqq; in bfq_allow_bio_merge()
3231 new_bfqq = bfq_setup_cooperator(bfqd, bfqq, bio, false, bfqd->bio_bic); in bfq_allow_bio_merge()
3240 bfq_merge_bfqqs(bfqd, bfqd->bio_bic, bfqq, in bfq_allow_bio_merge()
3255 bfqd->bio_bfqq = bfqq; in bfq_allow_bio_merge()
3267 static void bfq_set_budget_timeout(struct bfq_data *bfqd, in bfq_set_budget_timeout() argument
3272 if (bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time) in bfq_set_budget_timeout()
3277 bfqd->last_budget_start = ktime_get(); in bfq_set_budget_timeout()
3280 bfqd->bfq_timeout * timeout_coeff; in bfq_set_budget_timeout()
3283 static void __bfq_set_in_service_queue(struct bfq_data *bfqd, in __bfq_set_in_service_queue() argument
3289 bfqd->budgets_assigned = (bfqd->budgets_assigned * 7 + 256) / 8; in __bfq_set_in_service_queue()
3293 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in __bfq_set_in_service_queue()
3327 bfq_set_budget_timeout(bfqd, bfqq); in __bfq_set_in_service_queue()
3328 bfq_log_bfqq(bfqd, bfqq, in __bfq_set_in_service_queue()
3333 bfqd->in_service_queue = bfqq; in __bfq_set_in_service_queue()
3334 bfqd->in_serv_last_pos = 0; in __bfq_set_in_service_queue()
3340 static struct bfq_queue *bfq_set_in_service_queue(struct bfq_data *bfqd) in bfq_set_in_service_queue() argument
3342 struct bfq_queue *bfqq = bfq_get_next_queue(bfqd); in bfq_set_in_service_queue()
3344 __bfq_set_in_service_queue(bfqd, bfqq); in bfq_set_in_service_queue()
3348 static void bfq_arm_slice_timer(struct bfq_data *bfqd) in bfq_arm_slice_timer() argument
3350 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_arm_slice_timer()
3360 sl = bfqd->bfq_slice_idle; in bfq_arm_slice_timer()
3372 !bfq_asymmetric_scenario(bfqd, bfqq)) in bfq_arm_slice_timer()
3377 bfqd->last_idling_start = ktime_get(); in bfq_arm_slice_timer()
3378 bfqd->last_idling_start_jiffies = jiffies; in bfq_arm_slice_timer()
3380 hrtimer_start(&bfqd->idle_slice_timer, ns_to_ktime(sl), in bfq_arm_slice_timer()
3392 static unsigned long bfq_calc_max_budget(struct bfq_data *bfqd) in bfq_calc_max_budget() argument
3394 return (u64)bfqd->peak_rate * USEC_PER_MSEC * in bfq_calc_max_budget()
3395 jiffies_to_msecs(bfqd->bfq_timeout)>>BFQ_RATE_SHIFT; in bfq_calc_max_budget()
3403 static void update_thr_responsiveness_params(struct bfq_data *bfqd) in update_thr_responsiveness_params() argument
3405 if (bfqd->bfq_user_max_budget == 0) { in update_thr_responsiveness_params()
3406 bfqd->bfq_max_budget = in update_thr_responsiveness_params()
3407 bfq_calc_max_budget(bfqd); in update_thr_responsiveness_params()
3408 bfq_log(bfqd, "new max_budget = %d", bfqd->bfq_max_budget); in update_thr_responsiveness_params()
3412 static void bfq_reset_rate_computation(struct bfq_data *bfqd, in bfq_reset_rate_computation() argument
3416 bfqd->last_dispatch = bfqd->first_dispatch = ktime_get_ns(); in bfq_reset_rate_computation()
3417 bfqd->peak_rate_samples = 1; in bfq_reset_rate_computation()
3418 bfqd->sequential_samples = 0; in bfq_reset_rate_computation()
3419 bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size = in bfq_reset_rate_computation()
3422 bfqd->peak_rate_samples = 0; /* full re-init on next disp. */ in bfq_reset_rate_computation()
3424 bfq_log(bfqd, in bfq_reset_rate_computation()
3426 bfqd->peak_rate_samples, bfqd->sequential_samples, in bfq_reset_rate_computation()
3427 bfqd->tot_sectors_dispatched); in bfq_reset_rate_computation()
3430 static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) in bfq_update_rate_reset() argument
3442 if (bfqd->peak_rate_samples < BFQ_RATE_MIN_SAMPLES || in bfq_update_rate_reset()
3443 bfqd->delta_from_first < BFQ_RATE_MIN_INTERVAL) in bfq_update_rate_reset()
3452 bfqd->delta_from_first = in bfq_update_rate_reset()
3453 max_t(u64, bfqd->delta_from_first, in bfq_update_rate_reset()
3454 bfqd->last_completion - bfqd->first_dispatch); in bfq_update_rate_reset()
3460 rate = div64_ul(bfqd->tot_sectors_dispatched<<BFQ_RATE_SHIFT, in bfq_update_rate_reset()
3461 div_u64(bfqd->delta_from_first, NSEC_PER_USEC)); in bfq_update_rate_reset()
3469 if ((bfqd->sequential_samples < (3 * bfqd->peak_rate_samples)>>2 && in bfq_update_rate_reset()
3470 rate <= bfqd->peak_rate) || in bfq_update_rate_reset()
3497 weight = (9 * bfqd->sequential_samples) / bfqd->peak_rate_samples; in bfq_update_rate_reset()
3504 div_u64(weight * bfqd->delta_from_first, in bfq_update_rate_reset()
3518 bfqd->peak_rate *= divisor-1; in bfq_update_rate_reset()
3519 bfqd->peak_rate /= divisor; in bfq_update_rate_reset()
3522 bfqd->peak_rate += rate; in bfq_update_rate_reset()
3531 bfqd->peak_rate = max_t(u32, 1, bfqd->peak_rate); in bfq_update_rate_reset()
3533 update_thr_responsiveness_params(bfqd); in bfq_update_rate_reset()
3536 bfq_reset_rate_computation(bfqd, rq); in bfq_update_rate_reset()
3571 static void bfq_update_peak_rate(struct bfq_data *bfqd, struct request *rq) in bfq_update_peak_rate() argument
3575 if (bfqd->peak_rate_samples == 0) { /* first dispatch */ in bfq_update_peak_rate()
3576 bfq_log(bfqd, "update_peak_rate: goto reset, samples %d", in bfq_update_peak_rate()
3577 bfqd->peak_rate_samples); in bfq_update_peak_rate()
3578 bfq_reset_rate_computation(bfqd, rq); in bfq_update_peak_rate()
3594 if (now_ns - bfqd->last_dispatch > 100*NSEC_PER_MSEC && in bfq_update_peak_rate()
3595 bfqd->rq_in_driver == 0) in bfq_update_peak_rate()
3599 bfqd->peak_rate_samples++; in bfq_update_peak_rate()
3601 if ((bfqd->rq_in_driver > 0 || in bfq_update_peak_rate()
3602 now_ns - bfqd->last_completion < BFQ_MIN_TT) in bfq_update_peak_rate()
3603 && !BFQ_RQ_SEEKY(bfqd, bfqd->last_position, rq)) in bfq_update_peak_rate()
3604 bfqd->sequential_samples++; in bfq_update_peak_rate()
3606 bfqd->tot_sectors_dispatched += blk_rq_sectors(rq); in bfq_update_peak_rate()
3609 if (likely(bfqd->peak_rate_samples % 32)) in bfq_update_peak_rate()
3610 bfqd->last_rq_max_size = in bfq_update_peak_rate()
3611 max_t(u32, blk_rq_sectors(rq), bfqd->last_rq_max_size); in bfq_update_peak_rate()
3613 bfqd->last_rq_max_size = blk_rq_sectors(rq); in bfq_update_peak_rate()
3615 bfqd->delta_from_first = now_ns - bfqd->first_dispatch; in bfq_update_peak_rate()
3618 if (bfqd->delta_from_first < BFQ_RATE_REF_INTERVAL) in bfq_update_peak_rate()
3622 bfq_update_rate_reset(bfqd, rq); in bfq_update_peak_rate()
3624 bfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); in bfq_update_peak_rate()
3625 if (RQ_BFQQ(rq) == bfqd->in_service_queue) in bfq_update_peak_rate()
3626 bfqd->in_serv_last_pos = bfqd->last_position; in bfq_update_peak_rate()
3627 bfqd->last_dispatch = now_ns; in bfq_update_peak_rate()
3856 static bool idling_needed_for_service_guarantees(struct bfq_data *bfqd, in idling_needed_for_service_guarantees() argument
3859 int tot_busy_queues = bfq_tot_busy_queues(bfqd); in idling_needed_for_service_guarantees()
3866 (bfqd->wr_busy_queues < in idling_needed_for_service_guarantees()
3868 bfqd->rq_in_driver >= in idling_needed_for_service_guarantees()
3870 bfq_asymmetric_scenario(bfqd, bfqq) || in idling_needed_for_service_guarantees()
3874 static bool __bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, in __bfq_bfqq_expire() argument
3901 idling_needed_for_service_guarantees(bfqd, bfqq))) { in __bfq_bfqq_expire()
3913 bfq_requeue_bfqq(bfqd, bfqq, true); in __bfq_bfqq_expire()
3918 if (unlikely(!bfqd->nonrot_with_queueing && in __bfq_bfqq_expire()
3920 bfq_pos_tree_add_move(bfqd, bfqq); in __bfq_bfqq_expire()
3930 return __bfq_bfqd_reset_in_service(bfqd); in __bfq_bfqq_expire()
3942 static void __bfq_bfqq_recalc_budget(struct bfq_data *bfqd, in __bfq_bfqq_recalc_budget() argument
3949 min_budget = bfq_min_budget(bfqd); in __bfq_bfqq_recalc_budget()
3961 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last budg %d, budg left %d", in __bfq_bfqq_recalc_budget()
3963 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: last max_budg %d, min budg %d", in __bfq_bfqq_recalc_budget()
3964 budget, bfq_min_budget(bfqd)); in __bfq_bfqq_recalc_budget()
3965 bfq_log_bfqq(bfqd, bfqq, "recalc_budg: sync %d, seeky %d", in __bfq_bfqq_recalc_budget()
3966 bfq_bfqq_sync(bfqq), BFQQ_SEEKY(bfqd->in_service_queue)); in __bfq_bfqq_recalc_budget()
4000 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4015 budget = min(budget * 2, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4027 budget = min(budget * 4, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4074 budget = bfqd->bfq_max_budget; in __bfq_bfqq_recalc_budget()
4079 if (bfqd->budgets_assigned >= bfq_stats_min_budgets && in __bfq_bfqq_recalc_budget()
4080 !bfqd->bfq_user_max_budget) in __bfq_bfqq_recalc_budget()
4081 bfqq->max_budget = min(bfqq->max_budget, bfqd->bfq_max_budget); in __bfq_bfqq_recalc_budget()
4098 bfq_log_bfqq(bfqd, bfqq, "head sect: %u, new budget %d", in __bfq_bfqq_recalc_budget()
4134 static bool bfq_bfqq_is_slow(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_bfqq_is_slow() argument
4146 delta_ktime = bfqd->last_idling_start; in bfq_bfqq_is_slow()
4149 delta_ktime = ktime_sub(delta_ktime, bfqd->last_budget_start); in bfq_bfqq_is_slow()
4154 if (blk_queue_nonrot(bfqd->queue)) in bfq_bfqq_is_slow()
4183 slow = bfqq->entity.service < bfqd->bfq_max_budget / 2; in bfq_bfqq_is_slow()
4186 bfq_log_bfqq(bfqd, bfqq, "bfq_bfqq_is_slow: slow %d", slow); in bfq_bfqq_is_slow()
4284 static unsigned long bfq_bfqq_softrt_next_start(struct bfq_data *bfqd, in bfq_bfqq_softrt_next_start() argument
4290 bfqd->bfq_wr_max_softrt_rate, in bfq_bfqq_softrt_next_start()
4291 jiffies + nsecs_to_jiffies(bfqq->bfqd->bfq_slice_idle) + 4); in bfq_bfqq_softrt_next_start()
4320 void bfq_bfqq_expire(struct bfq_data *bfqd, in bfq_bfqq_expire() argument
4332 slow = bfq_bfqq_is_slow(bfqd, bfqq, compensate, reason, &delta); in bfq_bfqq_expire()
4353 bfq_bfqq_charge_time(bfqd, bfqq, delta); in bfq_bfqq_expire()
4355 if (bfqd->low_latency && bfqq->wr_coeff == 1) in bfq_bfqq_expire()
4358 if (bfqd->low_latency && bfqd->bfq_wr_max_softrt_rate > 0 && in bfq_bfqq_expire()
4374 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_bfqq_expire()
4384 bfq_log_bfqq(bfqd, bfqq, in bfq_bfqq_expire()
4393 bfqd->rqs_injected = bfqd->wait_dispatch = false; in bfq_bfqq_expire()
4394 bfqd->waited_rq = NULL; in bfq_bfqq_expire()
4400 __bfq_bfqq_recalc_budget(bfqd, bfqq, reason); in bfq_bfqq_expire()
4401 if (__bfq_bfqq_expire(bfqd, bfqq, reason)) in bfq_bfqq_expire()
4460 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_may_expire_for_budg_timeout()
4472 static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd, in idling_boosts_thr_without_issues() argument
4476 !blk_queue_nonrot(bfqd->queue) && !bfqd->hw_tag, in idling_boosts_thr_without_issues()
4510 ((!blk_queue_nonrot(bfqd->queue) || !bfqd->hw_tag) && in idling_boosts_thr_without_issues()
4548 bfqd->wr_busy_queues == 0; in idling_boosts_thr_without_issues()
4574 struct bfq_data *bfqd = bfqq->bfqd; in bfq_better_to_idle() local
4581 if (unlikely(bfqd->strict_guarantees)) in bfq_better_to_idle()
4592 if (bfqd->bfq_slice_idle == 0 || !bfq_bfqq_sync(bfqq) || in bfq_better_to_idle()
4597 idling_boosts_thr_without_issues(bfqd, bfqq); in bfq_better_to_idle()
4600 idling_needed_for_service_guarantees(bfqd, bfqq); in bfq_better_to_idle()
4636 bfq_choose_bfqq_for_injection(struct bfq_data *bfqd) in bfq_choose_bfqq_for_injection() argument
4638 struct bfq_queue *bfqq, *in_serv_bfqq = bfqd->in_service_queue; in bfq_choose_bfqq_for_injection()
4666 time_is_before_eq_jiffies(bfqd->last_idling_start_jiffies + in bfq_choose_bfqq_for_injection()
4667 bfqd->bfq_slice_idle) in bfq_choose_bfqq_for_injection()
4671 if (bfqd->rq_in_driver >= limit) in bfq_choose_bfqq_for_injection()
4686 list_for_each_entry(bfqq, &bfqd->active_list, bfqq_list) in bfq_choose_bfqq_for_injection()
4708 if (blk_queue_nonrot(bfqd->queue) && in bfq_choose_bfqq_for_injection()
4715 if (bfqd->rq_in_driver < limit) { in bfq_choose_bfqq_for_injection()
4716 bfqd->rqs_injected = true; in bfq_choose_bfqq_for_injection()
4728 static struct bfq_queue *bfq_select_queue(struct bfq_data *bfqd) in bfq_select_queue() argument
4734 bfqq = bfqd->in_service_queue; in bfq_select_queue()
4738 bfq_log_bfqq(bfqd, bfqq, "select_queue: already in-service queue"); in bfq_select_queue()
4795 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_select_queue()
4924 else if (!idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_select_queue()
4925 (bfqq->wr_coeff == 1 || bfqd->wr_busy_queues > 1 || in bfq_select_queue()
4927 bfqq = bfq_choose_bfqq_for_injection(bfqd); in bfq_select_queue()
4936 bfq_bfqq_expire(bfqd, bfqq, false, reason); in bfq_select_queue()
4938 bfqq = bfq_set_in_service_queue(bfqd); in bfq_select_queue()
4940 bfq_log_bfqq(bfqd, bfqq, "select_queue: checking new queue"); in bfq_select_queue()
4945 bfq_log_bfqq(bfqd, bfqq, "select_queue: returned this queue"); in bfq_select_queue()
4947 bfq_log(bfqd, "select_queue: no queue returned"); in bfq_select_queue()
4952 static void bfq_update_wr_data(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_update_wr_data() argument
4957 bfq_log_bfqq(bfqd, bfqq, in bfq_update_wr_data()
4965 bfq_log_bfqq(bfqd, bfqq, "WARN: pending prio change"); in bfq_update_wr_data()
4976 if (bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time || in bfq_update_wr_data()
4978 bfq_wr_duration(bfqd))) { in bfq_update_wr_data()
4993 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_wr_data()
4998 bfqq->wr_cur_max_time != bfqd->bfq_wr_rt_max_time && in bfq_update_wr_data()
5020 static struct request *bfq_dispatch_rq_from_bfqq(struct bfq_data *bfqd, in bfq_dispatch_rq_from_bfqq() argument
5030 if (bfqq == bfqd->in_service_queue && bfqd->wait_dispatch) { in bfq_dispatch_rq_from_bfqq()
5031 bfqd->wait_dispatch = false; in bfq_dispatch_rq_from_bfqq()
5032 bfqd->waited_rq = rq; in bfq_dispatch_rq_from_bfqq()
5035 bfq_dispatch_remove(bfqd->queue, rq); in bfq_dispatch_rq_from_bfqq()
5037 if (bfqq != bfqd->in_service_queue) in bfq_dispatch_rq_from_bfqq()
5051 bfq_update_wr_data(bfqd, bfqq); in bfq_dispatch_rq_from_bfqq()
5058 if (!(bfq_tot_busy_queues(bfqd) > 1 && bfq_class_idle(bfqq))) in bfq_dispatch_rq_from_bfqq()
5061 bfq_bfqq_expire(bfqd, bfqq, false, BFQQE_BUDGET_EXHAUSTED); in bfq_dispatch_rq_from_bfqq()
5069 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_has_work() local
5075 return !list_empty_careful(&bfqd->dispatch) || in bfq_has_work()
5076 READ_ONCE(bfqd->queued); in bfq_has_work()
5081 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in __bfq_dispatch_request() local
5085 if (!list_empty(&bfqd->dispatch)) { in __bfq_dispatch_request()
5086 rq = list_first_entry(&bfqd->dispatch, struct request, in __bfq_dispatch_request()
5130 bfq_log(bfqd, "dispatch requests: %d busy queues", in __bfq_dispatch_request()
5131 bfq_tot_busy_queues(bfqd)); in __bfq_dispatch_request()
5133 if (bfq_tot_busy_queues(bfqd) == 0) in __bfq_dispatch_request()
5148 if (bfqd->strict_guarantees && bfqd->rq_in_driver > 0) in __bfq_dispatch_request()
5151 bfqq = bfq_select_queue(bfqd); in __bfq_dispatch_request()
5155 rq = bfq_dispatch_rq_from_bfqq(bfqd, bfqq); in __bfq_dispatch_request()
5159 bfqd->rq_in_driver++; in __bfq_dispatch_request()
5221 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_dispatch_request() local
5226 spin_lock_irq(&bfqd->lock); in bfq_dispatch_request()
5228 in_serv_queue = bfqd->in_service_queue; in bfq_dispatch_request()
5232 if (in_serv_queue == bfqd->in_service_queue) { in bfq_dispatch_request()
5237 spin_unlock_irq(&bfqd->lock); in bfq_dispatch_request()
5258 bfq_log_bfqq(bfqq->bfqd, bfqq, "put_queue: %p %d", bfqq, bfqq->ref); in bfq_put_queue()
5292 if (bfqq->bic && bfqq->bfqd->burst_size > 0) in bfq_put_queue()
5293 bfqq->bfqd->burst_size--; in bfq_put_queue()
5322 if (bfqq->bfqd->last_completed_rq_bfqq == bfqq) in bfq_put_queue()
5323 bfqq->bfqd->last_completed_rq_bfqq = NULL; in bfq_put_queue()
5354 static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_exit_bfqq() argument
5356 if (bfqq == bfqd->in_service_queue) { in bfq_exit_bfqq()
5357 __bfq_bfqq_expire(bfqd, bfqq, BFQQE_BUDGET_TIMEOUT); in bfq_exit_bfqq()
5358 bfq_schedule_dispatch(bfqd); in bfq_exit_bfqq()
5361 bfq_log_bfqq(bfqd, bfqq, "exit_bfqq: %p, %d", bfqq, bfqq->ref); in bfq_exit_bfqq()
5365 bfq_release_process_ref(bfqd, bfqq); in bfq_exit_bfqq()
5371 struct bfq_data *bfqd; in bfq_exit_icq_bfqq() local
5374 bfqd = bfqq->bfqd; /* NULL if scheduler already exited */ in bfq_exit_icq_bfqq()
5376 if (bfqq && bfqd) { in bfq_exit_icq_bfqq()
5379 spin_lock_irqsave(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
5381 bfq_exit_bfqq(bfqd, bfqq); in bfq_exit_icq_bfqq()
5383 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_exit_icq_bfqq()
5392 struct bfq_data *bfqd = bic->stable_merge_bfqq->bfqd; in bfq_exit_icq() local
5398 if (bfqd) { in bfq_exit_icq()
5401 spin_lock_irqsave(&bfqd->lock, flags); in bfq_exit_icq()
5403 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_exit_icq()
5422 struct bfq_data *bfqd = bfqq->bfqd; in bfq_set_next_ioprio_data() local
5424 if (!bfqd) in bfq_set_next_ioprio_data()
5431 bdi_dev_name(bfqq->bfqd->queue->disk->bdi), in bfq_set_next_ioprio_data()
5462 bfq_log_bfqq(bfqd, bfqq, "new_ioprio %d new_weight %d", in bfq_set_next_ioprio_data()
5467 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd,
5474 struct bfq_data *bfqd = bic_to_bfqd(bic); in bfq_check_ioprio_change() local
5482 if (unlikely(!bfqd) || likely(bic->ioprio == ioprio)) in bfq_check_ioprio_change()
5489 bfq_release_process_ref(bfqd, bfqq); in bfq_check_ioprio_change()
5490 bfqq = bfq_get_queue(bfqd, bio, false, bic, true); in bfq_check_ioprio_change()
5499 static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_init_bfqq() argument
5511 bfqq->bfqd = bfqd; in bfq_init_bfqq()
5542 bfqq->max_budget = (2 * bfq_max_budget(bfqd)) / 3; in bfq_init_bfqq()
5565 static struct bfq_queue **bfq_async_queue_prio(struct bfq_data *bfqd, in bfq_async_queue_prio() argument
5585 bfq_do_early_stable_merge(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_do_early_stable_merge() argument
5606 bfq_merge_bfqqs(bfqd, bic, bfqq, new_bfqq); in bfq_do_early_stable_merge()
5657 static struct bfq_queue *bfq_do_or_sched_stable_merge(struct bfq_data *bfqd, in bfq_do_or_sched_stable_merge() argument
5663 &bfqd->last_bfqq_created; in bfq_do_or_sched_stable_merge()
5695 bfqd->bfq_burst_interval, in bfq_do_or_sched_stable_merge()
5697 if (likely(bfqd->nonrot_with_queueing)) in bfq_do_or_sched_stable_merge()
5704 bfqq = bfq_do_early_stable_merge(bfqd, bfqq, in bfq_do_or_sched_stable_merge()
5730 static struct bfq_queue *bfq_get_queue(struct bfq_data *bfqd, in bfq_get_queue() argument
5741 bfqg = bfq_bio_bfqg(bfqd, bio); in bfq_get_queue()
5743 async_bfqq = bfq_async_queue_prio(bfqd, bfqg, ioprio_class, in bfq_get_queue()
5752 bfqd->queue->node); in bfq_get_queue()
5755 bfq_init_bfqq(bfqd, bfqq, bic, current->pid, in bfq_get_queue()
5758 bfq_log_bfqq(bfqd, bfqq, "allocated"); in bfq_get_queue()
5760 bfqq = &bfqd->oom_bfqq; in bfq_get_queue()
5761 bfq_log_bfqq(bfqd, bfqq, "using oom bfqq"); in bfq_get_queue()
5777 bfq_log_bfqq(bfqd, bfqq, "get_queue, bfqq not in async: %p, %d", in bfq_get_queue()
5785 if (bfqq != &bfqd->oom_bfqq && is_sync && !respawn) in bfq_get_queue()
5786 bfqq = bfq_do_or_sched_stable_merge(bfqd, bfqq, bic); in bfq_get_queue()
5790 static void bfq_update_io_thinktime(struct bfq_data *bfqd, in bfq_update_io_thinktime() argument
5804 elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle); in bfq_update_io_thinktime()
5813 bfq_update_io_seektime(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_update_io_seektime() argument
5817 bfqq->seek_history |= BFQ_RQ_SEEKY(bfqd, bfqq->last_request_pos, rq); in bfq_update_io_seektime()
5820 bfqq->wr_cur_max_time == bfqd->bfq_wr_rt_max_time && in bfq_update_io_seektime()
5823 bfq_wr_duration(bfqd))) { in bfq_update_io_seektime()
5837 switch_back_to_interactive_wr(bfqq, bfqd); in bfq_update_io_seektime()
5843 static void bfq_update_has_short_ttime(struct bfq_data *bfqd, in bfq_update_has_short_ttime() argument
5855 bfqd->bfq_slice_idle == 0) in bfq_update_has_short_ttime()
5860 bfqd->bfq_wr_min_idle_time)) in bfq_update_has_short_ttime()
5870 bfqq->ttime.ttime_mean > bfqd->bfq_slice_idle>>1)) in bfq_update_has_short_ttime()
5968 bfq_reset_inject_limit(bfqd, bfqq); in bfq_update_has_short_ttime()
5975 static void bfq_rq_enqueued(struct bfq_data *bfqd, struct bfq_queue *bfqq, in bfq_rq_enqueued() argument
5983 if (bfqq == bfqd->in_service_queue && bfq_bfqq_wait_request(bfqq)) { in bfq_rq_enqueued()
6004 if (small_req && idling_boosts_thr_without_issues(bfqd, bfqq) && in bfq_rq_enqueued()
6016 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in bfq_rq_enqueued()
6026 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_rq_enqueued()
6048 static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq) in __bfq_insert_request() argument
6051 *new_bfqq = bfq_setup_cooperator(bfqd, bfqq, rq, true, in __bfq_insert_request()
6072 bfq_merge_bfqqs(bfqd, RQ_BIC(rq), in __bfq_insert_request()
6085 bfq_update_io_thinktime(bfqd, bfqq); in __bfq_insert_request()
6086 bfq_update_has_short_ttime(bfqd, bfqq, RQ_BIC(rq)); in __bfq_insert_request()
6087 bfq_update_io_seektime(bfqd, bfqq, rq); in __bfq_insert_request()
6093 rq->fifo_time = ktime_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; in __bfq_insert_request()
6096 bfq_rq_enqueued(bfqd, bfqq, rq); in __bfq_insert_request()
6139 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_insert_request() local
6149 spin_lock_irq(&bfqd->lock); in bfq_insert_request()
6152 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
6161 list_add(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
6163 list_add_tail(&rq->queuelist, &bfqd->dispatch); in bfq_insert_request()
6165 idle_timer_disabled = __bfq_insert_request(bfqd, rq); in bfq_insert_request()
6186 spin_unlock_irq(&bfqd->lock); in bfq_insert_request()
6204 static void bfq_update_hw_tag(struct bfq_data *bfqd) in bfq_update_hw_tag() argument
6206 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_update_hw_tag()
6208 bfqd->max_rq_in_driver = max_t(int, bfqd->max_rq_in_driver, in bfq_update_hw_tag()
6209 bfqd->rq_in_driver); in bfq_update_hw_tag()
6211 if (bfqd->hw_tag == 1) in bfq_update_hw_tag()
6220 if (bfqd->rq_in_driver + bfqd->queued <= BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
6231 bfqd->rq_in_driver < BFQ_HW_QUEUE_THRESHOLD) in bfq_update_hw_tag()
6234 if (bfqd->hw_tag_samples++ < BFQ_HW_QUEUE_SAMPLES) in bfq_update_hw_tag()
6237 bfqd->hw_tag = bfqd->max_rq_in_driver > BFQ_HW_QUEUE_THRESHOLD; in bfq_update_hw_tag()
6238 bfqd->max_rq_in_driver = 0; in bfq_update_hw_tag()
6239 bfqd->hw_tag_samples = 0; in bfq_update_hw_tag()
6241 bfqd->nonrot_with_queueing = in bfq_update_hw_tag()
6242 blk_queue_nonrot(bfqd->queue) && bfqd->hw_tag; in bfq_update_hw_tag()
6245 static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) in bfq_completed_request() argument
6250 bfq_update_hw_tag(bfqd); in bfq_completed_request()
6252 bfqd->rq_in_driver--; in bfq_completed_request()
6264 bfq_weights_tree_remove(bfqd, bfqq); in bfq_completed_request()
6275 delta_us = div_u64(now_ns - bfqd->last_completion, NSEC_PER_USEC); in bfq_completed_request()
6294 (bfqd->last_rq_max_size<<BFQ_RATE_SHIFT)/delta_us < in bfq_completed_request()
6296 bfq_update_rate_reset(bfqd, NULL); in bfq_completed_request()
6297 bfqd->last_completion = now_ns; in bfq_completed_request()
6308 bfqd->last_completed_rq_bfqq = bfqq; in bfq_completed_request()
6310 bfqd->last_completed_rq_bfqq = NULL; in bfq_completed_request()
6325 bfqq->wr_coeff != bfqd->bfq_wr_coeff) in bfq_completed_request()
6327 bfq_bfqq_softrt_next_start(bfqd, bfqq); in bfq_completed_request()
6333 if (bfqd->in_service_queue == bfqq) { in bfq_completed_request()
6336 bfq_arm_slice_timer(bfqd); in bfq_completed_request()
6362 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6367 bfq_bfqq_expire(bfqd, bfqq, false, in bfq_completed_request()
6371 if (!bfqd->rq_in_driver) in bfq_completed_request()
6372 bfq_schedule_dispatch(bfqd); in bfq_completed_request()
6479 static void bfq_update_inject_limit(struct bfq_data *bfqd, in bfq_update_inject_limit() argument
6482 u64 tot_time_ns = ktime_get_ns() - bfqd->last_empty_occupied_ns; in bfq_update_inject_limit()
6485 if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { in bfq_update_inject_limit()
6492 old_limit <= bfqd->max_rq_in_driver) in bfq_update_inject_limit()
6508 if ((bfqq->last_serv_time_ns == 0 && bfqd->rq_in_driver == 1) || in bfq_update_inject_limit()
6518 } else if (!bfqd->rqs_injected && bfqd->rq_in_driver == 1) in bfq_update_inject_limit()
6532 bfqd->waited_rq = NULL; in bfq_update_inject_limit()
6533 bfqd->rqs_injected = false; in bfq_update_inject_limit()
6545 struct bfq_data *bfqd; in bfq_finish_requeue_request() local
6556 bfqd = bfqq->bfqd; in bfq_finish_requeue_request()
6564 spin_lock_irqsave(&bfqd->lock, flags); in bfq_finish_requeue_request()
6566 if (rq == bfqd->waited_rq) in bfq_finish_requeue_request()
6567 bfq_update_inject_limit(bfqd, bfqq); in bfq_finish_requeue_request()
6569 bfq_completed_request(bfqq, bfqd); in bfq_finish_requeue_request()
6574 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_finish_requeue_request()
6616 bfq_log_bfqq(bfqq->bfqd, bfqq, "splitting queue"); in bfq_split_bfqq()
6629 bfq_release_process_ref(bfqq->bfqd, bfqq); in bfq_split_bfqq()
6633 static struct bfq_queue *bfq_get_bfqq_handle_split(struct bfq_data *bfqd, in bfq_get_bfqq_handle_split() argument
6641 if (likely(bfqq && bfqq != &bfqd->oom_bfqq)) in bfq_get_bfqq_handle_split()
6649 bfqq = bfq_get_queue(bfqd, bio, is_sync, bic, split); in bfq_get_bfqq_handle_split()
6653 if ((bic->was_in_burst_list && bfqd->large_burst) || in bfq_get_bfqq_handle_split()
6688 &bfqd->burst_list); in bfq_get_bfqq_handle_split()
6741 struct bfq_data *bfqd = q->elevator->elevator_data; in bfq_init_rq() local
6767 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, false, is_sync, in bfq_init_rq()
6784 bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, in bfq_init_rq()
6808 bfq_log_bfqq(bfqd, bfqq, "get_request %p: bfqq %p, %d", in bfq_init_rq()
6820 if (likely(bfqq != &bfqd->oom_bfqq) && bfqq_process_refs(bfqq) == 1) { in bfq_init_rq()
6828 bfq_bfqq_resume_state(bfqq, bfqd, bic, in bfq_init_rq()
6854 (bfqd->burst_size > 0 || in bfq_init_rq()
6855 bfq_tot_busy_queues(bfqd) == 0))) in bfq_init_rq()
6856 bfq_handle_burst(bfqd, bfqq); in bfq_init_rq()
6862 bfq_idle_slice_timer_body(struct bfq_data *bfqd, struct bfq_queue *bfqq) in bfq_idle_slice_timer_body() argument
6867 spin_lock_irqsave(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6876 if (bfqq != bfqd->in_service_queue) { in bfq_idle_slice_timer_body()
6877 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6901 bfq_bfqq_expire(bfqd, bfqq, true, reason); in bfq_idle_slice_timer_body()
6904 bfq_schedule_dispatch(bfqd); in bfq_idle_slice_timer_body()
6905 spin_unlock_irqrestore(&bfqd->lock, flags); in bfq_idle_slice_timer_body()
6914 struct bfq_data *bfqd = container_of(timer, struct bfq_data, in bfq_idle_slice_timer() local
6916 struct bfq_queue *bfqq = bfqd->in_service_queue; in bfq_idle_slice_timer()
6927 bfq_idle_slice_timer_body(bfqd, bfqq); in bfq_idle_slice_timer()
6932 static void __bfq_put_async_bfqq(struct bfq_data *bfqd, in __bfq_put_async_bfqq() argument
6937 bfq_log(bfqd, "put_async_bfqq: %p", bfqq); in __bfq_put_async_bfqq()
6939 bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); in __bfq_put_async_bfqq()
6941 bfq_log_bfqq(bfqd, bfqq, "put_async_bfqq: putting %p, %d", in __bfq_put_async_bfqq()
6954 void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg) in bfq_put_async_queues() argument
6960 __bfq_put_async_bfqq(bfqd, &bfqg->async_bfqq[i][j]); in bfq_put_async_queues()
6962 __bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq); in bfq_put_async_queues()
6969 static void bfq_update_depths(struct bfq_data *bfqd, struct sbitmap_queue *bt) in bfq_update_depths() argument
6973 bfqd->full_depth_shift = bt->sb.shift; in bfq_update_depths()
6985 bfqd->word_depths[0][0] = max(depth >> 1, 1U); in bfq_update_depths()
6991 bfqd->word_depths[0][1] = max((depth * 3) >> 2, 1U); in bfq_update_depths()
7001 bfqd->word_depths[1][0] = max((depth * 3) >> 4, 1U); in bfq_update_depths()
7003 bfqd->word_depths[1][1] = max((depth * 6) >> 4, 1U); in bfq_update_depths()
7008 struct bfq_data *bfqd = hctx->queue->elevator->elevator_data; in bfq_depth_updated() local
7011 bfq_update_depths(bfqd, &tags->bitmap_tags); in bfq_depth_updated()
7023 struct bfq_data *bfqd = e->elevator_data; in bfq_exit_queue() local
7026 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
7028 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
7029 list_for_each_entry_safe(bfqq, n, &bfqd->idle_list, bfqq_list) in bfq_exit_queue()
7030 bfq_deactivate_bfqq(bfqd, bfqq, false, false); in bfq_exit_queue()
7031 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
7033 hrtimer_cancel(&bfqd->idle_slice_timer); in bfq_exit_queue()
7036 bfqg_and_blkg_put(bfqd->root_group); in bfq_exit_queue()
7039 blkcg_deactivate_policy(bfqd->queue, &blkcg_policy_bfq); in bfq_exit_queue()
7041 spin_lock_irq(&bfqd->lock); in bfq_exit_queue()
7042 bfq_put_async_queues(bfqd, bfqd->root_group); in bfq_exit_queue()
7043 kfree(bfqd->root_group); in bfq_exit_queue()
7044 spin_unlock_irq(&bfqd->lock); in bfq_exit_queue()
7047 blk_stat_disable_accounting(bfqd->queue); in bfq_exit_queue()
7048 wbt_enable_default(bfqd->queue); in bfq_exit_queue()
7050 kfree(bfqd); in bfq_exit_queue()
7054 struct bfq_data *bfqd) in bfq_init_root_group() argument
7061 root_group->bfqd = bfqd; in bfq_init_root_group()
7071 struct bfq_data *bfqd; in bfq_init_queue() local
7078 bfqd = kzalloc_node(sizeof(*bfqd), GFP_KERNEL, q->node); in bfq_init_queue()
7079 if (!bfqd) { in bfq_init_queue()
7083 eq->elevator_data = bfqd; in bfq_init_queue()
7094 bfq_init_bfqq(bfqd, &bfqd->oom_bfqq, NULL, 1, 0); in bfq_init_queue()
7095 bfqd->oom_bfqq.ref++; in bfq_init_queue()
7096 bfqd->oom_bfqq.new_ioprio = BFQ_DEFAULT_QUEUE_IOPRIO; in bfq_init_queue()
7097 bfqd->oom_bfqq.new_ioprio_class = IOPRIO_CLASS_BE; in bfq_init_queue()
7098 bfqd->oom_bfqq.entity.new_weight = in bfq_init_queue()
7099 bfq_ioprio_to_weight(bfqd->oom_bfqq.new_ioprio); in bfq_init_queue()
7102 bfq_clear_bfqq_just_created(&bfqd->oom_bfqq); in bfq_init_queue()
7109 bfqd->oom_bfqq.entity.prio_changed = 1; in bfq_init_queue()
7111 bfqd->queue = q; in bfq_init_queue()
7113 INIT_LIST_HEAD(&bfqd->dispatch); in bfq_init_queue()
7115 hrtimer_init(&bfqd->idle_slice_timer, CLOCK_MONOTONIC, in bfq_init_queue()
7117 bfqd->idle_slice_timer.function = bfq_idle_slice_timer; in bfq_init_queue()
7119 bfqd->queue_weights_tree = RB_ROOT_CACHED; in bfq_init_queue()
7120 bfqd->num_groups_with_pending_reqs = 0; in bfq_init_queue()
7122 INIT_LIST_HEAD(&bfqd->active_list); in bfq_init_queue()
7123 INIT_LIST_HEAD(&bfqd->idle_list); in bfq_init_queue()
7124 INIT_HLIST_HEAD(&bfqd->burst_list); in bfq_init_queue()
7126 bfqd->hw_tag = -1; in bfq_init_queue()
7127 bfqd->nonrot_with_queueing = blk_queue_nonrot(bfqd->queue); in bfq_init_queue()
7129 bfqd->bfq_max_budget = bfq_default_max_budget; in bfq_init_queue()
7131 bfqd->bfq_fifo_expire[0] = bfq_fifo_expire[0]; in bfq_init_queue()
7132 bfqd->bfq_fifo_expire[1] = bfq_fifo_expire[1]; in bfq_init_queue()
7133 bfqd->bfq_back_max = bfq_back_max; in bfq_init_queue()
7134 bfqd->bfq_back_penalty = bfq_back_penalty; in bfq_init_queue()
7135 bfqd->bfq_slice_idle = bfq_slice_idle; in bfq_init_queue()
7136 bfqd->bfq_timeout = bfq_timeout; in bfq_init_queue()
7138 bfqd->bfq_large_burst_thresh = 8; in bfq_init_queue()
7139 bfqd->bfq_burst_interval = msecs_to_jiffies(180); in bfq_init_queue()
7141 bfqd->low_latency = true; in bfq_init_queue()
7146 bfqd->bfq_wr_coeff = 30; in bfq_init_queue()
7147 bfqd->bfq_wr_rt_max_time = msecs_to_jiffies(300); in bfq_init_queue()
7148 bfqd->bfq_wr_max_time = 0; in bfq_init_queue()
7149 bfqd->bfq_wr_min_idle_time = msecs_to_jiffies(2000); in bfq_init_queue()
7150 bfqd->bfq_wr_min_inter_arr_async = msecs_to_jiffies(500); in bfq_init_queue()
7151 bfqd->bfq_wr_max_softrt_rate = 7000; /* in bfq_init_queue()
7157 bfqd->wr_busy_queues = 0; in bfq_init_queue()
7163 bfqd->rate_dur_prod = ref_rate[blk_queue_nonrot(bfqd->queue)] * in bfq_init_queue()
7164 ref_wr_duration[blk_queue_nonrot(bfqd->queue)]; in bfq_init_queue()
7165 bfqd->peak_rate = ref_rate[blk_queue_nonrot(bfqd->queue)] * 2 / 3; in bfq_init_queue()
7167 spin_lock_init(&bfqd->lock); in bfq_init_queue()
7184 bfqd->root_group = bfq_create_group_hierarchy(bfqd, q->node); in bfq_init_queue()
7185 if (!bfqd->root_group) in bfq_init_queue()
7187 bfq_init_root_group(bfqd->root_group, bfqd); in bfq_init_queue()
7188 bfq_init_entity(&bfqd->oom_bfqq.entity, bfqd->root_group); in bfq_init_queue()
7199 kfree(bfqd); in bfq_init_queue()
7236 struct bfq_data *bfqd = e->elevator_data; \
7244 SHOW_FUNCTION(bfq_fifo_expire_sync_show, bfqd->bfq_fifo_expire[1], 2);
7245 SHOW_FUNCTION(bfq_fifo_expire_async_show, bfqd->bfq_fifo_expire[0], 2);
7246 SHOW_FUNCTION(bfq_back_seek_max_show, bfqd->bfq_back_max, 0);
7247 SHOW_FUNCTION(bfq_back_seek_penalty_show, bfqd->bfq_back_penalty, 0);
7248 SHOW_FUNCTION(bfq_slice_idle_show, bfqd->bfq_slice_idle, 2);
7249 SHOW_FUNCTION(bfq_max_budget_show, bfqd->bfq_user_max_budget, 0);
7250 SHOW_FUNCTION(bfq_timeout_sync_show, bfqd->bfq_timeout, 1);
7251 SHOW_FUNCTION(bfq_strict_guarantees_show, bfqd->strict_guarantees, 0);
7252 SHOW_FUNCTION(bfq_low_latency_show, bfqd->low_latency, 0);
7258 struct bfq_data *bfqd = e->elevator_data; \
7263 USEC_SHOW_FUNCTION(bfq_slice_idle_us_show, bfqd->bfq_slice_idle);
7270 struct bfq_data *bfqd = e->elevator_data; \
7289 STORE_FUNCTION(bfq_fifo_expire_sync_store, &bfqd->bfq_fifo_expire[1], 1,
7291 STORE_FUNCTION(bfq_fifo_expire_async_store, &bfqd->bfq_fifo_expire[0], 1,
7293 STORE_FUNCTION(bfq_back_seek_max_store, &bfqd->bfq_back_max, 0, INT_MAX, 0);
7294 STORE_FUNCTION(bfq_back_seek_penalty_store, &bfqd->bfq_back_penalty, 1,
7296 STORE_FUNCTION(bfq_slice_idle_store, &bfqd->bfq_slice_idle, 0, INT_MAX, 2);
7302 struct bfq_data *bfqd = e->elevator_data; \
7316 USEC_STORE_FUNCTION(bfq_slice_idle_us_store, &bfqd->bfq_slice_idle, 0,
7323 struct bfq_data *bfqd = e->elevator_data; in bfq_max_budget_store() local
7332 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_max_budget_store()
7336 bfqd->bfq_max_budget = __data; in bfq_max_budget_store()
7339 bfqd->bfq_user_max_budget = __data; in bfq_max_budget_store()
7351 struct bfq_data *bfqd = e->elevator_data; in bfq_timeout_sync_store() local
7364 bfqd->bfq_timeout = msecs_to_jiffies(__data); in bfq_timeout_sync_store()
7365 if (bfqd->bfq_user_max_budget == 0) in bfq_timeout_sync_store()
7366 bfqd->bfq_max_budget = bfq_calc_max_budget(bfqd); in bfq_timeout_sync_store()
7374 struct bfq_data *bfqd = e->elevator_data; in bfq_strict_guarantees_store() local
7384 if (!bfqd->strict_guarantees && __data == 1 in bfq_strict_guarantees_store()
7385 && bfqd->bfq_slice_idle < 8 * NSEC_PER_MSEC) in bfq_strict_guarantees_store()
7386 bfqd->bfq_slice_idle = 8 * NSEC_PER_MSEC; in bfq_strict_guarantees_store()
7388 bfqd->strict_guarantees = __data; in bfq_strict_guarantees_store()
7396 struct bfq_data *bfqd = e->elevator_data; in bfq_low_latency_store() local
7406 if (__data == 0 && bfqd->low_latency != 0) in bfq_low_latency_store()
7407 bfq_end_wr(bfqd); in bfq_low_latency_store()
7408 bfqd->low_latency = __data; in bfq_low_latency_store()