Skip to content

Commit

Permalink
Update bcachefs sources to 0bac91c2c902 bcachefs: BCH_DATA_unstriped
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
  • Loading branch information
Kent Overstreet committed Dec 21, 2023
1 parent 2b97686 commit 544a38d
Show file tree
Hide file tree
Showing 36 changed files with 368 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1a739db0b256dc56d4e9fdc33a11d0728d7672d2
0bac91c2c9022457751ad60e711ffb41ff18d5a3
30 changes: 23 additions & 7 deletions libbcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,41 @@ int bch2_alloc_v4_invalid(struct bch_fs *c, struct bkey_s_c k,
"invalid data type (got %u should be %u)",
a.v->data_type, alloc_data_type(*a.v, a.v->data_type));

unsigned stripe_sectors = BCH_ALLOC_V4_BACKPOINTERS_START(a.v) * sizeof(u64) >
offsetof(struct bch_alloc_v4, stripe_sectors)
? a.v->stripe_sectors
: 0;

switch (a.v->data_type) {
case BCH_DATA_free:
case BCH_DATA_need_gc_gens:
case BCH_DATA_need_discard:
bkey_fsck_err_on(bch2_bucket_sectors(*a.v) || a.v->stripe,
bkey_fsck_err_on(stripe_sectors ||
a.v->dirty_sectors ||
a.v->cached_sectors ||
a.v->stripe,
c, err, alloc_key_empty_but_have_data,
"empty data type free but have data");
"empty data type free but have data %u.%u.%u %u",
stripe_sectors,
a.v->dirty_sectors,
a.v->cached_sectors,
a.v->stripe);
break;
case BCH_DATA_sb:
case BCH_DATA_journal:
case BCH_DATA_btree:
case BCH_DATA_user:
case BCH_DATA_parity:
bkey_fsck_err_on(!bch2_bucket_sectors_dirty(*a.v),
bkey_fsck_err_on(!a.v->dirty_sectors &&
!stripe_sectors,
c, err, alloc_key_dirty_sectors_0,
"data_type %s but dirty_sectors==0",
bch2_data_types[a.v->data_type]);
break;
case BCH_DATA_cached:
bkey_fsck_err_on(!a.v->cached_sectors ||
bch2_bucket_sectors_dirty(*a.v) ||
a.v->dirty_sectors ||
stripe_sectors ||
a.v->stripe,
c, err, alloc_key_cached_inconsistency,
"data type inconsistency");
Expand Down Expand Up @@ -308,6 +322,7 @@ void bch2_alloc_v4_swab(struct bkey_s k)
a->stripe = swab32(a->stripe);
a->nr_external_backpointers = swab32(a->nr_external_backpointers);
a->fragmentation_lru = swab64(a->fragmentation_lru);
a->stripe_sectors = swab32(a->stripe_sectors);

bps = alloc_v4_backpointers(a);
for (bp = bps; bp < bps + BCH_ALLOC_V4_NR_BACKPOINTERS(a); bp++) {
Expand Down Expand Up @@ -340,6 +355,8 @@ void bch2_alloc_to_text(struct printbuf *out, struct bch_fs *c, struct bkey_s_c
prt_newline(out);
prt_printf(out, "dirty_sectors %u", a->dirty_sectors);
prt_newline(out);
prt_printf(out, "stripe_sectors %u", a->stripe_sectors);
prt_newline(out);
prt_printf(out, "cached_sectors %u", a->cached_sectors);
prt_newline(out);
prt_printf(out, "stripe %u", a->stripe);
Expand Down Expand Up @@ -466,7 +483,6 @@ bch2_trans_start_alloc_update(struct btree_trans *trans, struct btree_iter *iter
int ret;

k = bch2_bkey_get_iter(trans, iter, BTREE_ID_alloc, pos,
BTREE_ITER_WITH_UPDATES|
BTREE_ITER_CACHED|
BTREE_ITER_INTENT);
ret = bkey_err(k);
Expand Down Expand Up @@ -729,8 +745,7 @@ static noinline int bch2_bucket_gen_update(struct btree_trans *trans,
return ret;

k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_bucket_gens, pos,
BTREE_ITER_INTENT|
BTREE_ITER_WITH_UPDATES);
BTREE_ITER_INTENT);
ret = bkey_err(k);
if (ret)
return ret;
Expand Down Expand Up @@ -1743,6 +1758,7 @@ static int invalidate_one_bucket(struct btree_trans *trans,
a->v.gen++;
a->v.data_type = 0;
a->v.dirty_sectors = 0;
a->v.stripe_sectors = 0;
a->v.cached_sectors = 0;
a->v.io_time[READ] = atomic64_read(&c->io_clock[READ].now);
a->v.io_time[WRITE] = atomic64_read(&c->io_clock[WRITE].now);
Expand Down
14 changes: 10 additions & 4 deletions libbcachefs/alloc_background.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ static inline u8 alloc_gc_gen(struct bch_alloc_v4 a)
}

static inline enum bch_data_type __alloc_data_type(u32 dirty_sectors,
u32 stripe_sectors,
u32 cached_sectors,
u32 stripe,
struct bch_alloc_v4 a,
enum bch_data_type data_type)
{
if (stripe)
return data_type == BCH_DATA_parity ? data_type : BCH_DATA_stripe;
if (dirty_sectors)
if (dirty_sectors | stripe_sectors)
return data_type;
if (cached_sectors)
return BCH_DATA_cached;
Expand All @@ -62,7 +63,7 @@ static inline enum bch_data_type __alloc_data_type(u32 dirty_sectors,
static inline enum bch_data_type alloc_data_type(struct bch_alloc_v4 a,
enum bch_data_type data_type)
{
return __alloc_data_type(a.dirty_sectors, a.cached_sectors,
return __alloc_data_type(a.dirty_sectors, a.stripe_sectors, a.cached_sectors,
a.stripe, a, data_type);
}

Expand All @@ -73,12 +74,12 @@ static inline enum bch_data_type bucket_data_type(enum bch_data_type data_type)

static inline unsigned bch2_bucket_sectors(struct bch_alloc_v4 a)
{
return a.dirty_sectors + a.cached_sectors;
return a.stripe_sectors + a.dirty_sectors + a.cached_sectors;
}

static inline unsigned bch2_bucket_sectors_dirty(struct bch_alloc_v4 a)
{
return a.dirty_sectors;
return a.stripe_sectors + a.dirty_sectors;
}

static inline unsigned bch2_bucket_sectors_fragmented(struct bch_dev *ca,
Expand All @@ -89,6 +90,11 @@ static inline unsigned bch2_bucket_sectors_fragmented(struct bch_dev *ca,
return d ? max(0, ca->mi.bucket_size - d) : 0;
}

static inline unsigned bch2_bucket_sectors_unstriped(struct bch_alloc_v4 a)
{
return a.data_type == BCH_DATA_stripe ? a.dirty_sectors : 0;
}

static inline u64 alloc_lru_idx_read(struct bch_alloc_v4 a)
{
return a.data_type == BCH_DATA_cached ? a.io_time[READ] : 0;
Expand Down
14 changes: 11 additions & 3 deletions libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,17 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
goto alloc_done;

/* Don't retry from all devices if we're out of open buckets: */
if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
goto allocate_blocking;
if (bch2_err_matches(ret, BCH_ERR_open_buckets_empty)) {
int ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
target, erasure_code,
nr_replicas, &nr_effective,
&have_cache, watermark,
flags, cl);
if (!ret ||
bch2_err_matches(ret, BCH_ERR_transaction_restart) ||
bch2_err_matches(ret, BCH_ERR_open_buckets_empty))
goto alloc_done;
}

/*
* Only try to allocate cache (durability = 0 devices) from the
Expand All @@ -1375,7 +1384,6 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
&have_cache, watermark,
flags, cl);
} else {
allocate_blocking:
ret = open_bucket_add_buckets(trans, &ptrs, wp, devs_have,
target, erasure_code,
nr_replicas, &nr_effective,
Expand Down
3 changes: 1 addition & 2 deletions libbcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ int bch2_bucket_backpointer_mod_nowritebuffer(struct btree_trans *trans,
k = bch2_bkey_get_iter(trans, &bp_iter, BTREE_ID_backpointers,
bp_k->k.p,
BTREE_ITER_INTENT|
BTREE_ITER_SLOTS|
BTREE_ITER_WITH_UPDATES);
BTREE_ITER_SLOTS);
ret = bkey_err(k);
if (ret)
goto err;
Expand Down
6 changes: 6 additions & 0 deletions libbcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ do { \
bch_err(_c, "%s(): error %s", __func__, bch2_err_str(_ret));\
} while (0)

#define bch_err_fn_ratelimited(_c, _ret) \
do { \
if (should_print_err(_ret)) \
bch_err_ratelimited(_c, "%s(): error %s", __func__, bch2_err_str(_ret));\
} while (0)

#define bch_err_msg(_c, _ret, _msg, ...) \
do { \
if (should_print_err(_ret)) \
Expand Down
5 changes: 4 additions & 1 deletion libbcachefs/bcachefs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,8 @@ struct bch_alloc_v4 {
__u32 stripe;
__u32 nr_external_backpointers;
__u64 fragmentation_lru;
__u32 stripe_sectors;
__u32 pad;
} __packed __aligned(8);

#define BCH_ALLOC_V4_U64s_V0 6
Expand Down Expand Up @@ -1404,7 +1406,8 @@ LE64_BITMASK(BCH_KDF_SCRYPT_P, struct bch_sb_field_crypt, kdf_flags, 32, 48);
x(parity, 6) \
x(stripe, 7) \
x(need_gc_gens, 8) \
x(need_discard, 9)
x(need_discard, 9) \
x(unstriped, 10)

enum bch_data_type {
#define x(t, n) BCH_DATA_##t,
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/bcachefs_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct bch_ioctl_fsck_offline {
__u64 flags;
__u64 opts; /* string */
__u64 nr_devs;
__u64 devs[0];
__u64 devs[] __counted_by(nr_devs);
};

/*
Expand Down
10 changes: 8 additions & 2 deletions libbcachefs/btree_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ static int bch2_check_fix_ptrs(struct btree_trans *trans, enum btree_id btree_id
g->gen = p.ptr.gen;
g->data_type = 0;
g->dirty_sectors = 0;
g->stripe_sectors = 0;
g->cached_sectors = 0;
set_bit(BCH_FS_need_another_gc, &c->flags);
} else {
Expand Down Expand Up @@ -1348,6 +1349,7 @@ static inline bool bch2_alloc_v4_cmp(struct bch_alloc_v4 l,
l.oldest_gen != r.oldest_gen ||
l.data_type != r.data_type ||
l.dirty_sectors != r.dirty_sectors ||
l.stripe_sectors != r.stripe_sectors ||
l.cached_sectors != r.cached_sectors ||
l.stripe_redundancy != r.stripe_redundancy ||
l.stripe != r.stripe;
Expand Down Expand Up @@ -1378,6 +1380,7 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
* fix that here:
*/
type = __alloc_data_type(b->dirty_sectors,
b->stripe_sectors,
b->cached_sectors,
b->stripe,
*old,
Expand Down Expand Up @@ -1431,6 +1434,8 @@ static int bch2_alloc_write_key(struct btree_trans *trans,
gen);
copy_bucket_field(alloc_key_dirty_sectors_wrong,
dirty_sectors);
copy_bucket_field(alloc_key_stripe_sectors_wrong,
stripe_sectors);
copy_bucket_field(alloc_key_cached_sectors_wrong,
cached_sectors);
copy_bucket_field(alloc_key_stripe_wrong,
Expand Down Expand Up @@ -1518,6 +1523,7 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
a->data_type == BCH_DATA_parity)) {
g->data_type = a->data_type;
g->dirty_sectors = a->dirty_sectors;
g->stripe_sectors = a->stripe_sectors;
g->cached_sectors = a->cached_sectors;
g->stripe = a->stripe;
g->stripe_redundancy = a->stripe_redundancy;
Expand All @@ -1543,6 +1549,7 @@ static void bch2_gc_alloc_reset(struct bch_fs *c, bool metadata_only)
continue;
g->data_type = 0;
g->dirty_sectors = 0;
g->stripe_sectors = 0;
g->cached_sectors = 0;
}
}
Expand Down Expand Up @@ -1987,7 +1994,6 @@ static int bch2_gc_thread(void *arg)
struct io_clock *clock = &c->io_clock[WRITE];
unsigned long last = atomic64_read(&clock->now);
unsigned last_kick = atomic_read(&c->kick_gc);
int ret;

set_freezable();

Expand Down Expand Up @@ -2027,7 +2033,7 @@ static int bch2_gc_thread(void *arg)
#if 0
ret = bch2_gc(c, false, false);
#else
ret = bch2_gc_gens(c);
bch2_gc_gens(c);
#endif
debug_check_no_locks_held();
}
Expand Down
Loading

0 comments on commit 544a38d

Please # to comment.