Lines Matching refs:gc
16 * pblk-gc.c - pblk's garbage collector
33 struct pblk_gc *gc = &pblk->gc;
37 spin_lock(&gc->w_lock);
38 if (list_empty(&gc->w_list)) {
39 spin_unlock(&gc->w_lock);
43 list_cut_position(&w_list, &gc->w_list, gc->w_list.prev);
44 gc->w_entries = 0;
45 spin_unlock(&gc->w_lock);
57 static void pblk_gc_writer_kick(struct pblk_gc *gc)
59 wake_up_process(gc->gc_writer_ts);
77 * gc lists.
91 struct pblk_gc *gc = &pblk->gc;
96 up(&gc->gc_sem);
109 spin_lock(&gc->w_lock);
110 if (gc->w_entries >= PBLK_GC_RQ_QD) {
111 spin_unlock(&gc->w_lock);
112 pblk_gc_writer_kick(&pblk->gc);
116 gc->w_entries++;
117 list_add_tail(&gc_rq->list, &gc->w_list);
118 spin_unlock(&gc->w_lock);
120 pblk_gc_writer_kick(&pblk->gc);
185 struct pblk_gc *gc = &pblk->gc;
259 while (down_timeout(&gc->gc_sem, msecs_to_jiffies(30000)))
265 queue_work(gc->gc_line_reader_wq, &gc_rq_ws->ws);
277 atomic_dec(&gc->read_inflight_gc);
294 * gc to free line state transition.
297 atomic_dec(&gc->read_inflight_gc);
304 struct pblk_gc *gc = &pblk->gc;
316 atomic_inc(&gc->pipeline_gc);
318 queue_work(gc->gc_reader_wq, &line_ws->ws);
323 static void pblk_gc_reader_kick(struct pblk_gc *gc)
325 wake_up_process(gc->gc_reader_ts);
330 struct pblk_gc *gc = &pblk->gc;
332 pblk_gc_writer_kick(gc);
333 pblk_gc_reader_kick(gc);
336 if (gc->gc_enabled) {
337 wake_up_process(gc->gc_ts);
338 mod_timer(&gc->gc_timer,
345 struct pblk_gc *gc = &pblk->gc;
348 spin_lock(&gc->r_lock);
349 if (list_empty(&gc->r_list)) {
350 spin_unlock(&gc->r_lock);
354 line = list_first_entry(&gc->r_list, struct pblk_line, list);
356 spin_unlock(&gc->r_lock);
363 spin_lock(&gc->r_lock);
364 list_add_tail(&line->list, &gc->r_list);
365 spin_unlock(&gc->r_lock);
394 static bool pblk_gc_should_run(struct pblk_gc *gc, struct pblk_rl *rl)
404 ((gc->gc_active) && (nr_blocks_need > nr_blocks_free)));
410 struct pblk_gc *gc = &pblk->gc;
433 atomic_inc(&gc->pipeline_gc);
447 struct pblk_gc *gc = &pblk->gc;
455 run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
456 if (!run_gc || (atomic_read(&gc->read_inflight_gc) >= PBLK_GC_L_QD))
481 spin_lock(&gc->r_lock);
482 list_add_tail(&line->list, &gc->r_list);
483 spin_unlock(&gc->r_lock);
485 read_inflight_gc = atomic_inc_return(&gc->read_inflight_gc);
486 pblk_gc_reader_kick(gc);
491 run_gc = pblk_gc_should_run(&pblk->gc, &pblk->rl);
503 struct pblk *pblk = from_timer(pblk, t, gc.gc_timer);
538 struct pblk_gc *gc = &pblk->gc;
548 pblk_info(pblk, "flushing gc pipeline, %d lines left\n",
549 atomic_read(&gc->pipeline_gc));
553 if (!atomic_read(&gc->pipeline_gc))
564 pblk->gc.gc_active = 1;
565 pblk_debug(pblk, "gc start\n");
570 struct pblk_gc *gc = &pblk->gc;
572 if (gc->gc_enabled && !gc->gc_active) {
580 struct pblk_gc *gc = &pblk->gc;
582 if (gc->gc_active && !gc->gc_forced)
583 gc->gc_active = 0;
594 struct pblk_gc *gc = &pblk->gc;
596 spin_lock(&gc->lock);
597 *gc_enabled = gc->gc_enabled;
598 *gc_active = gc->gc_active;
599 spin_unlock(&gc->lock);
604 struct pblk_gc *gc = &pblk->gc;
609 spin_lock(&gc->lock);
610 gc->gc_forced = force;
613 gc->gc_enabled = 1;
615 gc->gc_enabled = 0;
616 spin_unlock(&gc->lock);
625 struct pblk_gc *gc = &pblk->gc;
628 gc->gc_ts = kthread_create(pblk_gc_ts, pblk, "pblk-gc-ts");
629 if (IS_ERR(gc->gc_ts)) {
631 return PTR_ERR(gc->gc_ts);
634 gc->gc_writer_ts = kthread_create(pblk_gc_writer_ts, pblk,
635 "pblk-gc-writer-ts");
636 if (IS_ERR(gc->gc_writer_ts)) {
638 ret = PTR_ERR(gc->gc_writer_ts);
642 gc->gc_reader_ts = kthread_create(pblk_gc_reader_ts, pblk,
643 "pblk-gc-reader-ts");
644 if (IS_ERR(gc->gc_reader_ts)) {
646 ret = PTR_ERR(gc->gc_reader_ts);
650 timer_setup(&gc->gc_timer, pblk_gc_timer, 0);
651 mod_timer(&gc->gc_timer, jiffies + msecs_to_jiffies(GC_TIME_MSECS));
653 gc->gc_active = 0;
654 gc->gc_forced = 0;
655 gc->gc_enabled = 1;
656 gc->w_entries = 0;
657 atomic_set(&gc->read_inflight_gc, 0);
658 atomic_set(&gc->pipeline_gc, 0);
663 gc->gc_line_reader_wq = alloc_workqueue("pblk-gc-line-reader-wq",
665 if (!gc->gc_line_reader_wq) {
672 gc->gc_reader_wq = alloc_workqueue("pblk-gc-line_wq",
674 if (!gc->gc_reader_wq) {
680 spin_lock_init(&gc->lock);
681 spin_lock_init(&gc->w_lock);
682 spin_lock_init(&gc->r_lock);
684 sema_init(&gc->gc_sem, PBLK_GC_RQ_QD);
686 INIT_LIST_HEAD(&gc->w_list);
687 INIT_LIST_HEAD(&gc->r_list);
692 destroy_workqueue(gc->gc_line_reader_wq);
694 kthread_stop(gc->gc_reader_ts);
696 kthread_stop(gc->gc_writer_ts);
698 kthread_stop(gc->gc_ts);
705 struct pblk_gc *gc = &pblk->gc;
707 gc->gc_enabled = 0;
708 del_timer_sync(&gc->gc_timer);
709 gc->gc_active = 0;
711 if (gc->gc_ts)
712 kthread_stop(gc->gc_ts);
714 if (gc->gc_reader_ts)
715 kthread_stop(gc->gc_reader_ts);
718 flush_workqueue(gc->gc_reader_wq);
719 flush_workqueue(gc->gc_line_reader_wq);
722 destroy_workqueue(gc->gc_reader_wq);
723 destroy_workqueue(gc->gc_line_reader_wq);
725 if (gc->gc_writer_ts)
726 kthread_stop(gc->gc_writer_ts);