[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20201206065004.GA6321@ubuntu>
Date: Sun, 6 Dec 2020 15:50:04 +0900
From: Levi Yun <ppbuk5246@...il.com>
To: akpm@...ux-foundation.org, yury.norov@...il.com,
andriy.shevchenko@...ux.intel.com,
richard.weiyang@...ux.alibaba.com, christian.brauner@...ntu.com,
arnd@...db.de, jpoimboe@...hat.com, changbin.du@...el.com,
rdunlap@...radead.org, masahiroy@...nel.org,
gregkh@...uxfoundation.org, peterz@...radead.org,
peter.enderborg@...y.com, krzk@...nel.org,
brendanhiggins@...gle.com, keescook@...omium.org,
broonie@...nel.org, matti.vaittinen@...rohmeurope.com,
mhiramat@...nel.org, jpa@....mail.kapsi.fi, nivedita@...m.mit.edu,
glider@...gle.com, orson.zhai@...soc.com,
takahiro.akashi@...aro.org, clm@...com, josef@...icpanda.com,
dsterba@...e.com, dushistov@...l.ru
Cc: linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org,
linux-btrfs@...r.kernel.org
Subject: [PATCH v2 7/8] btrfs/free-space-cache.c: Apply find_last_zero_bit
In steal_from_bitmap_to_front function, it finds last_zero_bit from i
using for_each_clear_bit.
But this makes some overhead that it starts from the 0 bit.
By adding find_last_zero_bit, I try to remove this overhead and
improve readibility.
Signed-off-by: Levi Yun <ppbuk5246@...il.com>
---
fs/btrfs/free-space-cache.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index af0013d3df63..6d393c834fdd 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -2372,7 +2372,6 @@ static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl,
u64 bitmap_offset;
unsigned long i;
unsigned long j;
- unsigned long prev_j;
u64 bytes;
bitmap_offset = offset_to_bitmap(ctl, info->offset);
@@ -2388,20 +2387,15 @@ static bool steal_from_bitmap_to_front(struct btrfs_free_space_ctl *ctl,
return false;
i = offset_to_bit(bitmap->offset, ctl->unit, info->offset) - 1;
- j = 0;
- prev_j = (unsigned long)-1;
- for_each_clear_bit_from(j, bitmap->bitmap, BITS_PER_BITMAP) {
- if (j > i)
- break;
- prev_j = j;
- }
- if (prev_j == i)
- return false;
+ j = find_last_zero_bit(bitmap->bitmap, i);
- if (prev_j == (unsigned long)-1)
- bytes = (i + 1) * ctl->unit;
- else
- bytes = (i - prev_j) * ctl->unit;
+ if (j == i) {
+ if (!test_bit(i, bitmap->bitmap))
+ return false;
+ else
+ bytes = (i + 1) * ctl->unit;
+ } else
+ bytes = (i - j) * ctl->unit;
info->offset -= bytes;
info->bytes += bytes;
--
2.27.0
Powered by blists - more mailing lists