pblk-gc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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->csecs);
  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. goto fail_free_ws;
  130. emeta_buf = pblk_malloc(lm->emeta_len[0], l_mg->emeta_alloc_type,
  131. GFP_KERNEL);
  132. if (!emeta_buf) {
  133. pr_err("pblk: cannot use GC emeta\n");
  134. goto fail_free_bitmap;
  135. }
  136. ret = pblk_line_read_emeta(pblk, line, emeta_buf);
  137. if (ret) {
  138. pr_err("pblk: line %d read emeta failed (%d)\n", line->id, ret);
  139. goto fail_free_emeta;
  140. }
  141. /* If this read fails, it means that emeta is corrupted. For now, leave
  142. * the line untouched. TODO: Implement a recovery routine that scans and
  143. * moves all sectors on the line.
  144. */
  145. ret = pblk_recov_check_emeta(pblk, emeta_buf);
  146. if (ret) {
  147. pr_err("pblk: inconsistent emeta (line %d)\n", line->id);
  148. goto fail_free_emeta;
  149. }
  150. lba_list = emeta_to_lbas(pblk, emeta_buf);
  151. if (!lba_list) {
  152. pr_err("pblk: could not interpret emeta (line %d)\n", line->id);
  153. goto fail_free_emeta;
  154. }
  155. spin_lock(&line->lock);
  156. bitmap_copy(invalid_bitmap, line->invalid_bitmap, lm->sec_per_line);
  157. sec_left = pblk_line_vsc(line);
  158. spin_unlock(&line->lock);
  159. if (sec_left < 0) {
  160. pr_err("pblk: corrupted GC line (%d)\n", line->id);
  161. goto fail_free_emeta;
  162. }
  163. bit = -1;
  164. next_rq:
  165. gc_rq = kmalloc(sizeof(struct pblk_gc_rq), GFP_KERNEL);
  166. if (!gc_rq)
  167. goto fail_free_emeta;
  168. nr_secs = 0;
  169. do {
  170. bit = find_next_zero_bit(invalid_bitmap, lm->sec_per_line,
  171. bit + 1);
  172. if (bit > line->emeta_ssec)
  173. break;
  174. gc_rq->paddr_list[nr_secs] = bit;
  175. gc_rq->lba_list[nr_secs++] = le64_to_cpu(lba_list[bit]);
  176. } while (nr_secs < pblk->max_write_pgs);
  177. if (unlikely(!nr_secs)) {
  178. kfree(gc_rq);
  179. goto out;
  180. }
  181. gc_rq->nr_secs = nr_secs;
  182. gc_rq->line = line;
  183. gc_rq_ws = kmalloc(sizeof(struct pblk_line_ws), GFP_KERNEL);
  184. if (!gc_rq_ws)
  185. goto fail_free_gc_rq;
  186. gc_rq_ws->pblk = pblk;
  187. gc_rq_ws->line = line;
  188. gc_rq_ws->priv = gc_rq;
  189. /* The write GC path can be much slower than the read GC one due to
  190. * the budget imposed by the rate-limiter. Balance in case that we get
  191. * back pressure from the write GC path.
  192. */
  193. while (down_timeout(&gc->gc_sem, msecs_to_jiffies(30000)))
  194. io_schedule();
  195. kref_get(&line->ref);
  196. INIT_WORK(&gc_rq_ws->ws, pblk_gc_line_ws);
  197. queue_work(gc->gc_line_reader_wq, &gc_rq_ws->ws);
  198. sec_left -= nr_secs;
  199. if (sec_left > 0)
  200. goto next_rq;
  201. out:
  202. pblk_mfree(emeta_buf, l_mg->emeta_alloc_type);
  203. kfree(line_ws);
  204. kfree(invalid_bitmap);
  205. kref_put(&line->ref, pblk_line_put);
  206. atomic_dec(&gc->read_inflight_gc);
  207. return;
  208. fail_free_gc_rq:
  209. kfree(gc_rq);
  210. fail_free_emeta:
  211. pblk_mfree(emeta_buf, l_mg->emeta_alloc_type);
  212. fail_free_bitmap:
  213. kfree(invalid_bitmap);
  214. fail_free_ws:
  215. kfree(line_ws);
  216. pblk_put_line_back(pblk, line);
  217. kref_put(&line->ref, pblk_line_put);
  218. atomic_dec(&gc->read_inflight_gc);
  219. pr_err("pblk: Failed to GC line %d\n", line->id);
  220. }
  221. static int pblk_gc_line(struct pblk *pblk, struct pblk_line *line)
  222. {
  223. struct pblk_gc *gc = &pblk->gc;
  224. struct pblk_line_ws *line_ws;
  225. pr_debug("pblk: line '%d' being reclaimed for GC\n", line->id);
  226. line_ws = kmalloc(sizeof(struct pblk_line_ws), GFP_KERNEL);
  227. if (!line_ws)
  228. return -ENOMEM;
  229. line_ws->pblk = pblk;
  230. line_ws->line = line;
  231. atomic_inc(&gc->pipeline_gc);
  232. INIT_WORK(&line_ws->ws, pblk_gc_line_prepare_ws);
  233. queue_work(gc->gc_reader_wq, &line_ws->ws);
  234. return 0;
  235. }
  236. static void pblk_gc_reader_kick(struct pblk_gc *gc)
  237. {
  238. wake_up_process(gc->gc_reader_ts);
  239. }
  240. static void pblk_gc_kick(struct pblk *pblk)
  241. {
  242. struct pblk_gc *gc = &pblk->gc;
  243. pblk_gc_writer_kick(gc);
  244. pblk_gc_reader_kick(gc);
  245. /* If we're shutting down GC, let's not start it up again */
  246. if (gc->gc_enabled) {
  247. wake_up_process(gc->gc_ts);
  248. mod_timer(&gc->gc_timer,
  249. jiffies + msecs_to_jiffies(GC_TIME_MSECS));
  250. }
  251. }
  252. static int pblk_gc_read(struct pblk *pblk)
  253. {
  254. struct pblk_gc *gc = &pblk->gc;
  255. struct pblk_line *line;
  256. spin_lock(&gc->r_lock);
  257. if (list_empty(&gc->r_list)) {
  258. spin_unlock(&gc->r_lock);
  259. return 1;
  260. }
  261. line = list_first_entry(&gc->r_list, struct pblk_line, list);
  262. list_del(&line->list);
  263. spin_unlock(&gc->r_lock);
  264. pblk_gc_kick(pblk);
  265. if (pblk_gc_line(pblk, line))
  266. pr_err("pblk: failed to GC line %d\n", line->id);
  267. return 0;
  268. }
  269. static struct pblk_line *pblk_gc_get_victim_line(struct pblk *pblk,
  270. struct list_head *group_list)
  271. {
  272. struct pblk_line *line, *victim;
  273. int line_vsc, victim_vsc;
  274. victim = list_first_entry(group_list, struct pblk_line, list);
  275. list_for_each_entry(line, group_list, list) {
  276. line_vsc = le32_to_cpu(*line->vsc);
  277. victim_vsc = le32_to_cpu(*victim->vsc);
  278. if (line_vsc < victim_vsc)
  279. victim = line;
  280. }
  281. return victim;
  282. }
  283. static bool pblk_gc_should_run(struct pblk_gc *gc, struct pblk_rl *rl)
  284. {
  285. unsigned int nr_blocks_free, nr_blocks_need;
  286. nr_blocks_need = pblk_rl_high_thrs(rl);
  287. nr_blocks_free = pblk_rl_nr_free_blks(rl);
  288. /* This is not critical, no need to take lock here */
  289. return ((gc->gc_active) && (nr_blocks_need > nr_blocks_free));
  290. }
  291. void pblk_gc_free_full_lines(struct pblk *pblk)
  292. {
  293. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  294. struct pblk_gc *gc = &pblk->gc;
  295. struct pblk_line *line;
  296. do {
  297. spin_lock(&l_mg->gc_lock);
  298. if (list_empty(&l_mg->gc_full_list)) {
  299. spin_unlock(&l_mg->gc_lock);
  300. return;
  301. }
  302. line = list_first_entry(&l_mg->gc_full_list,
  303. struct pblk_line, list);
  304. spin_lock(&line->lock);
  305. WARN_ON(line->state != PBLK_LINESTATE_CLOSED);
  306. line->state = PBLK_LINESTATE_GC;
  307. spin_unlock(&line->lock);
  308. list_del(&line->list);
  309. spin_unlock(&l_mg->gc_lock);
  310. atomic_inc(&gc->pipeline_gc);
  311. kref_put(&line->ref, pblk_line_put);
  312. } while (1);
  313. }
  314. /*
  315. * Lines with no valid sectors will be returned to the free list immediately. If
  316. * GC is activated - either because the free block count is under the determined
  317. * threshold, or because it is being forced from user space - only lines with a
  318. * high count of invalid sectors will be recycled.
  319. */
  320. static void pblk_gc_run(struct pblk *pblk)
  321. {
  322. struct pblk_line_mgmt *l_mg = &pblk->l_mg;
  323. struct pblk_gc *gc = &pblk->gc;
  324. struct pblk_line *line;
  325. struct list_head *group_list;
  326. bool run_gc;
  327. int read_inflight_gc, gc_group = 0, prev_group = 0;
  328. pblk_gc_free_full_lines(pblk);
  329. run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
  330. if (!run_gc || (atomic_read(&gc->read_inflight_gc) >= PBLK_GC_L_QD))
  331. return;
  332. next_gc_group:
  333. group_list = l_mg->gc_lists[gc_group++];
  334. do {
  335. spin_lock(&l_mg->gc_lock);
  336. if (list_empty(group_list)) {
  337. spin_unlock(&l_mg->gc_lock);
  338. break;
  339. }
  340. line = pblk_gc_get_victim_line(pblk, group_list);
  341. spin_lock(&line->lock);
  342. WARN_ON(line->state != PBLK_LINESTATE_CLOSED);
  343. line->state = PBLK_LINESTATE_GC;
  344. spin_unlock(&line->lock);
  345. list_del(&line->list);
  346. spin_unlock(&l_mg->gc_lock);
  347. spin_lock(&gc->r_lock);
  348. list_add_tail(&line->list, &gc->r_list);
  349. spin_unlock(&gc->r_lock);
  350. read_inflight_gc = atomic_inc_return(&gc->read_inflight_gc);
  351. pblk_gc_reader_kick(gc);
  352. prev_group = 1;
  353. /* No need to queue up more GC lines than we can handle */
  354. run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
  355. if (!run_gc || read_inflight_gc >= PBLK_GC_L_QD)
  356. break;
  357. } while (1);
  358. if (!prev_group && pblk->rl.rb_state > gc_group &&
  359. gc_group < PBLK_GC_NR_LISTS)
  360. goto next_gc_group;
  361. }
  362. static void pblk_gc_timer(struct timer_list *t)
  363. {
  364. struct pblk *pblk = from_timer(pblk, t, gc.gc_timer);
  365. pblk_gc_kick(pblk);
  366. }
  367. static int pblk_gc_ts(void *data)
  368. {
  369. struct pblk *pblk = data;
  370. while (!kthread_should_stop()) {
  371. pblk_gc_run(pblk);
  372. set_current_state(TASK_INTERRUPTIBLE);
  373. io_schedule();
  374. }
  375. return 0;
  376. }
  377. static int pblk_gc_writer_ts(void *data)
  378. {
  379. struct pblk *pblk = data;
  380. while (!kthread_should_stop()) {
  381. if (!pblk_gc_write(pblk))
  382. continue;
  383. set_current_state(TASK_INTERRUPTIBLE);
  384. io_schedule();
  385. }
  386. return 0;
  387. }
  388. static int pblk_gc_reader_ts(void *data)
  389. {
  390. struct pblk *pblk = data;
  391. struct pblk_gc *gc = &pblk->gc;
  392. while (!kthread_should_stop()) {
  393. if (!pblk_gc_read(pblk))
  394. continue;
  395. set_current_state(TASK_INTERRUPTIBLE);
  396. io_schedule();
  397. }
  398. #ifdef CONFIG_NVM_DEBUG
  399. pr_info("pblk: flushing gc pipeline, %d lines left\n",
  400. atomic_read(&gc->pipeline_gc));
  401. #endif
  402. do {
  403. if (!atomic_read(&gc->pipeline_gc))
  404. break;
  405. schedule();
  406. } while (1);
  407. return 0;
  408. }
  409. static void pblk_gc_start(struct pblk *pblk)
  410. {
  411. pblk->gc.gc_active = 1;
  412. pr_debug("pblk: gc start\n");
  413. }
  414. void pblk_gc_should_start(struct pblk *pblk)
  415. {
  416. struct pblk_gc *gc = &pblk->gc;
  417. if (gc->gc_enabled && !gc->gc_active) {
  418. pblk_gc_start(pblk);
  419. pblk_gc_kick(pblk);
  420. }
  421. }
  422. void pblk_gc_should_stop(struct pblk *pblk)
  423. {
  424. struct pblk_gc *gc = &pblk->gc;
  425. if (gc->gc_active && !gc->gc_forced)
  426. gc->gc_active = 0;
  427. }
  428. void pblk_gc_should_kick(struct pblk *pblk)
  429. {
  430. pblk_rl_update_rates(&pblk->rl);
  431. }
  432. void pblk_gc_sysfs_state_show(struct pblk *pblk, int *gc_enabled,
  433. int *gc_active)
  434. {
  435. struct pblk_gc *gc = &pblk->gc;
  436. spin_lock(&gc->lock);
  437. *gc_enabled = gc->gc_enabled;
  438. *gc_active = gc->gc_active;
  439. spin_unlock(&gc->lock);
  440. }
  441. int pblk_gc_sysfs_force(struct pblk *pblk, int force)
  442. {
  443. struct pblk_gc *gc = &pblk->gc;
  444. if (force < 0 || force > 1)
  445. return -EINVAL;
  446. spin_lock(&gc->lock);
  447. gc->gc_forced = force;
  448. if (force)
  449. gc->gc_enabled = 1;
  450. else
  451. gc->gc_enabled = 0;
  452. spin_unlock(&gc->lock);
  453. pblk_gc_should_start(pblk);
  454. return 0;
  455. }
  456. int pblk_gc_init(struct pblk *pblk)
  457. {
  458. struct pblk_gc *gc = &pblk->gc;
  459. int ret;
  460. gc->gc_ts = kthread_create(pblk_gc_ts, pblk, "pblk-gc-ts");
  461. if (IS_ERR(gc->gc_ts)) {
  462. pr_err("pblk: could not allocate GC main kthread\n");
  463. return PTR_ERR(gc->gc_ts);
  464. }
  465. gc->gc_writer_ts = kthread_create(pblk_gc_writer_ts, pblk,
  466. "pblk-gc-writer-ts");
  467. if (IS_ERR(gc->gc_writer_ts)) {
  468. pr_err("pblk: could not allocate GC writer kthread\n");
  469. ret = PTR_ERR(gc->gc_writer_ts);
  470. goto fail_free_main_kthread;
  471. }
  472. gc->gc_reader_ts = kthread_create(pblk_gc_reader_ts, pblk,
  473. "pblk-gc-reader-ts");
  474. if (IS_ERR(gc->gc_reader_ts)) {
  475. pr_err("pblk: could not allocate GC reader kthread\n");
  476. ret = PTR_ERR(gc->gc_reader_ts);
  477. goto fail_free_writer_kthread;
  478. }
  479. timer_setup(&gc->gc_timer, pblk_gc_timer, 0);
  480. mod_timer(&gc->gc_timer, jiffies + msecs_to_jiffies(GC_TIME_MSECS));
  481. gc->gc_active = 0;
  482. gc->gc_forced = 0;
  483. gc->gc_enabled = 1;
  484. gc->w_entries = 0;
  485. atomic_set(&gc->read_inflight_gc, 0);
  486. atomic_set(&gc->pipeline_gc, 0);
  487. /* Workqueue that reads valid sectors from a line and submit them to the
  488. * GC writer to be recycled.
  489. */
  490. gc->gc_line_reader_wq = alloc_workqueue("pblk-gc-line-reader-wq",
  491. WQ_MEM_RECLAIM | WQ_UNBOUND, PBLK_GC_MAX_READERS);
  492. if (!gc->gc_line_reader_wq) {
  493. pr_err("pblk: could not allocate GC line reader workqueue\n");
  494. ret = -ENOMEM;
  495. goto fail_free_reader_kthread;
  496. }
  497. /* Workqueue that prepare lines for GC */
  498. gc->gc_reader_wq = alloc_workqueue("pblk-gc-line_wq",
  499. WQ_MEM_RECLAIM | WQ_UNBOUND, 1);
  500. if (!gc->gc_reader_wq) {
  501. pr_err("pblk: could not allocate GC reader workqueue\n");
  502. ret = -ENOMEM;
  503. goto fail_free_reader_line_wq;
  504. }
  505. spin_lock_init(&gc->lock);
  506. spin_lock_init(&gc->w_lock);
  507. spin_lock_init(&gc->r_lock);
  508. sema_init(&gc->gc_sem, PBLK_GC_RQ_QD);
  509. INIT_LIST_HEAD(&gc->w_list);
  510. INIT_LIST_HEAD(&gc->r_list);
  511. return 0;
  512. fail_free_reader_line_wq:
  513. destroy_workqueue(gc->gc_line_reader_wq);
  514. fail_free_reader_kthread:
  515. kthread_stop(gc->gc_reader_ts);
  516. fail_free_writer_kthread:
  517. kthread_stop(gc->gc_writer_ts);
  518. fail_free_main_kthread:
  519. kthread_stop(gc->gc_ts);
  520. return ret;
  521. }
  522. void pblk_gc_exit(struct pblk *pblk)
  523. {
  524. struct pblk_gc *gc = &pblk->gc;
  525. gc->gc_enabled = 0;
  526. del_timer_sync(&gc->gc_timer);
  527. gc->gc_active = 0;
  528. if (gc->gc_ts)
  529. kthread_stop(gc->gc_ts);
  530. if (gc->gc_reader_ts)
  531. kthread_stop(gc->gc_reader_ts);
  532. flush_workqueue(gc->gc_reader_wq);
  533. destroy_workqueue(gc->gc_reader_wq);
  534. flush_workqueue(gc->gc_line_reader_wq);
  535. destroy_workqueue(gc->gc_line_reader_wq);
  536. if (gc->gc_writer_ts)
  537. kthread_stop(gc->gc_writer_ts);
  538. }