]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: simplify last record detection at set_extent_bit()
authorFilipe Manana <fdmanana@suse.com>
Wed, 16 Apr 2025 16:05:11 +0000 (17:05 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:52 +0000 (14:30 +0200)
There's no need to compare the current extent state's end offset to
(u64)-1 to check if we have the last possible record and to check as
as well if after updating the start offset to the end offset of the
current record plus one we are still inside the target range.

Instead we can simplify and exit if the current extent state ends at or
after the target range and then remove the check for the (u64)-1 as well
as the check to see if the updated start offset (to last_end + 1) is still
inside the target range. Besides the simplification, this also avoids
seaching for the next extent state record (through next_state()) when the
current extent state record ends at the same offset as our target range,
which is pointless and only wastes times iterating through the rb tree.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-io-tree.c

index 36bdf9df7b4caef82f3d67cef342208afff27a66..f7487b853f9b631c0e95af13025ae649ffaf7deb 100644 (file)
@@ -1126,12 +1126,11 @@ hit_next:
                set_state_bits(tree, state, bits, changeset);
                cache_state(state, cached_state);
                merge_state(tree, state);
-               if (last_end == (u64)-1)
+               if (last_end >= end)
                        goto out;
                start = last_end + 1;
                state = next_state(state);
-               if (start < end && state && state->start == start &&
-                   !need_resched())
+               if (state && state->start == start && !need_resched())
                        goto hit_next;
                goto search_again;
        }
@@ -1183,12 +1182,11 @@ hit_next:
                        set_state_bits(tree, state, bits, changeset);
                        cache_state(state, cached_state);
                        merge_state(tree, state);
-                       if (last_end == (u64)-1)
+                       if (last_end >= end)
                                goto out;
                        start = last_end + 1;
                        state = next_state(state);
-                       if (start < end && state && state->start == start &&
-                           !need_resched())
+                       if (state && state->start == start && !need_resched())
                                goto hit_next;
                }
                goto search_again;