Re: [PATCH v1 3/8] md/raid5: Move common stripe count increment code into __find_stripe()

From: Christoph Hellwig
Date: Fri Apr 08 2022 - 02:02:00 EST


On Thu, Apr 07, 2022 at 10:45:06AM -0600, Logan Gunthorpe wrote:
> static struct stripe_head *__find_stripe(struct r5conf *conf, sector_t sector,
> - short generation)
> + short generation, int hash)
> {
> + int inc_empty_inactive_list_flag;
> struct stripe_head *sh;
>
> pr_debug("__find_stripe, sector %llu\n", (unsigned long long)sector);
> hlist_for_each_entry(sh, stripe_hash(conf, sector), hash)
> if (sh->sector == sector && sh->generation == generation)
> - return sh;
> + goto found;
> pr_debug("__stripe %llu not in cache\n", (unsigned long long)sector);
> return NULL;
> +
> +found:
> + if (!atomic_inc_not_zero(&sh->count)) {

There is a way on list iterators outside the loop body waging right
now. So maybe just leave __find_stripe as-is and add a new
find_get_stripe that wraps it. And then just return early when the
atomic_inc_not_zero dos not succeed and save on one level of
indentation.