mq-deadline.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * MQ Deadline i/o scheduler - adaptation of the legacy deadline scheduler,
  4. * for the blk-mq scheduling framework
  5. *
  6. * Copyright (C) 2016 Jens Axboe <[email protected]>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/fs.h>
  10. #include <linux/blkdev.h>
  11. #include <linux/blk-mq.h>
  12. #include <linux/bio.h>
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/init.h>
  16. #include <linux/compiler.h>
  17. #include <linux/rbtree.h>
  18. #include <linux/sbitmap.h>
  19. #include <trace/events/block.h>
  20. #include "elevator.h"
  21. #include "blk.h"
  22. #include "blk-mq.h"
  23. #include "blk-mq-debugfs.h"
  24. #include "blk-mq-tag.h"
  25. #include "blk-mq-sched.h"
  26. /*
  27. * See Documentation/block/deadline-iosched.rst
  28. */
  29. static const int read_expire = HZ / 2; /* max time before a read is submitted. */
  30. static const int write_expire = 5 * HZ; /* ditto for writes, these limits are SOFT! */
  31. /*
  32. * Time after which to dispatch lower priority requests even if higher
  33. * priority requests are pending.
  34. */
  35. static const int prio_aging_expire = 10 * HZ;
  36. static const int writes_starved = 2; /* max times reads can starve a write */
  37. static const int fifo_batch = 16; /* # of sequential requests treated as one
  38. by the above parameters. For throughput. */
  39. enum dd_data_dir {
  40. DD_READ = READ,
  41. DD_WRITE = WRITE,
  42. };
  43. enum { DD_DIR_COUNT = 2 };
  44. enum dd_prio {
  45. DD_RT_PRIO = 0,
  46. DD_BE_PRIO = 1,
  47. DD_IDLE_PRIO = 2,
  48. DD_PRIO_MAX = 2,
  49. };
  50. enum { DD_PRIO_COUNT = 3 };
  51. /*
  52. * I/O statistics per I/O priority. It is fine if these counters overflow.
  53. * What matters is that these counters are at least as wide as
  54. * log2(max_outstanding_requests).
  55. */
  56. struct io_stats_per_prio {
  57. uint32_t inserted;
  58. uint32_t merged;
  59. uint32_t dispatched;
  60. atomic_t completed;
  61. };
  62. /*
  63. * Deadline scheduler data per I/O priority (enum dd_prio). Requests are
  64. * present on both sort_list[] and fifo_list[].
  65. */
  66. struct dd_per_prio {
  67. struct list_head dispatch;
  68. struct rb_root sort_list[DD_DIR_COUNT];
  69. struct list_head fifo_list[DD_DIR_COUNT];
  70. /* Next request in FIFO order. Read, write or both are NULL. */
  71. struct request *next_rq[DD_DIR_COUNT];
  72. struct io_stats_per_prio stats;
  73. };
  74. struct deadline_data {
  75. /*
  76. * run time data
  77. */
  78. struct dd_per_prio per_prio[DD_PRIO_COUNT];
  79. /* Data direction of latest dispatched request. */
  80. enum dd_data_dir last_dir;
  81. unsigned int batching; /* number of sequential requests made */
  82. unsigned int starved; /* times reads have starved writes */
  83. /*
  84. * settings that change how the i/o scheduler behaves
  85. */
  86. int fifo_expire[DD_DIR_COUNT];
  87. int fifo_batch;
  88. int writes_starved;
  89. int front_merges;
  90. u32 async_depth;
  91. int prio_aging_expire;
  92. spinlock_t lock;
  93. spinlock_t zone_lock;
  94. };
  95. /* Maps an I/O priority class to a deadline scheduler priority. */
  96. static const enum dd_prio ioprio_class_to_prio[] = {
  97. [IOPRIO_CLASS_NONE] = DD_BE_PRIO,
  98. [IOPRIO_CLASS_RT] = DD_RT_PRIO,
  99. [IOPRIO_CLASS_BE] = DD_BE_PRIO,
  100. [IOPRIO_CLASS_IDLE] = DD_IDLE_PRIO,
  101. };
  102. static inline struct rb_root *
  103. deadline_rb_root(struct dd_per_prio *per_prio, struct request *rq)
  104. {
  105. return &per_prio->sort_list[rq_data_dir(rq)];
  106. }
  107. /*
  108. * Returns the I/O priority class (IOPRIO_CLASS_*) that has been assigned to a
  109. * request.
  110. */
  111. static u8 dd_rq_ioclass(struct request *rq)
  112. {
  113. return IOPRIO_PRIO_CLASS(req_get_ioprio(rq));
  114. }
  115. /*
  116. * get the request before `rq' in sector-sorted order
  117. */
  118. static inline struct request *
  119. deadline_earlier_request(struct request *rq)
  120. {
  121. struct rb_node *node = rb_prev(&rq->rb_node);
  122. if (node)
  123. return rb_entry_rq(node);
  124. return NULL;
  125. }
  126. /*
  127. * get the request after `rq' in sector-sorted order
  128. */
  129. static inline struct request *
  130. deadline_latter_request(struct request *rq)
  131. {
  132. struct rb_node *node = rb_next(&rq->rb_node);
  133. if (node)
  134. return rb_entry_rq(node);
  135. return NULL;
  136. }
  137. static void
  138. deadline_add_rq_rb(struct dd_per_prio *per_prio, struct request *rq)
  139. {
  140. struct rb_root *root = deadline_rb_root(per_prio, rq);
  141. elv_rb_add(root, rq);
  142. }
  143. static inline void
  144. deadline_del_rq_rb(struct dd_per_prio *per_prio, struct request *rq)
  145. {
  146. const enum dd_data_dir data_dir = rq_data_dir(rq);
  147. if (per_prio->next_rq[data_dir] == rq)
  148. per_prio->next_rq[data_dir] = deadline_latter_request(rq);
  149. elv_rb_del(deadline_rb_root(per_prio, rq), rq);
  150. }
  151. /*
  152. * remove rq from rbtree and fifo.
  153. */
  154. static void deadline_remove_request(struct request_queue *q,
  155. struct dd_per_prio *per_prio,
  156. struct request *rq)
  157. {
  158. list_del_init(&rq->queuelist);
  159. /*
  160. * We might not be on the rbtree, if we are doing an insert merge
  161. */
  162. if (!RB_EMPTY_NODE(&rq->rb_node))
  163. deadline_del_rq_rb(per_prio, rq);
  164. elv_rqhash_del(q, rq);
  165. if (q->last_merge == rq)
  166. q->last_merge = NULL;
  167. }
  168. static void dd_request_merged(struct request_queue *q, struct request *req,
  169. enum elv_merge type)
  170. {
  171. struct deadline_data *dd = q->elevator->elevator_data;
  172. const u8 ioprio_class = dd_rq_ioclass(req);
  173. const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
  174. struct dd_per_prio *per_prio = &dd->per_prio[prio];
  175. /*
  176. * if the merge was a front merge, we need to reposition request
  177. */
  178. if (type == ELEVATOR_FRONT_MERGE) {
  179. elv_rb_del(deadline_rb_root(per_prio, req), req);
  180. deadline_add_rq_rb(per_prio, req);
  181. }
  182. }
  183. /*
  184. * Callback function that is invoked after @next has been merged into @req.
  185. */
  186. static void dd_merged_requests(struct request_queue *q, struct request *req,
  187. struct request *next)
  188. {
  189. struct deadline_data *dd = q->elevator->elevator_data;
  190. const u8 ioprio_class = dd_rq_ioclass(next);
  191. const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
  192. lockdep_assert_held(&dd->lock);
  193. dd->per_prio[prio].stats.merged++;
  194. /*
  195. * if next expires before rq, assign its expire time to rq
  196. * and move into next position (next will be deleted) in fifo
  197. */
  198. if (!list_empty(&req->queuelist) && !list_empty(&next->queuelist)) {
  199. if (time_before((unsigned long)next->fifo_time,
  200. (unsigned long)req->fifo_time)) {
  201. list_move(&req->queuelist, &next->queuelist);
  202. req->fifo_time = next->fifo_time;
  203. }
  204. }
  205. /*
  206. * kill knowledge of next, this one is a goner
  207. */
  208. deadline_remove_request(q, &dd->per_prio[prio], next);
  209. }
  210. /*
  211. * move an entry to dispatch queue
  212. */
  213. static void
  214. deadline_move_request(struct deadline_data *dd, struct dd_per_prio *per_prio,
  215. struct request *rq)
  216. {
  217. const enum dd_data_dir data_dir = rq_data_dir(rq);
  218. per_prio->next_rq[data_dir] = deadline_latter_request(rq);
  219. /*
  220. * take it off the sort and fifo list
  221. */
  222. deadline_remove_request(rq->q, per_prio, rq);
  223. }
  224. /* Number of requests queued for a given priority level. */
  225. static u32 dd_queued(struct deadline_data *dd, enum dd_prio prio)
  226. {
  227. const struct io_stats_per_prio *stats = &dd->per_prio[prio].stats;
  228. lockdep_assert_held(&dd->lock);
  229. return stats->inserted - atomic_read(&stats->completed);
  230. }
  231. /*
  232. * deadline_check_fifo returns 0 if there are no expired requests on the fifo,
  233. * 1 otherwise. Requires !list_empty(&dd->fifo_list[data_dir])
  234. */
  235. static inline int deadline_check_fifo(struct dd_per_prio *per_prio,
  236. enum dd_data_dir data_dir)
  237. {
  238. struct request *rq = rq_entry_fifo(per_prio->fifo_list[data_dir].next);
  239. /*
  240. * rq is expired!
  241. */
  242. if (time_after_eq(jiffies, (unsigned long)rq->fifo_time))
  243. return 1;
  244. return 0;
  245. }
  246. /*
  247. * Check if rq has a sequential request preceding it.
  248. */
  249. static bool deadline_is_seq_write(struct deadline_data *dd, struct request *rq)
  250. {
  251. struct request *prev = deadline_earlier_request(rq);
  252. if (!prev)
  253. return false;
  254. return blk_rq_pos(prev) + blk_rq_sectors(prev) == blk_rq_pos(rq);
  255. }
  256. /*
  257. * Skip all write requests that are sequential from @rq, even if we cross
  258. * a zone boundary.
  259. */
  260. static struct request *deadline_skip_seq_writes(struct deadline_data *dd,
  261. struct request *rq)
  262. {
  263. sector_t pos = blk_rq_pos(rq);
  264. sector_t skipped_sectors = 0;
  265. while (rq) {
  266. if (blk_rq_pos(rq) != pos + skipped_sectors)
  267. break;
  268. skipped_sectors += blk_rq_sectors(rq);
  269. rq = deadline_latter_request(rq);
  270. }
  271. return rq;
  272. }
  273. /*
  274. * For the specified data direction, return the next request to
  275. * dispatch using arrival ordered lists.
  276. */
  277. static struct request *
  278. deadline_fifo_request(struct deadline_data *dd, struct dd_per_prio *per_prio,
  279. enum dd_data_dir data_dir)
  280. {
  281. struct request *rq;
  282. unsigned long flags;
  283. if (list_empty(&per_prio->fifo_list[data_dir]))
  284. return NULL;
  285. rq = rq_entry_fifo(per_prio->fifo_list[data_dir].next);
  286. if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
  287. return rq;
  288. /*
  289. * Look for a write request that can be dispatched, that is one with
  290. * an unlocked target zone. For some HDDs, breaking a sequential
  291. * write stream can lead to lower throughput, so make sure to preserve
  292. * sequential write streams, even if that stream crosses into the next
  293. * zones and these zones are unlocked.
  294. */
  295. spin_lock_irqsave(&dd->zone_lock, flags);
  296. list_for_each_entry(rq, &per_prio->fifo_list[DD_WRITE], queuelist) {
  297. if (blk_req_can_dispatch_to_zone(rq) &&
  298. (blk_queue_nonrot(rq->q) ||
  299. !deadline_is_seq_write(dd, rq)))
  300. goto out;
  301. }
  302. rq = NULL;
  303. out:
  304. spin_unlock_irqrestore(&dd->zone_lock, flags);
  305. return rq;
  306. }
  307. /*
  308. * For the specified data direction, return the next request to
  309. * dispatch using sector position sorted lists.
  310. */
  311. static struct request *
  312. deadline_next_request(struct deadline_data *dd, struct dd_per_prio *per_prio,
  313. enum dd_data_dir data_dir)
  314. {
  315. struct request *rq;
  316. unsigned long flags;
  317. rq = per_prio->next_rq[data_dir];
  318. if (!rq)
  319. return NULL;
  320. if (data_dir == DD_READ || !blk_queue_is_zoned(rq->q))
  321. return rq;
  322. /*
  323. * Look for a write request that can be dispatched, that is one with
  324. * an unlocked target zone. For some HDDs, breaking a sequential
  325. * write stream can lead to lower throughput, so make sure to preserve
  326. * sequential write streams, even if that stream crosses into the next
  327. * zones and these zones are unlocked.
  328. */
  329. spin_lock_irqsave(&dd->zone_lock, flags);
  330. while (rq) {
  331. if (blk_req_can_dispatch_to_zone(rq))
  332. break;
  333. if (blk_queue_nonrot(rq->q))
  334. rq = deadline_latter_request(rq);
  335. else
  336. rq = deadline_skip_seq_writes(dd, rq);
  337. }
  338. spin_unlock_irqrestore(&dd->zone_lock, flags);
  339. return rq;
  340. }
  341. /*
  342. * Returns true if and only if @rq started after @latest_start where
  343. * @latest_start is in jiffies.
  344. */
  345. static bool started_after(struct deadline_data *dd, struct request *rq,
  346. unsigned long latest_start)
  347. {
  348. unsigned long start_time = (unsigned long)rq->fifo_time;
  349. start_time -= dd->fifo_expire[rq_data_dir(rq)];
  350. return time_after(start_time, latest_start);
  351. }
  352. /*
  353. * deadline_dispatch_requests selects the best request according to
  354. * read/write expire, fifo_batch, etc and with a start time <= @latest_start.
  355. */
  356. static struct request *__dd_dispatch_request(struct deadline_data *dd,
  357. struct dd_per_prio *per_prio,
  358. unsigned long latest_start)
  359. {
  360. struct request *rq, *next_rq;
  361. enum dd_data_dir data_dir;
  362. enum dd_prio prio;
  363. u8 ioprio_class;
  364. lockdep_assert_held(&dd->lock);
  365. if (!list_empty(&per_prio->dispatch)) {
  366. rq = list_first_entry(&per_prio->dispatch, struct request,
  367. queuelist);
  368. if (started_after(dd, rq, latest_start))
  369. return NULL;
  370. list_del_init(&rq->queuelist);
  371. goto done;
  372. }
  373. /*
  374. * batches are currently reads XOR writes
  375. */
  376. rq = deadline_next_request(dd, per_prio, dd->last_dir);
  377. if (rq && dd->batching < dd->fifo_batch)
  378. /* we have a next request are still entitled to batch */
  379. goto dispatch_request;
  380. /*
  381. * at this point we are not running a batch. select the appropriate
  382. * data direction (read / write)
  383. */
  384. if (!list_empty(&per_prio->fifo_list[DD_READ])) {
  385. BUG_ON(RB_EMPTY_ROOT(&per_prio->sort_list[DD_READ]));
  386. if (deadline_fifo_request(dd, per_prio, DD_WRITE) &&
  387. (dd->starved++ >= dd->writes_starved))
  388. goto dispatch_writes;
  389. data_dir = DD_READ;
  390. goto dispatch_find_request;
  391. }
  392. /*
  393. * there are either no reads or writes have been starved
  394. */
  395. if (!list_empty(&per_prio->fifo_list[DD_WRITE])) {
  396. dispatch_writes:
  397. BUG_ON(RB_EMPTY_ROOT(&per_prio->sort_list[DD_WRITE]));
  398. dd->starved = 0;
  399. data_dir = DD_WRITE;
  400. goto dispatch_find_request;
  401. }
  402. return NULL;
  403. dispatch_find_request:
  404. /*
  405. * we are not running a batch, find best request for selected data_dir
  406. */
  407. next_rq = deadline_next_request(dd, per_prio, data_dir);
  408. if (deadline_check_fifo(per_prio, data_dir) || !next_rq) {
  409. /*
  410. * A deadline has expired, the last request was in the other
  411. * direction, or we have run out of higher-sectored requests.
  412. * Start again from the request with the earliest expiry time.
  413. */
  414. rq = deadline_fifo_request(dd, per_prio, data_dir);
  415. } else {
  416. /*
  417. * The last req was the same dir and we have a next request in
  418. * sort order. No expired requests so continue on from here.
  419. */
  420. rq = next_rq;
  421. }
  422. /*
  423. * For a zoned block device, if we only have writes queued and none of
  424. * them can be dispatched, rq will be NULL.
  425. */
  426. if (!rq)
  427. return NULL;
  428. dd->last_dir = data_dir;
  429. dd->batching = 0;
  430. dispatch_request:
  431. if (started_after(dd, rq, latest_start))
  432. return NULL;
  433. /*
  434. * rq is the selected appropriate request.
  435. */
  436. dd->batching++;
  437. deadline_move_request(dd, per_prio, rq);
  438. done:
  439. ioprio_class = dd_rq_ioclass(rq);
  440. prio = ioprio_class_to_prio[ioprio_class];
  441. dd->per_prio[prio].stats.dispatched++;
  442. /*
  443. * If the request needs its target zone locked, do it.
  444. */
  445. blk_req_zone_write_lock(rq);
  446. rq->rq_flags |= RQF_STARTED;
  447. return rq;
  448. }
  449. /*
  450. * Check whether there are any requests with priority other than DD_RT_PRIO
  451. * that were inserted more than prio_aging_expire jiffies ago.
  452. */
  453. static struct request *dd_dispatch_prio_aged_requests(struct deadline_data *dd,
  454. unsigned long now)
  455. {
  456. struct request *rq;
  457. enum dd_prio prio;
  458. int prio_cnt;
  459. lockdep_assert_held(&dd->lock);
  460. prio_cnt = !!dd_queued(dd, DD_RT_PRIO) + !!dd_queued(dd, DD_BE_PRIO) +
  461. !!dd_queued(dd, DD_IDLE_PRIO);
  462. if (prio_cnt < 2)
  463. return NULL;
  464. for (prio = DD_BE_PRIO; prio <= DD_PRIO_MAX; prio++) {
  465. rq = __dd_dispatch_request(dd, &dd->per_prio[prio],
  466. now - dd->prio_aging_expire);
  467. if (rq)
  468. return rq;
  469. }
  470. return NULL;
  471. }
  472. /*
  473. * Called from blk_mq_run_hw_queue() -> __blk_mq_sched_dispatch_requests().
  474. *
  475. * One confusing aspect here is that we get called for a specific
  476. * hardware queue, but we may return a request that is for a
  477. * different hardware queue. This is because mq-deadline has shared
  478. * state for all hardware queues, in terms of sorting, FIFOs, etc.
  479. */
  480. static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
  481. {
  482. struct deadline_data *dd = hctx->queue->elevator->elevator_data;
  483. const unsigned long now = jiffies;
  484. struct request *rq;
  485. enum dd_prio prio;
  486. spin_lock(&dd->lock);
  487. rq = dd_dispatch_prio_aged_requests(dd, now);
  488. if (rq)
  489. goto unlock;
  490. /*
  491. * Next, dispatch requests in priority order. Ignore lower priority
  492. * requests if any higher priority requests are pending.
  493. */
  494. for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
  495. rq = __dd_dispatch_request(dd, &dd->per_prio[prio], now);
  496. if (rq || dd_queued(dd, prio))
  497. break;
  498. }
  499. unlock:
  500. spin_unlock(&dd->lock);
  501. return rq;
  502. }
  503. /*
  504. * Called by __blk_mq_alloc_request(). The shallow_depth value set by this
  505. * function is used by __blk_mq_get_tag().
  506. */
  507. static void dd_limit_depth(blk_opf_t opf, struct blk_mq_alloc_data *data)
  508. {
  509. struct deadline_data *dd = data->q->elevator->elevator_data;
  510. /* Do not throttle synchronous reads. */
  511. if (op_is_sync(opf) && !op_is_write(opf))
  512. return;
  513. /*
  514. * Throttle asynchronous requests and writes such that these requests
  515. * do not block the allocation of synchronous requests.
  516. */
  517. data->shallow_depth = dd->async_depth;
  518. }
  519. /* Called by blk_mq_update_nr_requests(). */
  520. static void dd_depth_updated(struct blk_mq_hw_ctx *hctx)
  521. {
  522. struct request_queue *q = hctx->queue;
  523. struct deadline_data *dd = q->elevator->elevator_data;
  524. struct blk_mq_tags *tags = hctx->sched_tags;
  525. unsigned int shift = tags->bitmap_tags.sb.shift;
  526. dd->async_depth = max(1U, 3 * (1U << shift) / 4);
  527. sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, dd->async_depth);
  528. }
  529. /* Called by blk_mq_init_hctx() and blk_mq_init_sched(). */
  530. static int dd_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx)
  531. {
  532. dd_depth_updated(hctx);
  533. return 0;
  534. }
  535. static void dd_exit_sched(struct elevator_queue *e)
  536. {
  537. struct deadline_data *dd = e->elevator_data;
  538. enum dd_prio prio;
  539. for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
  540. struct dd_per_prio *per_prio = &dd->per_prio[prio];
  541. const struct io_stats_per_prio *stats = &per_prio->stats;
  542. uint32_t queued;
  543. WARN_ON_ONCE(!list_empty(&per_prio->fifo_list[DD_READ]));
  544. WARN_ON_ONCE(!list_empty(&per_prio->fifo_list[DD_WRITE]));
  545. spin_lock(&dd->lock);
  546. queued = dd_queued(dd, prio);
  547. spin_unlock(&dd->lock);
  548. WARN_ONCE(queued != 0,
  549. "statistics for priority %d: i %u m %u d %u c %u\n",
  550. prio, stats->inserted, stats->merged,
  551. stats->dispatched, atomic_read(&stats->completed));
  552. }
  553. kfree(dd);
  554. }
  555. /*
  556. * initialize elevator private data (deadline_data).
  557. */
  558. static int dd_init_sched(struct request_queue *q, struct elevator_type *e)
  559. {
  560. struct deadline_data *dd;
  561. struct elevator_queue *eq;
  562. enum dd_prio prio;
  563. int ret = -ENOMEM;
  564. eq = elevator_alloc(q, e);
  565. if (!eq)
  566. return ret;
  567. dd = kzalloc_node(sizeof(*dd), GFP_KERNEL, q->node);
  568. if (!dd)
  569. goto put_eq;
  570. eq->elevator_data = dd;
  571. for (prio = 0; prio <= DD_PRIO_MAX; prio++) {
  572. struct dd_per_prio *per_prio = &dd->per_prio[prio];
  573. INIT_LIST_HEAD(&per_prio->dispatch);
  574. INIT_LIST_HEAD(&per_prio->fifo_list[DD_READ]);
  575. INIT_LIST_HEAD(&per_prio->fifo_list[DD_WRITE]);
  576. per_prio->sort_list[DD_READ] = RB_ROOT;
  577. per_prio->sort_list[DD_WRITE] = RB_ROOT;
  578. }
  579. dd->fifo_expire[DD_READ] = read_expire;
  580. dd->fifo_expire[DD_WRITE] = write_expire;
  581. dd->writes_starved = writes_starved;
  582. dd->front_merges = 1;
  583. dd->last_dir = DD_WRITE;
  584. dd->fifo_batch = fifo_batch;
  585. dd->prio_aging_expire = prio_aging_expire;
  586. spin_lock_init(&dd->lock);
  587. spin_lock_init(&dd->zone_lock);
  588. /* We dispatch from request queue wide instead of hw queue */
  589. blk_queue_flag_set(QUEUE_FLAG_SQ_SCHED, q);
  590. q->elevator = eq;
  591. return 0;
  592. put_eq:
  593. kobject_put(&eq->kobj);
  594. return ret;
  595. }
  596. /*
  597. * Try to merge @bio into an existing request. If @bio has been merged into
  598. * an existing request, store the pointer to that request into *@rq.
  599. */
  600. static int dd_request_merge(struct request_queue *q, struct request **rq,
  601. struct bio *bio)
  602. {
  603. struct deadline_data *dd = q->elevator->elevator_data;
  604. const u8 ioprio_class = IOPRIO_PRIO_CLASS(bio->bi_ioprio);
  605. const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
  606. struct dd_per_prio *per_prio = &dd->per_prio[prio];
  607. sector_t sector = bio_end_sector(bio);
  608. struct request *__rq;
  609. if (!dd->front_merges)
  610. return ELEVATOR_NO_MERGE;
  611. __rq = elv_rb_find(&per_prio->sort_list[bio_data_dir(bio)], sector);
  612. if (__rq) {
  613. BUG_ON(sector != blk_rq_pos(__rq));
  614. if (elv_bio_merge_ok(__rq, bio)) {
  615. *rq = __rq;
  616. if (blk_discard_mergable(__rq))
  617. return ELEVATOR_DISCARD_MERGE;
  618. return ELEVATOR_FRONT_MERGE;
  619. }
  620. }
  621. return ELEVATOR_NO_MERGE;
  622. }
  623. /*
  624. * Attempt to merge a bio into an existing request. This function is called
  625. * before @bio is associated with a request.
  626. */
  627. static bool dd_bio_merge(struct request_queue *q, struct bio *bio,
  628. unsigned int nr_segs)
  629. {
  630. struct deadline_data *dd = q->elevator->elevator_data;
  631. struct request *free = NULL;
  632. bool ret;
  633. spin_lock(&dd->lock);
  634. ret = blk_mq_sched_try_merge(q, bio, nr_segs, &free);
  635. spin_unlock(&dd->lock);
  636. if (free)
  637. blk_mq_free_request(free);
  638. return ret;
  639. }
  640. /*
  641. * add rq to rbtree and fifo
  642. */
  643. static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
  644. bool at_head)
  645. {
  646. struct request_queue *q = hctx->queue;
  647. struct deadline_data *dd = q->elevator->elevator_data;
  648. const enum dd_data_dir data_dir = rq_data_dir(rq);
  649. u16 ioprio = req_get_ioprio(rq);
  650. u8 ioprio_class = IOPRIO_PRIO_CLASS(ioprio);
  651. struct dd_per_prio *per_prio;
  652. enum dd_prio prio;
  653. LIST_HEAD(free);
  654. lockdep_assert_held(&dd->lock);
  655. /*
  656. * This may be a requeue of a write request that has locked its
  657. * target zone. If it is the case, this releases the zone lock.
  658. */
  659. blk_req_zone_write_unlock(rq);
  660. prio = ioprio_class_to_prio[ioprio_class];
  661. per_prio = &dd->per_prio[prio];
  662. if (!rq->elv.priv[0]) {
  663. per_prio->stats.inserted++;
  664. rq->elv.priv[0] = (void *)(uintptr_t)1;
  665. }
  666. if (blk_mq_sched_try_insert_merge(q, rq, &free)) {
  667. blk_mq_free_requests(&free);
  668. return;
  669. }
  670. trace_block_rq_insert(rq);
  671. if (at_head) {
  672. list_add(&rq->queuelist, &per_prio->dispatch);
  673. rq->fifo_time = jiffies;
  674. } else {
  675. deadline_add_rq_rb(per_prio, rq);
  676. if (rq_mergeable(rq)) {
  677. elv_rqhash_add(q, rq);
  678. if (!q->last_merge)
  679. q->last_merge = rq;
  680. }
  681. /*
  682. * set expire time and add to fifo list
  683. */
  684. rq->fifo_time = jiffies + dd->fifo_expire[data_dir];
  685. list_add_tail(&rq->queuelist, &per_prio->fifo_list[data_dir]);
  686. }
  687. }
  688. /*
  689. * Called from blk_mq_sched_insert_request() or blk_mq_sched_insert_requests().
  690. */
  691. static void dd_insert_requests(struct blk_mq_hw_ctx *hctx,
  692. struct list_head *list, bool at_head)
  693. {
  694. struct request_queue *q = hctx->queue;
  695. struct deadline_data *dd = q->elevator->elevator_data;
  696. spin_lock(&dd->lock);
  697. while (!list_empty(list)) {
  698. struct request *rq;
  699. rq = list_first_entry(list, struct request, queuelist);
  700. list_del_init(&rq->queuelist);
  701. dd_insert_request(hctx, rq, at_head);
  702. }
  703. spin_unlock(&dd->lock);
  704. }
  705. /* Callback from inside blk_mq_rq_ctx_init(). */
  706. static void dd_prepare_request(struct request *rq)
  707. {
  708. rq->elv.priv[0] = NULL;
  709. }
  710. static bool dd_has_write_work(struct blk_mq_hw_ctx *hctx)
  711. {
  712. struct deadline_data *dd = hctx->queue->elevator->elevator_data;
  713. enum dd_prio p;
  714. for (p = 0; p <= DD_PRIO_MAX; p++)
  715. if (!list_empty_careful(&dd->per_prio[p].fifo_list[DD_WRITE]))
  716. return true;
  717. return false;
  718. }
  719. /*
  720. * Callback from inside blk_mq_free_request().
  721. *
  722. * For zoned block devices, write unlock the target zone of
  723. * completed write requests. Do this while holding the zone lock
  724. * spinlock so that the zone is never unlocked while deadline_fifo_request()
  725. * or deadline_next_request() are executing. This function is called for
  726. * all requests, whether or not these requests complete successfully.
  727. *
  728. * For a zoned block device, __dd_dispatch_request() may have stopped
  729. * dispatching requests if all the queued requests are write requests directed
  730. * at zones that are already locked due to on-going write requests. To ensure
  731. * write request dispatch progress in this case, mark the queue as needing a
  732. * restart to ensure that the queue is run again after completion of the
  733. * request and zones being unlocked.
  734. */
  735. static void dd_finish_request(struct request *rq)
  736. {
  737. struct request_queue *q = rq->q;
  738. struct deadline_data *dd = q->elevator->elevator_data;
  739. const u8 ioprio_class = dd_rq_ioclass(rq);
  740. const enum dd_prio prio = ioprio_class_to_prio[ioprio_class];
  741. struct dd_per_prio *per_prio = &dd->per_prio[prio];
  742. /*
  743. * The block layer core may call dd_finish_request() without having
  744. * called dd_insert_requests(). Skip requests that bypassed I/O
  745. * scheduling. See also blk_mq_request_bypass_insert().
  746. */
  747. if (!rq->elv.priv[0])
  748. return;
  749. atomic_inc(&per_prio->stats.completed);
  750. if (blk_queue_is_zoned(q)) {
  751. unsigned long flags;
  752. spin_lock_irqsave(&dd->zone_lock, flags);
  753. blk_req_zone_write_unlock(rq);
  754. spin_unlock_irqrestore(&dd->zone_lock, flags);
  755. if (dd_has_write_work(rq->mq_hctx))
  756. blk_mq_sched_mark_restart_hctx(rq->mq_hctx);
  757. }
  758. }
  759. static bool dd_has_work_for_prio(struct dd_per_prio *per_prio)
  760. {
  761. return !list_empty_careful(&per_prio->dispatch) ||
  762. !list_empty_careful(&per_prio->fifo_list[DD_READ]) ||
  763. !list_empty_careful(&per_prio->fifo_list[DD_WRITE]);
  764. }
  765. static bool dd_has_work(struct blk_mq_hw_ctx *hctx)
  766. {
  767. struct deadline_data *dd = hctx->queue->elevator->elevator_data;
  768. enum dd_prio prio;
  769. for (prio = 0; prio <= DD_PRIO_MAX; prio++)
  770. if (dd_has_work_for_prio(&dd->per_prio[prio]))
  771. return true;
  772. return false;
  773. }
  774. /*
  775. * sysfs parts below
  776. */
  777. #define SHOW_INT(__FUNC, __VAR) \
  778. static ssize_t __FUNC(struct elevator_queue *e, char *page) \
  779. { \
  780. struct deadline_data *dd = e->elevator_data; \
  781. \
  782. return sysfs_emit(page, "%d\n", __VAR); \
  783. }
  784. #define SHOW_JIFFIES(__FUNC, __VAR) SHOW_INT(__FUNC, jiffies_to_msecs(__VAR))
  785. SHOW_JIFFIES(deadline_read_expire_show, dd->fifo_expire[DD_READ]);
  786. SHOW_JIFFIES(deadline_write_expire_show, dd->fifo_expire[DD_WRITE]);
  787. SHOW_JIFFIES(deadline_prio_aging_expire_show, dd->prio_aging_expire);
  788. SHOW_INT(deadline_writes_starved_show, dd->writes_starved);
  789. SHOW_INT(deadline_front_merges_show, dd->front_merges);
  790. SHOW_INT(deadline_async_depth_show, dd->async_depth);
  791. SHOW_INT(deadline_fifo_batch_show, dd->fifo_batch);
  792. #undef SHOW_INT
  793. #undef SHOW_JIFFIES
  794. #define STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, __CONV) \
  795. static ssize_t __FUNC(struct elevator_queue *e, const char *page, size_t count) \
  796. { \
  797. struct deadline_data *dd = e->elevator_data; \
  798. int __data, __ret; \
  799. \
  800. __ret = kstrtoint(page, 0, &__data); \
  801. if (__ret < 0) \
  802. return __ret; \
  803. if (__data < (MIN)) \
  804. __data = (MIN); \
  805. else if (__data > (MAX)) \
  806. __data = (MAX); \
  807. *(__PTR) = __CONV(__data); \
  808. return count; \
  809. }
  810. #define STORE_INT(__FUNC, __PTR, MIN, MAX) \
  811. STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, )
  812. #define STORE_JIFFIES(__FUNC, __PTR, MIN, MAX) \
  813. STORE_FUNCTION(__FUNC, __PTR, MIN, MAX, msecs_to_jiffies)
  814. STORE_JIFFIES(deadline_read_expire_store, &dd->fifo_expire[DD_READ], 0, INT_MAX);
  815. STORE_JIFFIES(deadline_write_expire_store, &dd->fifo_expire[DD_WRITE], 0, INT_MAX);
  816. STORE_JIFFIES(deadline_prio_aging_expire_store, &dd->prio_aging_expire, 0, INT_MAX);
  817. STORE_INT(deadline_writes_starved_store, &dd->writes_starved, INT_MIN, INT_MAX);
  818. STORE_INT(deadline_front_merges_store, &dd->front_merges, 0, 1);
  819. STORE_INT(deadline_async_depth_store, &dd->async_depth, 1, INT_MAX);
  820. STORE_INT(deadline_fifo_batch_store, &dd->fifo_batch, 0, INT_MAX);
  821. #undef STORE_FUNCTION
  822. #undef STORE_INT
  823. #undef STORE_JIFFIES
  824. #define DD_ATTR(name) \
  825. __ATTR(name, 0644, deadline_##name##_show, deadline_##name##_store)
  826. static struct elv_fs_entry deadline_attrs[] = {
  827. DD_ATTR(read_expire),
  828. DD_ATTR(write_expire),
  829. DD_ATTR(writes_starved),
  830. DD_ATTR(front_merges),
  831. DD_ATTR(async_depth),
  832. DD_ATTR(fifo_batch),
  833. DD_ATTR(prio_aging_expire),
  834. __ATTR_NULL
  835. };
  836. #ifdef CONFIG_BLK_DEBUG_FS
  837. #define DEADLINE_DEBUGFS_DDIR_ATTRS(prio, data_dir, name) \
  838. static void *deadline_##name##_fifo_start(struct seq_file *m, \
  839. loff_t *pos) \
  840. __acquires(&dd->lock) \
  841. { \
  842. struct request_queue *q = m->private; \
  843. struct deadline_data *dd = q->elevator->elevator_data; \
  844. struct dd_per_prio *per_prio = &dd->per_prio[prio]; \
  845. \
  846. spin_lock(&dd->lock); \
  847. return seq_list_start(&per_prio->fifo_list[data_dir], *pos); \
  848. } \
  849. \
  850. static void *deadline_##name##_fifo_next(struct seq_file *m, void *v, \
  851. loff_t *pos) \
  852. { \
  853. struct request_queue *q = m->private; \
  854. struct deadline_data *dd = q->elevator->elevator_data; \
  855. struct dd_per_prio *per_prio = &dd->per_prio[prio]; \
  856. \
  857. return seq_list_next(v, &per_prio->fifo_list[data_dir], pos); \
  858. } \
  859. \
  860. static void deadline_##name##_fifo_stop(struct seq_file *m, void *v) \
  861. __releases(&dd->lock) \
  862. { \
  863. struct request_queue *q = m->private; \
  864. struct deadline_data *dd = q->elevator->elevator_data; \
  865. \
  866. spin_unlock(&dd->lock); \
  867. } \
  868. \
  869. static const struct seq_operations deadline_##name##_fifo_seq_ops = { \
  870. .start = deadline_##name##_fifo_start, \
  871. .next = deadline_##name##_fifo_next, \
  872. .stop = deadline_##name##_fifo_stop, \
  873. .show = blk_mq_debugfs_rq_show, \
  874. }; \
  875. \
  876. static int deadline_##name##_next_rq_show(void *data, \
  877. struct seq_file *m) \
  878. { \
  879. struct request_queue *q = data; \
  880. struct deadline_data *dd = q->elevator->elevator_data; \
  881. struct dd_per_prio *per_prio = &dd->per_prio[prio]; \
  882. struct request *rq = per_prio->next_rq[data_dir]; \
  883. \
  884. if (rq) \
  885. __blk_mq_debugfs_rq_show(m, rq); \
  886. return 0; \
  887. }
  888. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_READ, read0);
  889. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_RT_PRIO, DD_WRITE, write0);
  890. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_READ, read1);
  891. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_BE_PRIO, DD_WRITE, write1);
  892. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_READ, read2);
  893. DEADLINE_DEBUGFS_DDIR_ATTRS(DD_IDLE_PRIO, DD_WRITE, write2);
  894. #undef DEADLINE_DEBUGFS_DDIR_ATTRS
  895. static int deadline_batching_show(void *data, struct seq_file *m)
  896. {
  897. struct request_queue *q = data;
  898. struct deadline_data *dd = q->elevator->elevator_data;
  899. seq_printf(m, "%u\n", dd->batching);
  900. return 0;
  901. }
  902. static int deadline_starved_show(void *data, struct seq_file *m)
  903. {
  904. struct request_queue *q = data;
  905. struct deadline_data *dd = q->elevator->elevator_data;
  906. seq_printf(m, "%u\n", dd->starved);
  907. return 0;
  908. }
  909. static int dd_async_depth_show(void *data, struct seq_file *m)
  910. {
  911. struct request_queue *q = data;
  912. struct deadline_data *dd = q->elevator->elevator_data;
  913. seq_printf(m, "%u\n", dd->async_depth);
  914. return 0;
  915. }
  916. static int dd_queued_show(void *data, struct seq_file *m)
  917. {
  918. struct request_queue *q = data;
  919. struct deadline_data *dd = q->elevator->elevator_data;
  920. u32 rt, be, idle;
  921. spin_lock(&dd->lock);
  922. rt = dd_queued(dd, DD_RT_PRIO);
  923. be = dd_queued(dd, DD_BE_PRIO);
  924. idle = dd_queued(dd, DD_IDLE_PRIO);
  925. spin_unlock(&dd->lock);
  926. seq_printf(m, "%u %u %u\n", rt, be, idle);
  927. return 0;
  928. }
  929. /* Number of requests owned by the block driver for a given priority. */
  930. static u32 dd_owned_by_driver(struct deadline_data *dd, enum dd_prio prio)
  931. {
  932. const struct io_stats_per_prio *stats = &dd->per_prio[prio].stats;
  933. lockdep_assert_held(&dd->lock);
  934. return stats->dispatched + stats->merged -
  935. atomic_read(&stats->completed);
  936. }
  937. static int dd_owned_by_driver_show(void *data, struct seq_file *m)
  938. {
  939. struct request_queue *q = data;
  940. struct deadline_data *dd = q->elevator->elevator_data;
  941. u32 rt, be, idle;
  942. spin_lock(&dd->lock);
  943. rt = dd_owned_by_driver(dd, DD_RT_PRIO);
  944. be = dd_owned_by_driver(dd, DD_BE_PRIO);
  945. idle = dd_owned_by_driver(dd, DD_IDLE_PRIO);
  946. spin_unlock(&dd->lock);
  947. seq_printf(m, "%u %u %u\n", rt, be, idle);
  948. return 0;
  949. }
  950. #define DEADLINE_DISPATCH_ATTR(prio) \
  951. static void *deadline_dispatch##prio##_start(struct seq_file *m, \
  952. loff_t *pos) \
  953. __acquires(&dd->lock) \
  954. { \
  955. struct request_queue *q = m->private; \
  956. struct deadline_data *dd = q->elevator->elevator_data; \
  957. struct dd_per_prio *per_prio = &dd->per_prio[prio]; \
  958. \
  959. spin_lock(&dd->lock); \
  960. return seq_list_start(&per_prio->dispatch, *pos); \
  961. } \
  962. \
  963. static void *deadline_dispatch##prio##_next(struct seq_file *m, \
  964. void *v, loff_t *pos) \
  965. { \
  966. struct request_queue *q = m->private; \
  967. struct deadline_data *dd = q->elevator->elevator_data; \
  968. struct dd_per_prio *per_prio = &dd->per_prio[prio]; \
  969. \
  970. return seq_list_next(v, &per_prio->dispatch, pos); \
  971. } \
  972. \
  973. static void deadline_dispatch##prio##_stop(struct seq_file *m, void *v) \
  974. __releases(&dd->lock) \
  975. { \
  976. struct request_queue *q = m->private; \
  977. struct deadline_data *dd = q->elevator->elevator_data; \
  978. \
  979. spin_unlock(&dd->lock); \
  980. } \
  981. \
  982. static const struct seq_operations deadline_dispatch##prio##_seq_ops = { \
  983. .start = deadline_dispatch##prio##_start, \
  984. .next = deadline_dispatch##prio##_next, \
  985. .stop = deadline_dispatch##prio##_stop, \
  986. .show = blk_mq_debugfs_rq_show, \
  987. }
  988. DEADLINE_DISPATCH_ATTR(0);
  989. DEADLINE_DISPATCH_ATTR(1);
  990. DEADLINE_DISPATCH_ATTR(2);
  991. #undef DEADLINE_DISPATCH_ATTR
  992. #define DEADLINE_QUEUE_DDIR_ATTRS(name) \
  993. {#name "_fifo_list", 0400, \
  994. .seq_ops = &deadline_##name##_fifo_seq_ops}
  995. #define DEADLINE_NEXT_RQ_ATTR(name) \
  996. {#name "_next_rq", 0400, deadline_##name##_next_rq_show}
  997. static const struct blk_mq_debugfs_attr deadline_queue_debugfs_attrs[] = {
  998. DEADLINE_QUEUE_DDIR_ATTRS(read0),
  999. DEADLINE_QUEUE_DDIR_ATTRS(write0),
  1000. DEADLINE_QUEUE_DDIR_ATTRS(read1),
  1001. DEADLINE_QUEUE_DDIR_ATTRS(write1),
  1002. DEADLINE_QUEUE_DDIR_ATTRS(read2),
  1003. DEADLINE_QUEUE_DDIR_ATTRS(write2),
  1004. DEADLINE_NEXT_RQ_ATTR(read0),
  1005. DEADLINE_NEXT_RQ_ATTR(write0),
  1006. DEADLINE_NEXT_RQ_ATTR(read1),
  1007. DEADLINE_NEXT_RQ_ATTR(write1),
  1008. DEADLINE_NEXT_RQ_ATTR(read2),
  1009. DEADLINE_NEXT_RQ_ATTR(write2),
  1010. {"batching", 0400, deadline_batching_show},
  1011. {"starved", 0400, deadline_starved_show},
  1012. {"async_depth", 0400, dd_async_depth_show},
  1013. {"dispatch0", 0400, .seq_ops = &deadline_dispatch0_seq_ops},
  1014. {"dispatch1", 0400, .seq_ops = &deadline_dispatch1_seq_ops},
  1015. {"dispatch2", 0400, .seq_ops = &deadline_dispatch2_seq_ops},
  1016. {"owned_by_driver", 0400, dd_owned_by_driver_show},
  1017. {"queued", 0400, dd_queued_show},
  1018. {},
  1019. };
  1020. #undef DEADLINE_QUEUE_DDIR_ATTRS
  1021. #endif
  1022. static struct elevator_type mq_deadline = {
  1023. .ops = {
  1024. .depth_updated = dd_depth_updated,
  1025. .limit_depth = dd_limit_depth,
  1026. .insert_requests = dd_insert_requests,
  1027. .dispatch_request = dd_dispatch_request,
  1028. .prepare_request = dd_prepare_request,
  1029. .finish_request = dd_finish_request,
  1030. .next_request = elv_rb_latter_request,
  1031. .former_request = elv_rb_former_request,
  1032. .bio_merge = dd_bio_merge,
  1033. .request_merge = dd_request_merge,
  1034. .requests_merged = dd_merged_requests,
  1035. .request_merged = dd_request_merged,
  1036. .has_work = dd_has_work,
  1037. .init_sched = dd_init_sched,
  1038. .exit_sched = dd_exit_sched,
  1039. .init_hctx = dd_init_hctx,
  1040. },
  1041. #ifdef CONFIG_BLK_DEBUG_FS
  1042. .queue_debugfs_attrs = deadline_queue_debugfs_attrs,
  1043. #endif
  1044. .elevator_attrs = deadline_attrs,
  1045. .elevator_name = "mq-deadline",
  1046. .elevator_alias = "deadline",
  1047. .elevator_features = ELEVATOR_F_ZBD_SEQ_WRITE,
  1048. .elevator_owner = THIS_MODULE,
  1049. };
  1050. MODULE_ALIAS("mq-deadline-iosched");
  1051. static int __init deadline_init(void)
  1052. {
  1053. return elv_register(&mq_deadline);
  1054. }
  1055. static void __exit deadline_exit(void)
  1056. {
  1057. elv_unregister(&mq_deadline);
  1058. }
  1059. module_init(deadline_init);
  1060. module_exit(deadline_exit);
  1061. MODULE_AUTHOR("Jens Axboe, Damien Le Moal and Bart Van Assche");
  1062. MODULE_LICENSE("GPL");
  1063. MODULE_DESCRIPTION("MQ deadline IO scheduler");