pblk-gc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Copyright (C) 2016 CNEX Labs
  3. * Initial release: Javier Gonzalez <javier@cnexlabs.com>
  4. * Matias Bjorling <matias@cnexlabs.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * pblk-gc.c - pblk's garbage collector
  16. */
  17. #include "pblk.h"
  18. #include <linux/delay.h>
  19. static void pblk_gc_free_gc_rq(struct pblk_gc_rq *gc_rq)
  20. {
  21. if (gc_rq->data)
  22. vfree(gc_rq->data);
  23. kfree(gc_rq);
  24. }
  25. static int pblk_gc_write(struct pblk *pblk)
  26. {
  27. struct pblk_gc *gc = &pblk->gc;
  28. struct pblk_gc_rq *gc_rq, *tgc_rq;
  29. LIST_HEAD(w_list);
  30. spin_lock(&gc->w_lock);
  31. if (list_empty(&gc->w_list)) {
  32. spin_unlock(&gc->w_lock);
  33. return 1;
  34. }
  35. list_cut_position(&w_list, &gc->w_list, gc->w_list.prev);
  36. gc->w_entries = 0;
  37. spin_unlock(&gc->w_lock);
  38. list_for_each_entry_safe(gc_rq, tgc_rq, &w_list, list) {
  39. pblk_write_gc_to_cache(pblk, gc_rq);
  40. list_del(&gc_rq->list);
  41. kref_put(&gc_rq->line->ref, pblk_line_put);
  42. pblk_gc_free_gc_rq(gc_rq);
  43. }
  44. return 0;
  45. }
  46. static void pblk_gc_writer_kick(struct pblk_gc *gc)
  47. {
  48. wake_up_process(gc->gc_writer_ts);
  49. }
  50. static void pblk_put_line_back(struct pblk *pblk, struct pblk_line *line)
  51. {
  52. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  53. struct list_head *move_list;
  54. spin_lock(&line->lock);
  55. WARN_ON(line->state != PBLK_LINESTATE_GC);
  56. line->state = PBLK_LINESTATE_CLOSED;
  57. move_list = pblk_line_gc_list(pblk, line);
  58. spin_unlock(&line->lock);
  59. if (move_list) {
  60. spin_lock(&l_mg->gc_lock);
  61. list_add_tail(&line->list, move_list);
  62. spin_unlock(&l_mg->gc_lock);
  63. }
  64. }
  65. static void pblk_gc_line_ws(struct work_struct *work)
  66. {
  67. struct pblk_line_ws *gc_rq_ws = container_of(work,
  68. struct pblk_line_ws, ws);
  69. struct pblk *pblk = gc_rq_ws->pblk;
  70. struct nvm_tgt_dev *dev = pblk->dev;
  71. struct nvm_geo *geo = &dev->geo;
  72. struct pblk_gc *gc = &pblk->gc;
  73. struct pblk_line *line = gc_rq_ws->line;
  74. struct pblk_gc_rq *gc_rq = gc_rq_ws->priv;
  75. int ret;
  76. up(&gc->gc_sem);
  77. gc_rq->data = vmalloc(gc_rq->nr_secs * geo->sec_size);
  78. if (!gc_rq->data) {
  79. pr_err("pblk: could not GC line:%d (%d/%d)\n",
  80. line->id, *line->vsc, gc_rq->nr_secs);
  81. goto out;
  82. }
  83. /* Read from GC victim block */
  84. ret = pblk_submit_read_gc(pblk, gc_rq);
  85. if (ret) {
  86. pr_err("pblk: failed GC read in line:%d (err:%d)\n",
  87. line->id, ret);
  88. goto out;
  89. }
  90. if (!gc_rq->secs_to_gc)
  91. goto out;
  92. retry:
  93. spin_lock(&gc->w_lock);
  94. if (gc->w_entries >= PBLK_GC_RQ_QD) {
  95. spin_unlock(&gc->w_lock);
  96. pblk_gc_writer_kick(&pblk->gc);
  97. usleep_range(128, 256);
  98. goto retry;
  99. }
  100. gc->w_entries++;
  101. list_add_tail(&gc_rq->list, &gc->w_list);
  102. spin_unlock(&gc->w_lock);
  103. pblk_gc_writer_kick(&pblk->gc);
  104. kfree(gc_rq_ws);
  105. return;
  106. out:
  107. pblk_gc_free_gc_rq(gc_rq);
  108. kref_put(&line->ref, pblk_line_put);
  109. kfree(gc_rq_ws);
  110. }
  111. static void pblk_gc_line_prepare_ws(struct work_struct *work)
  112. {
  113. struct pblk_line_ws *line_ws = container_of(work, struct pblk_line_ws,
  114. ws);
  115. struct pblk *pblk = line_ws->pblk;
  116. struct pblk_line *line = line_ws->line;
  117. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  118. struct pblk_line_meta *lm = &pblk->lm;
  119. struct pblk_gc *gc = &pblk->gc;
  120. struct line_emeta *emeta_buf;
  121. struct pblk_line_ws *gc_rq_ws;
  122. struct pblk_gc_rq *gc_rq;
  123. __le64 *lba_list;
  124. unsigned long *invalid_bitmap;
  125. int sec_left, nr_secs, bit;
  126. int ret;
  127. invalid_bitmap = kmalloc(lm->sec_bitmap_len, GFP_KERNEL);
  128. if (!invalid_bitmap) {
  129. pr_err("pblk: could not allocate GC invalid bitmap\n");
  130. goto fail_free_ws;
  131. }
  132. emeta_buf = pblk_malloc(lm->emeta_len[0], l_mg->emeta_alloc_type,
  133. GFP_KERNEL);
  134. if (!emeta_buf) {
  135. pr_err("pblk: cannot use GC emeta\n");
  136. goto fail_free_bitmap;
  137. }
  138. ret = pblk_line_read_emeta(pblk, line, emeta_buf);
  139. if (ret) {
  140. pr_err("pblk: line %d read emeta failed (%d)\n", line->id, ret);
  141. goto fail_free_emeta;
  142. }
  143. /* If this read fails, it means that emeta is corrupted. For now, leave
  144. * the line untouched. TODO: Implement a recovery routine that scans and
  145. * moves all sectors on the line.
  146. */
  147. ret = pblk_recov_check_emeta(pblk, emeta_buf);
  148. if (ret) {
  149. pr_err("pblk: inconsistent emeta (line %d)\n", line->id);
  150. goto fail_free_emeta;
  151. }
  152. lba_list = emeta_to_lbas(pblk, emeta_buf);
  153. if (!lba_list) {
  154. pr_err("pblk: could not interpret emeta (line %d)\n", line->id);
  155. goto fail_free_emeta;
  156. }
  157. spin_lock(&line->lock);
  158. bitmap_copy(invalid_bitmap, line->invalid_bitmap, lm->sec_per_line);
  159. sec_left = pblk_line_vsc(line);
  160. spin_unlock(&line->lock);
  161. if (sec_left < 0) {
  162. pr_err("pblk: corrupted GC line (%d)\n", line->id);
  163. goto fail_free_emeta;
  164. }
  165. bit = -1;
  166. next_rq:
  167. gc_rq = kmalloc(sizeof(struct pblk_gc_rq), GFP_KERNEL);
  168. if (!gc_rq)
  169. goto fail_free_emeta;
  170. nr_secs = 0;
  171. do {
  172. bit = find_next_zero_bit(invalid_bitmap, lm->sec_per_line,
  173. bit + 1);
  174. if (bit > line->emeta_ssec)
  175. break;
  176. gc_rq->paddr_list[nr_secs] = bit;
  177. gc_rq->lba_list[nr_secs++] = le64_to_cpu(lba_list[bit]);
  178. } while (nr_secs < pblk->max_write_pgs);
  179. if (unlikely(!nr_secs)) {
  180. kfree(gc_rq);
  181. goto out;
  182. }
  183. gc_rq->nr_secs = nr_secs;
  184. gc_rq->line = line;
  185. gc_rq_ws = kmalloc(sizeof(struct pblk_line_ws), GFP_KERNEL);
  186. if (!gc_rq_ws)
  187. goto fail_free_gc_rq;
  188. gc_rq_ws->pblk = pblk;
  189. gc_rq_ws->line = line;
  190. gc_rq_ws->priv = gc_rq;
  191. /* The write GC path can be much slower than the read GC one due to
  192. * the budget imposed by the rate-limiter. Balance in case that we get
  193. * back pressure from the write GC path.
  194. */
  195. while (down_timeout(&gc->gc_sem, msecs_to_jiffies(30000)))
  196. io_schedule();
  197. kref_get(&line->ref);
  198. INIT_WORK(&gc_rq_ws->ws, pblk_gc_line_ws);
  199. queue_work(gc->gc_line_reader_wq, &gc_rq_ws->ws);
  200. sec_left -= nr_secs;
  201. if (sec_left > 0)
  202. goto next_rq;
  203. out:
  204. pblk_mfree(emeta_buf, l_mg->emeta_alloc_type);
  205. kfree(line_ws);
  206. kfree(invalid_bitmap);
  207. kref_put(&line->ref, pblk_line_put);
  208. atomic_dec(&gc->read_inflight_gc);
  209. return;
  210. fail_free_gc_rq:
  211. kfree(gc_rq);
  212. fail_free_emeta:
  213. pblk_mfree(emeta_buf, l_mg->emeta_alloc_type);
  214. fail_free_bitmap:
  215. kfree(invalid_bitmap);
  216. fail_free_ws:
  217. kfree(line_ws);
  218. pblk_put_line_back(pblk, line);
  219. kref_put(&line->ref, pblk_line_put);
  220. atomic_dec(&gc->read_inflight_gc);
  221. pr_err("pblk: Failed to GC line %d\n", line->id);
  222. }
  223. static int pblk_gc_line(struct pblk *pblk, struct pblk_line *line)
  224. {
  225. struct pblk_gc *gc = &pblk->gc;
  226. struct pblk_line_ws *line_ws;
  227. pr_debug("pblk: line '%d' being reclaimed for GC\n", line->id);
  228. line_ws = kmalloc(sizeof(struct pblk_line_ws), GFP_KERNEL);
  229. if (!line_ws)
  230. return -ENOMEM;
  231. line_ws->pblk = pblk;
  232. line_ws->line = line;
  233. atomic_inc(&gc->pipeline_gc);
  234. INIT_WORK(&line_ws->ws, pblk_gc_line_prepare_ws);
  235. queue_work(gc->gc_reader_wq, &line_ws->ws);
  236. return 0;
  237. }
  238. static void pblk_gc_reader_kick(struct pblk_gc *gc)
  239. {
  240. wake_up_process(gc->gc_reader_ts);
  241. }
  242. static void pblk_gc_kick(struct pblk *pblk)
  243. {
  244. struct pblk_gc *gc = &pblk->gc;
  245. pblk_gc_writer_kick(gc);
  246. pblk_gc_reader_kick(gc);
  247. /* If we're shutting down GC, let's not start it up again */
  248. if (gc->gc_enabled) {
  249. wake_up_process(gc->gc_ts);
  250. mod_timer(&gc->gc_timer,
  251. jiffies + msecs_to_jiffies(GC_TIME_MSECS));
  252. }
  253. }
  254. static int pblk_gc_read(struct pblk *pblk)
  255. {
  256. struct pblk_gc *gc = &pblk->gc;
  257. struct pblk_line *line;
  258. spin_lock(&gc->r_lock);
  259. if (list_empty(&gc->r_list)) {
  260. spin_unlock(&gc->r_lock);
  261. return 1;
  262. }
  263. line = list_first_entry(&gc->r_list, struct pblk_line, list);
  264. list_del(&line->list);
  265. spin_unlock(&gc->r_lock);
  266. pblk_gc_kick(pblk);
  267. if (pblk_gc_line(pblk, line))
  268. pr_err("pblk: failed to GC line %d\n", line->id);
  269. return 0;
  270. }
  271. static struct pblk_line *pblk_gc_get_victim_line(struct pblk *pblk,
  272. struct list_head *group_list)
  273. {
  274. struct pblk_line *line, *victim;
  275. int line_vsc, victim_vsc;
  276. victim = list_first_entry(group_list, struct pblk_line, list);
  277. list_for_each_entry(line, group_list, list) {
  278. line_vsc = le32_to_cpu(*line->vsc);
  279. victim_vsc = le32_to_cpu(*victim->vsc);
  280. if (line_vsc < victim_vsc)
  281. victim = line;
  282. }
  283. return victim;
  284. }
  285. static bool pblk_gc_should_run(struct pblk_gc *gc, struct pblk_rl *rl)
  286. {
  287. unsigned int nr_blocks_free, nr_blocks_need;
  288. nr_blocks_need = pblk_rl_high_thrs(rl);
  289. nr_blocks_free = pblk_rl_nr_free_blks(rl);
  290. /* This is not critical, no need to take lock here */
  291. return ((gc->gc_active) && (nr_blocks_need > nr_blocks_free));
  292. }
  293. void pblk_gc_free_full_lines(struct pblk *pblk)
  294. {
  295. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  296. struct pblk_gc *gc = &pblk->gc;
  297. struct pblk_line *line;
  298. do {
  299. spin_lock(&l_mg->gc_lock);
  300. if (list_empty(&l_mg->gc_full_list)) {
  301. spin_unlock(&l_mg->gc_lock);
  302. return;
  303. }
  304. line = list_first_entry(&l_mg->gc_full_list,
  305. struct pblk_line, list);
  306. spin_lock(&line->lock);
  307. WARN_ON(line->state != PBLK_LINESTATE_CLOSED);
  308. line->state = PBLK_LINESTATE_GC;
  309. spin_unlock(&line->lock);
  310. list_del(&line->list);
  311. spin_unlock(&l_mg->gc_lock);
  312. atomic_inc(&gc->pipeline_gc);
  313. kref_put(&line->ref, pblk_line_put);
  314. } while (1);
  315. }
  316. /*
  317. * Lines with no valid sectors will be returned to the free list immediately. If
  318. * GC is activated - either because the free block count is under the determined
  319. * threshold, or because it is being forced from user space - only lines with a
  320. * high count of invalid sectors will be recycled.
  321. */
  322. static void pblk_gc_run(struct pblk *pblk)
  323. {
  324. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  325. struct pblk_gc *gc = &pblk->gc;
  326. struct pblk_line *line;
  327. struct list_head *group_list;
  328. bool run_gc;
  329. int read_inflight_gc, gc_group = 0, prev_group = 0;
  330. pblk_gc_free_full_lines(pblk);
  331. run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
  332. if (!run_gc || (atomic_read(&gc->read_inflight_gc) >= PBLK_GC_L_QD))
  333. return;
  334. next_gc_group:
  335. group_list = l_mg->gc_lists[gc_group++];
  336. do {
  337. spin_lock(&l_mg->gc_lock);
  338. if (list_empty(group_list)) {
  339. spin_unlock(&l_mg->gc_lock);
  340. break;
  341. }
  342. line = pblk_gc_get_victim_line(pblk, group_list);
  343. spin_lock(&line->lock);
  344. WARN_ON(line->state != PBLK_LINESTATE_CLOSED);
  345. line->state = PBLK_LINESTATE_GC;
  346. spin_unlock(&line->lock);
  347. list_del(&line->list);
  348. spin_unlock(&l_mg->gc_lock);
  349. spin_lock(&gc->r_lock);
  350. list_add_tail(&line->list, &gc->r_list);
  351. spin_unlock(&gc->r_lock);
  352. read_inflight_gc = atomic_inc_return(&gc->read_inflight_gc);
  353. pblk_gc_reader_kick(gc);
  354. prev_group = 1;
  355. /* No need to queue up more GC lines than we can handle */
  356. run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
  357. if (!run_gc || read_inflight_gc >= PBLK_GC_L_QD)
  358. break;
  359. } while (1);
  360. if (!prev_group && pblk->rl.rb_state > gc_group &&
  361. gc_group < PBLK_GC_NR_LISTS)
  362. goto next_gc_group;
  363. }
  364. static void pblk_gc_timer(struct timer_list *t)
  365. {
  366. struct pblk *pblk = from_timer(pblk, t, gc.gc_timer);
  367. pblk_gc_kick(pblk);
  368. }
  369. static int pblk_gc_ts(void *data)
  370. {
  371. struct pblk *pblk = data;
  372. while (!kthread_should_stop()) {
  373. pblk_gc_run(pblk);
  374. set_current_state(TASK_INTERRUPTIBLE);
  375. io_schedule();
  376. }
  377. return 0;
  378. }
  379. static int pblk_gc_writer_ts(void *data)
  380. {
  381. struct pblk *pblk = data;
  382. while (!kthread_should_stop()) {
  383. if (!pblk_gc_write(pblk))
  384. continue;
  385. set_current_state(TASK_INTERRUPTIBLE);
  386. io_schedule();
  387. }
  388. return 0;
  389. }
  390. static int pblk_gc_reader_ts(void *data)
  391. {
  392. struct pblk *pblk = data;
  393. struct pblk_gc *gc = &pblk->gc;
  394. while (!kthread_should_stop()) {
  395. if (!pblk_gc_read(pblk))
  396. continue;
  397. set_current_state(TASK_INTERRUPTIBLE);
  398. io_schedule();
  399. }
  400. #ifdef CONFIG_NVM_DEBUG
  401. pr_info("pblk: flushing gc pipeline, %d lines left\n",
  402. atomic_read(&gc->pipeline_gc));
  403. #endif
  404. do {
  405. if (!atomic_read(&gc->pipeline_gc))
  406. break;
  407. schedule();
  408. } while (1);
  409. return 0;
  410. }
  411. static void pblk_gc_start(struct pblk *pblk)
  412. {
  413. pblk->gc.gc_active = 1;
  414. pr_debug("pblk: gc start\n");
  415. }
  416. void pblk_gc_should_start(struct pblk *pblk)
  417. {
  418. struct pblk_gc *gc = &pblk->gc;
  419. if (gc->gc_enabled && !gc->gc_active) {
  420. pblk_gc_start(pblk);
  421. pblk_gc_kick(pblk);
  422. }
  423. }
  424. void pblk_gc_should_stop(struct pblk *pblk)
  425. {
  426. struct pblk_gc *gc = &pblk->gc;
  427. if (gc->gc_active && !gc->gc_forced)
  428. gc->gc_active = 0;
  429. }
  430. void pblk_gc_should_kick(struct pblk *pblk)
  431. {
  432. pblk_rl_update_rates(&pblk->rl);
  433. }
  434. void pblk_gc_sysfs_state_show(struct pblk *pblk, int *gc_enabled,
  435. int *gc_active)
  436. {
  437. struct pblk_gc *gc = &pblk->gc;
  438. spin_lock(&gc->lock);
  439. *gc_enabled = gc->gc_enabled;
  440. *gc_active = gc->gc_active;
  441. spin_unlock(&gc->lock);
  442. }
  443. int pblk_gc_sysfs_force(struct pblk *pblk, int force)
  444. {
  445. struct pblk_gc *gc = &pblk->gc;
  446. if (force < 0 || force > 1)
  447. return -EINVAL;
  448. spin_lock(&gc->lock);
  449. gc->gc_forced = force;
  450. if (force)
  451. gc->gc_enabled = 1;
  452. else
  453. gc->gc_enabled = 0;
  454. spin_unlock(&gc->lock);
  455. pblk_gc_should_start(pblk);
  456. return 0;
  457. }
  458. int pblk_gc_init(struct pblk *pblk)
  459. {
  460. struct pblk_gc *gc = &pblk->gc;
  461. int ret;
  462. gc->gc_ts = kthread_create(pblk_gc_ts, pblk, "pblk-gc-ts");
  463. if (IS_ERR(gc->gc_ts)) {
  464. pr_err("pblk: could not allocate GC main kthread\n");
  465. return PTR_ERR(gc->gc_ts);
  466. }
  467. gc->gc_writer_ts = kthread_create(pblk_gc_writer_ts, pblk,
  468. "pblk-gc-writer-ts");
  469. if (IS_ERR(gc->gc_writer_ts)) {
  470. pr_err("pblk: could not allocate GC writer kthread\n");
  471. ret = PTR_ERR(gc->gc_writer_ts);
  472. goto fail_free_main_kthread;
  473. }
  474. gc->gc_reader_ts = kthread_create(pblk_gc_reader_ts, pblk,
  475. "pblk-gc-reader-ts");
  476. if (IS_ERR(gc->gc_reader_ts)) {
  477. pr_err("pblk: could not allocate GC reader kthread\n");
  478. ret = PTR_ERR(gc->gc_reader_ts);
  479. goto fail_free_writer_kthread;
  480. }
  481. timer_setup(&gc->gc_timer, pblk_gc_timer, 0);
  482. mod_timer(&gc->gc_timer, jiffies + msecs_to_jiffies(GC_TIME_MSECS));
  483. gc->gc_active = 0;
  484. gc->gc_forced = 0;
  485. gc->gc_enabled = 1;
  486. gc->w_entries = 0;
  487. atomic_set(&gc->read_inflight_gc, 0);
  488. atomic_set(&gc->pipeline_gc, 0);
  489. /* Workqueue that reads valid sectors from a line and submit them to the
  490. * GC writer to be recycled.
  491. */
  492. gc->gc_line_reader_wq = alloc_workqueue("pblk-gc-line-reader-wq",
  493. WQ_MEM_RECLAIM | WQ_UNBOUND, PBLK_GC_MAX_READERS);
  494. if (!gc->gc_line_reader_wq) {
  495. pr_err("pblk: could not allocate GC line reader workqueue\n");
  496. ret = -ENOMEM;
  497. goto fail_free_reader_kthread;
  498. }
  499. /* Workqueue that prepare lines for GC */
  500. gc->gc_reader_wq = alloc_workqueue("pblk-gc-line_wq",
  501. WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
  502. if (!gc->gc_reader_wq) {
  503. pr_err("pblk: could not allocate GC reader workqueue\n");
  504. ret = -ENOMEM;
  505. goto fail_free_reader_line_wq;
  506. }
  507. spin_lock_init(&gc->lock);
  508. spin_lock_init(&gc->w_lock);
  509. spin_lock_init(&gc->r_lock);
  510. sema_init(&gc->gc_sem, PBLK_GC_RQ_QD);
  511. INIT_LIST_HEAD(&gc->w_list);
  512. INIT_LIST_HEAD(&gc->r_list);
  513. return 0;
  514. fail_free_reader_line_wq:
  515. destroy_workqueue(gc->gc_line_reader_wq);
  516. fail_free_reader_kthread:
  517. kthread_stop(gc->gc_reader_ts);
  518. fail_free_writer_kthread:
  519. kthread_stop(gc->gc_writer_ts);
  520. fail_free_main_kthread:
  521. kthread_stop(gc->gc_ts);
  522. return ret;
  523. }
  524. void pblk_gc_exit(struct pblk *pblk)
  525. {
  526. struct pblk_gc *gc = &pblk->gc;
  527. gc->gc_enabled = 0;
  528. del_timer_sync(&gc->gc_timer);
  529. gc->gc_active = 0;
  530. if (gc->gc_ts)
  531. kthread_stop(gc->gc_ts);
  532. if (gc->gc_reader_ts)
  533. kthread_stop(gc->gc_reader_ts);
  534. flush_workqueue(gc->gc_reader_wq);
  535. if (gc->gc_reader_wq)
  536. destroy_workqueue(gc->gc_reader_wq);
  537. flush_workqueue(gc->gc_line_reader_wq);
  538. if (gc->gc_line_reader_wq)
  539. destroy_workqueue(gc->gc_line_reader_wq);
  540. if (gc->gc_writer_ts)
  541. kthread_stop(gc->gc_writer_ts);
  542. }