Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Moving/copying garbage collector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2012 Google, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "bcache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "request.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <trace/events/bcache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) struct moving_io {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	struct closure		cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	struct keybuf_key	*w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	struct data_insert_op	op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct bbio		bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static bool moving_pred(struct keybuf *buf, struct bkey *k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct cache_set *c = container_of(buf, struct cache_set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 					   moving_gc_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	for (i = 0; i < KEY_PTRS(k); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		if (ptr_available(c, k, i) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		    GC_MOVE(PTR_BUCKET(c, k, i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* Moving GC - IO loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static void moving_io_destructor(struct closure *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct moving_io *io = container_of(cl, struct moving_io, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	kfree(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static void write_moving_finish(struct closure *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct moving_io *io = container_of(cl, struct moving_io, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct bio *bio = &io->bio.bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	bio_free_pages(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (io->op.replace_collision)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		trace_bcache_gc_copy_collision(&io->w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	bch_keybuf_del(&io->op.c->moving_gc_keys, io->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	up(&io->op.c->moving_in_flight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	closure_return_with_destructor(cl, moving_io_destructor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static void read_moving_endio(struct bio *bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct bbio *b = container_of(bio, struct bbio, bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct moving_io *io = container_of(bio->bi_private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 					    struct moving_io, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (bio->bi_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		io->op.status = bio->bi_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	else if (!KEY_DIRTY(&b->key) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		 ptr_stale(io->op.c, &b->key, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		io->op.status = BLK_STS_IOERR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	bch_bbio_endio(io->op.c, bio, bio->bi_status, "reading data to move");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) static void moving_init(struct moving_io *io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct bio *bio = &io->bio.bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	bio_init(bio, bio->bi_inline_vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		 DIV_ROUND_UP(KEY_SIZE(&io->w->key), PAGE_SECTORS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	bio_get(bio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	bio_set_prio(bio, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	bio->bi_iter.bi_size	= KEY_SIZE(&io->w->key) << 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	bio->bi_private		= &io->cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	bch_bio_map(bio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static void write_moving(struct closure *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	struct moving_io *io = container_of(cl, struct moving_io, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	struct data_insert_op *op = &io->op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (!op->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		moving_init(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		io->bio.bio.bi_iter.bi_sector = KEY_START(&io->w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		op->write_prio		= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		op->bio			= &io->bio.bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		op->writeback		= KEY_DIRTY(&io->w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		op->csum		= KEY_CSUM(&io->w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		bkey_copy(&op->replace_key, &io->w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		op->replace		= true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		closure_call(&op->cl, bch_data_insert, NULL, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	continue_at(cl, write_moving_finish, op->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static void read_moving_submit(struct closure *cl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct moving_io *io = container_of(cl, struct moving_io, cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	struct bio *bio = &io->bio.bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	bch_submit_bbio(bio, io->op.c, &io->w->key, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	continue_at(cl, write_moving, io->op.wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static void read_moving(struct cache_set *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct keybuf_key *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct moving_io *io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct closure cl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	closure_init_stack(&cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* XXX: if we error, background writeback could stall indefinitely */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	while (!test_bit(CACHE_SET_STOPPING, &c->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		w = bch_keybuf_next_rescan(c, &c->moving_gc_keys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 					   &MAX_KEY, moving_pred);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (!w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		if (ptr_stale(c, &w->key, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			bch_keybuf_del(&c->moving_gc_keys, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		io = kzalloc(struct_size(io, bio.bio.bi_inline_vecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					 DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if (!io)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		w->private	= io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		io->w		= w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		io->op.inode	= KEY_INODE(&w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		io->op.c	= c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		io->op.wq	= c->moving_gc_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		moving_init(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		bio = &io->bio.bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		bio_set_op_attrs(bio, REQ_OP_READ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		bio->bi_end_io	= read_moving_endio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (bch_bio_alloc_pages(bio, GFP_KERNEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		trace_bcache_gc_copy(&w->key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		down(&c->moving_in_flight);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		closure_call(&io->cl, read_moving_submit, NULL, &cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) err:		if (!IS_ERR_OR_NULL(w->private))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			kfree(w->private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		bch_keybuf_del(&c->moving_gc_keys, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	closure_sync(&cl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static bool bucket_cmp(struct bucket *l, struct bucket *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return GC_SECTORS_USED(l) < GC_SECTORS_USED(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static unsigned int bucket_heap_top(struct cache *ca)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct bucket *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return (b = heap_peek(&ca->heap)) ? GC_SECTORS_USED(b) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) void bch_moving_gc(struct cache_set *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	struct cache *ca = c->cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	struct bucket *b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	unsigned long sectors_to_move, reserve_sectors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!c->copy_gc_enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	mutex_lock(&c->bucket_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	sectors_to_move = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	reserve_sectors = ca->sb.bucket_size *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			     fifo_used(&ca->free[RESERVE_MOVINGGC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	ca->heap.used = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	for_each_bucket(b, ca) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (GC_MARK(b) == GC_MARK_METADATA ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		    !GC_SECTORS_USED(b) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		    GC_SECTORS_USED(b) == ca->sb.bucket_size ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		    atomic_read(&b->pin))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (!heap_full(&ca->heap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			sectors_to_move += GC_SECTORS_USED(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			heap_add(&ca->heap, b, bucket_cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		} else if (bucket_cmp(b, heap_peek(&ca->heap))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			sectors_to_move -= bucket_heap_top(ca);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			sectors_to_move += GC_SECTORS_USED(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			ca->heap.data[0] = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			heap_sift(&ca->heap, 0, bucket_cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	while (sectors_to_move > reserve_sectors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		heap_pop(&ca->heap, b, bucket_cmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		sectors_to_move -= GC_SECTORS_USED(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	while (heap_pop(&ca->heap, b, bucket_cmp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		SET_GC_MOVE(b, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	mutex_unlock(&c->bucket_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	c->moving_gc_keys.last_scanned = ZERO_KEY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	read_moving(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void bch_moving_init_cache_set(struct cache_set *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	bch_keybuf_init(&c->moving_gc_keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	sema_init(&c->moving_in_flight, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }