linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <krisman@suse.de>
To: chengming.zhou@linux.dev
Cc: axboe@kernel.dk, osandov@fb.com, ming.lei@redhat.com,
	kbusch@kernel.org, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, zhouchengming@bytedance.com
Subject: Re: [PATCH 1/6] sbitmap: fix hint wrap in the failure case
Date: Thu, 20 Jul 2023 15:06:58 -0400	[thread overview]
Message-ID: <87r0p24d2l.fsf@suse.de> (raw)
In-Reply-To: <20230720094555.1397621-2-chengming.zhou@linux.dev> (chengming zhou's message of "Thu, 20 Jul 2023 17:45:50 +0800")

chengming.zhou@linux.dev writes:

> From: Chengming Zhou <zhouchengming@bytedance.com>
>
> ```
> hint = nr + 1;
> if (hint >= depth - 1)
> 	hint = 0;
> ```
>
> Now we wrap the hint to 0 in the failure case, but:
> 1. hint == depth - 1, is actually an available offset hint, which
>    we shouldn't wrap hint to 0.
> 2. In the strict round_robin non-wrap case, we shouldn't wrap at all.
>
> ```
> wrap = wrap && hint;
> ```
>
> We only need to check wrap based on the original hint ( > 0), don't need
> to recheck the new hint which maybe updated in the failure case.
> Also delete the mismatched comments by the way.
>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
> ---
>  lib/sbitmap.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/lib/sbitmap.c b/lib/sbitmap.c
> index eff4e42c425a..5ed6c2adf58e 100644
> --- a/lib/sbitmap.c
> +++ b/lib/sbitmap.c
> @@ -144,12 +144,7 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
>  	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) {
> +			if (wrap) {
>  				hint = 0;
>  				continue;

I think this is wrong.  If you start with an offset in the wrap case and
the bitmap is completely full this will become busy wait until a bit is
available. The hint check is what make you break out of the loop early,
after wrapping, re-walking the entire bitmap and failing to find any
available space.

> @@ -160,8 +155,13 @@ static int __sbitmap_get_word(unsigned long *word, unsigned long depth,
>  			break;
>  
>  		hint = nr + 1;
> -		if (hint >= depth - 1)
> -			hint = 0;
> +		if (hint >= depth) {
> +			if (wrap) {
> +				hint = 0;
> +				continue;
> +			}
> +			return -1;
> +		}
>  	}
>  
>  	return nr;

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2023-07-20 19:07 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 [this message]
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 ` [PATCH 4/6] sbitmap: remove offset wrap logic when finding bit in word chengming.zhou
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=87r0p24d2l.fsf@suse.de \
    --to=krisman@suse.de \
    --cc=axboe@kernel.dk \
    --cc=chengming.zhou@linux.dev \
    --cc=kbusch@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).