Skip to content

Commit f82755e

Browse files
author
Kent Overstreet
committed
bcachefs: Data move path now uses bch2_trans_unlock_long()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent c4accde commit f82755e

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

fs/bcachefs/btree_iter.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,13 @@ void *__bch2_trans_kmalloc(struct btree_trans *trans, size_t size)
28332833
return p;
28342834
}
28352835

2836+
static inline void check_srcu_held_too_long(struct btree_trans *trans)
2837+
{
2838+
WARN(trans->srcu_held && time_after(jiffies, trans->srcu_lock_time + HZ * 10),
2839+
"btree trans held srcu lock (delaying memory reclaim) for %lu seconds",
2840+
(jiffies - trans->srcu_lock_time) / HZ);
2841+
}
2842+
28362843
void bch2_trans_srcu_unlock(struct btree_trans *trans)
28372844
{
28382845
if (trans->srcu_held) {
@@ -2843,6 +2850,7 @@ void bch2_trans_srcu_unlock(struct btree_trans *trans)
28432850
if (path->cached && !btree_node_locked(path, 0))
28442851
path->l[0].b = ERR_PTR(-BCH_ERR_no_btree_node_srcu_reset);
28452852

2853+
check_srcu_held_too_long(trans);
28462854
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
28472855
trans->srcu_held = false;
28482856
}
@@ -3074,8 +3082,10 @@ void bch2_trans_put(struct btree_trans *trans)
30743082

30753083
check_btree_paths_leaked(trans);
30763084

3077-
if (trans->srcu_held)
3085+
if (trans->srcu_held) {
3086+
check_srcu_held_too_long(trans);
30783087
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
3088+
}
30793089

30803090
bch2_journal_preres_put(&c->journal, &trans->journal_preres);
30813091

fs/bcachefs/move.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ void bch2_moving_ctxt_do_pending_writes(struct moving_context *ctxt)
147147
{
148148
struct moving_io *io;
149149

150-
bch2_trans_unlock(ctxt->trans);
151-
152150
while ((io = bch2_moving_ctxt_next_pending_write(ctxt))) {
151+
bch2_trans_unlock_long(ctxt->trans);
153152
list_del(&io->read_list);
154153
move_write(io);
155154
}
@@ -485,8 +484,8 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
485484
struct bch_fs *c = ctxt->trans->c;
486485
u64 delay;
487486

488-
if (ctxt->wait_on_copygc) {
489-
bch2_trans_unlock(ctxt->trans);
487+
if (ctxt->wait_on_copygc && !c->copygc_running) {
488+
bch2_trans_unlock_long(ctxt->trans);
490489
wait_event_killable(c->copygc_running_wq,
491490
!c->copygc_running ||
492491
kthread_should_stop());
@@ -495,8 +494,12 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
495494
do {
496495
delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0;
497496

497+
498498
if (delay) {
499-
bch2_trans_unlock(ctxt->trans);
499+
if (delay > HZ / 10)
500+
bch2_trans_unlock_long(ctxt->trans);
501+
else
502+
bch2_trans_unlock(ctxt->trans);
500503
set_current_state(TASK_INTERRUPTIBLE);
501504
}
502505

fs/bcachefs/move.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ do { \
4545
\
4646
if (_cond) \
4747
break; \
48+
bch2_trans_unlock_long((_ctxt)->trans); \
4849
__wait_event((_ctxt)->wait, \
4950
bch2_moving_ctxt_next_pending_write(_ctxt) || \
5051
(cond_finished = (_cond))); \

fs/bcachefs/movinggc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static void move_buckets_wait(struct moving_context *ctxt,
128128
kfree(i);
129129
}
130130

131-
bch2_trans_unlock(ctxt->trans);
131+
bch2_trans_unlock_long(ctxt->trans);
132132
}
133133

134134
static bool bucket_in_flight(struct buckets_in_flight *list,
@@ -327,7 +327,7 @@ static int bch2_copygc_thread(void *arg)
327327
while (!ret && !kthread_should_stop()) {
328328
bool did_work = false;
329329

330-
bch2_trans_unlock(ctxt.trans);
330+
bch2_trans_unlock_long(ctxt.trans);
331331
cond_resched();
332332

333333
if (!c->copy_gc_enabled) {

fs/bcachefs/rebalance.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ static int do_rebalance(struct moving_context *ctxt)
348348
!kthread_should_stop() &&
349349
!atomic64_read(&r->work_stats.sectors_seen) &&
350350
!atomic64_read(&r->scan_stats.sectors_seen)) {
351-
bch2_trans_unlock(trans);
351+
bch2_trans_unlock_long(trans);
352352
rebalance_wait(c);
353353
}
354354

0 commit comments

Comments
 (0)