All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: Nikolay Borisov <nborisov@suse.com>
Subject: [PATCH 6/6] btrfs: Remove dead code exclude_super_stripes
Date: Tue, 19 Nov 2019 14:05:55 +0200	[thread overview]
Message-ID: <20191119120555.6465-7-nborisov@suse.com> (raw)
In-Reply-To: <20191119120555.6465-1-nborisov@suse.com>

Adresses held in 'logical' array are always guaranteed to fall within
the boundaries of the block group. That is, 'start' can never be
smaller than cache->start. This invariant follows from the way the
address are calculated in btrfs_rmap_block:

    stripe_nr = physical - map->stripes[i].physical;
    stripe_nr = div64_u64(stripe_nr, map->stripe_len);
    bytenr = chunk_start + stripe_nr * io_stripe_size;

I.e it's always some IO stripe within the given chunk.

Exploit this invariant to simplify the body of the loop by removing the
unnecessary 'if' since its 'else' part is the one always executed.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/block-group.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 2ab4d9cb598a..3c7c34b6a0a8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -1627,25 +1627,12 @@ static int exclude_super_stripes(struct btrfs_block_group *cache)
 			return ret;
 
 		while (nr--) {
-			u64 start, len;
-
-			if (logical[nr] > cache->start + cache->length)
-				continue;
-
-			if (logical[nr] + stripe_len <= cache->start)
-				continue;
-
-			start = logical[nr];
-			if (start < cache->start) {
-				start = cache->start;
-				len = (logical[nr] + stripe_len) - start;
-			} else {
-				len = min_t(u64, stripe_len,
-					    cache->start + cache->length - start);
-			}
+			u64 len = min_t(u64, stripe_len,
+				cache->start + cache->length - logical[nr]);
 
 			cache->bytes_super += len;
-			ret = btrfs_add_excluded_extent(fs_info, start, len);
+			ret = btrfs_add_excluded_extent(fs_info, logical[nr],
+							len);
 			if (ret) {
 				kfree(logical);
 				return ret;
-- 
2.17.1


      parent reply	other threads:[~2019-11-19 12:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19 12:05 [PATCH 0/6] Cleanup super block stripe exclusion code Nikolay Borisov
2019-11-19 12:05 ` [PATCH 1/6] btrfs: Move and unexport btrfs_rmap_block Nikolay Borisov
2019-11-26 15:53   ` David Sterba
2019-12-10 17:57     ` [PATCH v2] " Nikolay Borisov
2020-01-02 15:21       ` David Sterba
2019-11-19 12:05 ` [PATCH 2/6] btrfs: selftests: Add support for dummy devices Nikolay Borisov
2019-11-19 12:05 ` [PATCH 3/6] btrfs: Add self-tests for btrfs_rmap_block Nikolay Borisov
2019-11-26 16:04   ` David Sterba
2019-12-10 18:00     ` [PATCH v2] " Nikolay Borisov
2020-01-02 15:40       ` David Sterba
2020-01-10 14:46         ` Nikolay Borisov
2020-01-14 16:51           ` David Sterba
2019-11-19 12:05 ` [PATCH 4/6] btrfs: Refactor btrfs_rmap_block to improve readability Nikolay Borisov
2019-11-19 12:05 ` [PATCH 5/6] btrfs: Read stripe len directly in btrfs_rmap_block Nikolay Borisov
2020-01-14 16:54   ` David Sterba
2020-01-15 10:52     ` Nikolay Borisov
2019-11-19 12:05 ` Nikolay Borisov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191119120555.6465-7-nborisov@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.