1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/backing-dev.h>
5 #include <linux/blkdev.h>
7 #include <linux/init.h>
8 #include <linux/slab.h>
9 #include <linux/workqueue.h>
10 #include <linux/smp.h>
11 #include <linux/llist.h>
12 #include <linux/list_sort.h>
13 #include <linux/cpu.h>
14 #include <linux/cache.h>
15 #include <linux/sched/sysctl.h>
16 #include <linux/delay.h>
18 #include <trace/events/block.h>
20 #include <linux/blk-mq.h>
23 #include "blk-mq-tag.h"
25 static DEFINE_MUTEX(all_q_mutex
);
26 static LIST_HEAD(all_q_list
);
28 static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx
*hctx
);
30 static struct blk_mq_ctx
*__blk_mq_get_ctx(struct request_queue
*q
,
33 return per_cpu_ptr(q
->queue_ctx
, cpu
);
37 * This assumes per-cpu software queueing queues. They could be per-node
38 * as well, for instance. For now this is hardcoded as-is. Note that we don't
39 * care about preemption, since we know the ctx's are persistent. This does
40 * mean that we can't rely on ctx always matching the currently running CPU.
42 static struct blk_mq_ctx
*blk_mq_get_ctx(struct request_queue
*q
)
44 return __blk_mq_get_ctx(q
, get_cpu());
47 static void blk_mq_put_ctx(struct blk_mq_ctx
*ctx
)
53 * Check if any of the ctx's have pending work in this hardware queue
55 static bool blk_mq_hctx_has_pending(struct blk_mq_hw_ctx
*hctx
)
59 for (i
= 0; i
< hctx
->nr_ctx_map
; i
++)
67 * Mark this ctx as having pending work in this hardware queue
69 static void blk_mq_hctx_mark_pending(struct blk_mq_hw_ctx
*hctx
,
70 struct blk_mq_ctx
*ctx
)
72 if (!test_bit(ctx
->index_hw
, hctx
->ctx_map
))
73 set_bit(ctx
->index_hw
, hctx
->ctx_map
);
76 static struct request
*__blk_mq_alloc_request(struct blk_mq_hw_ctx
*hctx
,
77 struct blk_mq_ctx
*ctx
,
78 gfp_t gfp
, bool reserved
)
83 tag
= blk_mq_get_tag(hctx
->tags
, hctx
, &ctx
->last_tag
, gfp
, reserved
);
84 if (tag
!= BLK_MQ_TAG_FAIL
) {
85 rq
= hctx
->tags
->rqs
[tag
];
93 static int blk_mq_queue_enter(struct request_queue
*q
)
97 __percpu_counter_add(&q
->mq_usage_counter
, 1, 1000000);
99 /* we have problems to freeze the queue if it's initializing */
100 if (!blk_queue_bypass(q
) || !blk_queue_init_done(q
))
103 __percpu_counter_add(&q
->mq_usage_counter
, -1, 1000000);
105 spin_lock_irq(q
->queue_lock
);
106 ret
= wait_event_interruptible_lock_irq(q
->mq_freeze_wq
,
107 !blk_queue_bypass(q
) || blk_queue_dying(q
),
109 /* inc usage with lock hold to avoid freeze_queue runs here */
110 if (!ret
&& !blk_queue_dying(q
))
111 __percpu_counter_add(&q
->mq_usage_counter
, 1, 1000000);
112 else if (blk_queue_dying(q
))
114 spin_unlock_irq(q
->queue_lock
);
119 static void blk_mq_queue_exit(struct request_queue
*q
)
121 __percpu_counter_add(&q
->mq_usage_counter
, -1, 1000000);
124 static void __blk_mq_drain_queue(struct request_queue
*q
)
129 spin_lock_irq(q
->queue_lock
);
130 count
= percpu_counter_sum(&q
->mq_usage_counter
);
131 spin_unlock_irq(q
->queue_lock
);
135 blk_mq_run_queues(q
, false);
141 * Guarantee no request is in use, so we can change any data structure of
142 * the queue afterward.
144 static void blk_mq_freeze_queue(struct request_queue
*q
)
148 spin_lock_irq(q
->queue_lock
);
149 drain
= !q
->bypass_depth
++;
150 queue_flag_set(QUEUE_FLAG_BYPASS
, q
);
151 spin_unlock_irq(q
->queue_lock
);
154 __blk_mq_drain_queue(q
);
157 void blk_mq_drain_queue(struct request_queue
*q
)
159 __blk_mq_drain_queue(q
);
162 static void blk_mq_unfreeze_queue(struct request_queue
*q
)
166 spin_lock_irq(q
->queue_lock
);
167 if (!--q
->bypass_depth
) {
168 queue_flag_clear(QUEUE_FLAG_BYPASS
, q
);
171 WARN_ON_ONCE(q
->bypass_depth
< 0);
172 spin_unlock_irq(q
->queue_lock
);
174 wake_up_all(&q
->mq_freeze_wq
);
177 bool blk_mq_can_queue(struct blk_mq_hw_ctx
*hctx
)
179 return blk_mq_has_free_tags(hctx
->tags
);
181 EXPORT_SYMBOL(blk_mq_can_queue
);
183 static void blk_mq_rq_ctx_init(struct request_queue
*q
, struct blk_mq_ctx
*ctx
,
184 struct request
*rq
, unsigned int rw_flags
)
186 if (blk_queue_io_stat(q
))
187 rw_flags
|= REQ_IO_STAT
;
189 INIT_LIST_HEAD(&rq
->queuelist
);
190 /* csd/requeue_work/fifo_time is initialized before use */
193 rq
->cmd_flags
= rw_flags
;
195 /* do not touch atomic flags, it needs atomic ops against the timer */
198 rq
->__sector
= (sector_t
) -1;
201 INIT_HLIST_NODE(&rq
->hash
);
202 RB_CLEAR_NODE(&rq
->rb_node
);
203 memset(&rq
->flush
, 0, max(sizeof(rq
->flush
), sizeof(rq
->elv
)));
206 rq
->start_time
= jiffies
;
207 #ifdef CONFIG_BLK_CGROUP
209 set_start_time_ns(rq
);
210 rq
->io_start_time_ns
= 0;
212 rq
->nr_phys_segments
= 0;
213 #if defined(CONFIG_BLK_DEV_INTEGRITY)
214 rq
->nr_integrity_segments
= 0;
218 /* tag was already set */
220 memset(rq
->__cmd
, 0, sizeof(rq
->__cmd
));
222 rq
->cmd_len
= BLK_MAX_CDB
;
230 INIT_LIST_HEAD(&rq
->timeout_list
);
234 rq
->end_io_data
= NULL
;
237 ctx
->rq_dispatched
[rw_is_sync(rw_flags
)]++;
240 static struct request
*blk_mq_alloc_request_pinned(struct request_queue
*q
,
247 struct blk_mq_ctx
*ctx
= blk_mq_get_ctx(q
);
248 struct blk_mq_hw_ctx
*hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
250 rq
= __blk_mq_alloc_request(hctx
, ctx
, gfp
& ~__GFP_WAIT
,
253 blk_mq_rq_ctx_init(q
, ctx
, rq
, rw
);
257 if (gfp
& __GFP_WAIT
) {
258 __blk_mq_run_hw_queue(hctx
);
265 blk_mq_wait_for_tags(hctx
->tags
, hctx
, reserved
);
271 struct request
*blk_mq_alloc_request(struct request_queue
*q
, int rw
, gfp_t gfp
)
275 if (blk_mq_queue_enter(q
))
278 rq
= blk_mq_alloc_request_pinned(q
, rw
, gfp
, false);
280 blk_mq_put_ctx(rq
->mq_ctx
);
283 EXPORT_SYMBOL(blk_mq_alloc_request
);
285 struct request
*blk_mq_alloc_reserved_request(struct request_queue
*q
, int rw
,
290 if (blk_mq_queue_enter(q
))
293 rq
= blk_mq_alloc_request_pinned(q
, rw
, gfp
, true);
295 blk_mq_put_ctx(rq
->mq_ctx
);
298 EXPORT_SYMBOL(blk_mq_alloc_reserved_request
);
300 static void __blk_mq_free_request(struct blk_mq_hw_ctx
*hctx
,
301 struct blk_mq_ctx
*ctx
, struct request
*rq
)
303 const int tag
= rq
->tag
;
304 struct request_queue
*q
= rq
->q
;
306 clear_bit(REQ_ATOM_STARTED
, &rq
->atomic_flags
);
307 blk_mq_put_tag(hctx
->tags
, tag
, &ctx
->last_tag
);
308 blk_mq_queue_exit(q
);
311 void blk_mq_free_request(struct request
*rq
)
313 struct blk_mq_ctx
*ctx
= rq
->mq_ctx
;
314 struct blk_mq_hw_ctx
*hctx
;
315 struct request_queue
*q
= rq
->q
;
317 ctx
->rq_completed
[rq_is_sync(rq
)]++;
319 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
320 __blk_mq_free_request(hctx
, ctx
, rq
);
324 * Clone all relevant state from a request that has been put on hold in
325 * the flush state machine into the preallocated flush request that hangs
326 * off the request queue.
328 * For a driver the flush request should be invisible, that's why we are
329 * impersonating the original request here.
331 void blk_mq_clone_flush_request(struct request
*flush_rq
,
332 struct request
*orig_rq
)
334 struct blk_mq_hw_ctx
*hctx
=
335 orig_rq
->q
->mq_ops
->map_queue(orig_rq
->q
, orig_rq
->mq_ctx
->cpu
);
337 flush_rq
->mq_ctx
= orig_rq
->mq_ctx
;
338 flush_rq
->tag
= orig_rq
->tag
;
339 memcpy(blk_mq_rq_to_pdu(flush_rq
), blk_mq_rq_to_pdu(orig_rq
),
343 inline void __blk_mq_end_io(struct request
*rq
, int error
)
345 blk_account_io_done(rq
);
348 rq
->end_io(rq
, error
);
350 if (unlikely(blk_bidi_rq(rq
)))
351 blk_mq_free_request(rq
->next_rq
);
352 blk_mq_free_request(rq
);
355 EXPORT_SYMBOL(__blk_mq_end_io
);
357 void blk_mq_end_io(struct request
*rq
, int error
)
359 if (blk_update_request(rq
, error
, blk_rq_bytes(rq
)))
361 __blk_mq_end_io(rq
, error
);
363 EXPORT_SYMBOL(blk_mq_end_io
);
365 static void __blk_mq_complete_request_remote(void *data
)
367 struct request
*rq
= data
;
369 rq
->q
->softirq_done_fn(rq
);
372 void __blk_mq_complete_request(struct request
*rq
)
374 struct blk_mq_ctx
*ctx
= rq
->mq_ctx
;
378 if (!test_bit(QUEUE_FLAG_SAME_COMP
, &rq
->q
->queue_flags
)) {
379 rq
->q
->softirq_done_fn(rq
);
384 if (!test_bit(QUEUE_FLAG_SAME_FORCE
, &rq
->q
->queue_flags
))
385 shared
= cpus_share_cache(cpu
, ctx
->cpu
);
387 if (cpu
!= ctx
->cpu
&& !shared
&& cpu_online(ctx
->cpu
)) {
388 rq
->csd
.func
= __blk_mq_complete_request_remote
;
391 smp_call_function_single_async(ctx
->cpu
, &rq
->csd
);
393 rq
->q
->softirq_done_fn(rq
);
399 * blk_mq_complete_request - end I/O on a request
400 * @rq: the request being processed
403 * Ends all I/O on a request. It does not handle partial completions.
404 * The actual completion happens out-of-order, through a IPI handler.
406 void blk_mq_complete_request(struct request
*rq
)
408 if (unlikely(blk_should_fake_timeout(rq
->q
)))
410 if (!blk_mark_rq_complete(rq
))
411 __blk_mq_complete_request(rq
);
413 EXPORT_SYMBOL(blk_mq_complete_request
);
415 static void blk_mq_start_request(struct request
*rq
, bool last
)
417 struct request_queue
*q
= rq
->q
;
419 trace_block_rq_issue(q
, rq
);
421 rq
->resid_len
= blk_rq_bytes(rq
);
422 if (unlikely(blk_bidi_rq(rq
)))
423 rq
->next_rq
->resid_len
= blk_rq_bytes(rq
->next_rq
);
426 * Just mark start time and set the started bit. Due to memory
427 * ordering, we know we'll see the correct deadline as long as
428 * REQ_ATOMIC_STARTED is seen.
430 rq
->deadline
= jiffies
+ q
->rq_timeout
;
433 * Mark us as started and clear complete. Complete might have been
434 * set if requeue raced with timeout, which then marked it as
435 * complete. So be sure to clear complete again when we start
436 * the request, otherwise we'll ignore the completion event.
438 set_bit(REQ_ATOM_STARTED
, &rq
->atomic_flags
);
439 clear_bit(REQ_ATOM_COMPLETE
, &rq
->atomic_flags
);
441 if (q
->dma_drain_size
&& blk_rq_bytes(rq
)) {
443 * Make sure space for the drain appears. We know we can do
444 * this because max_hw_segments has been adjusted to be one
445 * fewer than the device can handle.
447 rq
->nr_phys_segments
++;
451 * Flag the last request in the series so that drivers know when IO
452 * should be kicked off, if they don't do it on a per-request basis.
454 * Note: the flag isn't the only condition drivers should do kick off.
455 * If drive is busy, the last request might not have the bit set.
458 rq
->cmd_flags
|= REQ_END
;
461 static void __blk_mq_requeue_request(struct request
*rq
)
463 struct request_queue
*q
= rq
->q
;
465 trace_block_rq_requeue(q
, rq
);
466 clear_bit(REQ_ATOM_STARTED
, &rq
->atomic_flags
);
468 rq
->cmd_flags
&= ~REQ_END
;
470 if (q
->dma_drain_size
&& blk_rq_bytes(rq
))
471 rq
->nr_phys_segments
--;
474 void blk_mq_requeue_request(struct request
*rq
)
476 __blk_mq_requeue_request(rq
);
477 blk_clear_rq_complete(rq
);
479 BUG_ON(blk_queued_rq(rq
));
480 blk_mq_insert_request(rq
, true, true, false);
482 EXPORT_SYMBOL(blk_mq_requeue_request
);
484 struct request
*blk_mq_tag_to_rq(struct blk_mq_tags
*tags
, unsigned int tag
)
486 return tags
->rqs
[tag
];
488 EXPORT_SYMBOL(blk_mq_tag_to_rq
);
490 struct blk_mq_timeout_data
{
491 struct blk_mq_hw_ctx
*hctx
;
493 unsigned int *next_set
;
496 static void blk_mq_timeout_check(void *__data
, unsigned long *free_tags
)
498 struct blk_mq_timeout_data
*data
= __data
;
499 struct blk_mq_hw_ctx
*hctx
= data
->hctx
;
502 /* It may not be in flight yet (this is where
503 * the REQ_ATOMIC_STARTED flag comes in). The requests are
504 * statically allocated, so we know it's always safe to access the
505 * memory associated with a bit offset into ->rqs[].
511 tag
= find_next_zero_bit(free_tags
, hctx
->tags
->nr_tags
, tag
);
512 if (tag
>= hctx
->tags
->nr_tags
)
515 rq
= blk_mq_tag_to_rq(hctx
->tags
, tag
++);
516 if (rq
->q
!= hctx
->queue
)
518 if (!test_bit(REQ_ATOM_STARTED
, &rq
->atomic_flags
))
521 blk_rq_check_expired(rq
, data
->next
, data
->next_set
);
525 static void blk_mq_hw_ctx_check_timeout(struct blk_mq_hw_ctx
*hctx
,
527 unsigned int *next_set
)
529 struct blk_mq_timeout_data data
= {
532 .next_set
= next_set
,
536 * Ask the tagging code to iterate busy requests, so we can
537 * check them for timeout.
539 blk_mq_tag_busy_iter(hctx
->tags
, blk_mq_timeout_check
, &data
);
542 static enum blk_eh_timer_return
blk_mq_rq_timed_out(struct request
*rq
)
544 struct request_queue
*q
= rq
->q
;
547 * We know that complete is set at this point. If STARTED isn't set
548 * anymore, then the request isn't active and the "timeout" should
549 * just be ignored. This can happen due to the bitflag ordering.
550 * Timeout first checks if STARTED is set, and if it is, assumes
551 * the request is active. But if we race with completion, then
552 * we both flags will get cleared. So check here again, and ignore
553 * a timeout event with a request that isn't active.
555 if (!test_bit(REQ_ATOM_STARTED
, &rq
->atomic_flags
))
556 return BLK_EH_NOT_HANDLED
;
558 if (!q
->mq_ops
->timeout
)
559 return BLK_EH_RESET_TIMER
;
561 return q
->mq_ops
->timeout(rq
);
564 static void blk_mq_rq_timer(unsigned long data
)
566 struct request_queue
*q
= (struct request_queue
*) data
;
567 struct blk_mq_hw_ctx
*hctx
;
568 unsigned long next
= 0;
571 queue_for_each_hw_ctx(q
, hctx
, i
)
572 blk_mq_hw_ctx_check_timeout(hctx
, &next
, &next_set
);
575 mod_timer(&q
->timeout
, round_jiffies_up(next
));
579 * Reverse check our software queue for entries that we could potentially
580 * merge with. Currently includes a hand-wavy stop count of 8, to not spend
581 * too much time checking for merges.
583 static bool blk_mq_attempt_merge(struct request_queue
*q
,
584 struct blk_mq_ctx
*ctx
, struct bio
*bio
)
589 list_for_each_entry_reverse(rq
, &ctx
->rq_list
, queuelist
) {
595 if (!blk_rq_merge_ok(rq
, bio
))
598 el_ret
= blk_try_merge(rq
, bio
);
599 if (el_ret
== ELEVATOR_BACK_MERGE
) {
600 if (bio_attempt_back_merge(q
, rq
, bio
)) {
605 } else if (el_ret
== ELEVATOR_FRONT_MERGE
) {
606 if (bio_attempt_front_merge(q
, rq
, bio
)) {
618 * Run this hardware queue, pulling any software queues mapped to it in.
619 * Note that this function currently has various problems around ordering
620 * of IO. In particular, we'd like FIFO behaviour on handling existing
621 * items on the hctx->dispatch list. Ignore that for now.
623 static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx
*hctx
)
625 struct request_queue
*q
= hctx
->queue
;
626 struct blk_mq_ctx
*ctx
;
631 WARN_ON(!cpumask_test_cpu(raw_smp_processor_id(), hctx
->cpumask
));
633 if (unlikely(test_bit(BLK_MQ_S_STOPPED
, &hctx
->state
)))
639 * Touch any software queue that has pending entries.
641 for_each_set_bit(bit
, hctx
->ctx_map
, hctx
->nr_ctx
) {
642 clear_bit(bit
, hctx
->ctx_map
);
643 ctx
= hctx
->ctxs
[bit
];
645 spin_lock(&ctx
->lock
);
646 list_splice_tail_init(&ctx
->rq_list
, &rq_list
);
647 spin_unlock(&ctx
->lock
);
651 * If we have previous entries on our dispatch list, grab them
652 * and stuff them at the front for more fair dispatch.
654 if (!list_empty_careful(&hctx
->dispatch
)) {
655 spin_lock(&hctx
->lock
);
656 if (!list_empty(&hctx
->dispatch
))
657 list_splice_init(&hctx
->dispatch
, &rq_list
);
658 spin_unlock(&hctx
->lock
);
662 * Delete and return all entries from our dispatch list
667 * Now process all the entries, sending them to the driver.
669 while (!list_empty(&rq_list
)) {
672 rq
= list_first_entry(&rq_list
, struct request
, queuelist
);
673 list_del_init(&rq
->queuelist
);
675 blk_mq_start_request(rq
, list_empty(&rq_list
));
677 ret
= q
->mq_ops
->queue_rq(hctx
, rq
);
679 case BLK_MQ_RQ_QUEUE_OK
:
682 case BLK_MQ_RQ_QUEUE_BUSY
:
683 list_add(&rq
->queuelist
, &rq_list
);
684 __blk_mq_requeue_request(rq
);
687 pr_err("blk-mq: bad return on queue: %d\n", ret
);
688 case BLK_MQ_RQ_QUEUE_ERROR
:
690 blk_mq_end_io(rq
, rq
->errors
);
694 if (ret
== BLK_MQ_RQ_QUEUE_BUSY
)
699 hctx
->dispatched
[0]++;
700 else if (queued
< (1 << (BLK_MQ_MAX_DISPATCH_ORDER
- 1)))
701 hctx
->dispatched
[ilog2(queued
) + 1]++;
704 * Any items that need requeuing? Stuff them into hctx->dispatch,
705 * that is where we will continue on next queue run.
707 if (!list_empty(&rq_list
)) {
708 spin_lock(&hctx
->lock
);
709 list_splice(&rq_list
, &hctx
->dispatch
);
710 spin_unlock(&hctx
->lock
);
715 * It'd be great if the workqueue API had a way to pass
716 * in a mask and had some smarts for more clever placement.
717 * For now we just round-robin here, switching for every
718 * BLK_MQ_CPU_WORK_BATCH queued items.
720 static int blk_mq_hctx_next_cpu(struct blk_mq_hw_ctx
*hctx
)
722 int cpu
= hctx
->next_cpu
;
724 if (--hctx
->next_cpu_batch
<= 0) {
727 next_cpu
= cpumask_next(hctx
->next_cpu
, hctx
->cpumask
);
728 if (next_cpu
>= nr_cpu_ids
)
729 next_cpu
= cpumask_first(hctx
->cpumask
);
731 hctx
->next_cpu
= next_cpu
;
732 hctx
->next_cpu_batch
= BLK_MQ_CPU_WORK_BATCH
;
738 void blk_mq_run_hw_queue(struct blk_mq_hw_ctx
*hctx
, bool async
)
740 if (unlikely(test_bit(BLK_MQ_S_STOPPED
, &hctx
->state
)))
743 if (!async
&& cpumask_test_cpu(smp_processor_id(), hctx
->cpumask
))
744 __blk_mq_run_hw_queue(hctx
);
745 else if (hctx
->queue
->nr_hw_queues
== 1)
746 kblockd_schedule_delayed_work(&hctx
->run_work
, 0);
750 cpu
= blk_mq_hctx_next_cpu(hctx
);
751 kblockd_schedule_delayed_work_on(cpu
, &hctx
->run_work
, 0);
755 void blk_mq_run_queues(struct request_queue
*q
, bool async
)
757 struct blk_mq_hw_ctx
*hctx
;
760 queue_for_each_hw_ctx(q
, hctx
, i
) {
761 if ((!blk_mq_hctx_has_pending(hctx
) &&
762 list_empty_careful(&hctx
->dispatch
)) ||
763 test_bit(BLK_MQ_S_STOPPED
, &hctx
->state
))
767 blk_mq_run_hw_queue(hctx
, async
);
771 EXPORT_SYMBOL(blk_mq_run_queues
);
773 void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx
*hctx
)
775 cancel_delayed_work(&hctx
->run_work
);
776 cancel_delayed_work(&hctx
->delay_work
);
777 set_bit(BLK_MQ_S_STOPPED
, &hctx
->state
);
779 EXPORT_SYMBOL(blk_mq_stop_hw_queue
);
781 void blk_mq_stop_hw_queues(struct request_queue
*q
)
783 struct blk_mq_hw_ctx
*hctx
;
786 queue_for_each_hw_ctx(q
, hctx
, i
)
787 blk_mq_stop_hw_queue(hctx
);
789 EXPORT_SYMBOL(blk_mq_stop_hw_queues
);
791 void blk_mq_start_hw_queue(struct blk_mq_hw_ctx
*hctx
)
793 clear_bit(BLK_MQ_S_STOPPED
, &hctx
->state
);
796 __blk_mq_run_hw_queue(hctx
);
799 EXPORT_SYMBOL(blk_mq_start_hw_queue
);
801 void blk_mq_start_hw_queues(struct request_queue
*q
)
803 struct blk_mq_hw_ctx
*hctx
;
806 queue_for_each_hw_ctx(q
, hctx
, i
)
807 blk_mq_start_hw_queue(hctx
);
809 EXPORT_SYMBOL(blk_mq_start_hw_queues
);
812 void blk_mq_start_stopped_hw_queues(struct request_queue
*q
, bool async
)
814 struct blk_mq_hw_ctx
*hctx
;
817 queue_for_each_hw_ctx(q
, hctx
, i
) {
818 if (!test_bit(BLK_MQ_S_STOPPED
, &hctx
->state
))
821 clear_bit(BLK_MQ_S_STOPPED
, &hctx
->state
);
823 blk_mq_run_hw_queue(hctx
, async
);
827 EXPORT_SYMBOL(blk_mq_start_stopped_hw_queues
);
829 static void blk_mq_run_work_fn(struct work_struct
*work
)
831 struct blk_mq_hw_ctx
*hctx
;
833 hctx
= container_of(work
, struct blk_mq_hw_ctx
, run_work
.work
);
835 __blk_mq_run_hw_queue(hctx
);
838 static void blk_mq_delay_work_fn(struct work_struct
*work
)
840 struct blk_mq_hw_ctx
*hctx
;
842 hctx
= container_of(work
, struct blk_mq_hw_ctx
, delay_work
.work
);
844 if (test_and_clear_bit(BLK_MQ_S_STOPPED
, &hctx
->state
))
845 __blk_mq_run_hw_queue(hctx
);
848 void blk_mq_delay_queue(struct blk_mq_hw_ctx
*hctx
, unsigned long msecs
)
850 unsigned long tmo
= msecs_to_jiffies(msecs
);
852 if (hctx
->queue
->nr_hw_queues
== 1)
853 kblockd_schedule_delayed_work(&hctx
->delay_work
, tmo
);
857 cpu
= blk_mq_hctx_next_cpu(hctx
);
858 kblockd_schedule_delayed_work_on(cpu
, &hctx
->delay_work
, tmo
);
861 EXPORT_SYMBOL(blk_mq_delay_queue
);
863 static void __blk_mq_insert_request(struct blk_mq_hw_ctx
*hctx
,
864 struct request
*rq
, bool at_head
)
866 struct blk_mq_ctx
*ctx
= rq
->mq_ctx
;
868 trace_block_rq_insert(hctx
->queue
, rq
);
871 list_add(&rq
->queuelist
, &ctx
->rq_list
);
873 list_add_tail(&rq
->queuelist
, &ctx
->rq_list
);
875 blk_mq_hctx_mark_pending(hctx
, ctx
);
878 * We do this early, to ensure we are on the right CPU.
883 void blk_mq_insert_request(struct request
*rq
, bool at_head
, bool run_queue
,
886 struct request_queue
*q
= rq
->q
;
887 struct blk_mq_hw_ctx
*hctx
;
888 struct blk_mq_ctx
*ctx
= rq
->mq_ctx
, *current_ctx
;
890 current_ctx
= blk_mq_get_ctx(q
);
891 if (!cpu_online(ctx
->cpu
))
892 rq
->mq_ctx
= ctx
= current_ctx
;
894 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
896 if (rq
->cmd_flags
& (REQ_FLUSH
| REQ_FUA
) &&
897 !(rq
->cmd_flags
& (REQ_FLUSH_SEQ
))) {
898 blk_insert_flush(rq
);
900 spin_lock(&ctx
->lock
);
901 __blk_mq_insert_request(hctx
, rq
, at_head
);
902 spin_unlock(&ctx
->lock
);
906 blk_mq_run_hw_queue(hctx
, async
);
908 blk_mq_put_ctx(current_ctx
);
911 static void blk_mq_insert_requests(struct request_queue
*q
,
912 struct blk_mq_ctx
*ctx
,
913 struct list_head
*list
,
918 struct blk_mq_hw_ctx
*hctx
;
919 struct blk_mq_ctx
*current_ctx
;
921 trace_block_unplug(q
, depth
, !from_schedule
);
923 current_ctx
= blk_mq_get_ctx(q
);
925 if (!cpu_online(ctx
->cpu
))
927 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
930 * preemption doesn't flush plug list, so it's possible ctx->cpu is
933 spin_lock(&ctx
->lock
);
934 while (!list_empty(list
)) {
937 rq
= list_first_entry(list
, struct request
, queuelist
);
938 list_del_init(&rq
->queuelist
);
940 __blk_mq_insert_request(hctx
, rq
, false);
942 spin_unlock(&ctx
->lock
);
944 blk_mq_run_hw_queue(hctx
, from_schedule
);
945 blk_mq_put_ctx(current_ctx
);
948 static int plug_ctx_cmp(void *priv
, struct list_head
*a
, struct list_head
*b
)
950 struct request
*rqa
= container_of(a
, struct request
, queuelist
);
951 struct request
*rqb
= container_of(b
, struct request
, queuelist
);
953 return !(rqa
->mq_ctx
< rqb
->mq_ctx
||
954 (rqa
->mq_ctx
== rqb
->mq_ctx
&&
955 blk_rq_pos(rqa
) < blk_rq_pos(rqb
)));
958 void blk_mq_flush_plug_list(struct blk_plug
*plug
, bool from_schedule
)
960 struct blk_mq_ctx
*this_ctx
;
961 struct request_queue
*this_q
;
967 list_splice_init(&plug
->mq_list
, &list
);
969 list_sort(NULL
, &list
, plug_ctx_cmp
);
975 while (!list_empty(&list
)) {
976 rq
= list_entry_rq(list
.next
);
977 list_del_init(&rq
->queuelist
);
979 if (rq
->mq_ctx
!= this_ctx
) {
981 blk_mq_insert_requests(this_q
, this_ctx
,
986 this_ctx
= rq
->mq_ctx
;
992 list_add_tail(&rq
->queuelist
, &ctx_list
);
996 * If 'this_ctx' is set, we know we have entries to complete
997 * on 'ctx_list'. Do those.
1000 blk_mq_insert_requests(this_q
, this_ctx
, &ctx_list
, depth
,
1005 static void blk_mq_bio_to_request(struct request
*rq
, struct bio
*bio
)
1007 init_request_from_bio(rq
, bio
);
1008 blk_account_io_start(rq
, 1);
1011 static void blk_mq_make_request(struct request_queue
*q
, struct bio
*bio
)
1013 struct blk_mq_hw_ctx
*hctx
;
1014 struct blk_mq_ctx
*ctx
;
1015 const int is_sync
= rw_is_sync(bio
->bi_rw
);
1016 const int is_flush_fua
= bio
->bi_rw
& (REQ_FLUSH
| REQ_FUA
);
1017 int rw
= bio_data_dir(bio
);
1019 unsigned int use_plug
, request_count
= 0;
1022 * If we have multiple hardware queues, just go directly to
1023 * one of those for sync IO.
1025 use_plug
= !is_flush_fua
&& ((q
->nr_hw_queues
== 1) || !is_sync
);
1027 blk_queue_bounce(q
, &bio
);
1029 if (bio_integrity_enabled(bio
) && bio_integrity_prep(bio
)) {
1030 bio_endio(bio
, -EIO
);
1034 if (use_plug
&& blk_attempt_plug_merge(q
, bio
, &request_count
))
1037 if (blk_mq_queue_enter(q
)) {
1038 bio_endio(bio
, -EIO
);
1042 ctx
= blk_mq_get_ctx(q
);
1043 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
1047 trace_block_getrq(q
, bio
, rw
);
1048 rq
= __blk_mq_alloc_request(hctx
, ctx
, GFP_ATOMIC
, false);
1050 blk_mq_rq_ctx_init(q
, ctx
, rq
, rw
);
1052 blk_mq_put_ctx(ctx
);
1053 trace_block_sleeprq(q
, bio
, rw
);
1054 rq
= blk_mq_alloc_request_pinned(q
, rw
, __GFP_WAIT
|GFP_ATOMIC
,
1057 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
1062 if (unlikely(is_flush_fua
)) {
1063 blk_mq_bio_to_request(rq
, bio
);
1064 blk_insert_flush(rq
);
1069 * A task plug currently exists. Since this is completely lockless,
1070 * utilize that to temporarily store requests until the task is
1071 * either done or scheduled away.
1074 struct blk_plug
*plug
= current
->plug
;
1077 blk_mq_bio_to_request(rq
, bio
);
1078 if (list_empty(&plug
->mq_list
))
1079 trace_block_plug(q
);
1080 else if (request_count
>= BLK_MAX_REQUEST_COUNT
) {
1081 blk_flush_plug_list(plug
, false);
1082 trace_block_plug(q
);
1084 list_add_tail(&rq
->queuelist
, &plug
->mq_list
);
1085 blk_mq_put_ctx(ctx
);
1090 if (!(hctx
->flags
& BLK_MQ_F_SHOULD_MERGE
)) {
1091 init_request_from_bio(rq
, bio
);
1093 spin_lock(&ctx
->lock
);
1095 __blk_mq_insert_request(hctx
, rq
, false);
1096 spin_unlock(&ctx
->lock
);
1097 blk_account_io_start(rq
, 1);
1099 spin_lock(&ctx
->lock
);
1100 if (!blk_mq_attempt_merge(q
, ctx
, bio
)) {
1101 init_request_from_bio(rq
, bio
);
1105 spin_unlock(&ctx
->lock
);
1106 __blk_mq_free_request(hctx
, ctx
, rq
);
1111 * For a SYNC request, send it to the hardware immediately. For an
1112 * ASYNC request, just ensure that we run it later on. The latter
1113 * allows for merging opportunities and more efficient dispatching.
1116 blk_mq_run_hw_queue(hctx
, !is_sync
|| is_flush_fua
);
1117 blk_mq_put_ctx(ctx
);
1121 * Default mapping to a software queue, since we use one per CPU.
1123 struct blk_mq_hw_ctx
*blk_mq_map_queue(struct request_queue
*q
, const int cpu
)
1125 return q
->queue_hw_ctx
[q
->mq_map
[cpu
]];
1127 EXPORT_SYMBOL(blk_mq_map_queue
);
1129 struct blk_mq_hw_ctx
*blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set
*set
,
1130 unsigned int hctx_index
)
1132 return kzalloc_node(sizeof(struct blk_mq_hw_ctx
), GFP_KERNEL
,
1135 EXPORT_SYMBOL(blk_mq_alloc_single_hw_queue
);
1137 void blk_mq_free_single_hw_queue(struct blk_mq_hw_ctx
*hctx
,
1138 unsigned int hctx_index
)
1142 EXPORT_SYMBOL(blk_mq_free_single_hw_queue
);
1144 static void blk_mq_hctx_notify(void *data
, unsigned long action
,
1147 struct blk_mq_hw_ctx
*hctx
= data
;
1148 struct request_queue
*q
= hctx
->queue
;
1149 struct blk_mq_ctx
*ctx
;
1152 if (action
!= CPU_DEAD
&& action
!= CPU_DEAD_FROZEN
)
1156 * Move ctx entries to new CPU, if this one is going away.
1158 ctx
= __blk_mq_get_ctx(q
, cpu
);
1160 spin_lock(&ctx
->lock
);
1161 if (!list_empty(&ctx
->rq_list
)) {
1162 list_splice_init(&ctx
->rq_list
, &tmp
);
1163 clear_bit(ctx
->index_hw
, hctx
->ctx_map
);
1165 spin_unlock(&ctx
->lock
);
1167 if (list_empty(&tmp
))
1170 ctx
= blk_mq_get_ctx(q
);
1171 spin_lock(&ctx
->lock
);
1173 while (!list_empty(&tmp
)) {
1176 rq
= list_first_entry(&tmp
, struct request
, queuelist
);
1178 list_move_tail(&rq
->queuelist
, &ctx
->rq_list
);
1181 hctx
= q
->mq_ops
->map_queue(q
, ctx
->cpu
);
1182 blk_mq_hctx_mark_pending(hctx
, ctx
);
1184 spin_unlock(&ctx
->lock
);
1186 blk_mq_run_hw_queue(hctx
, true);
1187 blk_mq_put_ctx(ctx
);
1190 static void blk_mq_free_rq_map(struct blk_mq_tag_set
*set
,
1191 struct blk_mq_tags
*tags
, unsigned int hctx_idx
)
1195 if (tags
->rqs
&& set
->ops
->exit_request
) {
1198 for (i
= 0; i
< tags
->nr_tags
; i
++) {
1201 set
->ops
->exit_request(set
->driver_data
, tags
->rqs
[i
],
1206 while (!list_empty(&tags
->page_list
)) {
1207 page
= list_first_entry(&tags
->page_list
, struct page
, lru
);
1208 list_del_init(&page
->lru
);
1209 __free_pages(page
, page
->private);
1214 blk_mq_free_tags(tags
);
1217 static size_t order_to_size(unsigned int order
)
1219 return (size_t)PAGE_SIZE
<< order
;
1222 static struct blk_mq_tags
*blk_mq_init_rq_map(struct blk_mq_tag_set
*set
,
1223 unsigned int hctx_idx
)
1225 struct blk_mq_tags
*tags
;
1226 unsigned int i
, j
, entries_per_page
, max_order
= 4;
1227 size_t rq_size
, left
;
1229 tags
= blk_mq_init_tags(set
->queue_depth
, set
->reserved_tags
,
1234 INIT_LIST_HEAD(&tags
->page_list
);
1236 tags
->rqs
= kmalloc_node(set
->queue_depth
* sizeof(struct request
*),
1237 GFP_KERNEL
, set
->numa_node
);
1239 blk_mq_free_tags(tags
);
1244 * rq_size is the size of the request plus driver payload, rounded
1245 * to the cacheline size
1247 rq_size
= round_up(sizeof(struct request
) + set
->cmd_size
,
1249 left
= rq_size
* set
->queue_depth
;
1251 for (i
= 0; i
< set
->queue_depth
; ) {
1252 int this_order
= max_order
;
1257 while (left
< order_to_size(this_order
- 1) && this_order
)
1261 page
= alloc_pages_node(set
->numa_node
, GFP_KERNEL
,
1267 if (order_to_size(this_order
) < rq_size
)
1274 page
->private = this_order
;
1275 list_add_tail(&page
->lru
, &tags
->page_list
);
1277 p
= page_address(page
);
1278 entries_per_page
= order_to_size(this_order
) / rq_size
;
1279 to_do
= min(entries_per_page
, set
->queue_depth
- i
);
1280 left
-= to_do
* rq_size
;
1281 for (j
= 0; j
< to_do
; j
++) {
1283 if (set
->ops
->init_request
) {
1284 if (set
->ops
->init_request(set
->driver_data
,
1285 tags
->rqs
[i
], hctx_idx
, i
,
1298 pr_warn("%s: failed to allocate requests\n", __func__
);
1299 blk_mq_free_rq_map(set
, tags
, hctx_idx
);
1303 static int blk_mq_init_hw_queues(struct request_queue
*q
,
1304 struct blk_mq_tag_set
*set
)
1306 struct blk_mq_hw_ctx
*hctx
;
1310 * Initialize hardware queues
1312 queue_for_each_hw_ctx(q
, hctx
, i
) {
1313 unsigned int num_maps
;
1316 node
= hctx
->numa_node
;
1317 if (node
== NUMA_NO_NODE
)
1318 node
= hctx
->numa_node
= set
->numa_node
;
1320 INIT_DELAYED_WORK(&hctx
->run_work
, blk_mq_run_work_fn
);
1321 INIT_DELAYED_WORK(&hctx
->delay_work
, blk_mq_delay_work_fn
);
1322 spin_lock_init(&hctx
->lock
);
1323 INIT_LIST_HEAD(&hctx
->dispatch
);
1325 hctx
->queue_num
= i
;
1326 hctx
->flags
= set
->flags
;
1327 hctx
->cmd_size
= set
->cmd_size
;
1329 blk_mq_init_cpu_notifier(&hctx
->cpu_notifier
,
1330 blk_mq_hctx_notify
, hctx
);
1331 blk_mq_register_cpu_notifier(&hctx
->cpu_notifier
);
1333 hctx
->tags
= set
->tags
[i
];
1336 * Allocate space for all possible cpus to avoid allocation in
1339 hctx
->ctxs
= kmalloc_node(nr_cpu_ids
* sizeof(void *),
1344 num_maps
= ALIGN(nr_cpu_ids
, BITS_PER_LONG
) / BITS_PER_LONG
;
1345 hctx
->ctx_map
= kzalloc_node(num_maps
* sizeof(unsigned long),
1350 hctx
->nr_ctx_map
= num_maps
;
1353 if (set
->ops
->init_hctx
&&
1354 set
->ops
->init_hctx(hctx
, set
->driver_data
, i
))
1358 if (i
== q
->nr_hw_queues
)
1364 queue_for_each_hw_ctx(q
, hctx
, j
) {
1368 if (set
->ops
->exit_hctx
)
1369 set
->ops
->exit_hctx(hctx
, j
);
1371 blk_mq_unregister_cpu_notifier(&hctx
->cpu_notifier
);
1373 kfree(hctx
->ctx_map
);
1379 static void blk_mq_init_cpu_queues(struct request_queue
*q
,
1380 unsigned int nr_hw_queues
)
1384 for_each_possible_cpu(i
) {
1385 struct blk_mq_ctx
*__ctx
= per_cpu_ptr(q
->queue_ctx
, i
);
1386 struct blk_mq_hw_ctx
*hctx
;
1388 memset(__ctx
, 0, sizeof(*__ctx
));
1390 spin_lock_init(&__ctx
->lock
);
1391 INIT_LIST_HEAD(&__ctx
->rq_list
);
1394 /* If the cpu isn't online, the cpu is mapped to first hctx */
1398 hctx
= q
->mq_ops
->map_queue(q
, i
);
1399 cpumask_set_cpu(i
, hctx
->cpumask
);
1403 * Set local node, IFF we have more than one hw queue. If
1404 * not, we remain on the home node of the device
1406 if (nr_hw_queues
> 1 && hctx
->numa_node
== NUMA_NO_NODE
)
1407 hctx
->numa_node
= cpu_to_node(i
);
1411 static void blk_mq_map_swqueue(struct request_queue
*q
)
1414 struct blk_mq_hw_ctx
*hctx
;
1415 struct blk_mq_ctx
*ctx
;
1417 queue_for_each_hw_ctx(q
, hctx
, i
) {
1418 cpumask_clear(hctx
->cpumask
);
1423 * Map software to hardware queues
1425 queue_for_each_ctx(q
, ctx
, i
) {
1426 /* If the cpu isn't online, the cpu is mapped to first hctx */
1430 hctx
= q
->mq_ops
->map_queue(q
, i
);
1431 cpumask_set_cpu(i
, hctx
->cpumask
);
1432 ctx
->index_hw
= hctx
->nr_ctx
;
1433 hctx
->ctxs
[hctx
->nr_ctx
++] = ctx
;
1436 queue_for_each_hw_ctx(q
, hctx
, i
) {
1437 hctx
->next_cpu
= cpumask_first(hctx
->cpumask
);
1438 hctx
->next_cpu_batch
= BLK_MQ_CPU_WORK_BATCH
;
1442 struct request_queue
*blk_mq_init_queue(struct blk_mq_tag_set
*set
)
1444 struct blk_mq_hw_ctx
**hctxs
;
1445 struct blk_mq_ctx
*ctx
;
1446 struct request_queue
*q
;
1449 ctx
= alloc_percpu(struct blk_mq_ctx
);
1451 return ERR_PTR(-ENOMEM
);
1453 hctxs
= kmalloc_node(set
->nr_hw_queues
* sizeof(*hctxs
), GFP_KERNEL
,
1459 for (i
= 0; i
< set
->nr_hw_queues
; i
++) {
1460 hctxs
[i
] = set
->ops
->alloc_hctx(set
, i
);
1464 if (!zalloc_cpumask_var(&hctxs
[i
]->cpumask
, GFP_KERNEL
))
1467 hctxs
[i
]->numa_node
= NUMA_NO_NODE
;
1468 hctxs
[i
]->queue_num
= i
;
1471 q
= blk_alloc_queue_node(GFP_KERNEL
, set
->numa_node
);
1475 q
->mq_map
= blk_mq_make_queue_map(set
);
1479 setup_timer(&q
->timeout
, blk_mq_rq_timer
, (unsigned long) q
);
1480 blk_queue_rq_timeout(q
, 30000);
1482 q
->nr_queues
= nr_cpu_ids
;
1483 q
->nr_hw_queues
= set
->nr_hw_queues
;
1486 q
->queue_hw_ctx
= hctxs
;
1488 q
->mq_ops
= set
->ops
;
1489 q
->queue_flags
|= QUEUE_FLAG_MQ_DEFAULT
;
1491 q
->sg_reserved_size
= INT_MAX
;
1493 blk_queue_make_request(q
, blk_mq_make_request
);
1494 blk_queue_rq_timed_out(q
, blk_mq_rq_timed_out
);
1496 blk_queue_rq_timeout(q
, set
->timeout
);
1498 if (set
->ops
->complete
)
1499 blk_queue_softirq_done(q
, set
->ops
->complete
);
1501 blk_mq_init_flush(q
);
1502 blk_mq_init_cpu_queues(q
, set
->nr_hw_queues
);
1504 q
->flush_rq
= kzalloc(round_up(sizeof(struct request
) +
1505 set
->cmd_size
, cache_line_size()),
1510 if (blk_mq_init_hw_queues(q
, set
))
1513 blk_mq_map_swqueue(q
);
1515 mutex_lock(&all_q_mutex
);
1516 list_add_tail(&q
->all_q_node
, &all_q_list
);
1517 mutex_unlock(&all_q_mutex
);
1526 blk_cleanup_queue(q
);
1528 for (i
= 0; i
< set
->nr_hw_queues
; i
++) {
1531 free_cpumask_var(hctxs
[i
]->cpumask
);
1532 set
->ops
->free_hctx(hctxs
[i
], i
);
1537 return ERR_PTR(-ENOMEM
);
1539 EXPORT_SYMBOL(blk_mq_init_queue
);
1541 void blk_mq_free_queue(struct request_queue
*q
)
1543 struct blk_mq_hw_ctx
*hctx
;
1546 queue_for_each_hw_ctx(q
, hctx
, i
) {
1547 kfree(hctx
->ctx_map
);
1549 blk_mq_unregister_cpu_notifier(&hctx
->cpu_notifier
);
1550 if (q
->mq_ops
->exit_hctx
)
1551 q
->mq_ops
->exit_hctx(hctx
, i
);
1552 free_cpumask_var(hctx
->cpumask
);
1553 q
->mq_ops
->free_hctx(hctx
, i
);
1556 free_percpu(q
->queue_ctx
);
1557 kfree(q
->queue_hw_ctx
);
1560 q
->queue_ctx
= NULL
;
1561 q
->queue_hw_ctx
= NULL
;
1564 mutex_lock(&all_q_mutex
);
1565 list_del_init(&q
->all_q_node
);
1566 mutex_unlock(&all_q_mutex
);
1569 /* Basically redo blk_mq_init_queue with queue frozen */
1570 static void blk_mq_queue_reinit(struct request_queue
*q
)
1572 blk_mq_freeze_queue(q
);
1574 blk_mq_update_queue_map(q
->mq_map
, q
->nr_hw_queues
);
1577 * redo blk_mq_init_cpu_queues and blk_mq_init_hw_queues. FIXME: maybe
1578 * we should change hctx numa_node according to new topology (this
1579 * involves free and re-allocate memory, worthy doing?)
1582 blk_mq_map_swqueue(q
);
1584 blk_mq_unfreeze_queue(q
);
1587 static int blk_mq_queue_reinit_notify(struct notifier_block
*nb
,
1588 unsigned long action
, void *hcpu
)
1590 struct request_queue
*q
;
1593 * Before new mappings are established, hotadded cpu might already
1594 * start handling requests. This doesn't break anything as we map
1595 * offline CPUs to first hardware queue. We will re-init the queue
1596 * below to get optimal settings.
1598 if (action
!= CPU_DEAD
&& action
!= CPU_DEAD_FROZEN
&&
1599 action
!= CPU_ONLINE
&& action
!= CPU_ONLINE_FROZEN
)
1602 mutex_lock(&all_q_mutex
);
1603 list_for_each_entry(q
, &all_q_list
, all_q_node
)
1604 blk_mq_queue_reinit(q
);
1605 mutex_unlock(&all_q_mutex
);
1609 int blk_mq_alloc_tag_set(struct blk_mq_tag_set
*set
)
1613 if (!set
->nr_hw_queues
)
1615 if (!set
->queue_depth
|| set
->queue_depth
> BLK_MQ_MAX_DEPTH
)
1617 if (set
->queue_depth
< set
->reserved_tags
+ BLK_MQ_TAG_MIN
)
1620 if (!set
->nr_hw_queues
||
1621 !set
->ops
->queue_rq
|| !set
->ops
->map_queue
||
1622 !set
->ops
->alloc_hctx
|| !set
->ops
->free_hctx
)
1626 set
->tags
= kmalloc_node(set
->nr_hw_queues
*
1627 sizeof(struct blk_mq_tags
*),
1628 GFP_KERNEL
, set
->numa_node
);
1632 for (i
= 0; i
< set
->nr_hw_queues
; i
++) {
1633 set
->tags
[i
] = blk_mq_init_rq_map(set
, i
);
1642 blk_mq_free_rq_map(set
, set
->tags
[i
], i
);
1646 EXPORT_SYMBOL(blk_mq_alloc_tag_set
);
1648 void blk_mq_free_tag_set(struct blk_mq_tag_set
*set
)
1652 for (i
= 0; i
< set
->nr_hw_queues
; i
++)
1653 blk_mq_free_rq_map(set
, set
->tags
[i
], i
);
1656 EXPORT_SYMBOL(blk_mq_free_tag_set
);
1658 void blk_mq_disable_hotplug(void)
1660 mutex_lock(&all_q_mutex
);
1663 void blk_mq_enable_hotplug(void)
1665 mutex_unlock(&all_q_mutex
);
1668 static int __init
blk_mq_init(void)
1672 /* Must be called after percpu_counter_hotcpu_callback() */
1673 hotcpu_notifier(blk_mq_queue_reinit_notify
, -10);
1677 subsys_initcall(blk_mq_init
);