From: chengming.zhou@linux.dev
To: axboe@kernel.dk, osandov@fb.com, ming.lei@redhat.com,
kbusch@kernel.org, krisman@suse.de
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
zhouchengming@bytedance.com
Subject: [PATCH v2 2/3] sbitmap: fix strict round-robin non-wrap with hint > 0
Date: Thu, 27 Jul 2023 23:20:19 +0800 [thread overview]
Message-ID: <20230727152020.3633009-2-chengming.zhou@linux.dev> (raw)
In-Reply-To: <20230727152020.3633009-1-chengming.zhou@linux.dev>
From: Chengming Zhou <zhouchengming@bytedance.com>
If we have alloc_hint > 0 and don't wrap, we need to recheck
sb->map[index] with hint == 0 to exhaust the map.
For example: we have 8 words to search, index == 4, hint > 0
In sb->map[4] word, we only search [hint, 63] bits in the first
word search. Then we search left 7 words, the sb->map[4] [0, hint-1]
bits aren't searched.
This patch fix it by searching 9 words in this case, so we will
search sb->map[4] the second time at last with hint == 0.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
lib/sbitmap.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/sbitmap.c b/lib/sbitmap.c
index ac4027884765..6e098a46be26 100644
--- a/lib/sbitmap.c
+++ b/lib/sbitmap.c
@@ -199,10 +199,18 @@ static int sbitmap_find_bit(struct sbitmap *sb,
unsigned int alloc_hint,
bool wrap)
{
+ unsigned int map_nr = sb->map_nr;
unsigned int i;
int nr = -1;
- for (i = 0; i < sb->map_nr; i++) {
+ /*
+ * 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)
+ map_nr += 1;
+
+ for (i = 0; i < map_nr; i++) {
nr = sbitmap_find_bit_in_word(&sb->map[index],
min_t(unsigned int,
__map_depth(sb, index),
--
2.41.0
next prev parent reply other threads:[~2023-07-27 15:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-27 15:20 [PATCH v2 1/3] sbitmap: fix hint wrap in the failure case chengming.zhou
2023-07-27 15:20 ` chengming.zhou [this message]
2023-07-27 15:20 ` [PATCH v2 3/3] sbitmap: drop wrap logic in __sbitmap_get_word() 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=20230727152020.3633009-2-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