blk-mq-sched.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * blk-mq scheduling framework
  3. *
  4. * Copyright (C) 2016 Jens Axboe
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. #include <linux/blk-mq.h>
  9. #include <trace/events/block.h>
  10. #include "blk.h"
  11. #include "blk-mq.h"
  12. #include "blk-mq-debugfs.h"
  13. #include "blk-mq-sched.h"
  14. #include "blk-mq-tag.h"
  15. #include "blk-wbt.h"
  16. void blk_mq_sched_free_hctx_data(struct request_queue *q,
  17. void (*exit)(struct blk_mq_hw_ctx *))
  18. {
  19. struct blk_mq_hw_ctx *hctx;
  20. int i;
  21. queue_for_each_hw_ctx(q, hctx, i) {
  22. if (exit && hctx->sched_data)
  23. exit(hctx);
  24. kfree(hctx->sched_data);
  25. hctx->sched_data = NULL;
  26. }
  27. }
  28. EXPORT_SYMBOL_GPL(blk_mq_sched_free_hctx_data);
  29. void blk_mq_sched_assign_ioc(struct request *rq, struct bio *bio)
  30. {
  31. struct request_queue *q = rq->q;
  32. struct io_context *ioc = rq_ioc(bio);
  33. struct io_cq *icq;
  34. spin_lock_irq(q->queue_lock);
  35. icq = ioc_lookup_icq(ioc, q);
  36. spin_unlock_irq(q->queue_lock);
  37. if (!icq) {
  38. icq = ioc_create_icq(ioc, q, GFP_ATOMIC);
  39. if (!icq)
  40. return;
  41. }
  42. get_io_context(icq->ioc);
  43. rq->elv.icq = icq;
  44. }
  45. /*
  46. * Mark a hardware queue as needing a restart. For shared queues, maintain
  47. * a count of how many hardware queues are marked for restart.
  48. */
  49. static void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
  50. {
  51. if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  52. return;
  53. if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
  54. struct request_queue *q = hctx->queue;
  55. if (!test_and_set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  56. atomic_inc(&q->shared_hctx_restart);
  57. } else
  58. set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
  59. }
  60. static bool blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
  61. {
  62. if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  63. return false;
  64. if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
  65. struct request_queue *q = hctx->queue;
  66. if (test_and_clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
  67. atomic_dec(&q->shared_hctx_restart);
  68. } else
  69. clear_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
  70. return blk_mq_run_hw_queue(hctx, true);
  71. }
  72. /*
  73. * Only SCSI implements .get_budget and .put_budget, and SCSI restarts
  74. * its queue by itself in its completion handler, so we don't need to
  75. * restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
  76. */
  77. static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
  78. {
  79. struct request_queue *q = hctx->queue;
  80. struct elevator_queue *e = q->elevator;
  81. LIST_HEAD(rq_list);
  82. do {
  83. struct request *rq;
  84. if (e->type->ops.mq.has_work &&
  85. !e->type->ops.mq.has_work(hctx))
  86. break;
  87. if (!blk_mq_get_dispatch_budget(hctx))
  88. break;
  89. rq = e->type->ops.mq.dispatch_request(hctx);
  90. if (!rq) {
  91. blk_mq_put_dispatch_budget(hctx);
  92. break;
  93. }
  94. /*
  95. * Now this rq owns the budget which has to be released
  96. * if this rq won't be queued to driver via .queue_rq()
  97. * in blk_mq_dispatch_rq_list().
  98. */
  99. list_add(&rq->queuelist, &rq_list);
  100. } while (blk_mq_dispatch_rq_list(q, &rq_list, true));
  101. }
  102. static struct blk_mq_ctx *blk_mq_next_ctx(struct blk_mq_hw_ctx *hctx,
  103. struct blk_mq_ctx *ctx)
  104. {
  105. unsigned idx = ctx->index_hw;
  106. if (++idx == hctx->nr_ctx)
  107. idx = 0;
  108. return hctx->ctxs[idx];
  109. }
  110. /*
  111. * Only SCSI implements .get_budget and .put_budget, and SCSI restarts
  112. * its queue by itself in its completion handler, so we don't need to
  113. * restart queue if .get_budget() returns BLK_STS_NO_RESOURCE.
  114. */
  115. static void blk_mq_do_dispatch_ctx(struct blk_mq_hw_ctx *hctx)
  116. {
  117. struct request_queue *q = hctx->queue;
  118. LIST_HEAD(rq_list);
  119. struct blk_mq_ctx *ctx = READ_ONCE(hctx->dispatch_from);
  120. do {
  121. struct request *rq;
  122. if (!sbitmap_any_bit_set(&hctx->ctx_map))
  123. break;
  124. if (!blk_mq_get_dispatch_budget(hctx))
  125. break;
  126. rq = blk_mq_dequeue_from_ctx(hctx, ctx);
  127. if (!rq) {
  128. blk_mq_put_dispatch_budget(hctx);
  129. break;
  130. }
  131. /*
  132. * Now this rq owns the budget which has to be released
  133. * if this rq won't be queued to driver via .queue_rq()
  134. * in blk_mq_dispatch_rq_list().
  135. */
  136. list_add(&rq->queuelist, &rq_list);
  137. /* round robin for fair dispatch */
  138. ctx = blk_mq_next_ctx(hctx, rq->mq_ctx);
  139. } while (blk_mq_dispatch_rq_list(q, &rq_list, true));
  140. WRITE_ONCE(hctx->dispatch_from, ctx);
  141. }
  142. /* return true if hw queue need to be run again */
  143. void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
  144. {
  145. struct request_queue *q = hctx->queue;
  146. struct elevator_queue *e = q->elevator;
  147. const bool has_sched_dispatch = e && e->type->ops.mq.dispatch_request;
  148. LIST_HEAD(rq_list);
  149. /* RCU or SRCU read lock is needed before checking quiesced flag */
  150. if (unlikely(blk_mq_hctx_stopped(hctx) || blk_queue_quiesced(q)))
  151. return;
  152. hctx->run++;
  153. /*
  154. * If we have previous entries on our dispatch list, grab them first for
  155. * more fair dispatch.
  156. */
  157. if (!list_empty_careful(&hctx->dispatch)) {
  158. spin_lock(&hctx->lock);
  159. if (!list_empty(&hctx->dispatch))
  160. list_splice_init(&hctx->dispatch, &rq_list);
  161. spin_unlock(&hctx->lock);
  162. }
  163. /*
  164. * Only ask the scheduler for requests, if we didn't have residual
  165. * requests from the dispatch list. This is to avoid the case where
  166. * we only ever dispatch a fraction of the requests available because
  167. * of low device queue depth. Once we pull requests out of the IO
  168. * scheduler, we can no longer merge or sort them. So it's best to
  169. * leave them there for as long as we can. Mark the hw queue as
  170. * needing a restart in that case.
  171. *
  172. * We want to dispatch from the scheduler if there was nothing
  173. * on the dispatch list or we were able to dispatch from the
  174. * dispatch list.
  175. */
  176. if (!list_empty(&rq_list)) {
  177. blk_mq_sched_mark_restart_hctx(hctx);
  178. if (blk_mq_dispatch_rq_list(q, &rq_list, false)) {
  179. if (has_sched_dispatch)
  180. blk_mq_do_dispatch_sched(hctx);
  181. else
  182. blk_mq_do_dispatch_ctx(hctx);
  183. }
  184. } else if (has_sched_dispatch) {
  185. blk_mq_do_dispatch_sched(hctx);
  186. } else if (q->mq_ops->get_budget) {
  187. /*
  188. * If we need to get budget before queuing request, we
  189. * dequeue request one by one from sw queue for avoiding
  190. * to mess up I/O merge when dispatch runs out of resource.
  191. *
  192. * TODO: get more budgets, and dequeue more requests in
  193. * one time.
  194. */
  195. blk_mq_do_dispatch_ctx(hctx);
  196. } else {
  197. blk_mq_flush_busy_ctxs(hctx, &rq_list);
  198. blk_mq_dispatch_rq_list(q, &rq_list, false);
  199. }
  200. }
  201. bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
  202. struct request **merged_request)
  203. {
  204. struct request *rq;
  205. switch (elv_merge(q, &rq, bio)) {
  206. case ELEVATOR_BACK_MERGE:
  207. if (!blk_mq_sched_allow_merge(q, rq, bio))
  208. return false;
  209. if (!bio_attempt_back_merge(q, rq, bio))
  210. return false;
  211. *merged_request = attempt_back_merge(q, rq);
  212. if (!*merged_request)
  213. elv_merged_request(q, rq, ELEVATOR_BACK_MERGE);
  214. return true;
  215. case ELEVATOR_FRONT_MERGE:
  216. if (!blk_mq_sched_allow_merge(q, rq, bio))
  217. return false;
  218. if (!bio_attempt_front_merge(q, rq, bio))
  219. return false;
  220. *merged_request = attempt_front_merge(q, rq);
  221. if (!*merged_request)
  222. elv_merged_request(q, rq, ELEVATOR_FRONT_MERGE);
  223. return true;
  224. default:
  225. return false;
  226. }
  227. }
  228. EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge);
  229. /*
  230. * Reverse check our software queue for entries that we could potentially
  231. * merge with. Currently includes a hand-wavy stop count of 8, to not spend
  232. * too much time checking for merges.
  233. */
  234. static bool blk_mq_attempt_merge(struct request_queue *q,
  235. struct blk_mq_ctx *ctx, struct bio *bio)
  236. {
  237. struct request *rq;
  238. int checked = 8;
  239. lockdep_assert_held(&ctx->lock);
  240. list_for_each_entry_reverse(rq, &ctx->rq_list, queuelist) {
  241. bool merged = false;
  242. if (!checked--)
  243. break;
  244. if (!blk_rq_merge_ok(rq, bio))
  245. continue;
  246. switch (blk_try_merge(rq, bio)) {
  247. case ELEVATOR_BACK_MERGE:
  248. if (blk_mq_sched_allow_merge(q, rq, bio))
  249. merged = bio_attempt_back_merge(q, rq, bio);
  250. break;
  251. case ELEVATOR_FRONT_MERGE:
  252. if (blk_mq_sched_allow_merge(q, rq, bio))
  253. merged = bio_attempt_front_merge(q, rq, bio);
  254. break;
  255. case ELEVATOR_DISCARD_MERGE:
  256. merged = bio_attempt_discard_merge(q, rq, bio);
  257. break;
  258. default:
  259. continue;
  260. }
  261. if (merged)
  262. ctx->rq_merged++;
  263. return merged;
  264. }
  265. return false;
  266. }
  267. bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio)
  268. {
  269. struct elevator_queue *e = q->elevator;
  270. struct blk_mq_ctx *ctx = blk_mq_get_ctx(q);
  271. struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
  272. bool ret = false;
  273. if (e && e->type->ops.mq.bio_merge) {
  274. blk_mq_put_ctx(ctx);
  275. return e->type->ops.mq.bio_merge(hctx, bio);
  276. }
  277. if (hctx->flags & BLK_MQ_F_SHOULD_MERGE) {
  278. /* default per sw-queue merge */
  279. spin_lock(&ctx->lock);
  280. ret = blk_mq_attempt_merge(q, ctx, bio);
  281. spin_unlock(&ctx->lock);
  282. }
  283. blk_mq_put_ctx(ctx);
  284. return ret;
  285. }
  286. bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq)
  287. {
  288. return rq_mergeable(rq) && elv_attempt_insert_merge(q, rq);
  289. }
  290. EXPORT_SYMBOL_GPL(blk_mq_sched_try_insert_merge);
  291. void blk_mq_sched_request_inserted(struct request *rq)
  292. {
  293. trace_block_rq_insert(rq->q, rq);
  294. }
  295. EXPORT_SYMBOL_GPL(blk_mq_sched_request_inserted);
  296. static bool blk_mq_sched_bypass_insert(struct blk_mq_hw_ctx *hctx,
  297. bool has_sched,
  298. struct request *rq)
  299. {
  300. /* dispatch flush rq directly */
  301. if (rq->rq_flags & RQF_FLUSH_SEQ) {
  302. spin_lock(&hctx->lock);
  303. list_add(&rq->queuelist, &hctx->dispatch);
  304. spin_unlock(&hctx->lock);
  305. return true;
  306. }
  307. if (has_sched)
  308. rq->rq_flags |= RQF_SORTED;
  309. return false;
  310. }
  311. /**
  312. * list_for_each_entry_rcu_rr - iterate in a round-robin fashion over rcu list
  313. * @pos: loop cursor.
  314. * @skip: the list element that will not be examined. Iteration starts at
  315. * @skip->next.
  316. * @head: head of the list to examine. This list must have at least one
  317. * element, namely @skip.
  318. * @member: name of the list_head structure within typeof(*pos).
  319. */
  320. #define list_for_each_entry_rcu_rr(pos, skip, head, member) \
  321. for ((pos) = (skip); \
  322. (pos = (pos)->member.next != (head) ? list_entry_rcu( \
  323. (pos)->member.next, typeof(*pos), member) : \
  324. list_entry_rcu((pos)->member.next->next, typeof(*pos), member)), \
  325. (pos) != (skip); )
  326. /*
  327. * Called after a driver tag has been freed to check whether a hctx needs to
  328. * be restarted. Restarts @hctx if its tag set is not shared. Restarts hardware
  329. * queues in a round-robin fashion if the tag set of @hctx is shared with other
  330. * hardware queues.
  331. */
  332. void blk_mq_sched_restart(struct blk_mq_hw_ctx *const hctx)
  333. {
  334. struct blk_mq_tags *const tags = hctx->tags;
  335. struct blk_mq_tag_set *const set = hctx->queue->tag_set;
  336. struct request_queue *const queue = hctx->queue, *q;
  337. struct blk_mq_hw_ctx *hctx2;
  338. unsigned int i, j;
  339. if (set->flags & BLK_MQ_F_TAG_SHARED) {
  340. /*
  341. * If this is 0, then we know that no hardware queues
  342. * have RESTART marked. We're done.
  343. */
  344. if (!atomic_read(&queue->shared_hctx_restart))
  345. return;
  346. rcu_read_lock();
  347. list_for_each_entry_rcu_rr(q, queue, &set->tag_list,
  348. tag_set_list) {
  349. queue_for_each_hw_ctx(q, hctx2, i)
  350. if (hctx2->tags == tags &&
  351. blk_mq_sched_restart_hctx(hctx2))
  352. goto done;
  353. }
  354. j = hctx->queue_num + 1;
  355. for (i = 0; i < queue->nr_hw_queues; i++, j++) {
  356. if (j == queue->nr_hw_queues)
  357. j = 0;
  358. hctx2 = queue->queue_hw_ctx[j];
  359. if (hctx2->tags == tags &&
  360. blk_mq_sched_restart_hctx(hctx2))
  361. break;
  362. }
  363. done:
  364. rcu_read_unlock();
  365. } else {
  366. blk_mq_sched_restart_hctx(hctx);
  367. }
  368. }
  369. void blk_mq_sched_insert_request(struct request *rq, bool at_head,
  370. bool run_queue, bool async, bool can_block)
  371. {
  372. struct request_queue *q = rq->q;
  373. struct elevator_queue *e = q->elevator;
  374. struct blk_mq_ctx *ctx = rq->mq_ctx;
  375. struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
  376. /* flush rq in flush machinery need to be dispatched directly */
  377. if (!(rq->rq_flags & RQF_FLUSH_SEQ) && op_is_flush(rq->cmd_flags)) {
  378. blk_insert_flush(rq);
  379. goto run;
  380. }
  381. WARN_ON(e && (rq->tag != -1));
  382. if (blk_mq_sched_bypass_insert(hctx, !!e, rq))
  383. goto run;
  384. if (e && e->type->ops.mq.insert_requests) {
  385. LIST_HEAD(list);
  386. list_add(&rq->queuelist, &list);
  387. e->type->ops.mq.insert_requests(hctx, &list, at_head);
  388. } else {
  389. spin_lock(&ctx->lock);
  390. __blk_mq_insert_request(hctx, rq, at_head);
  391. spin_unlock(&ctx->lock);
  392. }
  393. run:
  394. if (run_queue)
  395. blk_mq_run_hw_queue(hctx, async);
  396. }
  397. void blk_mq_sched_insert_requests(struct request_queue *q,
  398. struct blk_mq_ctx *ctx,
  399. struct list_head *list, bool run_queue_async)
  400. {
  401. struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
  402. struct elevator_queue *e = hctx->queue->elevator;
  403. if (e && e->type->ops.mq.insert_requests)
  404. e->type->ops.mq.insert_requests(hctx, list, false);
  405. else
  406. blk_mq_insert_requests(hctx, ctx, list);
  407. blk_mq_run_hw_queue(hctx, run_queue_async);
  408. }
  409. static void blk_mq_sched_free_tags(struct blk_mq_tag_set *set,
  410. struct blk_mq_hw_ctx *hctx,
  411. unsigned int hctx_idx)
  412. {
  413. if (hctx->sched_tags) {
  414. blk_mq_free_rqs(set, hctx->sched_tags, hctx_idx);
  415. blk_mq_free_rq_map(hctx->sched_tags);
  416. hctx->sched_tags = NULL;
  417. }
  418. }
  419. static int blk_mq_sched_alloc_tags(struct request_queue *q,
  420. struct blk_mq_hw_ctx *hctx,
  421. unsigned int hctx_idx)
  422. {
  423. struct blk_mq_tag_set *set = q->tag_set;
  424. int ret;
  425. hctx->sched_tags = blk_mq_alloc_rq_map(set, hctx_idx, q->nr_requests,
  426. set->reserved_tags);
  427. if (!hctx->sched_tags)
  428. return -ENOMEM;
  429. ret = blk_mq_alloc_rqs(set, hctx->sched_tags, hctx_idx, q->nr_requests);
  430. if (ret)
  431. blk_mq_sched_free_tags(set, hctx, hctx_idx);
  432. return ret;
  433. }
  434. static void blk_mq_sched_tags_teardown(struct request_queue *q)
  435. {
  436. struct blk_mq_tag_set *set = q->tag_set;
  437. struct blk_mq_hw_ctx *hctx;
  438. int i;
  439. queue_for_each_hw_ctx(q, hctx, i)
  440. blk_mq_sched_free_tags(set, hctx, i);
  441. }
  442. int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
  443. unsigned int hctx_idx)
  444. {
  445. struct elevator_queue *e = q->elevator;
  446. int ret;
  447. if (!e)
  448. return 0;
  449. ret = blk_mq_sched_alloc_tags(q, hctx, hctx_idx);
  450. if (ret)
  451. return ret;
  452. if (e->type->ops.mq.init_hctx) {
  453. ret = e->type->ops.mq.init_hctx(hctx, hctx_idx);
  454. if (ret) {
  455. blk_mq_sched_free_tags(q->tag_set, hctx, hctx_idx);
  456. return ret;
  457. }
  458. }
  459. blk_mq_debugfs_register_sched_hctx(q, hctx);
  460. return 0;
  461. }
  462. void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx,
  463. unsigned int hctx_idx)
  464. {
  465. struct elevator_queue *e = q->elevator;
  466. if (!e)
  467. return;
  468. blk_mq_debugfs_unregister_sched_hctx(hctx);
  469. if (e->type->ops.mq.exit_hctx && hctx->sched_data) {
  470. e->type->ops.mq.exit_hctx(hctx, hctx_idx);
  471. hctx->sched_data = NULL;
  472. }
  473. blk_mq_sched_free_tags(q->tag_set, hctx, hctx_idx);
  474. }
  475. int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e)
  476. {
  477. struct blk_mq_hw_ctx *hctx;
  478. struct elevator_queue *eq;
  479. unsigned int i;
  480. int ret;
  481. if (!e) {
  482. q->elevator = NULL;
  483. return 0;
  484. }
  485. /*
  486. * Default to double of smaller one between hw queue_depth and 128,
  487. * since we don't split into sync/async like the old code did.
  488. * Additionally, this is a per-hw queue depth.
  489. */
  490. q->nr_requests = 2 * min_t(unsigned int, q->tag_set->queue_depth,
  491. BLKDEV_MAX_RQ);
  492. queue_for_each_hw_ctx(q, hctx, i) {
  493. ret = blk_mq_sched_alloc_tags(q, hctx, i);
  494. if (ret)
  495. goto err;
  496. }
  497. ret = e->ops.mq.init_sched(q, e);
  498. if (ret)
  499. goto err;
  500. blk_mq_debugfs_register_sched(q);
  501. queue_for_each_hw_ctx(q, hctx, i) {
  502. if (e->ops.mq.init_hctx) {
  503. ret = e->ops.mq.init_hctx(hctx, i);
  504. if (ret) {
  505. eq = q->elevator;
  506. blk_mq_exit_sched(q, eq);
  507. kobject_put(&eq->kobj);
  508. return ret;
  509. }
  510. }
  511. blk_mq_debugfs_register_sched_hctx(q, hctx);
  512. }
  513. return 0;
  514. err:
  515. blk_mq_sched_tags_teardown(q);
  516. q->elevator = NULL;
  517. return ret;
  518. }
  519. void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e)
  520. {
  521. struct blk_mq_hw_ctx *hctx;
  522. unsigned int i;
  523. queue_for_each_hw_ctx(q, hctx, i) {
  524. blk_mq_debugfs_unregister_sched_hctx(hctx);
  525. if (e->type->ops.mq.exit_hctx && hctx->sched_data) {
  526. e->type->ops.mq.exit_hctx(hctx, i);
  527. hctx->sched_data = NULL;
  528. }
  529. }
  530. blk_mq_debugfs_unregister_sched(q);
  531. if (e->type->ops.mq.exit_sched)
  532. e->type->ops.mq.exit_sched(e);
  533. blk_mq_sched_tags_teardown(q);
  534. q->elevator = NULL;
  535. }
  536. int blk_mq_sched_init(struct request_queue *q)
  537. {
  538. int ret;
  539. mutex_lock(&q->sysfs_lock);
  540. ret = elevator_init(q, NULL);
  541. mutex_unlock(&q->sysfs_lock);
  542. return ret;
  543. }