diff options
Diffstat (limited to 'drivers/md/bcache/movinggc.c')
| -rw-r--r-- | drivers/md/bcache/movinggc.c | 124 | 
1 files changed, 63 insertions, 61 deletions
diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c index 1a3b4f4786c..cd7490311e5 100644 --- a/drivers/md/bcache/movinggc.c +++ b/drivers/md/bcache/movinggc.c @@ -12,8 +12,9 @@  #include <trace/events/bcache.h>  struct moving_io { +	struct closure		cl;  	struct keybuf_key	*w; -	struct search		s; +	struct data_insert_op	op;  	struct bbio		bio;  }; @@ -23,13 +24,10 @@ static bool moving_pred(struct keybuf *buf, struct bkey *k)  					   moving_gc_keys);  	unsigned i; -	for (i = 0; i < KEY_PTRS(k); i++) { -		struct cache *ca = PTR_CACHE(c, k, i); -		struct bucket *g = PTR_BUCKET(c, k, i); - -		if (GC_SECTORS_USED(g) < ca->gc_move_threshold) +	for (i = 0; i < KEY_PTRS(k); i++) +		if (ptr_available(c, k, i) && +		    GC_MOVE(PTR_BUCKET(c, k, i)))  			return true; -	}  	return false;  } @@ -38,13 +36,13 @@ static bool moving_pred(struct keybuf *buf, struct bkey *k)  static void moving_io_destructor(struct closure *cl)  { -	struct moving_io *io = container_of(cl, struct moving_io, s.cl); +	struct moving_io *io = container_of(cl, struct moving_io, cl);  	kfree(io);  }  static void write_moving_finish(struct closure *cl)  { -	struct moving_io *io = container_of(cl, struct moving_io, s.cl); +	struct moving_io *io = container_of(cl, struct moving_io, cl);  	struct bio *bio = &io->bio.bio;  	struct bio_vec *bv;  	int i; @@ -52,26 +50,30 @@ static void write_moving_finish(struct closure *cl)  	bio_for_each_segment_all(bv, bio, i)  		__free_page(bv->bv_page); -	if (io->s.op.insert_collision) +	if (io->op.replace_collision)  		trace_bcache_gc_copy_collision(&io->w->key); -	bch_keybuf_del(&io->s.op.c->moving_gc_keys, io->w); +	bch_keybuf_del(&io->op.c->moving_gc_keys, io->w); -	atomic_dec_bug(&io->s.op.c->in_flight); -	closure_wake_up(&io->s.op.c->moving_gc_wait); +	up(&io->op.c->moving_in_flight);  	closure_return_with_destructor(cl, moving_io_destructor);  }  static void read_moving_endio(struct bio *bio, int error)  { +	struct bbio *b = container_of(bio, struct bbio, bio);  	struct moving_io *io = container_of(bio->bi_private, -					    struct moving_io, s.cl); +					    struct moving_io, cl);  	if (error) -		io->s.error = error; +		io->op.error = error; +	else if (!KEY_DIRTY(&b->key) && +		 ptr_stale(io->op.c, &b->key, 0)) { +		io->op.error = -EINTR; +	} -	bch_bbio_endio(io->s.op.c, bio, error, "reading data to move"); +	bch_bbio_endio(io->op.c, bio, error, "reading data to move");  }  static void moving_init(struct moving_io *io) @@ -82,57 +84,56 @@ static void moving_init(struct moving_io *io)  	bio_get(bio);  	bio_set_prio(bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0)); -	bio->bi_size		= KEY_SIZE(&io->w->key) << 9; +	bio->bi_iter.bi_size	= KEY_SIZE(&io->w->key) << 9;  	bio->bi_max_vecs	= DIV_ROUND_UP(KEY_SIZE(&io->w->key),  					       PAGE_SECTORS); -	bio->bi_private		= &io->s.cl; +	bio->bi_private		= &io->cl;  	bio->bi_io_vec		= bio->bi_inline_vecs;  	bch_bio_map(bio, NULL);  }  static void write_moving(struct closure *cl)  { -	struct search *s = container_of(cl, struct search, cl); -	struct moving_io *io = container_of(s, struct moving_io, s); +	struct moving_io *io = container_of(cl, struct moving_io, cl); +	struct data_insert_op *op = &io->op; -	if (!s->error) { +	if (!op->error) {  		moving_init(io); -		io->bio.bio.bi_sector	= KEY_START(&io->w->key); -		s->op.lock		= -1; -		s->op.write_prio	= 1; -		s->op.cache_bio		= &io->bio.bio; +		io->bio.bio.bi_iter.bi_sector = KEY_START(&io->w->key); +		op->write_prio		= 1; +		op->bio			= &io->bio.bio; -		s->writeback		= KEY_DIRTY(&io->w->key); -		s->op.csum		= KEY_CSUM(&io->w->key); +		op->writeback		= KEY_DIRTY(&io->w->key); +		op->csum		= KEY_CSUM(&io->w->key); -		s->op.type = BTREE_REPLACE; -		bkey_copy(&s->op.replace, &io->w->key); +		bkey_copy(&op->replace_key, &io->w->key); +		op->replace		= true; -		closure_init(&s->op.cl, cl); -		bch_insert_data(&s->op.cl); +		closure_call(&op->cl, bch_data_insert, NULL, cl);  	} -	continue_at(cl, write_moving_finish, NULL); +	continue_at(cl, write_moving_finish, op->wq);  }  static void read_moving_submit(struct closure *cl)  { -	struct search *s = container_of(cl, struct search, cl); -	struct moving_io *io = container_of(s, struct moving_io, s); +	struct moving_io *io = container_of(cl, struct moving_io, cl);  	struct bio *bio = &io->bio.bio; -	bch_submit_bbio(bio, s->op.c, &io->w->key, 0); +	bch_submit_bbio(bio, io->op.c, &io->w->key, 0); -	continue_at(cl, write_moving, bch_gc_wq); +	continue_at(cl, write_moving, io->op.wq);  } -static void read_moving(struct closure *cl) +static void read_moving(struct cache_set *c)  { -	struct cache_set *c = container_of(cl, struct cache_set, moving_gc);  	struct keybuf_key *w;  	struct moving_io *io;  	struct bio *bio; +	struct closure cl; + +	closure_init_stack(&cl);  	/* XXX: if we error, background writeback could stall indefinitely */ @@ -142,6 +143,11 @@ static void read_moving(struct closure *cl)  		if (!w)  			break; +		if (ptr_stale(c, &w->key, 0)) { +			bch_keybuf_del(&c->moving_gc_keys, w); +			continue; +		} +  		io = kzalloc(sizeof(struct moving_io) + sizeof(struct bio_vec)  			     * DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS),  			     GFP_KERNEL); @@ -150,8 +156,9 @@ static void read_moving(struct closure *cl)  		w->private	= io;  		io->w		= w; -		io->s.op.inode	= KEY_INODE(&w->key); -		io->s.op.c	= c; +		io->op.inode	= KEY_INODE(&w->key); +		io->op.c	= c; +		io->op.wq	= c->moving_gc_wq;  		moving_init(io);  		bio = &io->bio.bio; @@ -164,13 +171,8 @@ static void read_moving(struct closure *cl)  		trace_bcache_gc_copy(&w->key); -		closure_call(&io->s.cl, read_moving_submit, NULL, &c->gc.cl); - -		if (atomic_inc_return(&c->in_flight) >= 64) { -			closure_wait_event(&c->moving_gc_wait, cl, -					   atomic_read(&c->in_flight) < 64); -			continue_at(cl, read_moving, bch_gc_wq); -		} +		down(&c->moving_in_flight); +		closure_call(&io->cl, read_moving_submit, NULL, &cl);  	}  	if (0) { @@ -180,7 +182,7 @@ err:		if (!IS_ERR_OR_NULL(w->private))  		bch_keybuf_del(&c->moving_gc_keys, w);  	} -	closure_return(cl); +	closure_sync(&cl);  }  static bool bucket_cmp(struct bucket *l, struct bucket *r) @@ -190,30 +192,33 @@ static bool bucket_cmp(struct bucket *l, struct bucket *r)  static unsigned bucket_heap_top(struct cache *ca)  { -	return GC_SECTORS_USED(heap_peek(&ca->heap)); +	struct bucket *b; +	return (b = heap_peek(&ca->heap)) ? GC_SECTORS_USED(b) : 0;  } -void bch_moving_gc(struct closure *cl) +void bch_moving_gc(struct cache_set *c)  { -	struct cache_set *c = container_of(cl, struct cache_set, gc.cl);  	struct cache *ca;  	struct bucket *b;  	unsigned i;  	if (!c->copy_gc_enabled) -		closure_return(cl); +		return;  	mutex_lock(&c->bucket_lock);  	for_each_cache(ca, c, i) {  		unsigned sectors_to_move = 0;  		unsigned reserve_sectors = ca->sb.bucket_size * -			min(fifo_used(&ca->free), ca->free.size / 2); +			fifo_used(&ca->free[RESERVE_MOVINGGC]);  		ca->heap.used = 0;  		for_each_bucket(b, ca) { -			if (!GC_SECTORS_USED(b)) +			if (GC_MARK(b) == GC_MARK_METADATA || +			    !GC_SECTORS_USED(b) || +			    GC_SECTORS_USED(b) == ca->sb.bucket_size || +			    atomic_read(&b->pin))  				continue;  			if (!heap_full(&ca->heap)) { @@ -233,22 +238,19 @@ void bch_moving_gc(struct closure *cl)  			sectors_to_move -= GC_SECTORS_USED(b);  		} -		ca->gc_move_threshold = bucket_heap_top(ca); - -		pr_debug("threshold %u", ca->gc_move_threshold); +		while (heap_pop(&ca->heap, b, bucket_cmp)) +			SET_GC_MOVE(b, 1);  	}  	mutex_unlock(&c->bucket_lock);  	c->moving_gc_keys.last_scanned = ZERO_KEY; -	closure_init(&c->moving_gc, cl); -	read_moving(&c->moving_gc); - -	closure_return(cl); +	read_moving(c);  }  void bch_moving_init_cache_set(struct cache_set *c)  {  	bch_keybuf_init(&c->moving_gc_keys); +	sema_init(&c->moving_in_flight, 64);  }  | 
