diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2022-07-13 06:03:21 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:09:35 -0400 |
commit | 43de721a33b214b253c07672c4c6ba7548f2d3e7 (patch) | |
tree | 874c14851b4a63c6e9ac22e968de2eb5ee033ab4 /fs/bcachefs/btree_iter.c | |
parent | a1783320d46e878ddf5d2bb3380c181d515a5ff3 (diff) | |
download | lwn-43de721a33b214b253c07672c4c6ba7548f2d3e7.tar.gz lwn-43de721a33b214b253c07672c4c6ba7548f2d3e7.zip |
bcachefs: Unlock in bch2_trans_begin() if we've held locks more than 10us
We try to ensure we never hold btree locks for too long - bcachefs tries
to be soft realtime. This adds a check when restarting a transaction,
where a transaction restart is cheap - if we've been holding locks for
too long, drop and retake them.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/btree_iter.c')
-rw-r--r-- | fs/bcachefs/btree_iter.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index b90aff2ad775..68d9d8ee6f97 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -3224,12 +3224,19 @@ void bch2_trans_begin(struct btree_trans *trans) 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) @@ -3259,6 +3266,7 @@ void __bch2_trans_init(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); |