Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp833787rwb; Thu, 11 Aug 2022 10:40:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR7dwkZM8d9/SxrSjxGaiC7RzEfVlRU1K7Wr9WfQv50soGFFRAht59RZ65+wlOmhfWYbPN4n X-Received: by 2002:a63:698a:0:b0:41c:8dfb:29cb with SMTP id e132-20020a63698a000000b0041c8dfb29cbmr149855pgc.170.1660239640278; Thu, 11 Aug 2022 10:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660239640; cv=none; d=google.com; s=arc-20160816; b=TaM+9Ju/qiMSIkDBADupU6WUJzXyTQJxLNWvS+jN/JjHZaK6LECUD1MXITojsnwbCO dDCnKh2VHRqiuzci5Kz3h5ImVFrPJxjqWVdtcrfR5MTR6Q75Q1UAApT0tyZ206MvmAnr EK6ZlsD7DVwPwh0QlnZx3epjqhPb2cgD+tKEjBZyI7ijq5NKDLpA1AxTTs60u+r7uawl wsb/fPVqJZUs6DWMo+4Q7Dj5frvKwn7C33/ODtE2wAe3GtxIcPx+v8tn9tRuvp8yNEtL qXUxZ/BGKlxsfG8ef29cGhWtHshARuSMg8fQdb/rJ9m6wj3NUyaOtti7f1T5dF8jyn1E Y+Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=KCWC1BAEeEOwJreUQh1JdYR/8BO5Nhl2E/sklHpn2Ck=; b=gEbQRlE4iHfGyDmHprWWPGUq2eca5TQZr2xlbjGxsMbfTbsafmWAdwfDR48TnlvPFu btcC8wQV5awA0nCU6FMMLBz3/FMHAlf3WPeFXkhQVOc8Mueyodcjd5QwxmRtER/ZP2nO uIqbGh4Kiy6i1leUkHuONeunfq1/PepAoYl2bAxZjShKADpy0E8ed2GyD8rX6+h1o9zn EhCLJ+trv54/9JV0nffXKkVUPE4Csvp1m1LoQ23WpbM7MMg9nI7qEjscl+VtYMJN0vxD f9DQXMyISneZtv/A5JkXdfaWUO/9KxIGy7/xDkwYMPhOWU3zhnfrXWQQFEYRSRJVLPVl Z8CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=sXLYh49k; 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=deltatee.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a170902f68700b00169ff93b923si6186883plg.48.2022.08.11.10.40.24; Thu, 11 Aug 2022 10:40:40 -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=@deltatee.com header.s=20200525 header.b=sXLYh49k; 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=deltatee.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235872AbiHKRTG (ORCPT + 99 others); Thu, 11 Aug 2022 13:19:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235247AbiHKRSf (ORCPT ); Thu, 11 Aug 2022 13:18:35 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008C385AB2; Thu, 11 Aug 2022 10:14:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=KCWC1BAEeEOwJreUQh1JdYR/8BO5Nhl2E/sklHpn2Ck=; b=sXLYh49k+1n6XS6E8KFAq2f63I 9fzc/JF/Q7zJfb+MEHo/tt/JCJysj2k299OPy7tiKEj/MzFEtQFjdyG2a4Z7CXj0jgd+t9j97wrOW o3JEIaEdBgVX88dnCbuCsgEXsm7o9SnAacPAcFeWS2kikUKUM4gbLJ0bxIQ32euHFah+BJddzZhHw DhIButxjqoAudX1AmcFkBDood03WdsbwqtLcH8bozKlAMW7JOCCmBHrhcl0yfm8qc244IIR2ce0x9 YFfiUyr5gq0sn1p8/0WkLDaPmMKITkenrPOsgfrd9DstuBzaAXm4LPsLXKCzqzjDMpzS8tXM4Wznz fccuWofg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oMBlJ-00EAyh-Rj; Thu, 11 Aug 2022 11:14:26 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1oMBlH-000cRA-VO; Thu, 11 Aug 2022 11:14:24 -0600 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu Cc: Christoph Hellwig , Guoqing Jiang , Stephen Bates , Martin Oliveira , David Sloan , Logan Gunthorpe Date: Thu, 11 Aug 2022 11:14:14 -0600 Message-Id: <20220811171417.147697-3-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220811171417.147697-1-logang@deltatee.com> References: <20220811171417.147697-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, song@kernel.org, hch@infradead.org, guoqing.jiang@linux.dev, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 2/5] md/raid5: Refactor raid5_get_active_stripe() X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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