]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bcachefs: Set PF_MEMALLOC_NOFS when trans->locked
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 4 Jul 2024 00:35:36 +0000 (20:35 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 12 Jul 2024 00:10:55 +0000 (20:10 -0400)
proper lock ordering is: fs_reclaim -> btree node locks

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/btree_locking.c
fs/bcachefs/btree_locking.h
fs/bcachefs/btree_types.h

index 0ed9e6574fcd0db7ca70deb197a19faaa57498aa..19352a08ea204bb7e18c9ed61378a6b52c1e303e 100644 (file)
@@ -996,7 +996,7 @@ retry_all:
 
        bch2_trans_unlock(trans);
        cond_resched();
-       trans->locked = true;
+       trans_set_locked(trans);
 
        if (unlikely(trans->memory_allocation_failure)) {
                struct closure cl;
@@ -3089,7 +3089,8 @@ u32 bch2_trans_begin(struct btree_trans *trans)
                bch2_trans_srcu_unlock(trans);
 
        trans->last_begin_ip = _RET_IP_;
-       trans->locked  = true;
+
+       trans_set_locked(trans);
 
        if (trans->restarted) {
                bch2_btree_path_traverse_all(trans);
@@ -3159,7 +3160,6 @@ got_trans:
        trans->last_begin_time  = local_clock();
        trans->fn_idx           = fn_idx;
        trans->locking_wait.task = current;
-       trans->locked           = true;
        trans->journal_replay_not_finished =
                unlikely(!test_bit(JOURNAL_replay_done, &c->journal.flags)) &&
                atomic_inc_not_zero(&c->journal_keys.ref);
@@ -3193,6 +3193,7 @@ got_trans:
        trans->srcu_idx         = srcu_read_lock(&c->btree_trans_barrier);
        trans->srcu_lock_time   = jiffies;
        trans->srcu_held        = true;
+       trans_set_locked(trans);
 
        closure_init_stack_release(&trans->ref);
        return trans;
index 191d9a50378aa1e59f22e6b57fa5150de6768d6a..c51826fd557f5e0796a25eb434406b0035ba7f47 100644 (file)
@@ -792,7 +792,7 @@ static inline int __bch2_trans_relock(struct btree_trans *trans, bool trace)
                        return bch2_trans_relock_fail(trans, path, &f, trace);
        }
 
-       trans->locked = true;
+       trans_set_locked(trans);
 out:
        bch2_trans_verify_locks(trans);
        return 0;
@@ -812,16 +812,14 @@ void bch2_trans_unlock_noassert(struct btree_trans *trans)
 {
        __bch2_trans_unlock(trans);
 
-       trans->locked = false;
-       trans->last_unlock_ip = _RET_IP_;
+       trans_set_unlocked(trans);
 }
 
 void bch2_trans_unlock(struct btree_trans *trans)
 {
        __bch2_trans_unlock(trans);
 
-       trans->locked = false;
-       trans->last_unlock_ip = _RET_IP_;
+       trans_set_unlocked(trans);
 }
 
 void bch2_trans_unlock_long(struct btree_trans *trans)
index 7f41545b9147f858c6459bdbcf3c78abbf2ebce3..75a6274c7d272c329d492c67e6424bf43eb418b9 100644 (file)
@@ -193,6 +193,28 @@ int bch2_six_check_for_deadlock(struct six_lock *lock, void *p);
 
 /* lock: */
 
+static inline void trans_set_locked(struct btree_trans *trans)
+{
+       if (!trans->locked) {
+               trans->locked = true;
+               trans->last_unlock_ip = 0;
+
+               trans->pf_memalloc_nofs = (current->flags & PF_MEMALLOC_NOFS) != 0;
+               current->flags |= PF_MEMALLOC_NOFS;
+       }
+}
+
+static inline void trans_set_unlocked(struct btree_trans *trans)
+{
+       if (trans->locked) {
+               trans->locked = false;
+               trans->last_unlock_ip = _RET_IP_;
+
+               if (!trans->pf_memalloc_nofs)
+                       current->flags &= ~PF_MEMALLOC_NOFS;
+       }
+}
+
 static inline int __btree_node_lock_nopath(struct btree_trans *trans,
                                         struct btree_bkey_cached_common *b,
                                         enum six_lock_type type,
index 87f485e9c552d97dad450d1967bc4fe88f043406..48cb1a7d31c51333c5beb4e8b0bc6ff238d070eb 100644 (file)
@@ -484,6 +484,7 @@ struct btree_trans {
        bool                    lock_may_not_fail:1;
        bool                    srcu_held:1;
        bool                    locked:1;
+       bool                    pf_memalloc_nofs:1;
        bool                    write_locked:1;
        bool                    used_mempool:1;
        bool                    in_traverse_all:1;