From: chengming.zhou@linux.dev
To: axboe@kernel.dk, osandov@fb.com, ming.lei@redhat.com,
kbusch@kernel.org, krisman@suse.de
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
zhouchengming@bytedance.com
Subject: [PATCH 4/6] sbitmap: remove offset wrap logic when finding bit in word
Date: Thu, 20 Jul 2023 17:45:53 +0800 [thread overview]
Message-ID: <20230720094555.1397621-5-chengming.zhou@linux.dev> (raw)
In-Reply-To: <20230720094555.1397621-1-chengming.zhou@linux.dev>
From: Chengming Zhou <zhouchengming@bytedance.com>
We actually don't need the offset hint wrap logic in word:
1. Strict round-robin mode: just search from that offset hint,
we will recheck that word at last if offset hint > 0.
2. No round-robin mode: we use offset hint == 0, so don't need
to wrap offset hint too.
We remove offset wrap logic and simplify the code.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
lib/sbitmap.c | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index 0f3943bd3940..50bdf3a31947 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -134,34 +134,21 @@ 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,
- unsigned int hint, bool wrap)
+ unsigned int hint)
{
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)) {
- if (wrap) {
- hint = 0;
- continue;
- }
+ if (unlikely(nr >= depth))
return -1;
- }
if (!test_and_set_bit_lock(nr, word))
break;
hint = nr + 1;
- if (hint >= depth) {
- if (wrap) {
- hint = 0;
- continue;
- }
+ if (hint >= depth)
return -1;
- }
}
return nr;
@@ -169,14 +156,13 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
static int sbitmap_find_bit_in_word(struct sbitmap_word *map,
unsigned int depth,
- unsigned int alloc_hint,
- bool wrap)
+ unsigned int alloc_hint)
{
int nr;
do {
nr = __sbitmap_get_word(&map->word, depth,
- alloc_hint, wrap);
+ alloc_hint);
if (nr != -1)
break;
if (!sbitmap_deferred_clear(map))
@@ -189,8 +175,7 @@ static int sbitmap_find_bit_in_word(struct sbitmap_word *map,
static int sbitmap_find_bit(struct sbitmap *sb,
unsigned int depth,
unsigned int index,
- unsigned int alloc_hint,
- bool wrap)
+ unsigned int alloc_hint)
{
unsigned int map_nr = sb->map_nr;
unsigned int i;
@@ -200,7 +185,7 @@ static int sbitmap_find_bit(struct sbitmap *sb,
* If we have alloc_hint > 0 and don't wrap, we need to
* recheck sb->map[index] with hint == 0 to exhaust the map.
*/
- if (alloc_hint && !wrap)
+ if (alloc_hint)
map_nr += 1;
for (i = 0; i < map_nr; i++) {
@@ -208,7 +193,7 @@ static int sbitmap_find_bit(struct sbitmap *sb,
min_t(unsigned int,
__map_depth(sb, index),
depth),
- alloc_hint, wrap);
+ alloc_hint);
if (nr != -1) {
nr += index << sb->shift;
@@ -240,8 +225,7 @@ static int __sbitmap_get(struct sbitmap *sb, unsigned int alloc_hint)
else
alloc_hint = 0;
- return sbitmap_find_bit(sb, UINT_MAX, index, alloc_hint,
- !sb->round_robin);
+ return sbitmap_find_bit(sb, UINT_MAX, index, alloc_hint);
}
int sbitmap_get(struct sbitmap *sb)
@@ -272,7 +256,7 @@ static int __sbitmap_get_shallow(struct sbitmap *sb,
/* No point in looping twice in find_next_zero_bit() for this case. */
alloc_hint = 0;
- return sbitmap_find_bit(sb, shallow_depth, index, alloc_hint, true);
+ return sbitmap_find_bit(sb, shallow_depth, index, alloc_hint);
}
int sbitmap_get_shallow(struct sbitmap *sb, unsigned long shallow_depth)
--
2.41.0
next prev parent reply other threads:[~2023-07-20 9:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 9:45 [PATCH 0/6] sbitmap: fix offset hint wrap and some optimizations chengming.zhou
2023-07-20 9:45 ` [PATCH 1/6] sbitmap: fix hint wrap in the failure case chengming.zhou
2023-07-20 19:06 ` Gabriel Krisman Bertazi
2023-07-21 3:51 ` Chengming Zhou
2023-07-20 9:45 ` [PATCH 2/6] sbitmap: fix round-robin non-wrap find with hint > 0 chengming.zhou
2023-07-20 9:45 ` [PATCH 3/6] sbitmap: don't loop twice in find_next_zero_bit() chengming.zhou
2023-07-20 9:45 ` chengming.zhou [this message]
2023-07-20 9:45 ` [PATCH 5/6] sbitmap: wake_index doesn't need to be atomic_t chengming.zhou
2023-07-20 9:45 ` [PATCH 6/6] sbitmap: check ws_active before check waitqueues chengming.zhou
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=20230720094555.1397621-5-chengming.zhou@linux.dev \
--to=chengming.zhou@linux.dev \
--cc=axboe@kernel.dk \
--cc=kbusch@kernel.org \
--cc=krisman@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=osandov@fb.com \
--cc=zhouchengming@bytedance.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome