Skip to content

Commit

Permalink
Update bcachefs sources to c3e4d892b77b mean and variance: Promote to…
Browse files Browse the repository at this point in the history
… lib/math
  • Loading branch information
Kent Overstreet committed Nov 29, 2023
1 parent 1dc5842 commit 89b361f
Show file tree
Hide file tree
Showing 29 changed files with 224 additions and 176 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
feaca6edbd240bbd98d261097a97037c56a09eec
c3e4d892b77b9361c88854b0192223f68947b6b0
19 changes: 7 additions & 12 deletions libbcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ int bch2_bucket_gens_init(struct bch_fs *c)

if (have_bucket_gens_key && bkey_cmp(iter.pos, pos)) {
ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_no_enospc|
BCH_TRANS_COMMIT_lazy_rw,
BCH_TRANS_COMMIT_no_enospc,
bch2_btree_insert_trans(trans, BTREE_ID_bucket_gens, &g.k_i, 0));
if (ret)
break;
Expand All @@ -578,8 +577,7 @@ int bch2_bucket_gens_init(struct bch_fs *c)

if (have_bucket_gens_key && !ret)
ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_no_enospc|
BCH_TRANS_COMMIT_lazy_rw,
BCH_TRANS_COMMIT_no_enospc,
bch2_btree_insert_trans(trans, BTREE_ID_bucket_gens, &g.k_i, 0));

bch2_trans_put(trans);
Expand Down Expand Up @@ -1276,7 +1274,7 @@ static noinline_for_stack int bch2_check_discard_freespace_key(struct btree_tran
ret = bch2_btree_delete_extent_at(trans, iter,
iter->btree_id == BTREE_ID_freespace ? 1 : 0, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
BCH_TRANS_COMMIT_no_enospc|BCH_TRANS_COMMIT_lazy_rw);
BCH_TRANS_COMMIT_no_enospc);
goto out;
}

Expand Down Expand Up @@ -1413,8 +1411,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
}

ret = bch2_trans_commit(trans, NULL, NULL,
BCH_TRANS_COMMIT_no_enospc|
BCH_TRANS_COMMIT_lazy_rw);
BCH_TRANS_COMMIT_no_enospc);
if (ret)
goto bkey_err;

