bcachefs: Use sort_nonatomic() instead of sort()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 26 Mar 2025 15:44:30 +0000 (11:44 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 6 Apr 2025 23:33:53 +0000 (19:33 -0400)
Fixes "task out to lunch" warnings during recovery on large machines
with lots of dirty data in the journal.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_journal_iter.c
fs/bcachefs/btree_node_scan.c
fs/bcachefs/btree_write_buffer.c
fs/bcachefs/recovery.c

index d1ad1a7613c9f722e8250f7a75cfcdb43f99c663..7d6c971db23c330003c71072664256b87e7d8577 100644 (file)
@@ -644,8 +644,6 @@ void bch2_btree_and_journal_iter_init_node_iter(struct btree_trans *trans,
  */
 static int journal_sort_key_cmp(const void *_l, const void *_r)
 {
-       cond_resched();
-
        const struct journal_key *l = _l;
        const struct journal_key *r = _r;
 
@@ -689,7 +687,8 @@ void bch2_journal_keys_put(struct bch_fs *c)
 
 static void __journal_keys_sort(struct journal_keys *keys)
 {
-       sort(keys->data, keys->nr, sizeof(keys->data[0]), journal_sort_key_cmp, NULL);
+       sort_nonatomic(keys->data, keys->nr, sizeof(keys->data[0]),
+                      journal_sort_key_cmp, NULL);
 
        cond_resched();
 
index f520fbcd0455406bb818603a6b485d56c272a3a4..86acf037590ccc529176105c32602e2b17366dce 100644 (file)
@@ -398,7 +398,7 @@ int bch2_scan_for_btree_nodes(struct bch_fs *c)
                bch2_print_string_as_lines(KERN_INFO, buf.buf);
        }
 
-       sort(f->nodes.data, f->nodes.nr, sizeof(f->nodes.data[0]), found_btree_node_cmp_cookie, NULL);
+       sort_nonatomic(f->nodes.data, f->nodes.nr, sizeof(f->nodes.data[0]), found_btree_node_cmp_cookie, NULL);
 
        dst = 0;
        darray_for_each(f->nodes, i) {
@@ -418,7 +418,7 @@ int bch2_scan_for_btree_nodes(struct bch_fs *c)
        }
        f->nodes.nr = dst;
 
-       sort(f->nodes.data, f->nodes.nr, sizeof(f->nodes.data[0]), found_btree_node_cmp_pos, NULL);
+       sort_nonatomic(f->nodes.data, f->nodes.nr, sizeof(f->nodes.data[0]), found_btree_node_cmp_pos, NULL);
 
        if (0 && c->opts.verbose) {
                printbuf_reset(&buf);
index adbe576ec77ee3f52e403da00c4526d6a108f225..0941fb2c026d546fcbf61fbf1e80d78b7ddcb532 100644 (file)
@@ -428,10 +428,10 @@ static int bch2_btree_write_buffer_flush_locked(struct btree_trans *trans)
                 */
                trace_and_count(c, write_buffer_flush_slowpath, trans, slowpath, wb->flushing.keys.nr);
 
-               sort(wb->flushing.keys.data,
-                    wb->flushing.keys.nr,
-                    sizeof(wb->flushing.keys.data[0]),
-                    wb_key_seq_cmp, NULL);
+               sort_nonatomic(wb->flushing.keys.data,
+                              wb->flushing.keys.nr,
+                              sizeof(wb->flushing.keys.data[0]),
+                              wb_key_seq_cmp, NULL);
 
                darray_for_each(wb->flushing.keys, i) {
                        if (!i->journal_seq)
index 79fd18a5a07c434a38fd21ca7083f5df380b66a0..d2b07f602da95a2fb83b101af9cdaf3a3a373f08 100644 (file)
@@ -389,9 +389,9 @@ int bch2_journal_replay(struct bch_fs *c)
         * Now, replay any remaining keys in the order in which they appear in
         * the journal, unpinning those journal entries as we go:
         */
-       sort(keys_sorted.data, keys_sorted.nr,
-            sizeof(keys_sorted.data[0]),
-            journal_sort_seq_cmp, NULL);
+       sort_nonatomic(keys_sorted.data, keys_sorted.nr,
+                      sizeof(keys_sorted.data[0]),
+                      journal_sort_seq_cmp, NULL);
 
        darray_for_each(keys_sorted, kp) {
                cond_resched();