]> git.hungrycats.org Git - linux/commitdiff
Btrfs: don't iterate mod seq list when putting a tree mod seq
authorFilipe Manana <fdmanana@suse.com>
Wed, 22 Jan 2020 12:23:54 +0000 (12:23 +0000)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 10 Feb 2020 02:37:36 +0000 (21:37 -0500)
Each new element added to the mod seq list is always appended to the list,
and each one gets a sequence number coming from a counter which gets
incremented everytime a new element is added to the list (or a new node
is added to the tree mod log rbtree). Therefore the element with the
lowest sequence number is always the first element in the list.

So just remove the list iteration at btrfs_put_tree_mod_seq() that
computes the minimum sequence number in the list and replace it with
a check for the first element's sequence number.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
(cherry picked from commit 5630d5632266052619739f1b7e582954bc62cab4)

fs/btrfs/ctree.c

index ebd2ab53e00d0a747f7c0557c1af6dcd5fbb5975..7e859c9fd3d56d6ccb96d80154696caca98a6a8d 100644 (file)
@@ -323,7 +323,6 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
        struct rb_root *tm_root;
        struct rb_node *node;
        struct rb_node *next;
-       struct seq_list *cur_elem;
        struct tree_mod_elem *tm;
        u64 min_seq = (u64)-1;
        u64 seq_putting = elem->seq;
@@ -335,18 +334,20 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
        list_del(&elem->list);
        elem->seq = 0;
 
-       list_for_each_entry(cur_elem, &fs_info->tree_mod_seq_list, list) {
-               if (cur_elem->seq < min_seq) {
-                       if (seq_putting > cur_elem->seq) {
-                               /*
-                                * blocker with lower sequence number exists, we
-                                * cannot remove anything from the log
-                                */
-                               write_unlock(&fs_info->tree_mod_log_lock);
-                               return;
-                       }
-                       min_seq = cur_elem->seq;
+       if (!list_empty(&fs_info->tree_mod_seq_list)) {
+               struct seq_list *first;
+
+               first = list_first_entry(&fs_info->tree_mod_seq_list,
+                                        struct seq_list, list);
+               if (seq_putting > first->seq) {
+                       /*
+                        * Blocker with lower sequence number exists, we
+                        * cannot remove anything from the log.
+                        */
+                       write_unlock(&fs_info->tree_mod_log_lock);
+                       return;
                }
+               min_seq = first->seq;
        }
 
        /*