Expand Down Expand Up @@ -1472,7 +1469,7 @@ int bch2_check_alloc_info(struct bch_fs *c)
ret = for_each_btree_key_commit(trans, iter,
BTREE_ID_bucket_gens, POS_MIN,
BTREE_ITER_PREFETCH, k,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc|BCH_TRANS_COMMIT_lazy_rw,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
bch2_check_bucket_gens_key(trans, &iter, k));
err:
bch2_trans_put(trans);
Expand Down Expand Up @@ -1562,7 +1559,7 @@ int bch2_check_alloc_to_lru_refs(struct bch_fs *c)
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|BCH_TRANS_COMMIT_lazy_rw,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
bch2_check_alloc_to_lru_ref(trans, &iter)));
bch_err_fn(c, ret);
return ret;
Expand Down Expand Up @@ -1674,7 +1671,7 @@ static int bch2_discard_one_bucket(struct btree_trans *trans,
if (ret)
goto out;

this_cpu_inc(c->counters[BCH_COUNTER_bucket_discard]);
count_event(c, bucket_discard);
(*discarded)++;
out:
(*seen)++;
Expand Down Expand Up @@ -1877,7 +1874,6 @@ int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca,

ret = bch2_bucket_do_index(trans, k, a, true) ?:
bch2_trans_commit(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc);
if (ret)
goto bkey_err;
Expand All @@ -1898,7 +1894,6 @@ int bch2_dev_freespace_init(struct bch_fs *c, struct bch_dev *ca,

ret = bch2_btree_insert_trans(trans, BTREE_ID_freespace, freespace, 0) ?:
bch2_trans_commit(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc);
if (ret)
goto bkey_err;
Expand Down
4 changes: 2 additions & 2 deletions libbcachefs/alloc_background.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ static inline unsigned bch2_bucket_sectors_dirty(struct bch_alloc_v4 a)
static inline unsigned bch2_bucket_sectors_fragmented(struct bch_dev *ca,
struct bch_alloc_v4 a)
{
unsigned d = bch2_bucket_sectors_dirty(a);
int d = bch2_bucket_sectors_dirty(a);

return d ? max(0U, ca->mi.bucket_size - d) : 0;
return d ? max(0, ca->mi.bucket_size - d) : 0;
}

static inline u64 alloc_lru_idx_read(struct bch_alloc_v4 a)
Expand Down
4 changes: 1 addition & 3 deletions libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,11 +697,9 @@ static int add_new_bucket(struct bch_fs *c,
bch_dev_bkey_exists(c, ob->dev)->mi.durability;

BUG_ON(*nr_effective >= nr_replicas);
BUG_ON(flags & BCH_WRITE_ONLY_SPECIFIED_DEVS);

__clear_bit(ob->dev, devs_may_alloc->d);
*nr_effective += (flags & BCH_WRITE_ONLY_SPECIFIED_DEVS)
? durability : 1;
*nr_effective += durability;
*have_cache |= !durability;

ob_push(c, ptrs, ob);
Expand Down
6 changes: 2 additions & 4 deletions libbcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ int bch2_check_btree_backpointers(struct bch_fs *c)
ret = bch2_trans_run(c,
for_each_btree_key_commit(trans, iter,
BTREE_ID_backpointers, POS_MIN, 0, k,
NULL, NULL, BCH_TRANS_COMMIT_lazy_rw|BCH_TRANS_COMMIT_no_enospc,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
bch2_check_btree_backpointer(trans, &iter, k)));
if (ret)
bch_err_fn(c, ret);
Expand Down Expand Up @@ -621,7 +621,6 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
int level, depth = btree_type_has_ptrs(btree_id) ? 0 : 1;

ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc,
check_btree_root_to_backpointers(trans, btree_id,
bucket_start, bucket_end,
Expand All @@ -635,7 +634,6 @@ static int bch2_check_extents_to_backpointers_pass(struct btree_trans *trans,
BTREE_ITER_PREFETCH);
for_each_btree_key_continue(trans, iter, BTREE_ITER_PREFETCH, k, ret) {
ret = commit_do(trans, NULL, NULL,
BCH_TRANS_COMMIT_lazy_rw|
BCH_TRANS_COMMIT_no_enospc,
check_extent_to_backpointers(trans, btree_id, level,
bucket_start, bucket_end,
Expand Down Expand Up @@ -810,7 +808,7 @@ static int bch2_check_backpointers_to_extents_pass(struct btree_trans *trans,

return for_each_btree_key_commit(trans, iter, BTREE_ID_backpointers,
POS_MIN, BTREE_ITER_PREFETCH, k,
NULL, NULL, BCH_TRANS_COMMIT_lazy_rw|BCH_TRANS_COMMIT_no_enospc,
NULL, NULL, BCH_TRANS_COMMIT_no_enospc,
check_one_backpointer(trans, start, end,
bkey_s_c_to_backpointer(k),
&last_flushed_pos));
Expand Down
4 changes: 3 additions & 1 deletion libbcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@

#define race_fault(...) dynamic_fault("bcachefs:race")

#define count_event(_c, _name) this_cpu_inc((_c)->counters[BCH_COUNTER_##_name])

#define trace_and_count(_c, _name, ...) \
do { \
this_cpu_inc((_c)->counters[BCH_COUNTER_##_name]); \
count_event(_c, _name); \
trace_##_name(__VA_ARGS__); \
} while (0)

Expand Down
4 changes: 2 additions & 2 deletions libbcachefs/bcachefs_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ struct bch_ioctl_fs_usage {
__u32 replica_entries_bytes;
__u32 pad;

struct bch_replicas_usage replicas[0];
struct bch_replicas_usage replicas[];
};

/*
Expand Down Expand Up @@ -313,7 +313,7 @@ struct bch_ioctl_dev_usage_v2 {
__u32 bucket_size;
__u64 nr_buckets;

struct bch_ioctl_dev_usage_type d[0];
struct bch_ioctl_dev_usage_type d[];
};

/*
Expand Down
9 changes: 5 additions & 4 deletions libbcachefs/btree_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,8 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
rcu_assign_pointer(ca->buckets_gc, buckets);
}

for_each_btree_key(trans, iter, BTREE_ID_alloc, POS_MIN,
BTREE_ITER_PREFETCH, k, ret) {
ret = for_each_btree_key2(trans, iter, BTREE_ID_alloc, POS_MIN,
BTREE_ITER_PREFETCH, k, ({
ca = bch_dev_bkey_exists(c, k.k->p.inode);
g = gc_bucket(ca, k.k->p.offset);

Expand All @@ -1561,8 +1561,9 @@ static int bch2_gc_alloc_start(struct bch_fs *c, bool metadata_only)
g->stripe = a->stripe;
g->stripe_redundancy = a->stripe_redundancy;
}
}
bch2_trans_iter_exit(trans, &iter);

0;
}));
err:
bch2_trans_put(trans);
if (ret)
Expand Down
19 changes: 18 additions & 1 deletion libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,22 @@ static void bch2_trans_update_max_paths(struct btree_trans *trans)
trans->nr_max_paths = hweight64(trans->paths_allocated);
}

noinline __cold
int __bch2_btree_trans_too_many_iters(struct btree_trans *trans)
{
if (trace_trans_restart_too_many_iters_enabled()) {
struct printbuf buf = PRINTBUF;

bch2_trans_paths_to_text(&buf, trans);
trace_trans_restart_too_many_iters(trans, _THIS_IP_, buf.buf);
printbuf_exit(&buf);
}

count_event(trans->c, trans_restart_too_many_iters);

return btree_trans_restart(trans, BCH_ERR_transaction_restart_too_many_iters);
}

static noinline void btree_path_overflow(struct btree_trans *trans)
{
bch2_dump_trans_paths_updates(trans);
Expand Down Expand Up @@ -3027,14 +3043,15 @@ void bch2_btree_trans_to_text(struct printbuf *out, struct btree_trans *trans)
struct btree_path *path;
struct btree_bkey_cached_common *b;
static char lock_types[] = { 'r', 'i', 'w' };
struct task_struct *task = READ_ONCE(trans->locking_wait.task);
unsigned l, idx;

if (!out->nr_tabstops) {
printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 32);
}

prt_printf(out, "%i %s\n", trans->locking_wait.task->pid, trans->fn);
prt_printf(out, "%i %s\n", task ? task->pid : 0, trans->fn);

trans_for_each_path_safe(trans, path, idx) {
if (!path->nodes_locked)
Expand Down
8 changes: 4 additions & 4 deletions libbcachefs/btree_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,12 @@ static inline struct bkey_s_c bch2_btree_iter_peek_upto_type(struct btree_iter *
return bch2_btree_iter_peek_slot(iter);
}

int __bch2_btree_trans_too_many_iters(struct btree_trans *);

static inline int btree_trans_too_many_iters(struct btree_trans *trans)
{
if (hweight64(trans->paths_allocated) > BTREE_ITER_MAX - 8) {
trace_and_count(trans->c, trans_restart_too_many_iters, trans, _THIS_IP_);
return btree_trans_restart(trans, BCH_ERR_transaction_restart_too_many_iters);
}
if (hweight64(trans->paths_allocated) > BTREE_ITER_MAX - 8)
return __bch2_btree_trans_too_many_iters(trans);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_key_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ int bch2_btree_key_cache_journal_flush(struct journal *j,
}
six_unlock_read(&ck->c.lock);

ret = commit_do(trans, NULL, NULL, 0,
ret = lockrestart_do(trans,
btree_key_cache_flush_pos(trans, key, seq,
BCH_TRANS_COMMIT_journal_reclaim, false));
unlock:
Expand Down
25 changes: 22 additions & 3 deletions libbcachefs/btree_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,28 @@ static bool lock_graph_remove_non_waiters(struct lock_graph *g)
return false;
}

static void trace_would_deadlock(struct lock_graph *g, struct btree_trans *trans,
unsigned long ip)
{
struct bch_fs *c = trans->c;

count_event(c, trans_restart_would_deadlock);

if (trace_trans_restart_would_deadlock_enabled()) {
struct printbuf buf = PRINTBUF;

buf.atomic++;
print_cycle(&buf, g);

trace_trans_restart_would_deadlock(trans, ip, buf.buf);
printbuf_exit(&buf);
}
}

static int abort_lock(struct lock_graph *g, struct trans_waiting_for_lock *i)
{
if (i == g->g) {
trace_and_count(i->trans->c, trans_restart_would_deadlock, i->trans, _RET_IP_);
trace_would_deadlock(g, i->trans, _RET_IP_);
return btree_trans_restart(i->trans, BCH_ERR_transaction_restart_would_deadlock);
} else {
i->trans->lock_must_abort = true;
Expand Down Expand Up @@ -265,15 +283,16 @@ int bch2_check_for_deadlock(struct btree_trans *trans, struct printbuf *cycle)
unsigned path_idx;
int ret;

g.nr = 0;

if (trans->lock_must_abort) {
if (cycle)
return -1;

trace_and_count(trans->c, trans_restart_would_deadlock, trans, _RET_IP_);
trace_would_deadlock(&g, trans, _RET_IP_);
return btree_trans_restart(trans, BCH_ERR_transaction_restart_would_deadlock);
}

g.nr = 0;
lock_graph_down(&g, trans);
next:
if (!g.nr)
Expand Down
4 changes: 4 additions & 0 deletions libbcachefs/btree_update_interior.c
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,10 @@ int bch2_btree_node_update_key_get_iter(struct btree_trans *trans,

BUG_ON(!btree_node_hashed(b));

struct bch_extent_ptr *ptr;
bch2_bkey_drop_ptrs(bkey_i_to_s(new_key), ptr,
!bch2_bkey_has_device(bkey_i_to_s(&b->key), ptr->dev));

ret = bch2_btree_node_update_key(trans, &iter, b, new_key,
commit_flags, skip_triggers);
out:
Expand Down
Loading

0 comments on commit 89b361f

Please sign in to comment.