blk-throttle.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /*
  2. * Interface for controlling IO bandwidth on a request queue
  3. *
  4. * Copyright (C) 2010 Vivek Goyal <vgoyal@redhat.com>
  5. */
  6. #include <linux/module.h>
  7. #include <linux/slab.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/bio.h>
  10. #include <linux/blktrace_api.h>
  11. #include "blk-cgroup.h"
  12. #include "blk.h"
  13. /* Max dispatch from a group in 1 round */
  14. static int throtl_grp_quantum = 8;
  15. /* Total max dispatch from all groups in one round */
  16. static int throtl_quantum = 32;
  17. /* Throttling is performed over 100ms slice and after that slice is renewed */
  18. static unsigned long throtl_slice = HZ/10; /* 100 ms */
  19. /* A workqueue to queue throttle related work */
  20. static struct workqueue_struct *kthrotld_workqueue;
  21. static void throtl_schedule_delayed_work(struct throtl_data *td,
  22. unsigned long delay);
  23. struct throtl_rb_root {
  24. struct rb_root rb;
  25. struct rb_node *left;
  26. unsigned int count;
  27. unsigned long min_disptime;
  28. };
  29. #define THROTL_RB_ROOT (struct throtl_rb_root) { .rb = RB_ROOT, .left = NULL, \
  30. .count = 0, .min_disptime = 0}
  31. #define rb_entry_tg(node) rb_entry((node), struct throtl_grp, rb_node)
  32. struct throtl_grp {
  33. /* List of throtl groups on the request queue*/
  34. struct hlist_node tg_node;
  35. /* active throtl group service_tree member */
  36. struct rb_node rb_node;
  37. /*
  38. * Dispatch time in jiffies. This is the estimated time when group
  39. * will unthrottle and is ready to dispatch more bio. It is used as
  40. * key to sort active groups in service tree.
  41. */
  42. unsigned long disptime;
  43. struct blkio_group blkg;
  44. atomic_t ref;
  45. unsigned int flags;
  46. /* Two lists for READ and WRITE */
  47. struct bio_list bio_lists[2];
  48. /* Number of queued bios on READ and WRITE lists */
  49. unsigned int nr_queued[2];
  50. /* bytes per second rate limits */
  51. uint64_t bps[2];
  52. /* IOPS limits */
  53. unsigned int iops[2];
  54. /* Number of bytes disptached in current slice */
  55. uint64_t bytes_disp[2];
  56. /* Number of bio's dispatched in current slice */
  57. unsigned int io_disp[2];
  58. /* When did we start a new slice */
  59. unsigned long slice_start[2];
  60. unsigned long slice_end[2];
  61. /* Some throttle limits got updated for the group */
  62. int limits_changed;
  63. struct rcu_head rcu_head;
  64. };
  65. struct throtl_data
  66. {
  67. /* List of throtl groups */
  68. struct hlist_head tg_list;
  69. /* service tree for active throtl groups */
  70. struct throtl_rb_root tg_service_tree;
  71. struct throtl_grp *root_tg;
  72. struct request_queue *queue;
  73. /* Total Number of queued bios on READ and WRITE lists */
  74. unsigned int nr_queued[2];
  75. /*
  76. * number of total undestroyed groups
  77. */
  78. unsigned int nr_undestroyed_grps;
  79. /* Work for dispatching throttled bios */
  80. struct delayed_work throtl_work;
  81. int limits_changed;
  82. };
  83. enum tg_state_flags {
  84. THROTL_TG_FLAG_on_rr = 0, /* on round-robin busy list */
  85. };
  86. #define THROTL_TG_FNS(name) \
  87. static inline void throtl_mark_tg_##name(struct throtl_grp *tg) \
  88. { \
  89. (tg)->flags |= (1 << THROTL_TG_FLAG_##name); \
  90. } \
  91. static inline void throtl_clear_tg_##name(struct throtl_grp *tg) \
  92. { \
  93. (tg)->flags &= ~(1 << THROTL_TG_FLAG_##name); \
  94. } \
  95. static inline int throtl_tg_##name(const struct throtl_grp *tg) \
  96. { \
  97. return ((tg)->flags & (1 << THROTL_TG_FLAG_##name)) != 0; \
  98. }
  99. THROTL_TG_FNS(on_rr);
  100. #define throtl_log_tg(td, tg, fmt, args...) \
  101. blk_add_trace_msg((td)->queue, "throtl %s " fmt, \
  102. blkg_path(&(tg)->blkg), ##args); \
  103. #define throtl_log(td, fmt, args...) \
  104. blk_add_trace_msg((td)->queue, "throtl " fmt, ##args)
  105. static inline struct throtl_grp *tg_of_blkg(struct blkio_group *blkg)
  106. {
  107. if (blkg)
  108. return container_of(blkg, struct throtl_grp, blkg);
  109. return NULL;
  110. }
  111. static inline unsigned int total_nr_queued(struct throtl_data *td)
  112. {
  113. return td->nr_queued[0] + td->nr_queued[1];
  114. }
  115. static inline struct throtl_grp *throtl_ref_get_tg(struct throtl_grp *tg)
  116. {
  117. atomic_inc(&tg->ref);
  118. return tg;
  119. }
  120. static void throtl_free_tg(struct rcu_head *head)
  121. {
  122. struct throtl_grp *tg;
  123. tg = container_of(head, struct throtl_grp, rcu_head);
  124. free_percpu(tg->blkg.stats_cpu);
  125. kfree(tg);
  126. }
  127. static void throtl_put_tg(struct throtl_grp *tg)
  128. {
  129. BUG_ON(atomic_read(&tg->ref) <= 0);
  130. if (!atomic_dec_and_test(&tg->ref))
  131. return;
  132. /*
  133. * A group is freed in rcu manner. But having an rcu lock does not
  134. * mean that one can access all the fields of blkg and assume these
  135. * are valid. For example, don't try to follow throtl_data and
  136. * request queue links.
  137. *
  138. * Having a reference to blkg under an rcu allows acess to only
  139. * values local to groups like group stats and group rate limits
  140. */
  141. call_rcu(&tg->rcu_head, throtl_free_tg);
  142. }
  143. static void throtl_init_group(struct throtl_grp *tg)
  144. {
  145. INIT_HLIST_NODE(&tg->tg_node);
  146. RB_CLEAR_NODE(&tg->rb_node);
  147. bio_list_init(&tg->bio_lists[0]);
  148. bio_list_init(&tg->bio_lists[1]);
  149. tg->limits_changed = false;
  150. /* Practically unlimited BW */
  151. tg->bps[0] = tg->bps[1] = -1;
  152. tg->iops[0] = tg->iops[1] = -1;
  153. /*
  154. * Take the initial reference that will be released on destroy
  155. * This can be thought of a joint reference by cgroup and
  156. * request queue which will be dropped by either request queue
  157. * exit or cgroup deletion path depending on who is exiting first.
  158. */
  159. atomic_set(&tg->ref, 1);
  160. }
  161. /* Should be called with rcu read lock held (needed for blkcg) */
  162. static void
  163. throtl_add_group_to_td_list(struct throtl_data *td, struct throtl_grp *tg)
  164. {
  165. hlist_add_head(&tg->tg_node, &td->tg_list);
  166. td->nr_undestroyed_grps++;
  167. }
  168. static void
  169. __throtl_tg_fill_dev_details(struct throtl_data *td, struct throtl_grp *tg)
  170. {
  171. struct backing_dev_info *bdi = &td->queue->backing_dev_info;
  172. unsigned int major, minor;
  173. if (!tg || tg->blkg.dev)
  174. return;
  175. /*
  176. * Fill in device details for a group which might not have been
  177. * filled at group creation time as queue was being instantiated
  178. * and driver had not attached a device yet
  179. */
  180. if (bdi->dev && dev_name(bdi->dev)) {
  181. sscanf(dev_name(bdi->dev), "%u:%u", &major, &minor);
  182. tg->blkg.dev = MKDEV(major, minor);
  183. }
  184. }
  185. /*
  186. * Should be called with without queue lock held. Here queue lock will be
  187. * taken rarely. It will be taken only once during life time of a group
  188. * if need be
  189. */
  190. static void
  191. throtl_tg_fill_dev_details(struct throtl_data *td, struct throtl_grp *tg)
  192. {
  193. if (!tg || tg->blkg.dev)
  194. return;
  195. spin_lock_irq(td->queue->queue_lock);
  196. __throtl_tg_fill_dev_details(td, tg);
  197. spin_unlock_irq(td->queue->queue_lock);
  198. }
  199. static void throtl_init_add_tg_lists(struct throtl_data *td,
  200. struct throtl_grp *tg, struct blkio_cgroup *blkcg)
  201. {
  202. __throtl_tg_fill_dev_details(td, tg);
  203. /* Add group onto cgroup list */
  204. blkiocg_add_blkio_group(blkcg, &tg->blkg, (void *)td,
  205. tg->blkg.dev, BLKIO_POLICY_THROTL);
  206. tg->bps[READ] = blkcg_get_read_bps(blkcg, tg->blkg.dev);
  207. tg->bps[WRITE] = blkcg_get_write_bps(blkcg, tg->blkg.dev);
  208. tg->iops[READ] = blkcg_get_read_iops(blkcg, tg->blkg.dev);
  209. tg->iops[WRITE] = blkcg_get_write_iops(blkcg, tg->blkg.dev);
  210. throtl_add_group_to_td_list(td, tg);
  211. }
  212. /* Should be called without queue lock and outside of rcu period */
  213. static struct throtl_grp *throtl_alloc_tg(struct throtl_data *td)
  214. {
  215. struct throtl_grp *tg = NULL;
  216. int ret;
  217. tg = kzalloc_node(sizeof(*tg), GFP_ATOMIC, td->queue->node);
  218. if (!tg)
  219. return NULL;
  220. ret = blkio_alloc_blkg_stats(&tg->blkg);
  221. if (ret) {
  222. kfree(tg);
  223. return NULL;
  224. }
  225. throtl_init_group(tg);
  226. return tg;
  227. }
  228. static struct
  229. throtl_grp *throtl_find_tg(struct throtl_data *td, struct blkio_cgroup *blkcg)
  230. {
  231. struct throtl_grp *tg = NULL;
  232. void *key = td;
  233. /*
  234. * This is the common case when there are no blkio cgroups.
  235. * Avoid lookup in this case
  236. */
  237. if (blkcg == &blkio_root_cgroup)
  238. tg = td->root_tg;
  239. else
  240. tg = tg_of_blkg(blkiocg_lookup_group(blkcg, key));
  241. __throtl_tg_fill_dev_details(td, tg);
  242. return tg;
  243. }
  244. static struct throtl_grp * throtl_get_tg(struct throtl_data *td)
  245. {
  246. struct throtl_grp *tg = NULL, *__tg = NULL;
  247. struct blkio_cgroup *blkcg;
  248. struct request_queue *q = td->queue;
  249. /* no throttling for dead queue */
  250. if (unlikely(blk_queue_dead(q)))
  251. return NULL;
  252. rcu_read_lock();
  253. blkcg = task_blkio_cgroup(current);
  254. tg = throtl_find_tg(td, blkcg);
  255. if (tg) {
  256. rcu_read_unlock();
  257. return tg;
  258. }
  259. /*
  260. * Need to allocate a group. Allocation of group also needs allocation
  261. * of per cpu stats which in-turn takes a mutex() and can block. Hence
  262. * we need to drop rcu lock and queue_lock before we call alloc.
  263. */
  264. rcu_read_unlock();
  265. spin_unlock_irq(q->queue_lock);
  266. tg = throtl_alloc_tg(td);
  267. /* Group allocated and queue is still alive. take the lock */
  268. spin_lock_irq(q->queue_lock);
  269. /* Make sure @q is still alive */
  270. if (unlikely(blk_queue_dead(q))) {
  271. kfree(tg);
  272. return NULL;
  273. }
  274. /*
  275. * Initialize the new group. After sleeping, read the blkcg again.
  276. */
  277. rcu_read_lock();
  278. blkcg = task_blkio_cgroup(current);
  279. /*
  280. * If some other thread already allocated the group while we were
  281. * not holding queue lock, free up the group
  282. */
  283. __tg = throtl_find_tg(td, blkcg);
  284. if (__tg) {
  285. kfree(tg);
  286. rcu_read_unlock();
  287. return __tg;
  288. }
  289. /* Group allocation failed. Account the IO to root group */
  290. if (!tg) {
  291. tg = td->root_tg;
  292. return tg;
  293. }
  294. throtl_init_add_tg_lists(td, tg, blkcg);
  295. rcu_read_unlock();
  296. return tg;
  297. }
  298. static struct throtl_grp *throtl_rb_first(struct throtl_rb_root *root)
  299. {
  300. /* Service tree is empty */
  301. if (!root->count)
  302. return NULL;
  303. if (!root->left)
  304. root->left = rb_first(&root->rb);
  305. if (root->left)
  306. return rb_entry_tg(root->left);
  307. return NULL;
  308. }
  309. static void rb_erase_init(struct rb_node *n, struct rb_root *root)
  310. {
  311. rb_erase(n, root);
  312. RB_CLEAR_NODE(n);
  313. }
  314. static void throtl_rb_erase(struct rb_node *n, struct throtl_rb_root *root)
  315. {
  316. if (root->left == n)
  317. root->left = NULL;
  318. rb_erase_init(n, &root->rb);
  319. --root->count;
  320. }
  321. static void update_min_dispatch_time(struct throtl_rb_root *st)
  322. {
  323. struct throtl_grp *tg;
  324. tg = throtl_rb_first(st);
  325. if (!tg)
  326. return;
  327. st->min_disptime = tg->disptime;
  328. }
  329. static void
  330. tg_service_tree_add(struct throtl_rb_root *st, struct throtl_grp *tg)
  331. {
  332. struct rb_node **node = &st->rb.rb_node;
  333. struct rb_node *parent = NULL;
  334. struct throtl_grp *__tg;
  335. unsigned long key = tg->disptime;
  336. int left = 1;
  337. while (*node != NULL) {
  338. parent = *node;
  339. __tg = rb_entry_tg(parent);
  340. if (time_before(key, __tg->disptime))
  341. node = &parent->rb_left;
  342. else {
  343. node = &parent->rb_right;
  344. left = 0;
  345. }
  346. }
  347. if (left)
  348. st->left = &tg->rb_node;
  349. rb_link_node(&tg->rb_node, parent, node);
  350. rb_insert_color(&tg->rb_node, &st->rb);
  351. }
  352. static void __throtl_enqueue_tg(struct throtl_data *td, struct throtl_grp *tg)
  353. {
  354. struct throtl_rb_root *st = &td->tg_service_tree;
  355. tg_service_tree_add(st, tg);
  356. throtl_mark_tg_on_rr(tg);
  357. st->count++;
  358. }
  359. static void throtl_enqueue_tg(struct throtl_data *td, struct throtl_grp *tg)
  360. {
  361. if (!throtl_tg_on_rr(tg))
  362. __throtl_enqueue_tg(td, tg);
  363. }
  364. static void __throtl_dequeue_tg(struct throtl_data *td, struct throtl_grp *tg)
  365. {
  366. throtl_rb_erase(&tg->rb_node, &td->tg_service_tree);
  367. throtl_clear_tg_on_rr(tg);
  368. }
  369. static void throtl_dequeue_tg(struct throtl_data *td, struct throtl_grp *tg)
  370. {
  371. if (throtl_tg_on_rr(tg))
  372. __throtl_dequeue_tg(td, tg);
  373. }
  374. static void throtl_schedule_next_dispatch(struct throtl_data *td)
  375. {
  376. struct throtl_rb_root *st = &td->tg_service_tree;
  377. /*
  378. * If there are more bios pending, schedule more work.
  379. */
  380. if (!total_nr_queued(td))
  381. return;
  382. BUG_ON(!st->count);
  383. update_min_dispatch_time(st);
  384. if (time_before_eq(st->min_disptime, jiffies))
  385. throtl_schedule_delayed_work(td, 0);
  386. else
  387. throtl_schedule_delayed_work(td, (st->min_disptime - jiffies));
  388. }
  389. static inline void
  390. throtl_start_new_slice(struct throtl_data *td, struct throtl_grp *tg, bool rw)
  391. {
  392. tg->bytes_disp[rw] = 0;
  393. tg->io_disp[rw] = 0;
  394. tg->slice_start[rw] = jiffies;
  395. tg->slice_end[rw] = jiffies + throtl_slice;
  396. throtl_log_tg(td, tg, "[%c] new slice start=%lu end=%lu jiffies=%lu",
  397. rw == READ ? 'R' : 'W', tg->slice_start[rw],
  398. tg->slice_end[rw], jiffies);
  399. }
  400. static inline void throtl_set_slice_end(struct throtl_data *td,
  401. struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
  402. {
  403. tg->slice_end[rw] = roundup(jiffy_end, throtl_slice);
  404. }
  405. static inline void throtl_extend_slice(struct throtl_data *td,
  406. struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
  407. {
  408. tg->slice_end[rw] = roundup(jiffy_end, throtl_slice);
  409. throtl_log_tg(td, tg, "[%c] extend slice start=%lu end=%lu jiffies=%lu",
  410. rw == READ ? 'R' : 'W', tg->slice_start[rw],
  411. tg->slice_end[rw], jiffies);
  412. }
  413. /* Determine if previously allocated or extended slice is complete or not */
  414. static bool
  415. throtl_slice_used(struct throtl_data *td, struct throtl_grp *tg, bool rw)
  416. {
  417. if (time_in_range(jiffies, tg->slice_start[rw], tg->slice_end[rw]))
  418. return 0;
  419. return 1;
  420. }
  421. /* Trim the used slices and adjust slice start accordingly */
  422. static inline void
  423. throtl_trim_slice(struct throtl_data *td, struct throtl_grp *tg, bool rw)
  424. {
  425. unsigned long nr_slices, time_elapsed, io_trim;
  426. u64 bytes_trim, tmp;
  427. BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
  428. /*
  429. * If bps are unlimited (-1), then time slice don't get
  430. * renewed. Don't try to trim the slice if slice is used. A new
  431. * slice will start when appropriate.
  432. */
  433. if (throtl_slice_used(td, tg, rw))
  434. return;
  435. /*
  436. * A bio has been dispatched. Also adjust slice_end. It might happen
  437. * that initially cgroup limit was very low resulting in high
  438. * slice_end, but later limit was bumped up and bio was dispached
  439. * sooner, then we need to reduce slice_end. A high bogus slice_end
  440. * is bad because it does not allow new slice to start.
  441. */
  442. throtl_set_slice_end(td, tg, rw, jiffies + throtl_slice);
  443. time_elapsed = jiffies - tg->slice_start[rw];
  444. nr_slices = time_elapsed / throtl_slice;
  445. if (!nr_slices)
  446. return;
  447. tmp = tg->bps[rw] * throtl_slice * nr_slices;
  448. do_div(tmp, HZ);
  449. bytes_trim = tmp;
  450. io_trim = (tg->iops[rw] * throtl_slice * nr_slices)/HZ;
  451. if (!bytes_trim && !io_trim)
  452. return;
  453. if (tg->bytes_disp[rw] >= bytes_trim)
  454. tg->bytes_disp[rw] -= bytes_trim;
  455. else
  456. tg->bytes_disp[rw] = 0;
  457. if (tg->io_disp[rw] >= io_trim)
  458. tg->io_disp[rw] -= io_trim;
  459. else
  460. tg->io_disp[rw] = 0;
  461. tg->slice_start[rw] += nr_slices * throtl_slice;
  462. throtl_log_tg(td, tg, "[%c] trim slice nr=%lu bytes=%llu io=%lu"
  463. " start=%lu end=%lu jiffies=%lu",
  464. rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
  465. tg->slice_start[rw], tg->slice_end[rw], jiffies);
  466. }
  467. static bool tg_with_in_iops_limit(struct throtl_data *td, struct throtl_grp *tg,
  468. struct bio *bio, unsigned long *wait)
  469. {
  470. bool rw = bio_data_dir(bio);
  471. unsigned int io_allowed;
  472. unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
  473. u64 tmp;
  474. jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
  475. /* Slice has just started. Consider one slice interval */
  476. if (!jiffy_elapsed)
  477. jiffy_elapsed_rnd = throtl_slice;
  478. jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, throtl_slice);
  479. /*
  480. * jiffy_elapsed_rnd should not be a big value as minimum iops can be
  481. * 1 then at max jiffy elapsed should be equivalent of 1 second as we
  482. * will allow dispatch after 1 second and after that slice should
  483. * have been trimmed.
  484. */
  485. tmp = (u64)tg->iops[rw] * jiffy_elapsed_rnd;
  486. do_div(tmp, HZ);
  487. if (tmp > UINT_MAX)
  488. io_allowed = UINT_MAX;
  489. else
  490. io_allowed = tmp;
  491. if (tg->io_disp[rw] + 1 <= io_allowed) {
  492. if (wait)
  493. *wait = 0;
  494. return 1;
  495. }
  496. /* Calc approx time to dispatch */
  497. jiffy_wait = ((tg->io_disp[rw] + 1) * HZ)/tg->iops[rw] + 1;
  498. if (jiffy_wait > jiffy_elapsed)
  499. jiffy_wait = jiffy_wait - jiffy_elapsed;
  500. else
  501. jiffy_wait = 1;
  502. if (wait)
  503. *wait = jiffy_wait;
  504. return 0;
  505. }
  506. static bool tg_with_in_bps_limit(struct throtl_data *td, struct throtl_grp *tg,
  507. struct bio *bio, unsigned long *wait)
  508. {
  509. bool rw = bio_data_dir(bio);
  510. u64 bytes_allowed, extra_bytes, tmp;
  511. unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
  512. jiffy_elapsed = jiffy_elapsed_rnd = jiffies - tg->slice_start[rw];
  513. /* Slice has just started. Consider one slice interval */
  514. if (!jiffy_elapsed)
  515. jiffy_elapsed_rnd = throtl_slice;
  516. jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, throtl_slice);
  517. tmp = tg->bps[rw] * jiffy_elapsed_rnd;
  518. do_div(tmp, HZ);
  519. bytes_allowed = tmp;
  520. if (tg->bytes_disp[rw] + bio->bi_size <= bytes_allowed) {
  521. if (wait)
  522. *wait = 0;
  523. return 1;
  524. }
  525. /* Calc approx time to dispatch */
  526. extra_bytes = tg->bytes_disp[rw] + bio->bi_size - bytes_allowed;
  527. jiffy_wait = div64_u64(extra_bytes * HZ, tg->bps[rw]);
  528. if (!jiffy_wait)
  529. jiffy_wait = 1;
  530. /*
  531. * This wait time is without taking into consideration the rounding
  532. * up we did. Add that time also.
  533. */
  534. jiffy_wait = jiffy_wait + (jiffy_elapsed_rnd - jiffy_elapsed);
  535. if (wait)
  536. *wait = jiffy_wait;
  537. return 0;
  538. }
  539. static bool tg_no_rule_group(struct throtl_grp *tg, bool rw) {
  540. if (tg->bps[rw] == -1 && tg->iops[rw] == -1)
  541. return 1;
  542. return 0;
  543. }
  544. /*
  545. * Returns whether one can dispatch a bio or not. Also returns approx number
  546. * of jiffies to wait before this bio is with-in IO rate and can be dispatched
  547. */
  548. static bool tg_may_dispatch(struct throtl_data *td, struct throtl_grp *tg,
  549. struct bio *bio, unsigned long *wait)
  550. {
  551. bool rw = bio_data_dir(bio);
  552. unsigned long bps_wait = 0, iops_wait = 0, max_wait = 0;
  553. /*
  554. * Currently whole state machine of group depends on first bio
  555. * queued in the group bio list. So one should not be calling
  556. * this function with a different bio if there are other bios
  557. * queued.
  558. */
  559. BUG_ON(tg->nr_queued[rw] && bio != bio_list_peek(&tg->bio_lists[rw]));
  560. /* If tg->bps = -1, then BW is unlimited */
  561. if (tg->bps[rw] == -1 && tg->iops[rw] == -1) {
  562. if (wait)
  563. *wait = 0;
  564. return 1;
  565. }
  566. /*
  567. * If previous slice expired, start a new one otherwise renew/extend
  568. * existing slice to make sure it is at least throtl_slice interval
  569. * long since now.
  570. */
  571. if (throtl_slice_used(td, tg, rw))
  572. throtl_start_new_slice(td, tg, rw);
  573. else {
  574. if (time_before(tg->slice_end[rw], jiffies + throtl_slice))
  575. throtl_extend_slice(td, tg, rw, jiffies + throtl_slice);
  576. }
  577. if (tg_with_in_bps_limit(td, tg, bio, &bps_wait)
  578. && tg_with_in_iops_limit(td, tg, bio, &iops_wait)) {
  579. if (wait)
  580. *wait = 0;
  581. return 1;
  582. }
  583. max_wait = max(bps_wait, iops_wait);
  584. if (wait)
  585. *wait = max_wait;
  586. if (time_before(tg->slice_end[rw], jiffies + max_wait))
  587. throtl_extend_slice(td, tg, rw, jiffies + max_wait);
  588. return 0;
  589. }
  590. static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
  591. {
  592. bool rw = bio_data_dir(bio);
  593. bool sync = rw_is_sync(bio->bi_rw);
  594. /* Charge the bio to the group */
  595. tg->bytes_disp[rw] += bio->bi_size;
  596. tg->io_disp[rw]++;
  597. blkiocg_update_dispatch_stats(&tg->blkg, bio->bi_size, rw, sync);
  598. }
  599. static void throtl_add_bio_tg(struct throtl_data *td, struct throtl_grp *tg,
  600. struct bio *bio)
  601. {
  602. bool rw = bio_data_dir(bio);
  603. bio_list_add(&tg->bio_lists[rw], bio);
  604. /* Take a bio reference on tg */
  605. throtl_ref_get_tg(tg);
  606. tg->nr_queued[rw]++;
  607. td->nr_queued[rw]++;
  608. throtl_enqueue_tg(td, tg);
  609. }
  610. static void tg_update_disptime(struct throtl_data *td, struct throtl_grp *tg)
  611. {
  612. unsigned long read_wait = -1, write_wait = -1, min_wait = -1, disptime;
  613. struct bio *bio;
  614. if ((bio = bio_list_peek(&tg->bio_lists[READ])))
  615. tg_may_dispatch(td, tg, bio, &read_wait);
  616. if ((bio = bio_list_peek(&tg->bio_lists[WRITE])))
  617. tg_may_dispatch(td, tg, bio, &write_wait);
  618. min_wait = min(read_wait, write_wait);
  619. disptime = jiffies + min_wait;
  620. /* Update dispatch time */
  621. throtl_dequeue_tg(td, tg);
  622. tg->disptime = disptime;
  623. throtl_enqueue_tg(td, tg);
  624. }
  625. static void tg_dispatch_one_bio(struct throtl_data *td, struct throtl_grp *tg,
  626. bool rw, struct bio_list *bl)
  627. {
  628. struct bio *bio;
  629. bio = bio_list_pop(&tg->bio_lists[rw]);
  630. tg->nr_queued[rw]--;
  631. /* Drop bio reference on tg */
  632. throtl_put_tg(tg);
  633. BUG_ON(td->nr_queued[rw] <= 0);
  634. td->nr_queued[rw]--;
  635. throtl_charge_bio(tg, bio);
  636. bio_list_add(bl, bio);
  637. bio->bi_rw |= REQ_THROTTLED;
  638. throtl_trim_slice(td, tg, rw);
  639. }
  640. static int throtl_dispatch_tg(struct throtl_data *td, struct throtl_grp *tg,
  641. struct bio_list *bl)
  642. {
  643. unsigned int nr_reads = 0, nr_writes = 0;
  644. unsigned int max_nr_reads = throtl_grp_quantum*3/4;
  645. unsigned int max_nr_writes = throtl_grp_quantum - max_nr_reads;
  646. struct bio *bio;
  647. /* Try to dispatch 75% READS and 25% WRITES */
  648. while ((bio = bio_list_peek(&tg->bio_lists[READ]))
  649. && tg_may_dispatch(td, tg, bio, NULL)) {
  650. tg_dispatch_one_bio(td, tg, bio_data_dir(bio), bl);
  651. nr_reads++;
  652. if (nr_reads >= max_nr_reads)
  653. break;
  654. }
  655. while ((bio = bio_list_peek(&tg->bio_lists[WRITE]))
  656. && tg_may_dispatch(td, tg, bio, NULL)) {
  657. tg_dispatch_one_bio(td, tg, bio_data_dir(bio), bl);
  658. nr_writes++;
  659. if (nr_writes >= max_nr_writes)
  660. break;
  661. }
  662. return nr_reads + nr_writes;
  663. }
  664. static int throtl_select_dispatch(struct throtl_data *td, struct bio_list *bl)
  665. {
  666. unsigned int nr_disp = 0;
  667. struct throtl_grp *tg;
  668. struct throtl_rb_root *st = &td->tg_service_tree;
  669. while (1) {
  670. tg = throtl_rb_first(st);
  671. if (!tg)
  672. break;
  673. if (time_before(jiffies, tg->disptime))
  674. break;
  675. throtl_dequeue_tg(td, tg);
  676. nr_disp += throtl_dispatch_tg(td, tg, bl);
  677. if (tg->nr_queued[0] || tg->nr_queued[1]) {
  678. tg_update_disptime(td, tg);
  679. throtl_enqueue_tg(td, tg);
  680. }
  681. if (nr_disp >= throtl_quantum)
  682. break;
  683. }
  684. return nr_disp;
  685. }
  686. static void throtl_process_limit_change(struct throtl_data *td)
  687. {
  688. struct throtl_grp *tg;
  689. struct hlist_node *pos, *n;
  690. if (!td->limits_changed)
  691. return;
  692. xchg(&td->limits_changed, false);
  693. throtl_log(td, "limits changed");
  694. hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
  695. if (!tg->limits_changed)
  696. continue;
  697. if (!xchg(&tg->limits_changed, false))
  698. continue;
  699. throtl_log_tg(td, tg, "limit change rbps=%llu wbps=%llu"
  700. " riops=%u wiops=%u", tg->bps[READ], tg->bps[WRITE],
  701. tg->iops[READ], tg->iops[WRITE]);
  702. /*
  703. * Restart the slices for both READ and WRITES. It
  704. * might happen that a group's limit are dropped
  705. * suddenly and we don't want to account recently
  706. * dispatched IO with new low rate
  707. */
  708. throtl_start_new_slice(td, tg, 0);
  709. throtl_start_new_slice(td, tg, 1);
  710. if (throtl_tg_on_rr(tg))
  711. tg_update_disptime(td, tg);
  712. }
  713. }
  714. /* Dispatch throttled bios. Should be called without queue lock held. */
  715. static int throtl_dispatch(struct request_queue *q)
  716. {
  717. struct throtl_data *td = q->td;
  718. unsigned int nr_disp = 0;
  719. struct bio_list bio_list_on_stack;
  720. struct bio *bio;
  721. struct blk_plug plug;
  722. spin_lock_irq(q->queue_lock);
  723. throtl_process_limit_change(td);
  724. if (!total_nr_queued(td))
  725. goto out;
  726. bio_list_init(&bio_list_on_stack);
  727. throtl_log(td, "dispatch nr_queued=%u read=%u write=%u",
  728. total_nr_queued(td), td->nr_queued[READ],
  729. td->nr_queued[WRITE]);
  730. nr_disp = throtl_select_dispatch(td, &bio_list_on_stack);
  731. if (nr_disp)
  732. throtl_log(td, "bios disp=%u", nr_disp);
  733. throtl_schedule_next_dispatch(td);
  734. out:
  735. spin_unlock_irq(q->queue_lock);
  736. /*
  737. * If we dispatched some requests, unplug the queue to make sure
  738. * immediate dispatch
  739. */
  740. if (nr_disp) {
  741. blk_start_plug(&plug);
  742. while((bio = bio_list_pop(&bio_list_on_stack)))
  743. generic_make_request(bio);
  744. blk_finish_plug(&plug);
  745. }
  746. return nr_disp;
  747. }
  748. void blk_throtl_work(struct work_struct *work)
  749. {
  750. struct throtl_data *td = container_of(work, struct throtl_data,
  751. throtl_work.work);
  752. struct request_queue *q = td->queue;
  753. throtl_dispatch(q);
  754. }
  755. /* Call with queue lock held */
  756. static void
  757. throtl_schedule_delayed_work(struct throtl_data *td, unsigned long delay)
  758. {
  759. struct delayed_work *dwork = &td->throtl_work;
  760. /* schedule work if limits changed even if no bio is queued */
  761. if (total_nr_queued(td) || td->limits_changed) {
  762. /*
  763. * We might have a work scheduled to be executed in future.
  764. * Cancel that and schedule a new one.
  765. */
  766. __cancel_delayed_work(dwork);
  767. queue_delayed_work(kthrotld_workqueue, dwork, delay);
  768. throtl_log(td, "schedule work. delay=%lu jiffies=%lu",
  769. delay, jiffies);
  770. }
  771. }
  772. static void
  773. throtl_destroy_tg(struct throtl_data *td, struct throtl_grp *tg)
  774. {
  775. /* Something wrong if we are trying to remove same group twice */
  776. BUG_ON(hlist_unhashed(&tg->tg_node));
  777. hlist_del_init(&tg->tg_node);
  778. /*
  779. * Put the reference taken at the time of creation so that when all
  780. * queues are gone, group can be destroyed.
  781. */
  782. throtl_put_tg(tg);
  783. td->nr_undestroyed_grps--;
  784. }
  785. static void throtl_release_tgs(struct throtl_data *td)
  786. {
  787. struct hlist_node *pos, *n;
  788. struct throtl_grp *tg;
  789. hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
  790. /*
  791. * If cgroup removal path got to blk_group first and removed
  792. * it from cgroup list, then it will take care of destroying
  793. * cfqg also.
  794. */
  795. if (!blkiocg_del_blkio_group(&tg->blkg))
  796. throtl_destroy_tg(td, tg);
  797. }
  798. }
  799. /*
  800. * Blk cgroup controller notification saying that blkio_group object is being
  801. * delinked as associated cgroup object is going away. That also means that
  802. * no new IO will come in this group. So get rid of this group as soon as
  803. * any pending IO in the group is finished.
  804. *
  805. * This function is called under rcu_read_lock(). key is the rcu protected
  806. * pointer. That means "key" is a valid throtl_data pointer as long as we are
  807. * rcu read lock.
  808. *
  809. * "key" was fetched from blkio_group under blkio_cgroup->lock. That means
  810. * it should not be NULL as even if queue was going away, cgroup deltion
  811. * path got to it first.
  812. */
  813. void throtl_unlink_blkio_group(void *key, struct blkio_group *blkg)
  814. {
  815. unsigned long flags;
  816. struct throtl_data *td = key;
  817. spin_lock_irqsave(td->queue->queue_lock, flags);
  818. throtl_destroy_tg(td, tg_of_blkg(blkg));
  819. spin_unlock_irqrestore(td->queue->queue_lock, flags);
  820. }
  821. static void throtl_update_blkio_group_common(struct throtl_data *td,
  822. struct throtl_grp *tg)
  823. {
  824. xchg(&tg->limits_changed, true);
  825. xchg(&td->limits_changed, true);
  826. /* Schedule a work now to process the limit change */
  827. throtl_schedule_delayed_work(td, 0);
  828. }
  829. /*
  830. * For all update functions, key should be a valid pointer because these
  831. * update functions are called under blkcg_lock, that means, blkg is
  832. * valid and in turn key is valid. queue exit path can not race because
  833. * of blkcg_lock
  834. *
  835. * Can not take queue lock in update functions as queue lock under blkcg_lock
  836. * is not allowed. Under other paths we take blkcg_lock under queue_lock.
  837. */
  838. static void throtl_update_blkio_group_read_bps(void *key,
  839. struct blkio_group *blkg, u64 read_bps)
  840. {
  841. struct throtl_data *td = key;
  842. struct throtl_grp *tg = tg_of_blkg(blkg);
  843. tg->bps[READ] = read_bps;
  844. throtl_update_blkio_group_common(td, tg);
  845. }
  846. static void throtl_update_blkio_group_write_bps(void *key,
  847. struct blkio_group *blkg, u64 write_bps)
  848. {
  849. struct throtl_data *td = key;
  850. struct throtl_grp *tg = tg_of_blkg(blkg);
  851. tg->bps[WRITE] = write_bps;
  852. throtl_update_blkio_group_common(td, tg);
  853. }
  854. static void throtl_update_blkio_group_read_iops(void *key,
  855. struct blkio_group *blkg, unsigned int read_iops)
  856. {
  857. struct throtl_data *td = key;
  858. struct throtl_grp *tg = tg_of_blkg(blkg);
  859. tg->iops[READ] = read_iops;
  860. throtl_update_blkio_group_common(td, tg);
  861. }
  862. static void throtl_update_blkio_group_write_iops(void *key,
  863. struct blkio_group *blkg, unsigned int write_iops)
  864. {
  865. struct throtl_data *td = key;
  866. struct throtl_grp *tg = tg_of_blkg(blkg);
  867. tg->iops[WRITE] = write_iops;
  868. throtl_update_blkio_group_common(td, tg);
  869. }
  870. static void throtl_shutdown_wq(struct request_queue *q)
  871. {
  872. struct throtl_data *td = q->td;
  873. cancel_delayed_work_sync(&td->throtl_work);
  874. }
  875. static struct blkio_policy_type blkio_policy_throtl = {
  876. .ops = {
  877. .blkio_unlink_group_fn = throtl_unlink_blkio_group,
  878. .blkio_update_group_read_bps_fn =
  879. throtl_update_blkio_group_read_bps,
  880. .blkio_update_group_write_bps_fn =
  881. throtl_update_blkio_group_write_bps,
  882. .blkio_update_group_read_iops_fn =
  883. throtl_update_blkio_group_read_iops,
  884. .blkio_update_group_write_iops_fn =
  885. throtl_update_blkio_group_write_iops,
  886. },
  887. .plid = BLKIO_POLICY_THROTL,
  888. };
  889. bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
  890. {
  891. struct throtl_data *td = q->td;
  892. struct throtl_grp *tg;
  893. bool rw = bio_data_dir(bio), update_disptime = true;
  894. struct blkio_cgroup *blkcg;
  895. bool throttled = false;
  896. if (bio->bi_rw & REQ_THROTTLED) {
  897. bio->bi_rw &= ~REQ_THROTTLED;
  898. goto out;
  899. }
  900. /*
  901. * A throtl_grp pointer retrieved under rcu can be used to access
  902. * basic fields like stats and io rates. If a group has no rules,
  903. * just update the dispatch stats in lockless manner and return.
  904. */
  905. rcu_read_lock();
  906. blkcg = task_blkio_cgroup(current);
  907. tg = throtl_find_tg(td, blkcg);
  908. if (tg) {
  909. throtl_tg_fill_dev_details(td, tg);
  910. if (tg_no_rule_group(tg, rw)) {
  911. blkiocg_update_dispatch_stats(&tg->blkg, bio->bi_size,
  912. rw, rw_is_sync(bio->bi_rw));
  913. rcu_read_unlock();
  914. goto out;
  915. }
  916. }
  917. rcu_read_unlock();
  918. /*
  919. * Either group has not been allocated yet or it is not an unlimited
  920. * IO group
  921. */
  922. spin_lock_irq(q->queue_lock);
  923. tg = throtl_get_tg(td);
  924. if (unlikely(!tg))
  925. goto out_unlock;
  926. if (tg->nr_queued[rw]) {
  927. /*
  928. * There is already another bio queued in same dir. No
  929. * need to update dispatch time.
  930. */
  931. update_disptime = false;
  932. goto queue_bio;
  933. }
  934. /* Bio is with-in rate limit of group */
  935. if (tg_may_dispatch(td, tg, bio, NULL)) {
  936. throtl_charge_bio(tg, bio);
  937. /*
  938. * We need to trim slice even when bios are not being queued
  939. * otherwise it might happen that a bio is not queued for
  940. * a long time and slice keeps on extending and trim is not
  941. * called for a long time. Now if limits are reduced suddenly
  942. * we take into account all the IO dispatched so far at new
  943. * low rate and * newly queued IO gets a really long dispatch
  944. * time.
  945. *
  946. * So keep on trimming slice even if bio is not queued.
  947. */
  948. throtl_trim_slice(td, tg, rw);
  949. goto out_unlock;
  950. }
  951. queue_bio:
  952. throtl_log_tg(td, tg, "[%c] bio. bdisp=%llu sz=%u bps=%llu"
  953. " iodisp=%u iops=%u queued=%d/%d",
  954. rw == READ ? 'R' : 'W',
  955. tg->bytes_disp[rw], bio->bi_size, tg->bps[rw],
  956. tg->io_disp[rw], tg->iops[rw],
  957. tg->nr_queued[READ], tg->nr_queued[WRITE]);
  958. throtl_add_bio_tg(q->td, tg, bio);
  959. throttled = true;
  960. if (update_disptime) {
  961. tg_update_disptime(td, tg);
  962. throtl_schedule_next_dispatch(td);
  963. }
  964. out_unlock:
  965. spin_unlock_irq(q->queue_lock);
  966. out:
  967. return throttled;
  968. }
  969. /**
  970. * blk_throtl_drain - drain throttled bios
  971. * @q: request_queue to drain throttled bios for
  972. *
  973. * Dispatch all currently throttled bios on @q through ->make_request_fn().
  974. */
  975. void blk_throtl_drain(struct request_queue *q)
  976. __releases(q->queue_lock) __acquires(q->queue_lock)
  977. {
  978. struct throtl_data *td = q->td;
  979. struct throtl_rb_root *st = &td->tg_service_tree;
  980. struct throtl_grp *tg;
  981. struct bio_list bl;
  982. struct bio *bio;
  983. queue_lockdep_assert_held(q);
  984. bio_list_init(&bl);
  985. while ((tg = throtl_rb_first(st))) {
  986. throtl_dequeue_tg(td, tg);
  987. while ((bio = bio_list_peek(&tg->bio_lists[READ])))
  988. tg_dispatch_one_bio(td, tg, bio_data_dir(bio), &bl);
  989. while ((bio = bio_list_peek(&tg->bio_lists[WRITE])))
  990. tg_dispatch_one_bio(td, tg, bio_data_dir(bio), &bl);
  991. }
  992. spin_unlock_irq(q->queue_lock);
  993. while ((bio = bio_list_pop(&bl)))
  994. generic_make_request(bio);
  995. spin_lock_irq(q->queue_lock);
  996. }
  997. int blk_throtl_init(struct request_queue *q)
  998. {
  999. struct throtl_data *td;
  1000. struct throtl_grp *tg;
  1001. td = kzalloc_node(sizeof(*td), GFP_KERNEL, q->node);
  1002. if (!td)
  1003. return -ENOMEM;
  1004. INIT_HLIST_HEAD(&td->tg_list);
  1005. td->tg_service_tree = THROTL_RB_ROOT;
  1006. td->limits_changed = false;
  1007. INIT_DELAYED_WORK(&td->throtl_work, blk_throtl_work);
  1008. /* alloc and Init root group. */
  1009. td->queue = q;
  1010. tg = throtl_alloc_tg(td);
  1011. if (!tg) {
  1012. kfree(td);
  1013. return -ENOMEM;
  1014. }
  1015. td->root_tg = tg;
  1016. rcu_read_lock();
  1017. throtl_init_add_tg_lists(td, tg, &blkio_root_cgroup);
  1018. rcu_read_unlock();
  1019. /* Attach throtl data to request queue */
  1020. q->td = td;
  1021. return 0;
  1022. }
  1023. void blk_throtl_exit(struct request_queue *q)
  1024. {
  1025. struct throtl_data *td = q->td;
  1026. bool wait = false;
  1027. BUG_ON(!td);
  1028. throtl_shutdown_wq(q);
  1029. spin_lock_irq(q->queue_lock);
  1030. throtl_release_tgs(td);
  1031. /* If there are other groups */
  1032. if (td->nr_undestroyed_grps > 0)
  1033. wait = true;
  1034. spin_unlock_irq(q->queue_lock);
  1035. /*
  1036. * Wait for tg->blkg->key accessors to exit their grace periods.
  1037. * Do this wait only if there are other undestroyed groups out
  1038. * there (other than root group). This can happen if cgroup deletion
  1039. * path claimed the responsibility of cleaning up a group before
  1040. * queue cleanup code get to the group.
  1041. *
  1042. * Do not call synchronize_rcu() unconditionally as there are drivers
  1043. * which create/delete request queue hundreds of times during scan/boot
  1044. * and synchronize_rcu() can take significant time and slow down boot.
  1045. */
  1046. if (wait)
  1047. synchronize_rcu();
  1048. /*
  1049. * Just being safe to make sure after previous flush if some body did
  1050. * update limits through cgroup and another work got queued, cancel
  1051. * it.
  1052. */
  1053. throtl_shutdown_wq(q);
  1054. }
  1055. void blk_throtl_release(struct request_queue *q)
  1056. {
  1057. kfree(q->td);
  1058. }
  1059. static int __init throtl_init(void)
  1060. {
  1061. kthrotld_workqueue = alloc_workqueue("kthrotld", WQ_MEM_RECLAIM, 0);
  1062. if (!kthrotld_workqueue)
  1063. panic("Failed to create kthrotld\n");
  1064. blkio_policy_register(&blkio_policy_throtl);
  1065. return 0;
  1066. }
  1067. module_init(throtl_init);