[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231118155105.25678-3-yury.norov@gmail.com>
Date: Sat, 18 Nov 2023 07:50:33 -0800
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
linux-block@...r.kernel.org
Cc: Yury Norov <yury.norov@...il.com>, Jan Kara <jack@...e.cz>,
Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
Matthew Wilcox <willy@...radead.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Maxim Kuvyrkov <maxim.kuvyrkov@...aro.org>,
Alexey Klimov <klimov.linux@...il.com>
Subject: [PATCH 02/34] lib/sbitmap; make __sbitmap_get_word() using find_and_set_bit()
__sbitmap_get_word() opencodes either find_and_set_bit_wrap(), or
find_and_set_next_bit() depending on hint and wrap parameters.
Switch it to use the atomic find_bit() API. While here, simplify
sbitmap_find_bit_in_word(), which calls it.
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
lib/sbitmap.c | 46 ++++++++--------------------------------------
1 file changed, 8 insertions(+), 38 deletions(-)
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index d0a5081dfd12..b21aebd07fd6 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -133,38 +133,11 @@ void sbitmap_resize(struct sbitmap *sb, unsigned int depth)
}
EXPORT_SYMBOL_GPL(sbitmap_resize);
-static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
+static inline int __sbitmap_get_word(unsigned long *word, unsigned long depth,
unsigned int hint, bool wrap)
{
- int nr;
-
- /* don't wrap if starting from 0 */
- wrap = wrap && hint;
-
- while (1) {
- nr = find_next_zero_bit(word, depth, hint);
- if (unlikely(nr >= depth)) {
- /*
- * We started with an offset, and we didn't reset the
- * offset to 0 in a failure case, so start from 0 to
- * exhaust the map.
- */
- if (hint && wrap) {
- hint = 0;
- continue;
- }
- return -1;
- }
-
- if (!test_and_set_bit_lock(nr, word))
- break;
-
- hint = nr + 1;
- if (hint >= depth - 1)
- hint = 0;
- }
-
- return nr;
+ return wrap ? find_and_set_bit_wrap_lock(word, depth, hint) :
+ find_and_set_next_bit_lock(word, depth, hint);
}
static int sbitmap_find_bit_in_word(struct sbitmap_word *map,
@@ -175,15 +148,12 @@ static int sbitmap_find_bit_in_word(struct sbitmap_word *map,
int nr;
do {
- nr = __sbitmap_get_word(&map->word, depth,
- alloc_hint, wrap);
- if (nr != -1)
- break;
- if (!sbitmap_deferred_clear(map))
- break;
- } while (1);
+ nr = __sbitmap_get_word(&map->word, depth, alloc_hint, wrap);
+ if (nr < depth)
+ return nr;
+ } while (sbitmap_deferred_clear(map));
- return nr;
+ return -1;
}
static int sbitmap_find_bit(struct sbitmap *sb,
--
2.39.2
Powered by blists - more mailing lists