Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3636133rwe; Mon, 29 Aug 2022 16:30:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR7nnSIhIeVbddqL9+EgZhYfyVy+F0GzpcSO4UycY8fJwwesv2Quuj87ZOwyP8iBPnlr+d7l X-Received: by 2002:a17:907:7e92:b0:741:5f7e:f1ac with SMTP id qb18-20020a1709077e9200b007415f7ef1acmr7546552ejc.176.1661815822526; Mon, 29 Aug 2022 16:30:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661815822; cv=none; d=google.com; s=arc-20160816; b=GftcgiQKM0oWhCVqZL5BKud6U8J/V9h7hCPFdxNeHvRgeufxspmkEamhpFiaqHByg+ Wnr7+dfxfiu9WK9evWF3eUa8YQdEjP+6cKbUl+0DPYFbqAZWXcyepdlYh6NGTf2PSihA sPj5x0gGh3VAuZUY0TZAN7YV64GMKSyQfiy7e5R5rP3CIGvKhopUq3tyTf4ijPOou0tG +A9ifCXWNV5q88Xs5PCF1pTa/1egoJ09VvvGx7fz3tm5jE5MOQXN0C0bzqtr8+v2kf73 EhAGL4VWvqMRAlMXphZ8TUlfVsDYRGqRXZMSb3B/6PWsn97As8s1UqNTrheqMMmrbTiD BVDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YxRgBFQomeDQUlbRJr4O5/teGkWUccKqBMaAjx3iIao=; b=IaSF5Lh55U7LwwQMo0FqyYaCfMgLO7Gh4amxQGv9U2xGfg5VbX+MfCkcmw9hmlBlPj nO7TEqdpSYWgzSIGhRmg9ah6nr5mpIzeoT8jymTVuAyB5jXAAn0s+0lQ20rXD3qI53wV /aoXmPTgQITjTORsJfFwnCDNPhCALU3xwirRY20JsMvBMxdK/oK5lOudPtxQ/peoIWI9 qB53mEXz/nAyUGIkm889WVV+Y0JlJYl1q9IOFIe84Gm9G+vRxKQfay/bF7XjU2Dr2hkn zmxi4ZMm7ntmLmXCrOBHzF/wx6aStfT8KoiOJBZssiC8MD/PDhEl1pIMg+SWdtNF/9Wn RzQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uVzIJsFV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm17-20020a170907949100b0072f1c8d0ec4si8150260ejc.584.2022.08.29.16.29.52; Mon, 29 Aug 2022 16:30:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uVzIJsFV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229804AbiH2WXt (ORCPT + 99 others); Mon, 29 Aug 2022 18:23:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229486AbiH2WXs (ORCPT ); Mon, 29 Aug 2022 18:23:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 695968276A; Mon, 29 Aug 2022 15:23:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 04E9B612EE; Mon, 29 Aug 2022 22:23:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6317BC433B5; Mon, 29 Aug 2022 22:23:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661811826; bh=2ngJC3O39kPRPMioYMTDLmYI3pojOfPaE67eugc3YTA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=uVzIJsFVejbF0ji2G2ZS+ClcNFicRXvUKBMgcETzO0C8MUpFf0YPCrVc5jXQe8uke C039MfGScOmsjUqhizIbXZX1jH1NVSqXDA7eSLjOsnEiYVmy/gbMvGjRZ03Ir3wx66 IYhYkzlT791FN+ZHPysYm2FrTL38XUWvzpuwdB0ucBxADL+zh1tdqSpP4xN5YA5loG kA4APiDCL4AfuE+ZfRH5NZ5Mr0UbXlipB4hiVTZBhbc0Pw0RcdKcr5So1lLwJEpYX1 PHiLhpF92+B2LTdc/yXaVSGztt3LhLPhm+36AnG5ArjAPctIYPE0tBmwbn3Ihi5d4i MP2h5xKYQFWQQ== Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-334dc616f86so230897167b3.8; Mon, 29 Aug 2022 15:23:46 -0700 (PDT) X-Gm-Message-State: ACgBeo1jAvBoLB78M/kIvtjCaPKbmBHUH4FsrhC3g/4WuDex0d5uBGpy 9O6Ll6wga0h/CQdC+/h6fb5VD9/zF5NAQ/cMMHA= X-Received: by 2002:a05:6902:1501:b0:697:c614:2079 with SMTP id q1-20020a056902150100b00697c6142079mr9813353ybu.389.1661811825340; Mon, 29 Aug 2022 15:23:45 -0700 (PDT) MIME-Version: 1.0 References: <20220811171417.147697-1-logang@deltatee.com> <20220811171417.147697-3-logang@deltatee.com> In-Reply-To: <20220811171417.147697-3-logang@deltatee.com> From: Song Liu Date: Mon, 29 Aug 2022 15:23:34 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/5] md/raid5: Refactor raid5_get_active_stripe() To: Logan Gunthorpe Cc: open list , linux-raid , Christoph Hellwig , Guoqing Jiang , Stephen Bates , Martin Oliveira , David Sloan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 11, 2022 at 10:14 AM Logan Gunthorpe wrote: > > Refactor raid5_get_active_stripe() without the gotos with an > explicit infinite loop and some additional nesting. > > Suggested-by: Christoph Hellwig > Signed-off-by: Logan Gunthorpe Applied to md-next. Thanks! Song > --- > drivers/md/raid5.c | 82 +++++++++++++++++++++++----------------------- > 1 file changed, 41 insertions(+), 41 deletions(-) > > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c > index 4456ac51f7c5..1288ef9e1571 100644 > --- a/drivers/md/raid5.c > +++ b/drivers/md/raid5.c > @@ -811,54 +811,54 @@ static struct stripe_head *__raid5_get_active_stripe(struct r5conf *conf, > > spin_lock_irq(conf->hash_locks + hash); > > -retry: > - if (!noquiesce && conf->quiesce) { > - /* > - * Must release the reference to batch_last before waiting, > - * on quiesce, otherwise the batch_last will hold a reference > - * to a stripe and raid5_quiesce() will deadlock waiting for > - * active_stripes to go to zero. > - */ > - if (ctx && ctx->batch_last) { > - raid5_release_stripe(ctx->batch_last); > - ctx->batch_last = NULL; > - } > - > - wait_event_lock_irq(conf->wait_for_quiescent, !conf->quiesce, > - *(conf->hash_locks + hash)); > - } > + for (;;) { > + if (!noquiesce && conf->quiesce) { > + /* > + * Must release the reference to batch_last before > + * waiting, on quiesce, otherwise the batch_last will > + * hold a reference to a stripe and raid5_quiesce() > + * will deadlock waiting for active_stripes to go to > + * zero. > + */ > + if (ctx && ctx->batch_last) { > + raid5_release_stripe(ctx->batch_last); > + ctx->batch_last = NULL; > + } > > - sh = find_get_stripe(conf, sector, conf->generation - previous, hash); > - if (sh) > - goto out; > + wait_event_lock_irq(conf->wait_for_quiescent, > + !conf->quiesce, > + *(conf->hash_locks + hash)); > + } > > - if (test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) > - goto wait_for_stripe; > + sh = find_get_stripe(conf, sector, conf->generation - previous, > + hash); > + if (sh) > + break; > > - sh = get_free_stripe(conf, hash); > - if (sh) { > - r5c_check_stripe_cache_usage(conf); > - init_stripe(sh, sector, previous); > - atomic_inc(&sh->count); > - goto out; > - } > + if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { > + sh = get_free_stripe(conf, hash); > + if (sh) { > + r5c_check_stripe_cache_usage(conf); > + init_stripe(sh, sector, previous); > + atomic_inc(&sh->count); > + break; > + } > > - if (!test_bit(R5_DID_ALLOC, &conf->cache_state)) > - set_bit(R5_ALLOC_MORE, &conf->cache_state); > + if (!test_bit(R5_DID_ALLOC, &conf->cache_state)) > + set_bit(R5_ALLOC_MORE, &conf->cache_state); > + } > > -wait_for_stripe: > - if (noblock) > - goto out; > + if (noblock) > + break; > > - set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); > - r5l_wake_reclaim(conf->log, 0); > - wait_event_lock_irq(conf->wait_for_stripe, > - is_inactive_blocked(conf, hash), > - *(conf->hash_locks + hash)); > - clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); > - goto retry; > + set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); > + r5l_wake_reclaim(conf->log, 0); > + wait_event_lock_irq(conf->wait_for_stripe, > + is_inactive_blocked(conf, hash), > + *(conf->hash_locks + hash)); > + clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); > + } > > -out: > spin_unlock_irq(conf->hash_locks + hash); > return sh; > } > -- > 2.30.2 >