#include "journal.h"
#include "journal_reclaim.h"
#include "keylist.h"
+#include "recovery.h"
#include "replicas.h"
#include "super-io.h"
BUG_ON(!b->c.level);
- if (!test_bit(BCH_FS_BTREE_INTERIOR_REPLAY_DONE, &c->flags))
+ if (!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags))
return;
bch2_btree_node_iter_init_from_start(&iter, b);
if (IS_ERR(wp))
return ERR_CAST(wp);
- if (wp->sectors_free < c->opts.btree_node_size) {
+ if (wp->sectors_free < btree_sectors(c)) {
struct open_bucket *ob;
unsigned i;
open_bucket_for_each(c, &wp->ptrs, ob, i)
- if (ob->sectors_free < c->opts.btree_node_size)
+ if (ob->sectors_free < btree_sectors(c))
ob->sectors_free = 0;
bch2_alloc_sectors_done(c, wp);
}
bkey_btree_ptr_v2_init(&tmp.k);
- bch2_alloc_sectors_append_ptrs(c, wp, &tmp.k, c->opts.btree_node_size);
+ bch2_alloc_sectors_append_ptrs(c, wp, &tmp.k, btree_sectors(c), false);
bch2_open_bucket_get(c, wp, &ob);
bch2_alloc_sectors_done(c, wp);
bch2_disk_reservation_put(c, &as->disk_res);
bch2_btree_reserve_put(as);
+ bch2_time_stats_update(&c->times[BCH_TIME_btree_interior_update_total],
+ as->start_time);
+
mutex_lock(&c->btree_interior_update_lock);
list_del(&as->unwritten_list);
list_del(&as->list);
- mutex_unlock(&c->btree_interior_update_lock);
closure_debug_destroy(&as->cl);
mempool_free(as, &c->btree_interior_update_pool);
+ /*
+ * Have to do the wakeup with btree_interior_update_lock still held,
+ * since being on btree_interior_update_list is our ref on @c:
+ */
closure_wake_up(&c->btree_interior_update_wait);
+
+ mutex_unlock(&c->btree_interior_update_lock);
}
static void btree_update_will_delete_key(struct btree_update *as,
static void bch2_btree_update_done(struct btree_update *as)
{
+ struct bch_fs *c = as->c;
+ u64 start_time = as->start_time;
+
BUG_ON(as->mode == BTREE_INTERIOR_NO_UPDATE);
if (as->took_gc_lock)
continue_at(&as->cl, btree_update_set_nodes_written,
as->c->btree_interior_update_worker);
+
+ bch2_time_stats_update(&c->times[BCH_TIME_btree_interior_update_foreground],
+ start_time);
}
static struct btree_update *
struct bch_fs *c = trans->c;
struct btree_update *as;
struct closure cl;
+ u64 start_time = local_clock();
int disk_res_flags = (flags & BTREE_INSERT_NOFAIL)
? BCH_DISK_RESERVATION_NOFAIL : 0;
int journal_flags = 0;
* instead of locking/reserving all the way to the root:
*/
if (!bch2_btree_path_upgrade(trans, path, U8_MAX)) {
- trace_trans_restart_iter_upgrade(trans->ip, _RET_IP_,
+ trace_trans_restart_iter_upgrade(trans->fn, _RET_IP_,
path->btree_id, &path->pos);
ret = btree_trans_restart(trans);
return ERR_PTR(ret);
memset(as, 0, sizeof(*as));
closure_init(&as->cl, NULL);
as->c = c;
+ as->start_time = start_time;
as->mode = BTREE_INTERIOR_NO_UPDATE;
as->took_gc_lock = !(flags & BTREE_INSERT_GC_LOCK_HELD);
as->btree_id = path->btree_id;
BTREE_UPDATE_JOURNAL_RES,
journal_flags);
if (ret) {
- trace_trans_restart_journal_preres_get(trans->ip, _RET_IP_);
+ trace_trans_restart_journal_preres_get(trans->fn, _RET_IP_);
goto err;
}
}
ret = bch2_disk_reservation_get(c, &as->disk_res,
- nr_nodes * c->opts.btree_node_size,
+ nr_nodes * btree_sectors(c),
c->opts.metadata_replicas,
disk_res_flags);
if (ret)
BUG_ON(insert->k.type == KEY_TYPE_btree_ptr_v2 &&
!btree_ptr_sectors_written(insert));
+ if (unlikely(!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags)))
+ bch2_journal_key_overwritten(c, b->c.btree_id, b->c.level, insert->k.p);
+
invalid = bch2_bkey_invalid(c, bkey_i_to_s_c(insert), btree_node_type(b)) ?:
bch2_bkey_in_btree_node(b, bkey_i_to_s_c(insert));
if (invalid) {
bch2_trans_verify_locks(trans);
- bch2_time_stats_update(&c->times[BCH_TIME_btree_node_split],
+ bch2_time_stats_update(&c->times[n2
+ ? BCH_TIME_btree_node_split
+ : BCH_TIME_btree_node_compact],
start_time);
}
struct btree *b, *m, *n, *prev, *next, *parent;
struct bpos sib_pos;
size_t sib_u64s;
+ u64 start_time = local_clock();
int ret = 0;
BUG_ON(!path->should_be_locked);
? bpos_predecessor(b->data->min_key)
: bpos_successor(b->data->max_key);
- sib_path = bch2_path_get(trans, false, path->btree_id, sib_pos,
- U8_MAX, level, true, _THIS_IP_);
+ sib_path = bch2_path_get(trans, path->btree_id, sib_pos,
+ U8_MAX, level, BTREE_ITER_INTENT, _THIS_IP_);
ret = bch2_btree_path_traverse(trans, sib_path, false);
if (ret)
goto err;
six_unlock_intent(&n->c.lock);
bch2_btree_update_done(as);
+
+ bch2_time_stats_update(&c->times[BCH_TIME_btree_node_merge], start_time);
out:
err:
bch2_path_put(trans, sib_path, true);
{
struct async_btree_rewrite *a;
- if (!test_bit(BCH_FS_BTREE_INTERIOR_REPLAY_DONE, &c->flags))
- return;
-
if (!percpu_ref_tryget(&c->writes))
return;