Linux block layer
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Yury Norov <yury.norov@gmail.com>
Cc: linux-kernel@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Jan Kara <jack@suse.cz>,
	Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
	Matthew Wilcox <willy@infradead.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>,
	Alexey Klimov <klimov.linux@gmail.com>,
	Bart Van Assche <bvanassche@acm.org>,
	Sergey Shtylyov <s.shtylyov@omp.ru>
Subject: Re: [PATCH v2 03/35] lib/sbitmap; make __sbitmap_get_word() using find_and_set_bit()
Date: Mon, 4 Dec 2023 19:22:28 +0100	[thread overview]
Message-ID: <20231204182228.7qzfgjyfmx7ubmx2@quack3> (raw)
In-Reply-To: <20231203193307.542794-2-yury.norov@gmail.com>

On Sun 03-12-23 11:32:35, Yury Norov wrote:
> __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@gmail.com>

Looks good to me. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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.40.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2023-12-04 18:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-03 19:23 [PATCH v2 00/35] bitops: add atomic find_bit() operations Yury Norov
2023-12-03 19:23 ` [PATCH v2 01/35] lib/find: add atomic find_bit() primitives Yury Norov
2023-12-03 19:32 ` [PATCH v2 02/35] lib/find: add test for atomic find_bit() ops Yury Norov
2023-12-03 19:32   ` [PATCH v2 03/35] lib/sbitmap; make __sbitmap_get_word() using find_and_set_bit() Yury Norov
2023-12-04 18:22     ` Jan Kara [this message]
2023-12-04 18:40     ` Jens Axboe
2023-12-03 19:32   ` [PATCH v2 24/35] block: null_blk: fix opencoded find_and_set_bit() in get_tag() Yury Norov
2023-12-04 18:26     ` Jan Kara
2023-12-05  2:39     ` Chengming Zhou
2023-12-04 13:07 ` [PATCH v2 00/35] bitops: add atomic find_bit() operations Andy Shevchenko
2023-12-04 18:51 ` Jan Kara
2023-12-06  5:22   ` Yury Norov
2023-12-07  9:10     ` Jan Kara

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=20231204182228.7qzfgjyfmx7ubmx2@quack3 \
    --to=jack@suse.cz \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=klimov.linux@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=maxim.kuvyrkov@linaro.org \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --cc=s.shtylyov@omp.ru \
    --cc=willy@infradead.org \
    --cc=yury.norov@gmail.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