Skip to content

Commit

Permalink
Update bcachefs sources to 2be6fc9b111c bcachefs: bch2_gc_btree() sho…
Browse files Browse the repository at this point in the history
…uld not use btree_root_lock

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Jul 5, 2024
1 parent d061c7e commit 8b06995
Show file tree
Hide file tree
Showing 40 changed files with 477 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9404a01d3dc5553b106fa590602f4771b8e0b8ae
2be6fc9b111cad37da8838e39c66244767bc7d0a
7 changes: 7 additions & 0 deletions include/linux/closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct closure {
#ifdef CONFIG_DEBUG_CLOSURES
#define CLOSURE_MAGIC_DEAD 0xc054dead
#define CLOSURE_MAGIC_ALIVE 0xc054a11e
#define CLOSURE_MAGIC_STACK 0xc05451cc

unsigned int magic;
struct list_head all;
Expand Down Expand Up @@ -323,12 +324,18 @@ static inline void closure_init_stack(struct closure *cl)
{
memset(cl, 0, sizeof(struct closure));
atomic_set(&cl->remaining, CLOSURE_REMAINING_INITIALIZER);
#ifdef CONFIG_DEBUG_CLOSURES
cl->magic = CLOSURE_MAGIC_STACK;
#endif
}

static inline void closure_init_stack_release(struct closure *cl)
{
memset(cl, 0, sizeof(struct closure));
atomic_set_release(&cl->remaining, CLOSURE_REMAINING_INITIALIZER);
#ifdef CONFIG_DEBUG_CLOSURES
cl->magic = CLOSURE_MAGIC_STACK;
#endif
}

/**
Expand Down
2 changes: 2 additions & 0 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ struct lock_class_key {};
struct task_struct;

# define lock_acquire(l, s, t, r, c, n, i) do { } while (0)
# define lock_acquire_exclusive(...) do { } while (0)
# define lockdep_set_notrack_class(...) do { } while (0)
# define lock_release(l, i) do { } while (0)
# define lock_set_class(l, n, k, s, i) do { } while (0)
# define lock_set_subclass(l, s, i) do { } while (0)
Expand Down
4 changes: 2 additions & 2 deletions libbcachefs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ int bch2_set_acl(struct mnt_idmap *idmap,
{
struct bch_inode_info *inode = to_bch_ei(dentry->d_inode);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct btree_trans *trans = bch2_trans_get(c);
struct btree_iter inode_iter = { NULL };
struct bch_inode_unpacked inode_u;
struct posix_acl *acl;
umode_t mode;
int ret;

mutex_lock(&inode->ei_update_lock);
struct btree_trans *trans = bch2_trans_get(c);
retry:
bch2_trans_begin(trans);
acl = _acl;
Expand Down Expand Up @@ -394,8 +394,8 @@ int bch2_set_acl(struct mnt_idmap *idmap,

set_cached_acl(&inode->v, type, acl);
err:
mutex_unlock(&inode->ei_update_lock);
bch2_trans_put(trans);
mutex_unlock(&inode->ei_update_lock);

return ret;
}
Expand Down
48 changes: 23 additions & 25 deletions libbcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "alloc_background.h"
#include "alloc_foreground.h"
#include "backpointers.h"
#include "bkey_buf.h"
#include "btree_cache.h"
#include "btree_io.h"
#include "btree_key_cache.h"
Expand Down Expand Up @@ -1600,13 +1601,13 @@ int bch2_check_alloc_info(struct bch_fs *c)
}

static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
struct btree_iter *alloc_iter)
struct btree_iter *alloc_iter,
struct bkey_buf *last_flushed)
{
struct bch_fs *c = trans->c;
struct btree_iter lru_iter;
struct bch_alloc_v4 a_convert;
const struct bch_alloc_v4 *a;
struct bkey_s_c alloc_k, lru_k;
struct bkey_s_c alloc_k;
struct printbuf buf = PRINTBUF;
int ret;

Expand All @@ -1620,6 +1621,14 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,

a = bch2_alloc_to_v4(alloc_k, &a_convert);

if (a->fragmentation_lru) {
ret = bch2_lru_check_set(trans, BCH_LRU_FRAGMENTATION_START,
a->fragmentation_lru,
alloc_k, last_flushed);
if (ret)
return ret;
}

if (a->data_type != BCH_DATA_cached)
return 0;

Expand All @@ -1644,41 +1653,30 @@ static int bch2_check_alloc_to_lru_ref(struct btree_trans *trans,
a = &a_mut->v;
}

lru_k = bch2_bkey_get_iter(trans, &lru_iter, BTREE_ID_lru,
lru_pos(alloc_k.k->p.inode,
bucket_to_u64(alloc_k.k->p),
a->io_time[READ]), 0);
ret = bkey_err(lru_k);
ret = bch2_lru_check_set(trans, alloc_k.k->p.inode, a->io_time[READ],
alloc_k, last_flushed);
if (ret)
return ret;

if (fsck_err_on(lru_k.k->type != KEY_TYPE_set,
trans, alloc_key_to_missing_lru_entry,
"missing lru entry\n"
" %s",
(printbuf_reset(&buf),
bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
ret = bch2_lru_set(trans,
alloc_k.k->p.inode,
bucket_to_u64(alloc_k.k->p),
a->io_time[READ]);
if (ret)
goto err;
}
goto err;
err:
fsck_err:
bch2_trans_iter_exit(trans, &lru_iter);
printbuf_exit(&buf);
return ret;
}

int bch2_check_alloc_to_lru_refs(struct bch_fs *c)
{
struct bkey_buf last_flushed;

bch2_bkey_buf_init(&last_flushed);
bkey_init(&last_flushed.k->k);

int ret = bch2_trans_run(c,
for_each_btree_key_commit(trans, iter, BTREE_ID_alloc,
POS_MIN, BTREE_ITER_prefetch, k,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
bch2_check_alloc_to_lru_ref(trans, &iter)));
bch2_check_alloc_to_lru_ref(trans, &iter, &last_flushed)));

bch2_bkey_buf_exit(&last_flushed, c);
bch_err_fn(c, ret);
return ret;
}
Expand Down
10 changes: 9 additions & 1 deletion libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,14 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
if (usage->d[BCH_DATA_need_gc_gens].buckets > avail)
bch2_gc_gens_async(c);

if (should_invalidate_buckets(ca, *usage))
if (should_invalidate_buckets(ca, *usage)) {
bch2_dev_do_invalidates(ca);
rcu_read_lock();
struct task_struct *t = rcu_dereference(c->copygc_thread);
if (t)
wake_up_process(t);
rcu_read_unlock();
}

if (!avail) {
if (cl && !waiting) {
Expand Down Expand Up @@ -1703,6 +1709,7 @@ void bch2_fs_alloc_debug_to_text(struct printbuf *out, struct bch_fs *c)
for (unsigned i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
nr[c->open_buckets[i].data_type]++;

printbuf_tabstops_reset(out);
printbuf_tabstop_push(out, 24);

prt_printf(out, "hidden\t%llu\n", percpu_u64_get(&c->usage->hidden));
Expand Down Expand Up @@ -1734,6 +1741,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
for (unsigned i = 0; i < ARRAY_SIZE(c->open_buckets); i++)
nr[c->open_buckets[i].data_type]++;

printbuf_tabstops_reset(out);
printbuf_tabstop_push(out, 12);
printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 16);
Expand Down
70 changes: 26 additions & 44 deletions libbcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,6 @@ int bch2_check_btree_backpointers(struct bch_fs *c)
return ret;
}

static inline bool bkey_and_val_eq(struct bkey_s_c l, struct bkey_s_c r)
{
return bpos_eq(l.k->p, r.k->p) &&
bkey_bytes(l.k) == bkey_bytes(r.k) &&
!memcmp(l.v, r.v, bkey_val_bytes(l.k));
}

struct extents_to_bp_state {
struct bpos bucket_start;
struct bpos bucket_end;
Expand Down Expand Up @@ -536,11 +529,8 @@ static int check_bp_exists(struct btree_trans *trans,
struct btree_iter other_extent_iter = {};
struct printbuf buf = PRINTBUF;
struct bkey_s_c bp_k;
struct bkey_buf tmp;
int ret = 0;

bch2_bkey_buf_init(&tmp);

struct bch_dev *ca = bch2_dev_bucket_tryget(c, bucket);
if (!ca) {
prt_str(&buf, "extent for nonexistent device:bucket ");
Expand All @@ -565,22 +555,9 @@ static int check_bp_exists(struct btree_trans *trans,

if (bp_k.k->type != KEY_TYPE_backpointer ||
memcmp(bkey_s_c_to_backpointer(bp_k).v, &bp, sizeof(bp))) {
bch2_bkey_buf_reassemble(&tmp, c, orig_k);

if (!bkey_and_val_eq(orig_k, bkey_i_to_s_c(s->last_flushed.k))) {
if (bp.level) {
bch2_trans_unlock(trans);
bch2_btree_interior_updates_flush(c);
}

ret = bch2_btree_write_buffer_flush_sync(trans);
if (ret)
goto err;

bch2_bkey_buf_copy(&s->last_flushed, c, tmp.k);
ret = -BCH_ERR_transaction_restart_write_buffer_flush;
goto out;
}
ret = bch2_btree_write_buffer_maybe_flush(trans, orig_k, &s->last_flushed);
if (ret)
goto err;

goto check_existing_bp;
}
Expand All @@ -589,7 +566,6 @@ static int check_bp_exists(struct btree_trans *trans,
fsck_err:
bch2_trans_iter_exit(trans, &other_extent_iter);
bch2_trans_iter_exit(trans, &bp_iter);
bch2_bkey_buf_exit(&tmp, c);
bch2_dev_put(ca);
printbuf_exit(&buf);
return ret;
Expand Down Expand Up @@ -794,6 +770,8 @@ static int bch2_get_btree_in_memory_pos(struct btree_trans *trans,
!((1U << btree) & btree_interior_mask))
continue;

bch2_trans_begin(trans);

__for_each_btree_node(trans, iter, btree,
btree == start.btree ? start.pos : POS_MIN,
0, depth, BTREE_ITER_prefetch, b, ret) {
Expand Down Expand Up @@ -905,7 +883,7 @@ static int check_one_backpointer(struct btree_trans *trans,
struct bbpos start,
struct bbpos end,
struct bkey_s_c_backpointer bp,
struct bpos *last_flushed_pos)
struct bkey_buf *last_flushed)
{
struct bch_fs *c = trans->c;
struct btree_iter iter;
Expand All @@ -925,20 +903,18 @@ static int check_one_backpointer(struct btree_trans *trans,
if (ret)
return ret;

if (!k.k && !bpos_eq(*last_flushed_pos, bp.k->p)) {
*last_flushed_pos = bp.k->p;
ret = bch2_btree_write_buffer_flush_sync(trans) ?:
-BCH_ERR_transaction_restart_write_buffer_flush;
goto out;
}
if (!k.k) {
ret = bch2_btree_write_buffer_maybe_flush(trans, bp.s_c, last_flushed);
if (ret)
goto out;

if (fsck_err_on(!k.k,
trans, backpointer_to_missing_ptr,
"backpointer for missing %s\n %s",
bp.v->level ? "btree node" : "extent",
(bch2_bkey_val_to_text(&buf, c, bp.s_c), buf.buf))) {
ret = bch2_btree_delete_at_buffered(trans, BTREE_ID_backpointers, bp.k->p);
goto out;
if (fsck_err(trans, backpointer_to_missing_ptr,
"backpointer for missing %s\n %s",
bp.v->level ? "btree node" : "extent",
(bch2_bkey_val_to_text(&buf, c, bp.s_c), buf.buf))) {
ret = bch2_btree_delete_at_buffered(trans, BTREE_ID_backpointers, bp.k->p);
goto out;
}
}
out:
fsck_err:
Expand All @@ -951,14 +927,20 @@ static int bch2_check_backpointers_to_extents_pass(struct btree_trans *trans,
struct bbpos start,
struct bbpos end)
{
struct bpos last_flushed_pos = SPOS_MAX;
struct bkey_buf last_flushed;

return for_each_btree_key_commit(trans, iter, BTREE_ID_backpointers,
bch2_bkey_buf_init(&last_flushed);
bkey_init(&last_flushed.k->k);

int ret = for_each_btree_key_commit(trans, iter, BTREE_ID_backpointers,
POS_MIN, BTREE_ITER_prefetch, k,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
check_one_backpointer(trans, start, end,
bkey_s_c_to_backpointer(k),
&last_flushed_pos));
&last_flushed));

bch2_bkey_buf_exit(&last_flushed, trans->c);
return ret;
}

int bch2_check_backpointers_to_extents(struct bch_fs *c)
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ struct bch_fs {
struct bch_fs_rebalance rebalance;

/* COPYGC */
struct task_struct *copygc_thread;
struct task_struct __rcu *copygc_thread;
struct write_point copygc_write_point;
s64 copygc_wait_at;
s64 copygc_wait;
Expand Down
5 changes: 3 additions & 2 deletions libbcachefs/bkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,9 @@ int bch2_bkey_format_invalid(struct bch_fs *c,
bch2_bkey_format_field_overflows(f, i)) {
unsigned unpacked_bits = bch2_bkey_format_current.bits_per_field[i];
u64 unpacked_max = ~((~0ULL << 1) << (unpacked_bits - 1));
u64 packed_max = f->bits_per_field[i]
? ~((~0ULL << 1) << (f->bits_per_field[i] - 1))
unsigned packed_bits = min(64, f->bits_per_field[i]);
u64 packed_max = packed_bits
? ~((~0ULL << 1) << (packed_bits - 1))
: 0;

prt_printf(err, "field %u too large: %llu + %llu > %llu",
Expand Down
7 changes: 7 additions & 0 deletions libbcachefs/bkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ static inline struct bpos bkey_max(struct bpos l, struct bpos r)
return bkey_gt(l, r) ? l : r;
}

static inline bool bkey_and_val_eq(struct bkey_s_c l, struct bkey_s_c r)
{
return bpos_eq(l.k->p, r.k->p) &&
bkey_bytes(l.k) == bkey_bytes(r.k) &&
!memcmp(l.v, r.v, bkey_val_bytes(l.k));
}

void bch2_bpos_swab(struct bpos *);
void bch2_bkey_swab_key(const struct bkey_format *, struct bkey_packed *);

Expand Down
Loading

0 comments on commit 8b06995

Please sign in to comment.