Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp26966imn; Wed, 27 Jul 2022 14:10:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tyvNfdbOzZu+8aP+Edzsrf9kSBiFWdz8tsc/V3uIcRDMipCeltDjLNLyJKYvf52awfkWJr X-Received: by 2002:a17:906:cc5d:b0:72b:1313:cd09 with SMTP id mm29-20020a170906cc5d00b0072b1313cd09mr18737859ejb.482.1658956259617; Wed, 27 Jul 2022 14:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658956259; cv=none; d=google.com; s=arc-20160816; b=E6rQhgmUHwLOZUXpu6AXgdlxa4vVOoCX1xiDxRN4DN3PU+SnVJNFOxyG30lLUVjIuC d2Ii2IPbi24RwVEVLQEiwfHQJFr8s2kYJ/zrFtkF71/HQ3bruz/2PpfV7bsT8bLDnfD8 959SSJT6Ys+/z3dJ/WN9/hnWBR/LLFaeiaowVoHyMhQxj/eKfYNpO791Wllc0bG696BC uf9roV0LBlng1ggZd8BEAxasJyDzgwHUjrEvm15Qjc/Kxq1pGVTSFIHWEdai04UMv56p h/Af7e63WKjQPAh7n60LGLwpBfhv6t0mAD6Bp/w/lUGCMaZ8CQO+aCjCjAm9dZOtj6z9 h9ig== 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=HhOI3hGzyoxvTH1ppc65L0p8gCIRg/9KN6nIT4rDGSU=; b=MlOIMAaP4x/n+n2RzgRlQVqLj1O/hFvCwIoFAY7hgglcdup3RF9gmfEj0jfsW1c1lR bH3U07/UIi6XcS2FG1oGPfM8YO1jGeI32boqyQBeY/Li8+ftu6vgPIq1q6t7XEjEskW+ bvsY8zmK/i3cozgyirJVJJFyu5VaZ24bw3REODTwS8Fpc+u/X8mNomhWPmEsD4k8iMyD Oa998qeGo74cE9JunkBzNq3ooUHBgFAuk9J9YXC1p3RRZEgEF+abEjzINdRZdpLzHRuF +WC5LSc5N6ZUuSjYwkvOt2zfMWRg5UP7/YEys7oG/8Nv6O4ziEbgmhX7t12I8lUeGuST 6tcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=M4azOJKu; 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 my11-20020a1709065a4b00b00726a675c097si16873177ejc.337.2022.07.27.14.10.34; Wed, 27 Jul 2022 14:10:59 -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=M4azOJKu; 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 S237422AbiG0VIt (ORCPT + 99 others); Wed, 27 Jul 2022 17:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234152AbiG0VI3 (ORCPT ); Wed, 27 Jul 2022 17:08:29 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ACF9664D8; Wed, 27 Jul 2022 14:06:21 -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=HhOI3hGzyoxvTH1ppc65L0p8gCIRg/9KN6nIT4rDGSU=; b=M4azOJKu6pkULnQP5RF/RO9/VI h+72Xg3/Qqfw4U8MrBKKJwqUhCtdyVatB6jx7im5pNuOef+MqWEcrwYjXupgqKeIE27RLs9X/SSP4 AjzExZJRTo5KpAl+Of2eonMg+8sVPB/dryupdvcbcmgQdZF6+AYOtvNViS+IFyB0n3yxP3fu23qD6 XdGuRZm38F1GvKOL4/IySlNqb7cIunw/VGCKqwSS4960+W1k5oKTfbIpJ89aL+9VhYsxgoHi3WIqZ 3FmT25CIr9CVkTaAOKCOeW2e8roSqzvzRw6HeaebUwl/QSAPDMMZImvw5hGASPIvbI+OPBV95yDOM JPsgy0/A==; 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 1oGoEG-001pyD-GI; Wed, 27 Jul 2022 15:06:05 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1oGoEE-000VHx-MT; Wed, 27 Jul 2022 15:06:02 -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: Wed, 27 Jul 2022 15:05:56 -0600 Message-Id: <20220727210600.120221-2-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220727210600.120221-1-logang@deltatee.com> References: <20220727210600.120221-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 autolearn=ham autolearn_force=no version=3.4.6 Subject: [PATCH 1/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 the raid5_get_active_stripe() to read more linearly in the order it's typically executed. The init_stripe() call is called if a free stripe is found and the function is exited early which removes a lot of if (sh) checks and unindents the following code. Remove the while loop in favour of the 'goto retry' pattern, which reduces indentation further. And use a 'goto wait_for_stripe' instead of an additional indent seeing it is the unusual path and this makes the code easier to read. No functional changes intended. Will make subsequent changes in patches easier to understand. Signed-off-by: Logan Gunthorpe --- drivers/md/raid5.c | 67 +++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 3b7887428cd0..b1cb0be8fa67 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -766,41 +766,46 @@ raid5_get_active_stripe(struct r5conf *conf, sector_t sector, spin_lock_irq(conf->hash_locks + hash); - do { - wait_event_lock_irq(conf->wait_for_quiescent, - conf->quiesce == 0 || noquiesce, - *(conf->hash_locks + hash)); - sh = find_get_stripe(conf, sector, conf->generation - previous, - hash); - if (sh) - break; +retry: + wait_event_lock_irq(conf->wait_for_quiescent, + conf->quiesce == 0 || noquiesce, + *(conf->hash_locks + hash)); + sh = find_get_stripe(conf, sector, conf->generation - previous, hash); + if (sh) + goto out; - if (!test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) { - sh = get_free_stripe(conf, hash); - if (!sh && !test_bit(R5_DID_ALLOC, &conf->cache_state)) - set_bit(R5_ALLOC_MORE, &conf->cache_state); - } - if (noblock && !sh) - break; + if (test_bit(R5_INACTIVE_BLOCKED, &conf->cache_state)) + goto wait_for_stripe; + sh = get_free_stripe(conf, hash); + if (sh) { r5c_check_stripe_cache_usage(conf); - if (!sh) { - set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); - r5l_wake_reclaim(conf->log, 0); - wait_event_lock_irq(conf->wait_for_stripe, - !list_empty(conf->inactive_list + hash) && - (atomic_read(&conf->active_stripes) - < (conf->max_nr_stripes * 3 / 4) - || !test_bit(R5_INACTIVE_BLOCKED, - &conf->cache_state)), - *(conf->hash_locks + hash)); - clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); - } else { - init_stripe(sh, sector, previous); - atomic_inc(&sh->count); - } - } while (sh == NULL); + init_stripe(sh, sector, previous); + atomic_inc(&sh->count); + goto out; + } + if (!test_bit(R5_DID_ALLOC, &conf->cache_state)) + set_bit(R5_ALLOC_MORE, &conf->cache_state); + +wait_for_stripe: + if (noblock) + goto out; + + r5c_check_stripe_cache_usage(conf); + set_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); + r5l_wake_reclaim(conf->log, 0); + wait_event_lock_irq(conf->wait_for_stripe, + !list_empty(conf->inactive_list + hash) && + (atomic_read(&conf->active_stripes) + < (conf->max_nr_stripes * 3 / 4) + || !test_bit(R5_INACTIVE_BLOCKED, + &conf->cache_state)), + *(conf->hash_locks + hash)); + clear_bit(R5_INACTIVE_BLOCKED, &conf->cache_state); + goto retry; + +out: spin_unlock_irq(conf->hash_locks + hash); return sh; } -- 2.30.2