]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Sort updates in bch2_trans_update()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 28 Mar 2019 04:34:25 +0000 (00:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:19 +0000 (17:08 -0400)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_update.h
fs/bcachefs/btree_update_leaf.c

index 879e7ae3958641af505b6d7f2c5a92a3ef8f6440..75ed02874767c7687cec29d85f38d9f4e802399a 100644 (file)
@@ -99,19 +99,13 @@ int bch2_btree_node_rewrite(struct bch_fs *c, struct btree_iter *,
 int bch2_btree_node_update_key(struct bch_fs *, struct btree_iter *,
                               struct btree *, struct bkey_i_btree_ptr *);
 
-static inline void
-bch2_trans_update(struct btree_trans *trans,
-                 struct btree_insert_entry entry)
-{
-       BUG_ON(trans->nr_updates >= trans->nr_iters + 4);
-
-       trans->updates[trans->nr_updates++] = entry;
-}
-
 int bch2_trans_commit(struct btree_trans *,
                      struct disk_reservation *,
                      u64 *, unsigned);
 
+struct btree_insert_entry *bch2_trans_update(struct btree_trans *,
+                                            struct btree_insert_entry);
+
 #define bch2_trans_do(_c, _journal_seq, _flags, _do)                   \
 ({                                                                     \
        struct btree_trans trans;                                       \
index d345f5a14fde4732abd8272f978899c22b9a50fb..d4d4329767da25b28d647950da93f0b3f321923a 100644 (file)
@@ -809,8 +809,6 @@ int bch2_trans_commit(struct btree_trans *trans,
        trans->journal_seq      = journal_seq;
        trans->flags            = flags;
 
-       bubble_sort(trans->updates, trans->nr_updates, btree_trans_cmp);
-
        trans_for_each_update(trans, i)
                btree_insert_entry_checks(trans, i);
        bch2_btree_trans_verify_locks(trans);
@@ -871,6 +869,26 @@ err:
        goto out;
 }
 
+struct btree_insert_entry *bch2_trans_update(struct btree_trans *trans,
+                                            struct btree_insert_entry entry)
+{
+       struct btree_insert_entry *i;
+
+       BUG_ON(trans->nr_updates >= trans->nr_iters + 4);
+
+       for (i = trans->updates;
+            i < trans->updates + trans->nr_updates;
+            i++)
+               if (btree_trans_cmp(entry, *i) < 0)
+                       break;
+
+       memmove(&i[1], &i[0],
+               (void *) &trans->updates[trans->nr_updates] - (void *) i);
+       trans->nr_updates++;
+       *i = entry;
+       return i;
+}
+
 int bch2_btree_delete_at(struct btree_trans *trans,
                         struct btree_iter *iter, unsigned flags)
 {