path->preserve = false;
}
- bch2_trans_cond_resched(trans);
+ if (!trans->restarted &&
+ (need_resched() ||
+ ktime_get_ns() - trans->last_begin_time > BTREE_TRANS_MAX_LOCK_HOLD_TIME_NS)) {
+ bch2_trans_unlock(trans);
+ cond_resched();
+ bch2_trans_relock(trans);
+ }
if (trans->restarted)
bch2_btree_path_traverse_all(trans);
trans->restarted = false;
+ trans->last_begin_time = ktime_get_ns();
}
static void bch2_trans_alloc_paths(struct btree_trans *trans, struct bch_fs *c)
memset(trans, 0, sizeof(*trans));
trans->c = c;
trans->fn = fn;
+ trans->last_begin_time = ktime_get_ns();
trans->task = current;
trans->journal_replay_not_finished =
!test_bit(JOURNAL_REPLAY_DONE, &c->journal.flags);
#define BTREE_TRANS_MEM_MAX (1U << 16)
+#define BTREE_TRANS_MAX_LOCK_HOLD_TIME_NS 10000
+
struct btree_trans {
struct bch_fs *c;
const char *fn;
struct list_head list;
+ u64 last_begin_time;
struct btree *locking;
unsigned locking_path_idx;
struct bpos locking_pos;