blk-cgroup.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  1. /*
  2. * Common Block IO controller cgroup interface
  3. *
  4. * Based on ideas and code from CFQ, CFS and BFQ:
  5. * Copyright (C) 2003 Jens Axboe <axboe@kernel.dk>
  6. *
  7. * Copyright (C) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
  8. * Paolo Valente <paolo.valente@unimore.it>
  9. *
  10. * Copyright (C) 2009 Vivek Goyal <vgoyal@redhat.com>
  11. * Nauman Rafique <nauman@google.com>
  12. */
  13. #include <linux/ioprio.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/kdev_t.h>
  16. #include <linux/module.h>
  17. #include <linux/err.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/slab.h>
  20. #include <linux/genhd.h>
  21. #include <linux/delay.h>
  22. #include "blk-cgroup.h"
  23. #include "blk.h"
  24. #define MAX_KEY_LEN 100
  25. static DEFINE_SPINLOCK(blkio_list_lock);
  26. static LIST_HEAD(blkio_list);
  27. static DEFINE_MUTEX(all_q_mutex);
  28. static LIST_HEAD(all_q_list);
  29. /* List of groups pending per cpu stats allocation */
  30. static DEFINE_SPINLOCK(alloc_list_lock);
  31. static LIST_HEAD(alloc_list);
  32. static void blkio_stat_alloc_fn(struct work_struct *);
  33. static DECLARE_DELAYED_WORK(blkio_stat_alloc_work, blkio_stat_alloc_fn);
  34. struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
  35. EXPORT_SYMBOL_GPL(blkio_root_cgroup);
  36. static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
  37. static struct cgroup_subsys_state *blkiocg_create(struct cgroup_subsys *,
  38. struct cgroup *);
  39. static int blkiocg_can_attach(struct cgroup_subsys *, struct cgroup *,
  40. struct cgroup_taskset *);
  41. static void blkiocg_attach(struct cgroup_subsys *, struct cgroup *,
  42. struct cgroup_taskset *);
  43. static int blkiocg_pre_destroy(struct cgroup_subsys *, struct cgroup *);
  44. static void blkiocg_destroy(struct cgroup_subsys *, struct cgroup *);
  45. static int blkiocg_populate(struct cgroup_subsys *, struct cgroup *);
  46. /* for encoding cft->private value on file */
  47. #define BLKIOFILE_PRIVATE(x, val) (((x) << 16) | (val))
  48. /* What policy owns the file, proportional or throttle */
  49. #define BLKIOFILE_POLICY(val) (((val) >> 16) & 0xffff)
  50. #define BLKIOFILE_ATTR(val) ((val) & 0xffff)
  51. struct cgroup_subsys blkio_subsys = {
  52. .name = "blkio",
  53. .create = blkiocg_create,
  54. .can_attach = blkiocg_can_attach,
  55. .attach = blkiocg_attach,
  56. .pre_destroy = blkiocg_pre_destroy,
  57. .destroy = blkiocg_destroy,
  58. .populate = blkiocg_populate,
  59. .subsys_id = blkio_subsys_id,
  60. .module = THIS_MODULE,
  61. };
  62. EXPORT_SYMBOL_GPL(blkio_subsys);
  63. struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
  64. {
  65. return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
  66. struct blkio_cgroup, css);
  67. }
  68. EXPORT_SYMBOL_GPL(cgroup_to_blkio_cgroup);
  69. static struct blkio_cgroup *task_blkio_cgroup(struct task_struct *tsk)
  70. {
  71. return container_of(task_subsys_state(tsk, blkio_subsys_id),
  72. struct blkio_cgroup, css);
  73. }
  74. struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
  75. {
  76. if (bio && bio->bi_css)
  77. return container_of(bio->bi_css, struct blkio_cgroup, css);
  78. return task_blkio_cgroup(current);
  79. }
  80. EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
  81. static inline void blkio_update_group_weight(struct blkio_group *blkg,
  82. int plid, unsigned int weight)
  83. {
  84. struct blkio_policy_type *blkiop;
  85. list_for_each_entry(blkiop, &blkio_list, list) {
  86. /* If this policy does not own the blkg, do not send updates */
  87. if (blkiop->plid != plid)
  88. continue;
  89. if (blkiop->ops.blkio_update_group_weight_fn)
  90. blkiop->ops.blkio_update_group_weight_fn(blkg->q,
  91. blkg, weight);
  92. }
  93. }
  94. static inline void blkio_update_group_bps(struct blkio_group *blkg, int plid,
  95. u64 bps, int fileid)
  96. {
  97. struct blkio_policy_type *blkiop;
  98. list_for_each_entry(blkiop, &blkio_list, list) {
  99. /* If this policy does not own the blkg, do not send updates */
  100. if (blkiop->plid != plid)
  101. continue;
  102. if (fileid == BLKIO_THROTL_read_bps_device
  103. && blkiop->ops.blkio_update_group_read_bps_fn)
  104. blkiop->ops.blkio_update_group_read_bps_fn(blkg->q,
  105. blkg, bps);
  106. if (fileid == BLKIO_THROTL_write_bps_device
  107. && blkiop->ops.blkio_update_group_write_bps_fn)
  108. blkiop->ops.blkio_update_group_write_bps_fn(blkg->q,
  109. blkg, bps);
  110. }
  111. }
  112. static inline void blkio_update_group_iops(struct blkio_group *blkg,
  113. int plid, unsigned int iops,
  114. int fileid)
  115. {
  116. struct blkio_policy_type *blkiop;
  117. list_for_each_entry(blkiop, &blkio_list, list) {
  118. /* If this policy does not own the blkg, do not send updates */
  119. if (blkiop->plid != plid)
  120. continue;
  121. if (fileid == BLKIO_THROTL_read_iops_device
  122. && blkiop->ops.blkio_update_group_read_iops_fn)
  123. blkiop->ops.blkio_update_group_read_iops_fn(blkg->q,
  124. blkg, iops);
  125. if (fileid == BLKIO_THROTL_write_iops_device
  126. && blkiop->ops.blkio_update_group_write_iops_fn)
  127. blkiop->ops.blkio_update_group_write_iops_fn(blkg->q,
  128. blkg,iops);
  129. }
  130. }
  131. /*
  132. * Add to the appropriate stat variable depending on the request type.
  133. * This should be called with queue_lock held.
  134. */
  135. static void blkio_add_stat(uint64_t *stat, uint64_t add, bool direction,
  136. bool sync)
  137. {
  138. if (direction)
  139. stat[BLKIO_STAT_WRITE] += add;
  140. else
  141. stat[BLKIO_STAT_READ] += add;
  142. if (sync)
  143. stat[BLKIO_STAT_SYNC] += add;
  144. else
  145. stat[BLKIO_STAT_ASYNC] += add;
  146. }
  147. /*
  148. * Decrements the appropriate stat variable if non-zero depending on the
  149. * request type. Panics on value being zero.
  150. * This should be called with the queue_lock held.
  151. */
  152. static void blkio_check_and_dec_stat(uint64_t *stat, bool direction, bool sync)
  153. {
  154. if (direction) {
  155. BUG_ON(stat[BLKIO_STAT_WRITE] == 0);
  156. stat[BLKIO_STAT_WRITE]--;
  157. } else {
  158. BUG_ON(stat[BLKIO_STAT_READ] == 0);
  159. stat[BLKIO_STAT_READ]--;
  160. }
  161. if (sync) {
  162. BUG_ON(stat[BLKIO_STAT_SYNC] == 0);
  163. stat[BLKIO_STAT_SYNC]--;
  164. } else {
  165. BUG_ON(stat[BLKIO_STAT_ASYNC] == 0);
  166. stat[BLKIO_STAT_ASYNC]--;
  167. }
  168. }
  169. #ifdef CONFIG_DEBUG_BLK_CGROUP
  170. /* This should be called with the queue_lock held. */
  171. static void blkio_set_start_group_wait_time(struct blkio_group *blkg,
  172. struct blkio_policy_type *pol,
  173. struct blkio_group *curr_blkg)
  174. {
  175. struct blkg_policy_data *pd = blkg->pd[pol->plid];
  176. if (blkio_blkg_waiting(&pd->stats))
  177. return;
  178. if (blkg == curr_blkg)
  179. return;
  180. pd->stats.start_group_wait_time = sched_clock();
  181. blkio_mark_blkg_waiting(&pd->stats);
  182. }
  183. /* This should be called with the queue_lock held. */
  184. static void blkio_update_group_wait_time(struct blkio_group_stats *stats)
  185. {
  186. unsigned long long now;
  187. if (!blkio_blkg_waiting(stats))
  188. return;
  189. now = sched_clock();
  190. if (time_after64(now, stats->start_group_wait_time))
  191. stats->group_wait_time += now - stats->start_group_wait_time;
  192. blkio_clear_blkg_waiting(stats);
  193. }
  194. /* This should be called with the queue_lock held. */
  195. static void blkio_end_empty_time(struct blkio_group_stats *stats)
  196. {
  197. unsigned long long now;
  198. if (!blkio_blkg_empty(stats))
  199. return;
  200. now = sched_clock();
  201. if (time_after64(now, stats->start_empty_time))
  202. stats->empty_time += now - stats->start_empty_time;
  203. blkio_clear_blkg_empty(stats);
  204. }
  205. void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
  206. struct blkio_policy_type *pol)
  207. {
  208. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  209. lockdep_assert_held(blkg->q->queue_lock);
  210. BUG_ON(blkio_blkg_idling(stats));
  211. stats->start_idle_time = sched_clock();
  212. blkio_mark_blkg_idling(stats);
  213. }
  214. EXPORT_SYMBOL_GPL(blkiocg_update_set_idle_time_stats);
  215. void blkiocg_update_idle_time_stats(struct blkio_group *blkg,
  216. struct blkio_policy_type *pol)
  217. {
  218. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  219. lockdep_assert_held(blkg->q->queue_lock);
  220. if (blkio_blkg_idling(stats)) {
  221. unsigned long long now = sched_clock();
  222. if (time_after64(now, stats->start_idle_time)) {
  223. u64_stats_update_begin(&stats->syncp);
  224. stats->idle_time += now - stats->start_idle_time;
  225. u64_stats_update_end(&stats->syncp);
  226. }
  227. blkio_clear_blkg_idling(stats);
  228. }
  229. }
  230. EXPORT_SYMBOL_GPL(blkiocg_update_idle_time_stats);
  231. void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
  232. struct blkio_policy_type *pol)
  233. {
  234. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  235. lockdep_assert_held(blkg->q->queue_lock);
  236. u64_stats_update_begin(&stats->syncp);
  237. stats->avg_queue_size_sum +=
  238. stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_READ] +
  239. stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_WRITE];
  240. stats->avg_queue_size_samples++;
  241. blkio_update_group_wait_time(stats);
  242. u64_stats_update_end(&stats->syncp);
  243. }
  244. EXPORT_SYMBOL_GPL(blkiocg_update_avg_queue_size_stats);
  245. void blkiocg_set_start_empty_time(struct blkio_group *blkg,
  246. struct blkio_policy_type *pol)
  247. {
  248. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  249. lockdep_assert_held(blkg->q->queue_lock);
  250. if (stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_READ] ||
  251. stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_WRITE])
  252. return;
  253. /*
  254. * group is already marked empty. This can happen if cfqq got new
  255. * request in parent group and moved to this group while being added
  256. * to service tree. Just ignore the event and move on.
  257. */
  258. if (blkio_blkg_empty(stats))
  259. return;
  260. stats->start_empty_time = sched_clock();
  261. blkio_mark_blkg_empty(stats);
  262. }
  263. EXPORT_SYMBOL_GPL(blkiocg_set_start_empty_time);
  264. void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
  265. struct blkio_policy_type *pol,
  266. unsigned long dequeue)
  267. {
  268. struct blkg_policy_data *pd = blkg->pd[pol->plid];
  269. lockdep_assert_held(blkg->q->queue_lock);
  270. pd->stats.dequeue += dequeue;
  271. }
  272. EXPORT_SYMBOL_GPL(blkiocg_update_dequeue_stats);
  273. #else
  274. static inline void blkio_set_start_group_wait_time(struct blkio_group *blkg,
  275. struct blkio_policy_type *pol,
  276. struct blkio_group *curr_blkg) { }
  277. static inline void blkio_end_empty_time(struct blkio_group_stats *stats) { }
  278. #endif
  279. void blkiocg_update_io_add_stats(struct blkio_group *blkg,
  280. struct blkio_policy_type *pol,
  281. struct blkio_group *curr_blkg, bool direction,
  282. bool sync)
  283. {
  284. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  285. lockdep_assert_held(blkg->q->queue_lock);
  286. u64_stats_update_begin(&stats->syncp);
  287. blkio_add_stat(stats->stat_arr[BLKIO_STAT_QUEUED], 1, direction, sync);
  288. blkio_end_empty_time(stats);
  289. u64_stats_update_end(&stats->syncp);
  290. blkio_set_start_group_wait_time(blkg, pol, curr_blkg);
  291. }
  292. EXPORT_SYMBOL_GPL(blkiocg_update_io_add_stats);
  293. void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
  294. struct blkio_policy_type *pol,
  295. bool direction, bool sync)
  296. {
  297. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  298. lockdep_assert_held(blkg->q->queue_lock);
  299. u64_stats_update_begin(&stats->syncp);
  300. blkio_check_and_dec_stat(stats->stat_arr[BLKIO_STAT_QUEUED], direction,
  301. sync);
  302. u64_stats_update_end(&stats->syncp);
  303. }
  304. EXPORT_SYMBOL_GPL(blkiocg_update_io_remove_stats);
  305. void blkiocg_update_timeslice_used(struct blkio_group *blkg,
  306. struct blkio_policy_type *pol,
  307. unsigned long time,
  308. unsigned long unaccounted_time)
  309. {
  310. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  311. lockdep_assert_held(blkg->q->queue_lock);
  312. u64_stats_update_begin(&stats->syncp);
  313. stats->time += time;
  314. #ifdef CONFIG_DEBUG_BLK_CGROUP
  315. stats->unaccounted_time += unaccounted_time;
  316. #endif
  317. u64_stats_update_end(&stats->syncp);
  318. }
  319. EXPORT_SYMBOL_GPL(blkiocg_update_timeslice_used);
  320. /*
  321. * should be called under rcu read lock or queue lock to make sure blkg pointer
  322. * is valid.
  323. */
  324. void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
  325. struct blkio_policy_type *pol,
  326. uint64_t bytes, bool direction, bool sync)
  327. {
  328. struct blkg_policy_data *pd = blkg->pd[pol->plid];
  329. struct blkio_group_stats_cpu *stats_cpu;
  330. unsigned long flags;
  331. /* If per cpu stats are not allocated yet, don't do any accounting. */
  332. if (pd->stats_cpu == NULL)
  333. return;
  334. /*
  335. * Disabling interrupts to provide mutual exclusion between two
  336. * writes on same cpu. It probably is not needed for 64bit. Not
  337. * optimizing that case yet.
  338. */
  339. local_irq_save(flags);
  340. stats_cpu = this_cpu_ptr(pd->stats_cpu);
  341. u64_stats_update_begin(&stats_cpu->syncp);
  342. stats_cpu->sectors += bytes >> 9;
  343. blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICED],
  344. 1, direction, sync);
  345. blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICE_BYTES],
  346. bytes, direction, sync);
  347. u64_stats_update_end(&stats_cpu->syncp);
  348. local_irq_restore(flags);
  349. }
  350. EXPORT_SYMBOL_GPL(blkiocg_update_dispatch_stats);
  351. void blkiocg_update_completion_stats(struct blkio_group *blkg,
  352. struct blkio_policy_type *pol,
  353. uint64_t start_time,
  354. uint64_t io_start_time, bool direction,
  355. bool sync)
  356. {
  357. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  358. unsigned long long now = sched_clock();
  359. lockdep_assert_held(blkg->q->queue_lock);
  360. u64_stats_update_begin(&stats->syncp);
  361. if (time_after64(now, io_start_time))
  362. blkio_add_stat(stats->stat_arr[BLKIO_STAT_SERVICE_TIME],
  363. now - io_start_time, direction, sync);
  364. if (time_after64(io_start_time, start_time))
  365. blkio_add_stat(stats->stat_arr[BLKIO_STAT_WAIT_TIME],
  366. io_start_time - start_time, direction, sync);
  367. u64_stats_update_end(&stats->syncp);
  368. }
  369. EXPORT_SYMBOL_GPL(blkiocg_update_completion_stats);
  370. /* Merged stats are per cpu. */
  371. void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
  372. struct blkio_policy_type *pol,
  373. bool direction, bool sync)
  374. {
  375. struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
  376. lockdep_assert_held(blkg->q->queue_lock);
  377. u64_stats_update_begin(&stats->syncp);
  378. blkio_add_stat(stats->stat_arr[BLKIO_STAT_MERGED], 1, direction, sync);
  379. u64_stats_update_end(&stats->syncp);
  380. }
  381. EXPORT_SYMBOL_GPL(blkiocg_update_io_merged_stats);
  382. /*
  383. * Worker for allocating per cpu stat for blk groups. This is scheduled on
  384. * the system_nrt_wq once there are some groups on the alloc_list waiting
  385. * for allocation.
  386. */
  387. static void blkio_stat_alloc_fn(struct work_struct *work)
  388. {
  389. static void *pcpu_stats[BLKIO_NR_POLICIES];
  390. struct delayed_work *dwork = to_delayed_work(work);
  391. struct blkio_group *blkg;
  392. int i;
  393. bool empty = false;
  394. alloc_stats:
  395. for (i = 0; i < BLKIO_NR_POLICIES; i++) {
  396. if (pcpu_stats[i] != NULL)
  397. continue;
  398. pcpu_stats[i] = alloc_percpu(struct blkio_group_stats_cpu);
  399. /* Allocation failed. Try again after some time. */
  400. if (pcpu_stats[i] == NULL) {
  401. queue_delayed_work(system_nrt_wq, dwork,
  402. msecs_to_jiffies(10));
  403. return;
  404. }
  405. }
  406. spin_lock_irq(&blkio_list_lock);
  407. spin_lock(&alloc_list_lock);
  408. /* cgroup got deleted or queue exited. */
  409. if (!list_empty(&alloc_list)) {
  410. blkg = list_first_entry(&alloc_list, struct blkio_group,
  411. alloc_node);
  412. for (i = 0; i < BLKIO_NR_POLICIES; i++) {
  413. struct blkg_policy_data *pd = blkg->pd[i];
  414. if (blkio_policy[i] && pd && !pd->stats_cpu)
  415. swap(pd->stats_cpu, pcpu_stats[i]);
  416. }
  417. list_del_init(&blkg->alloc_node);
  418. }
  419. empty = list_empty(&alloc_list);
  420. spin_unlock(&alloc_list_lock);
  421. spin_unlock_irq(&blkio_list_lock);
  422. if (!empty)
  423. goto alloc_stats;
  424. }
  425. /**
  426. * blkg_free - free a blkg
  427. * @blkg: blkg to free
  428. *
  429. * Free @blkg which may be partially allocated.
  430. */
  431. static void blkg_free(struct blkio_group *blkg)
  432. {
  433. int i;
  434. if (!blkg)
  435. return;
  436. for (i = 0; i < BLKIO_NR_POLICIES; i++) {
  437. struct blkg_policy_data *pd = blkg->pd[i];
  438. if (pd) {
  439. free_percpu(pd->stats_cpu);
  440. kfree(pd);
  441. }
  442. }
  443. kfree(blkg);
  444. }
  445. /**
  446. * blkg_alloc - allocate a blkg
  447. * @blkcg: block cgroup the new blkg is associated with
  448. * @q: request_queue the new blkg is associated with
  449. *
  450. * Allocate a new blkg assocating @blkcg and @q.
  451. */
  452. static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
  453. struct request_queue *q)
  454. {
  455. struct blkio_group *blkg;
  456. int i;
  457. /* alloc and init base part */
  458. blkg = kzalloc_node(sizeof(*blkg), GFP_ATOMIC, q->node);
  459. if (!blkg)
  460. return NULL;
  461. blkg->q = q;
  462. INIT_LIST_HEAD(&blkg->q_node);
  463. INIT_LIST_HEAD(&blkg->alloc_node);
  464. blkg->blkcg = blkcg;
  465. blkg->refcnt = 1;
  466. cgroup_path(blkcg->css.cgroup, blkg->path, sizeof(blkg->path));
  467. for (i = 0; i < BLKIO_NR_POLICIES; i++) {
  468. struct blkio_policy_type *pol = blkio_policy[i];
  469. struct blkg_policy_data *pd;
  470. if (!pol)
  471. continue;
  472. /* alloc per-policy data and attach it to blkg */
  473. pd = kzalloc_node(sizeof(*pd) + pol->pdata_size, GFP_ATOMIC,
  474. q->node);
  475. if (!pd) {
  476. blkg_free(blkg);
  477. return NULL;
  478. }
  479. blkg->pd[i] = pd;
  480. pd->blkg = blkg;
  481. }
  482. /* invoke per-policy init */
  483. for (i = 0; i < BLKIO_NR_POLICIES; i++) {
  484. struct blkio_policy_type *pol = blkio_policy[i];
  485. if (pol)
  486. pol->ops.blkio_init_group_fn(blkg);
  487. }
  488. return blkg;
  489. }
  490. struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
  491. struct request_queue *q,
  492. enum blkio_policy_id plid,
  493. bool for_root)
  494. __releases(q->queue_lock) __acquires(q->queue_lock)
  495. {
  496. struct blkio_group *blkg;
  497. WARN_ON_ONCE(!rcu_read_lock_held());
  498. lockdep_assert_held(q->queue_lock);
  499. /*
  500. * This could be the first entry point of blkcg implementation and
  501. * we shouldn't allow anything to go through for a bypassing queue.
  502. * The following can be removed if blkg lookup is guaranteed to
  503. * fail on a bypassing queue.
  504. */
  505. if (unlikely(blk_queue_bypass(q)) && !for_root)
  506. return ERR_PTR(blk_queue_dead(q) ? -EINVAL : -EBUSY);
  507. blkg = blkg_lookup(blkcg, q);
  508. if (blkg)
  509. return blkg;
  510. /* blkg holds a reference to blkcg */
  511. if (!css_tryget(&blkcg->css))
  512. return ERR_PTR(-EINVAL);
  513. /*
  514. * Allocate and initialize.
  515. */
  516. blkg = blkg_alloc(blkcg, q);
  517. /* did alloc fail? */
  518. if (unlikely(!blkg)) {
  519. blkg = ERR_PTR(-ENOMEM);
  520. goto out;
  521. }
  522. /* insert */
  523. spin_lock(&blkcg->lock);
  524. hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
  525. list_add(&blkg->q_node, &q->blkg_list);
  526. spin_unlock(&blkcg->lock);
  527. spin_lock(&alloc_list_lock);
  528. list_add(&blkg->alloc_node, &alloc_list);
  529. /* Queue per cpu stat allocation from worker thread. */
  530. queue_delayed_work(system_nrt_wq, &blkio_stat_alloc_work, 0);
  531. spin_unlock(&alloc_list_lock);
  532. out:
  533. return blkg;
  534. }
  535. EXPORT_SYMBOL_GPL(blkg_lookup_create);
  536. /* called under rcu_read_lock(). */
  537. struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
  538. struct request_queue *q)
  539. {
  540. struct blkio_group *blkg;
  541. struct hlist_node *n;
  542. hlist_for_each_entry_rcu(blkg, n, &blkcg->blkg_list, blkcg_node)
  543. if (blkg->q == q)
  544. return blkg;
  545. return NULL;
  546. }
  547. EXPORT_SYMBOL_GPL(blkg_lookup);
  548. static void blkg_destroy(struct blkio_group *blkg)
  549. {
  550. struct request_queue *q = blkg->q;
  551. struct blkio_cgroup *blkcg = blkg->blkcg;
  552. lockdep_assert_held(q->queue_lock);
  553. lockdep_assert_held(&blkcg->lock);
  554. /* Something wrong if we are trying to remove same group twice */
  555. WARN_ON_ONCE(list_empty(&blkg->q_node));
  556. WARN_ON_ONCE(hlist_unhashed(&blkg->blkcg_node));
  557. list_del_init(&blkg->q_node);
  558. hlist_del_init_rcu(&blkg->blkcg_node);
  559. spin_lock(&alloc_list_lock);
  560. list_del_init(&blkg->alloc_node);
  561. spin_unlock(&alloc_list_lock);
  562. /*
  563. * Put the reference taken at the time of creation so that when all
  564. * queues are gone, group can be destroyed.
  565. */
  566. blkg_put(blkg);
  567. }
  568. /*
  569. * XXX: This updates blkg policy data in-place for root blkg, which is
  570. * necessary across elevator switch and policy registration as root blkgs
  571. * aren't shot down. This broken and racy implementation is temporary.
  572. * Eventually, blkg shoot down will be replaced by proper in-place update.
  573. */
  574. void update_root_blkg_pd(struct request_queue *q, enum blkio_policy_id plid)
  575. {
  576. struct blkio_policy_type *pol = blkio_policy[plid];
  577. struct blkio_group *blkg = blkg_lookup(&blkio_root_cgroup, q);
  578. struct blkg_policy_data *pd;
  579. if (!blkg)
  580. return;
  581. kfree(blkg->pd[plid]);
  582. blkg->pd[plid] = NULL;
  583. if (!pol)
  584. return;
  585. pd = kzalloc(sizeof(*pd) + pol->pdata_size, GFP_KERNEL);
  586. WARN_ON_ONCE(!pd);
  587. pd->stats_cpu = alloc_percpu(struct blkio_group_stats_cpu);
  588. WARN_ON_ONCE(!pd->stats_cpu);
  589. blkg->pd[plid] = pd;
  590. pd->blkg = blkg;
  591. pol->ops.blkio_init_group_fn(blkg);
  592. }
  593. EXPORT_SYMBOL_GPL(update_root_blkg_pd);
  594. /**
  595. * blkg_destroy_all - destroy all blkgs associated with a request_queue
  596. * @q: request_queue of interest
  597. * @destroy_root: whether to destroy root blkg or not
  598. *
  599. * Destroy blkgs associated with @q. If @destroy_root is %true, all are
  600. * destroyed; otherwise, root blkg is left alone.
  601. */
  602. void blkg_destroy_all(struct request_queue *q, bool destroy_root)
  603. {
  604. struct blkio_group *blkg, *n;
  605. spin_lock_irq(q->queue_lock);
  606. list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
  607. struct blkio_cgroup *blkcg = blkg->blkcg;
  608. /* skip root? */
  609. if (!destroy_root && blkg->blkcg == &blkio_root_cgroup)
  610. continue;
  611. spin_lock(&blkcg->lock);
  612. blkg_destroy(blkg);
  613. spin_unlock(&blkcg->lock);
  614. }
  615. spin_unlock_irq(q->queue_lock);
  616. }
  617. EXPORT_SYMBOL_GPL(blkg_destroy_all);
  618. static void blkg_rcu_free(struct rcu_head *rcu_head)
  619. {
  620. blkg_free(container_of(rcu_head, struct blkio_group, rcu_head));
  621. }
  622. void __blkg_release(struct blkio_group *blkg)
  623. {
  624. /* release the extra blkcg reference this blkg has been holding */
  625. css_put(&blkg->blkcg->css);
  626. /*
  627. * A group is freed in rcu manner. But having an rcu lock does not
  628. * mean that one can access all the fields of blkg and assume these
  629. * are valid. For example, don't try to follow throtl_data and
  630. * request queue links.
  631. *
  632. * Having a reference to blkg under an rcu allows acess to only
  633. * values local to groups like group stats and group rate limits
  634. */
  635. call_rcu(&blkg->rcu_head, blkg_rcu_free);
  636. }
  637. EXPORT_SYMBOL_GPL(__blkg_release);
  638. static void blkio_reset_stats_cpu(struct blkio_group *blkg, int plid)
  639. {
  640. struct blkg_policy_data *pd = blkg->pd[plid];
  641. int cpu;
  642. if (pd->stats_cpu == NULL)
  643. return;
  644. for_each_possible_cpu(cpu) {
  645. struct blkio_group_stats_cpu *sc =
  646. per_cpu_ptr(pd->stats_cpu, cpu);
  647. sc->sectors = 0;
  648. memset(sc->stat_arr_cpu, 0, sizeof(sc->stat_arr_cpu));
  649. }
  650. }
  651. static int
  652. blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
  653. {
  654. struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
  655. struct blkio_group *blkg;
  656. struct hlist_node *n;
  657. int i;
  658. spin_lock(&blkio_list_lock);
  659. spin_lock_irq(&blkcg->lock);
  660. /*
  661. * Note that stat reset is racy - it doesn't synchronize against
  662. * stat updates. This is a debug feature which shouldn't exist
  663. * anyway. If you get hit by a race, retry.
  664. */
  665. hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
  666. struct blkio_policy_type *pol;
  667. list_for_each_entry(pol, &blkio_list, list) {
  668. struct blkg_policy_data *pd = blkg->pd[pol->plid];
  669. struct blkio_group_stats *stats = &pd->stats;
  670. /* queued stats shouldn't be cleared */
  671. for (i = 0; i < ARRAY_SIZE(stats->stat_arr); i++)
  672. if (i != BLKIO_STAT_QUEUED)
  673. memset(stats->stat_arr[i], 0,
  674. sizeof(stats->stat_arr[i]));
  675. stats->time = 0;
  676. #ifdef CONFIG_DEBUG_BLK_CGROUP
  677. memset((void *)stats + BLKG_STATS_DEBUG_CLEAR_START, 0,
  678. BLKG_STATS_DEBUG_CLEAR_SIZE);
  679. #endif
  680. blkio_reset_stats_cpu(blkg, pol->plid);
  681. }
  682. }
  683. spin_unlock_irq(&blkcg->lock);
  684. spin_unlock(&blkio_list_lock);
  685. return 0;
  686. }
  687. static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
  688. char *str, int chars_left, bool diskname_only)
  689. {
  690. snprintf(str, chars_left, "%s", dname);
  691. chars_left -= strlen(str);
  692. if (chars_left <= 0) {
  693. printk(KERN_WARNING
  694. "Possibly incorrect cgroup stat display format");
  695. return;
  696. }
  697. if (diskname_only)
  698. return;
  699. switch (type) {
  700. case BLKIO_STAT_READ:
  701. strlcat(str, " Read", chars_left);
  702. break;
  703. case BLKIO_STAT_WRITE:
  704. strlcat(str, " Write", chars_left);
  705. break;
  706. case BLKIO_STAT_SYNC:
  707. strlcat(str, " Sync", chars_left);
  708. break;
  709. case BLKIO_STAT_ASYNC:
  710. strlcat(str, " Async", chars_left);
  711. break;
  712. case BLKIO_STAT_TOTAL:
  713. strlcat(str, " Total", chars_left);
  714. break;
  715. default:
  716. strlcat(str, " Invalid", chars_left);
  717. }
  718. }
  719. static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid,
  720. enum stat_type_cpu type, enum stat_sub_type sub_type)
  721. {
  722. struct blkg_policy_data *pd = blkg->pd[plid];
  723. int cpu;
  724. struct blkio_group_stats_cpu *stats_cpu;
  725. u64 val = 0, tval;
  726. if (pd->stats_cpu == NULL)
  727. return val;
  728. for_each_possible_cpu(cpu) {
  729. unsigned int start;
  730. stats_cpu = per_cpu_ptr(pd->stats_cpu, cpu);
  731. do {
  732. start = u64_stats_fetch_begin(&stats_cpu->syncp);
  733. if (type == BLKIO_STAT_CPU_SECTORS)
  734. tval = stats_cpu->sectors;
  735. else
  736. tval = stats_cpu->stat_arr_cpu[type][sub_type];
  737. } while(u64_stats_fetch_retry(&stats_cpu->syncp, start));
  738. val += tval;
  739. }
  740. return val;
  741. }
  742. static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
  743. struct cgroup_map_cb *cb, const char *dname,
  744. enum stat_type_cpu type)
  745. {
  746. uint64_t disk_total, val;
  747. char key_str[MAX_KEY_LEN];
  748. enum stat_sub_type sub_type;
  749. if (type == BLKIO_STAT_CPU_SECTORS) {
  750. val = blkio_read_stat_cpu(blkg, plid, type, 0);
  751. blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
  752. cb->fill(cb, key_str, val);
  753. return val;
  754. }
  755. for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
  756. sub_type++) {
  757. blkio_get_key_name(sub_type, dname, key_str, MAX_KEY_LEN,
  758. false);
  759. val = blkio_read_stat_cpu(blkg, plid, type, sub_type);
  760. cb->fill(cb, key_str, val);
  761. }
  762. disk_total = blkio_read_stat_cpu(blkg, plid, type, BLKIO_STAT_READ) +
  763. blkio_read_stat_cpu(blkg, plid, type, BLKIO_STAT_WRITE);
  764. blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
  765. false);
  766. cb->fill(cb, key_str, disk_total);
  767. return disk_total;
  768. }
  769. static uint64_t blkio_get_stat(struct blkio_group *blkg, int plid,
  770. struct cgroup_map_cb *cb, const char *dname,
  771. enum stat_type type)
  772. {
  773. struct blkio_group_stats *stats = &blkg->pd[plid]->stats;
  774. uint64_t v = 0, disk_total = 0;
  775. char key_str[MAX_KEY_LEN];
  776. unsigned int sync_start;
  777. int st;
  778. if (type >= BLKIO_STAT_ARR_NR) {
  779. do {
  780. sync_start = u64_stats_fetch_begin(&stats->syncp);
  781. switch (type) {
  782. case BLKIO_STAT_TIME:
  783. v = stats->time;
  784. break;
  785. #ifdef CONFIG_DEBUG_BLK_CGROUP
  786. case BLKIO_STAT_UNACCOUNTED_TIME:
  787. v = stats->unaccounted_time;
  788. break;
  789. case BLKIO_STAT_AVG_QUEUE_SIZE: {
  790. uint64_t samples = stats->avg_queue_size_samples;
  791. if (samples) {
  792. v = stats->avg_queue_size_sum;
  793. do_div(v, samples);
  794. }
  795. break;
  796. }
  797. case BLKIO_STAT_IDLE_TIME:
  798. v = stats->idle_time;
  799. break;
  800. case BLKIO_STAT_EMPTY_TIME:
  801. v = stats->empty_time;
  802. break;
  803. case BLKIO_STAT_DEQUEUE:
  804. v = stats->dequeue;
  805. break;
  806. case BLKIO_STAT_GROUP_WAIT_TIME:
  807. v = stats->group_wait_time;
  808. break;
  809. #endif
  810. default:
  811. WARN_ON_ONCE(1);
  812. }
  813. } while (u64_stats_fetch_retry(&stats->syncp, sync_start));
  814. blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
  815. cb->fill(cb, key_str, v);
  816. return v;
  817. }
  818. for (st = BLKIO_STAT_READ; st < BLKIO_STAT_TOTAL; st++) {
  819. do {
  820. sync_start = u64_stats_fetch_begin(&stats->syncp);
  821. v = stats->stat_arr[type][st];
  822. } while (u64_stats_fetch_retry(&stats->syncp, sync_start));
  823. blkio_get_key_name(st, dname, key_str, MAX_KEY_LEN, false);
  824. cb->fill(cb, key_str, v);
  825. if (st == BLKIO_STAT_READ || st == BLKIO_STAT_WRITE)
  826. disk_total += v;
  827. }
  828. blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
  829. false);
  830. cb->fill(cb, key_str, disk_total);
  831. return disk_total;
  832. }
  833. static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
  834. int fileid, struct blkio_cgroup *blkcg)
  835. {
  836. struct gendisk *disk = NULL;
  837. struct blkio_group *blkg = NULL;
  838. struct blkg_policy_data *pd;
  839. char *s[4], *p, *major_s = NULL, *minor_s = NULL;
  840. unsigned long major, minor;
  841. int i = 0, ret = -EINVAL;
  842. int part;
  843. dev_t dev;
  844. u64 temp;
  845. memset(s, 0, sizeof(s));
  846. while ((p = strsep(&buf, " ")) != NULL) {
  847. if (!*p)
  848. continue;
  849. s[i++] = p;
  850. /* Prevent from inputing too many things */
  851. if (i == 3)
  852. break;
  853. }
  854. if (i != 2)
  855. goto out;
  856. p = strsep(&s[0], ":");
  857. if (p != NULL)
  858. major_s = p;
  859. else
  860. goto out;
  861. minor_s = s[0];
  862. if (!minor_s)
  863. goto out;
  864. if (strict_strtoul(major_s, 10, &major))
  865. goto out;
  866. if (strict_strtoul(minor_s, 10, &minor))
  867. goto out;
  868. dev = MKDEV(major, minor);
  869. if (strict_strtoull(s[1], 10, &temp))
  870. goto out;
  871. disk = get_gendisk(dev, &part);
  872. if (!disk || part)
  873. goto out;
  874. rcu_read_lock();
  875. spin_lock_irq(disk->queue->queue_lock);
  876. blkg = blkg_lookup_create(blkcg, disk->queue, plid, false);
  877. spin_unlock_irq(disk->queue->queue_lock);
  878. if (IS_ERR(blkg)) {
  879. ret = PTR_ERR(blkg);
  880. goto out_unlock;
  881. }
  882. pd = blkg->pd[plid];
  883. switch (plid) {
  884. case BLKIO_POLICY_PROP:
  885. if ((temp < BLKIO_WEIGHT_MIN && temp > 0) ||
  886. temp > BLKIO_WEIGHT_MAX)
  887. goto out_unlock;
  888. pd->conf.weight = temp;
  889. blkio_update_group_weight(blkg, plid, temp ?: blkcg->weight);
  890. break;
  891. case BLKIO_POLICY_THROTL:
  892. switch(fileid) {
  893. case BLKIO_THROTL_read_bps_device:
  894. pd->conf.bps[READ] = temp;
  895. blkio_update_group_bps(blkg, plid, temp ?: -1, fileid);
  896. break;
  897. case BLKIO_THROTL_write_bps_device:
  898. pd->conf.bps[WRITE] = temp;
  899. blkio_update_group_bps(blkg, plid, temp ?: -1, fileid);
  900. break;
  901. case BLKIO_THROTL_read_iops_device:
  902. if (temp > THROTL_IOPS_MAX)
  903. goto out_unlock;
  904. pd->conf.iops[READ] = temp;
  905. blkio_update_group_iops(blkg, plid, temp ?: -1, fileid);
  906. break;
  907. case BLKIO_THROTL_write_iops_device:
  908. if (temp > THROTL_IOPS_MAX)
  909. goto out_unlock;
  910. pd->conf.iops[WRITE] = temp;
  911. blkio_update_group_iops(blkg, plid, temp ?: -1, fileid);
  912. break;
  913. }
  914. break;
  915. default:
  916. BUG();
  917. }
  918. ret = 0;
  919. out_unlock:
  920. rcu_read_unlock();
  921. out:
  922. put_disk(disk);
  923. /*
  924. * If queue was bypassing, we should retry. Do so after a short
  925. * msleep(). It isn't strictly necessary but queue can be
  926. * bypassing for some time and it's always nice to avoid busy
  927. * looping.
  928. */
  929. if (ret == -EBUSY) {
  930. msleep(10);
  931. return restart_syscall();
  932. }
  933. return ret;
  934. }
  935. static int blkiocg_file_write(struct cgroup *cgrp, struct cftype *cft,
  936. const char *buffer)
  937. {
  938. int ret = 0;
  939. char *buf;
  940. struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
  941. enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
  942. int fileid = BLKIOFILE_ATTR(cft->private);
  943. buf = kstrdup(buffer, GFP_KERNEL);
  944. if (!buf)
  945. return -ENOMEM;
  946. ret = blkio_policy_parse_and_set(buf, plid, fileid, blkcg);
  947. kfree(buf);
  948. return ret;
  949. }
  950. static const char *blkg_dev_name(struct blkio_group *blkg)
  951. {
  952. /* some drivers (floppy) instantiate a queue w/o disk registered */
  953. if (blkg->q->backing_dev_info.dev)
  954. return dev_name(blkg->q->backing_dev_info.dev);
  955. return NULL;
  956. }
  957. static void blkio_print_group_conf(struct cftype *cft, struct blkio_group *blkg,
  958. struct seq_file *m)
  959. {
  960. int plid = BLKIOFILE_POLICY(cft->private);
  961. int fileid = BLKIOFILE_ATTR(cft->private);
  962. struct blkg_policy_data *pd = blkg->pd[plid];
  963. const char *dname = blkg_dev_name(blkg);
  964. int rw = WRITE;
  965. if (!dname)
  966. return;
  967. switch (plid) {
  968. case BLKIO_POLICY_PROP:
  969. if (pd->conf.weight)
  970. seq_printf(m, "%s\t%u\n",
  971. dname, pd->conf.weight);
  972. break;
  973. case BLKIO_POLICY_THROTL:
  974. switch (fileid) {
  975. case BLKIO_THROTL_read_bps_device:
  976. rw = READ;
  977. case BLKIO_THROTL_write_bps_device:
  978. if (pd->conf.bps[rw])
  979. seq_printf(m, "%s\t%llu\n",
  980. dname, pd->conf.bps[rw]);
  981. break;
  982. case BLKIO_THROTL_read_iops_device:
  983. rw = READ;
  984. case BLKIO_THROTL_write_iops_device:
  985. if (pd->conf.iops[rw])
  986. seq_printf(m, "%s\t%u\n",
  987. dname, pd->conf.iops[rw]);
  988. break;
  989. }
  990. break;
  991. default:
  992. BUG();
  993. }
  994. }
  995. /* cgroup files which read their data from policy nodes end up here */
  996. static void blkio_read_conf(struct cftype *cft, struct blkio_cgroup *blkcg,
  997. struct seq_file *m)
  998. {
  999. struct blkio_group *blkg;
  1000. struct hlist_node *n;
  1001. spin_lock_irq(&blkcg->lock);
  1002. hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
  1003. blkio_print_group_conf(cft, blkg, m);
  1004. spin_unlock_irq(&blkcg->lock);
  1005. }
  1006. static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
  1007. struct seq_file *m)
  1008. {
  1009. struct blkio_cgroup *blkcg;
  1010. enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
  1011. int name = BLKIOFILE_ATTR(cft->private);
  1012. blkcg = cgroup_to_blkio_cgroup(cgrp);
  1013. switch(plid) {
  1014. case BLKIO_POLICY_PROP:
  1015. switch(name) {
  1016. case BLKIO_PROP_weight_device:
  1017. blkio_read_conf(cft, blkcg, m);
  1018. return 0;
  1019. default:
  1020. BUG();
  1021. }
  1022. break;
  1023. case BLKIO_POLICY_THROTL:
  1024. switch(name){
  1025. case BLKIO_THROTL_read_bps_device:
  1026. case BLKIO_THROTL_write_bps_device:
  1027. case BLKIO_THROTL_read_iops_device:
  1028. case BLKIO_THROTL_write_iops_device:
  1029. blkio_read_conf(cft, blkcg, m);
  1030. return 0;
  1031. default:
  1032. BUG();
  1033. }
  1034. break;
  1035. default:
  1036. BUG();
  1037. }
  1038. return 0;
  1039. }
  1040. static int blkio_read_blkg_stats(struct blkio_cgroup *blkcg,
  1041. struct cftype *cft, struct cgroup_map_cb *cb,
  1042. enum stat_type type, bool show_total, bool pcpu)
  1043. {
  1044. struct blkio_group *blkg;
  1045. struct hlist_node *n;
  1046. uint64_t cgroup_total = 0;
  1047. spin_lock_irq(&blkcg->lock);
  1048. hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
  1049. const char *dname = blkg_dev_name(blkg);
  1050. int plid = BLKIOFILE_POLICY(cft->private);
  1051. if (!dname)
  1052. continue;
  1053. if (pcpu)
  1054. cgroup_total += blkio_get_stat_cpu(blkg, plid,
  1055. cb, dname, type);
  1056. else
  1057. cgroup_total += blkio_get_stat(blkg, plid,
  1058. cb, dname, type);
  1059. }
  1060. if (show_total)
  1061. cb->fill(cb, "Total", cgroup_total);
  1062. spin_unlock_irq(&blkcg->lock);
  1063. return 0;
  1064. }
  1065. /* All map kind of cgroup file get serviced by this function */
  1066. static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
  1067. struct cgroup_map_cb *cb)
  1068. {
  1069. struct blkio_cgroup *blkcg;
  1070. enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
  1071. int name = BLKIOFILE_ATTR(cft->private);
  1072. blkcg = cgroup_to_blkio_cgroup(cgrp);
  1073. switch(plid) {
  1074. case BLKIO_POLICY_PROP:
  1075. switch(name) {
  1076. case BLKIO_PROP_time:
  1077. return blkio_read_blkg_stats(blkcg, cft, cb,
  1078. BLKIO_STAT_TIME, 0, 0);
  1079. case BLKIO_PROP_sectors:
  1080. return blkio_read_blkg_stats(blkcg, cft, cb,
  1081. BLKIO_STAT_CPU_SECTORS, 0, 1);
  1082. case BLKIO_PROP_io_service_bytes:
  1083. return blkio_read_blkg_stats(blkcg, cft, cb,
  1084. BLKIO_STAT_CPU_SERVICE_BYTES, 1, 1);
  1085. case BLKIO_PROP_io_serviced:
  1086. return blkio_read_blkg_stats(blkcg, cft, cb,
  1087. BLKIO_STAT_CPU_SERVICED, 1, 1);
  1088. case BLKIO_PROP_io_service_time:
  1089. return blkio_read_blkg_stats(blkcg, cft, cb,
  1090. BLKIO_STAT_SERVICE_TIME, 1, 0);
  1091. case BLKIO_PROP_io_wait_time:
  1092. return blkio_read_blkg_stats(blkcg, cft, cb,
  1093. BLKIO_STAT_WAIT_TIME, 1, 0);
  1094. case BLKIO_PROP_io_merged:
  1095. return blkio_read_blkg_stats(blkcg, cft, cb,
  1096. BLKIO_STAT_MERGED, 1, 0);
  1097. case BLKIO_PROP_io_queued:
  1098. return blkio_read_blkg_stats(blkcg, cft, cb,
  1099. BLKIO_STAT_QUEUED, 1, 0);
  1100. #ifdef CONFIG_DEBUG_BLK_CGROUP
  1101. case BLKIO_PROP_unaccounted_time:
  1102. return blkio_read_blkg_stats(blkcg, cft, cb,
  1103. BLKIO_STAT_UNACCOUNTED_TIME, 0, 0);
  1104. case BLKIO_PROP_dequeue:
  1105. return blkio_read_blkg_stats(blkcg, cft, cb,
  1106. BLKIO_STAT_DEQUEUE, 0, 0);
  1107. case BLKIO_PROP_avg_queue_size:
  1108. return blkio_read_blkg_stats(blkcg, cft, cb,
  1109. BLKIO_STAT_AVG_QUEUE_SIZE, 0, 0);
  1110. case BLKIO_PROP_group_wait_time:
  1111. return blkio_read_blkg_stats(blkcg, cft, cb,
  1112. BLKIO_STAT_GROUP_WAIT_TIME, 0, 0);
  1113. case BLKIO_PROP_idle_time:
  1114. return blkio_read_blkg_stats(blkcg, cft, cb,
  1115. BLKIO_STAT_IDLE_TIME, 0, 0);
  1116. case BLKIO_PROP_empty_time:
  1117. return blkio_read_blkg_stats(blkcg, cft, cb,
  1118. BLKIO_STAT_EMPTY_TIME, 0, 0);
  1119. #endif
  1120. default:
  1121. BUG();
  1122. }
  1123. break;
  1124. case BLKIO_POLICY_THROTL:
  1125. switch(name){
  1126. case BLKIO_THROTL_io_service_bytes:
  1127. return blkio_read_blkg_stats(blkcg, cft, cb,
  1128. BLKIO_STAT_CPU_SERVICE_BYTES, 1, 1);
  1129. case BLKIO_THROTL_io_serviced:
  1130. return blkio_read_blkg_stats(blkcg, cft, cb,
  1131. BLKIO_STAT_CPU_SERVICED, 1, 1);
  1132. default:
  1133. BUG();
  1134. }
  1135. break;
  1136. default:
  1137. BUG();
  1138. }
  1139. return 0;
  1140. }
  1141. static int blkio_weight_write(struct blkio_cgroup *blkcg, int plid, u64 val)
  1142. {
  1143. struct blkio_group *blkg;
  1144. struct hlist_node *n;
  1145. if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX)
  1146. return -EINVAL;
  1147. spin_lock(&blkio_list_lock);
  1148. spin_lock_irq(&blkcg->lock);
  1149. blkcg->weight = (unsigned int)val;
  1150. hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
  1151. struct blkg_policy_data *pd = blkg->pd[plid];
  1152. if (!pd->conf.weight)
  1153. blkio_update_group_weight(blkg, plid, blkcg->weight);
  1154. }
  1155. spin_unlock_irq(&blkcg->lock);
  1156. spin_unlock(&blkio_list_lock);
  1157. return 0;
  1158. }
  1159. static u64 blkiocg_file_read_u64 (struct cgroup *cgrp, struct cftype *cft) {
  1160. struct blkio_cgroup *blkcg;
  1161. enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
  1162. int name = BLKIOFILE_ATTR(cft->private);
  1163. blkcg = cgroup_to_blkio_cgroup(cgrp);
  1164. switch(plid) {
  1165. case BLKIO_POLICY_PROP:
  1166. switch(name) {
  1167. case BLKIO_PROP_weight:
  1168. return (u64)blkcg->weight;
  1169. }
  1170. break;
  1171. default:
  1172. BUG();
  1173. }
  1174. return 0;
  1175. }
  1176. static int
  1177. blkiocg_file_write_u64(struct cgroup *cgrp, struct cftype *cft, u64 val)
  1178. {
  1179. struct blkio_cgroup *blkcg;
  1180. enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
  1181. int name = BLKIOFILE_ATTR(cft->private);
  1182. blkcg = cgroup_to_blkio_cgroup(cgrp);
  1183. switch(plid) {
  1184. case BLKIO_POLICY_PROP:
  1185. switch(name) {
  1186. case BLKIO_PROP_weight:
  1187. return blkio_weight_write(blkcg, plid, val);
  1188. }
  1189. break;
  1190. default:
  1191. BUG();
  1192. }
  1193. return 0;
  1194. }
  1195. struct cftype blkio_files[] = {
  1196. {
  1197. .name = "weight_device",
  1198. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1199. BLKIO_PROP_weight_device),
  1200. .read_seq_string = blkiocg_file_read,
  1201. .write_string = blkiocg_file_write,
  1202. .max_write_len = 256,
  1203. },
  1204. {
  1205. .name = "weight",
  1206. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1207. BLKIO_PROP_weight),
  1208. .read_u64 = blkiocg_file_read_u64,
  1209. .write_u64 = blkiocg_file_write_u64,
  1210. },
  1211. {
  1212. .name = "time",
  1213. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1214. BLKIO_PROP_time),
  1215. .read_map = blkiocg_file_read_map,
  1216. },
  1217. {
  1218. .name = "sectors",
  1219. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1220. BLKIO_PROP_sectors),
  1221. .read_map = blkiocg_file_read_map,
  1222. },
  1223. {
  1224. .name = "io_service_bytes",
  1225. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1226. BLKIO_PROP_io_service_bytes),
  1227. .read_map = blkiocg_file_read_map,
  1228. },
  1229. {
  1230. .name = "io_serviced",
  1231. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1232. BLKIO_PROP_io_serviced),
  1233. .read_map = blkiocg_file_read_map,
  1234. },
  1235. {
  1236. .name = "io_service_time",
  1237. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1238. BLKIO_PROP_io_service_time),
  1239. .read_map = blkiocg_file_read_map,
  1240. },
  1241. {
  1242. .name = "io_wait_time",
  1243. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1244. BLKIO_PROP_io_wait_time),
  1245. .read_map = blkiocg_file_read_map,
  1246. },
  1247. {
  1248. .name = "io_merged",
  1249. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1250. BLKIO_PROP_io_merged),
  1251. .read_map = blkiocg_file_read_map,
  1252. },
  1253. {
  1254. .name = "io_queued",
  1255. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1256. BLKIO_PROP_io_queued),
  1257. .read_map = blkiocg_file_read_map,
  1258. },
  1259. {
  1260. .name = "reset_stats",
  1261. .write_u64 = blkiocg_reset_stats,
  1262. },
  1263. #ifdef CONFIG_BLK_DEV_THROTTLING
  1264. {
  1265. .name = "throttle.read_bps_device",
  1266. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1267. BLKIO_THROTL_read_bps_device),
  1268. .read_seq_string = blkiocg_file_read,
  1269. .write_string = blkiocg_file_write,
  1270. .max_write_len = 256,
  1271. },
  1272. {
  1273. .name = "throttle.write_bps_device",
  1274. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1275. BLKIO_THROTL_write_bps_device),
  1276. .read_seq_string = blkiocg_file_read,
  1277. .write_string = blkiocg_file_write,
  1278. .max_write_len = 256,
  1279. },
  1280. {
  1281. .name = "throttle.read_iops_device",
  1282. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1283. BLKIO_THROTL_read_iops_device),
  1284. .read_seq_string = blkiocg_file_read,
  1285. .write_string = blkiocg_file_write,
  1286. .max_write_len = 256,
  1287. },
  1288. {
  1289. .name = "throttle.write_iops_device",
  1290. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1291. BLKIO_THROTL_write_iops_device),
  1292. .read_seq_string = blkiocg_file_read,
  1293. .write_string = blkiocg_file_write,
  1294. .max_write_len = 256,
  1295. },
  1296. {
  1297. .name = "throttle.io_service_bytes",
  1298. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1299. BLKIO_THROTL_io_service_bytes),
  1300. .read_map = blkiocg_file_read_map,
  1301. },
  1302. {
  1303. .name = "throttle.io_serviced",
  1304. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
  1305. BLKIO_THROTL_io_serviced),
  1306. .read_map = blkiocg_file_read_map,
  1307. },
  1308. #endif /* CONFIG_BLK_DEV_THROTTLING */
  1309. #ifdef CONFIG_DEBUG_BLK_CGROUP
  1310. {
  1311. .name = "avg_queue_size",
  1312. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1313. BLKIO_PROP_avg_queue_size),
  1314. .read_map = blkiocg_file_read_map,
  1315. },
  1316. {
  1317. .name = "group_wait_time",
  1318. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1319. BLKIO_PROP_group_wait_time),
  1320. .read_map = blkiocg_file_read_map,
  1321. },
  1322. {
  1323. .name = "idle_time",
  1324. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1325. BLKIO_PROP_idle_time),
  1326. .read_map = blkiocg_file_read_map,
  1327. },
  1328. {
  1329. .name = "empty_time",
  1330. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1331. BLKIO_PROP_empty_time),
  1332. .read_map = blkiocg_file_read_map,
  1333. },
  1334. {
  1335. .name = "dequeue",
  1336. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1337. BLKIO_PROP_dequeue),
  1338. .read_map = blkiocg_file_read_map,
  1339. },
  1340. {
  1341. .name = "unaccounted_time",
  1342. .private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
  1343. BLKIO_PROP_unaccounted_time),
  1344. .read_map = blkiocg_file_read_map,
  1345. },
  1346. #endif
  1347. };
  1348. static int blkiocg_populate(struct cgroup_subsys *subsys, struct cgroup *cgroup)
  1349. {
  1350. return cgroup_add_files(cgroup, subsys, blkio_files,
  1351. ARRAY_SIZE(blkio_files));
  1352. }
  1353. /**
  1354. * blkiocg_pre_destroy - cgroup pre_destroy callback
  1355. * @subsys: cgroup subsys
  1356. * @cgroup: cgroup of interest
  1357. *
  1358. * This function is called when @cgroup is about to go away and responsible
  1359. * for shooting down all blkgs associated with @cgroup. blkgs should be
  1360. * removed while holding both q and blkcg locks. As blkcg lock is nested
  1361. * inside q lock, this function performs reverse double lock dancing.
  1362. *
  1363. * This is the blkcg counterpart of ioc_release_fn().
  1364. */
  1365. static int blkiocg_pre_destroy(struct cgroup_subsys *subsys,
  1366. struct cgroup *cgroup)
  1367. {
  1368. struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
  1369. spin_lock_irq(&blkcg->lock);
  1370. while (!hlist_empty(&blkcg->blkg_list)) {
  1371. struct blkio_group *blkg = hlist_entry(blkcg->blkg_list.first,
  1372. struct blkio_group, blkcg_node);
  1373. struct request_queue *q = blkg->q;
  1374. if (spin_trylock(q->queue_lock)) {
  1375. blkg_destroy(blkg);
  1376. spin_unlock(q->queue_lock);
  1377. } else {
  1378. spin_unlock_irq(&blkcg->lock);
  1379. cpu_relax();
  1380. spin_lock(&blkcg->lock);
  1381. }
  1382. }
  1383. spin_unlock_irq(&blkcg->lock);
  1384. return 0;
  1385. }
  1386. static void blkiocg_destroy(struct cgroup_subsys *subsys, struct cgroup *cgroup)
  1387. {
  1388. struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
  1389. if (blkcg != &blkio_root_cgroup)
  1390. kfree(blkcg);
  1391. }
  1392. static struct cgroup_subsys_state *
  1393. blkiocg_create(struct cgroup_subsys *subsys, struct cgroup *cgroup)
  1394. {
  1395. struct blkio_cgroup *blkcg;
  1396. struct cgroup *parent = cgroup->parent;
  1397. if (!parent) {
  1398. blkcg = &blkio_root_cgroup;
  1399. goto done;
  1400. }
  1401. blkcg = kzalloc(sizeof(*blkcg), GFP_KERNEL);
  1402. if (!blkcg)
  1403. return ERR_PTR(-ENOMEM);
  1404. blkcg->weight = BLKIO_WEIGHT_DEFAULT;
  1405. done:
  1406. spin_lock_init(&blkcg->lock);
  1407. INIT_HLIST_HEAD(&blkcg->blkg_list);
  1408. return &blkcg->css;
  1409. }
  1410. /**
  1411. * blkcg_init_queue - initialize blkcg part of request queue
  1412. * @q: request_queue to initialize
  1413. *
  1414. * Called from blk_alloc_queue_node(). Responsible for initializing blkcg
  1415. * part of new request_queue @q.
  1416. *
  1417. * RETURNS:
  1418. * 0 on success, -errno on failure.
  1419. */
  1420. int blkcg_init_queue(struct request_queue *q)
  1421. {
  1422. int ret;
  1423. might_sleep();
  1424. ret = blk_throtl_init(q);
  1425. if (ret)
  1426. return ret;
  1427. mutex_lock(&all_q_mutex);
  1428. INIT_LIST_HEAD(&q->all_q_node);
  1429. list_add_tail(&q->all_q_node, &all_q_list);
  1430. mutex_unlock(&all_q_mutex);
  1431. return 0;
  1432. }
  1433. /**
  1434. * blkcg_drain_queue - drain blkcg part of request_queue
  1435. * @q: request_queue to drain
  1436. *
  1437. * Called from blk_drain_queue(). Responsible for draining blkcg part.
  1438. */
  1439. void blkcg_drain_queue(struct request_queue *q)
  1440. {
  1441. lockdep_assert_held(q->queue_lock);
  1442. blk_throtl_drain(q);
  1443. }
  1444. /**
  1445. * blkcg_exit_queue - exit and release blkcg part of request_queue
  1446. * @q: request_queue being released
  1447. *
  1448. * Called from blk_release_queue(). Responsible for exiting blkcg part.
  1449. */
  1450. void blkcg_exit_queue(struct request_queue *q)
  1451. {
  1452. mutex_lock(&all_q_mutex);
  1453. list_del_init(&q->all_q_node);
  1454. mutex_unlock(&all_q_mutex);
  1455. blkg_destroy_all(q, true);
  1456. blk_throtl_exit(q);
  1457. }
  1458. /*
  1459. * We cannot support shared io contexts, as we have no mean to support
  1460. * two tasks with the same ioc in two different groups without major rework
  1461. * of the main cic data structures. For now we allow a task to change
  1462. * its cgroup only if it's the only owner of its ioc.
  1463. */
  1464. static int blkiocg_can_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
  1465. struct cgroup_taskset *tset)
  1466. {
  1467. struct task_struct *task;
  1468. struct io_context *ioc;
  1469. int ret = 0;
  1470. /* task_lock() is needed to avoid races with exit_io_context() */
  1471. cgroup_taskset_for_each(task, cgrp, tset) {
  1472. task_lock(task);
  1473. ioc = task->io_context;
  1474. if (ioc && atomic_read(&ioc->nr_tasks) > 1)
  1475. ret = -EINVAL;
  1476. task_unlock(task);
  1477. if (ret)
  1478. break;
  1479. }
  1480. return ret;
  1481. }
  1482. static void blkiocg_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
  1483. struct cgroup_taskset *tset)
  1484. {
  1485. struct task_struct *task;
  1486. struct io_context *ioc;
  1487. cgroup_taskset_for_each(task, cgrp, tset) {
  1488. /* we don't lose anything even if ioc allocation fails */
  1489. ioc = get_task_io_context(task, GFP_ATOMIC, NUMA_NO_NODE);
  1490. if (ioc) {
  1491. ioc_cgroup_changed(ioc);
  1492. put_io_context(ioc);
  1493. }
  1494. }
  1495. }
  1496. static void blkcg_bypass_start(void)
  1497. __acquires(&all_q_mutex)
  1498. {
  1499. struct request_queue *q;
  1500. mutex_lock(&all_q_mutex);
  1501. list_for_each_entry(q, &all_q_list, all_q_node) {
  1502. blk_queue_bypass_start(q);
  1503. blkg_destroy_all(q, false);
  1504. }
  1505. }
  1506. static void blkcg_bypass_end(void)
  1507. __releases(&all_q_mutex)
  1508. {
  1509. struct request_queue *q;
  1510. list_for_each_entry(q, &all_q_list, all_q_node)
  1511. blk_queue_bypass_end(q);
  1512. mutex_unlock(&all_q_mutex);
  1513. }
  1514. void blkio_policy_register(struct blkio_policy_type *blkiop)
  1515. {
  1516. struct request_queue *q;
  1517. blkcg_bypass_start();
  1518. spin_lock(&blkio_list_lock);
  1519. BUG_ON(blkio_policy[blkiop->plid]);
  1520. blkio_policy[blkiop->plid] = blkiop;
  1521. list_add_tail(&blkiop->list, &blkio_list);
  1522. spin_unlock(&blkio_list_lock);
  1523. list_for_each_entry(q, &all_q_list, all_q_node)
  1524. update_root_blkg_pd(q, blkiop->plid);
  1525. blkcg_bypass_end();
  1526. }
  1527. EXPORT_SYMBOL_GPL(blkio_policy_register);
  1528. void blkio_policy_unregister(struct blkio_policy_type *blkiop)
  1529. {
  1530. struct request_queue *q;
  1531. blkcg_bypass_start();
  1532. spin_lock(&blkio_list_lock);
  1533. BUG_ON(blkio_policy[blkiop->plid] != blkiop);
  1534. blkio_policy[blkiop->plid] = NULL;
  1535. list_del_init(&blkiop->list);
  1536. spin_unlock(&blkio_list_lock);
  1537. list_for_each_entry(q, &all_q_list, all_q_node)
  1538. update_root_blkg_pd(q, blkiop->plid);
  1539. blkcg_bypass_end();
  1540. }
  1541. EXPORT_SYMBOL_GPL(blkio_policy_unregister);