Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp779570pxb; Fri, 22 Apr 2022 10:59:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTQeWRZ+lzMwA+MYhB/jn3iRS/HwGQNZi3LtFwg+vG8wbvRwLkULOgYLaDnAw1Zt2HFKsU X-Received: by 2002:a62:1611:0:b0:50a:41c5:e6fc with SMTP id 17-20020a621611000000b0050a41c5e6fcmr6211934pfw.35.1650650390665; Fri, 22 Apr 2022 10:59:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650650390; cv=none; d=google.com; s=arc-20160816; b=BRe5PwB6/Y7cjsYsxlNhaTlXNDH65xYyNQ6B+/QeBZicfWkW+5ohxkaUA933uDfluG seDL8Ig3irNBxRS832+LcAtjRTwfLXv+ljoVJCTE/0QVO17kcUTpXpW449RiPszjdWPh jE2siasZRc5LYZ7S+s7CygiBahOmuJIK+3jCtNnfDuqGIZeAQYyfOVO2cZUNKPSyuKRk LilbCS8hraahc3PM/kWetlxEJ5S7Z5WUtnvJWRbOcwGp5E3s/lYlMSYoeQTeyN9IH27V 9jbtUaWEsiNwstx/Y0KtwAvV9dzSnW5o6xrT6xqjLhLWZ8MZZtyEtGDcvgARDSgMV820 dLXA== 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:in-reply-to :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=hkyKr8j3OxoBTrWwgPc9PNlCF0d6AYPRaEfu+FOjftE=; b=zodgaoH1tp69C9Sz6YP+x0OQ0/Jv2HVouNUBmCmj0JoeWe/n1+sC3a6xih6aJPDoWG YFzM72pG78+WrCje1wJiF/3gw3WP4WAItLieVSc5WTRxM78n2nSaK/ZAw43Pg26Y+nEb nIKVakpAlBQbESBUllN4mb3KIrAwAj30XtcKac8LRzImEW1V8tQJHsAAI1jAKM3v1G0+ IgNzd40At5hIaVVKT7KE2p2UOHk6o9EbGZMpkaY0PQwthIxo0a/HOdwzK6QmK2AK5GJI KxV8HFHEcSlLeZBpAibuDd4/faEr2tKWwOdp59kDTUwuw8k4lyuRnwXHjjA2zf83j6ek Uhew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=MxidANs+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k14-20020a170902ba8e00b00154319ca2ddsi8062093pls.397.2022.04.22.10.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 10:59:50 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@deltatee.com header.s=20200525 header.b=MxidANs+; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=deltatee.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 02303110979; Fri, 22 Apr 2022 10:41:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390348AbiDUP5U (ORCPT + 99 others); Thu, 21 Apr 2022 11:57:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390336AbiDUP5S (ORCPT ); Thu, 21 Apr 2022 11:57:18 -0400 Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6983D47392; Thu, 21 Apr 2022 08:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:In-Reply-To:From:References:Cc:To: MIME-Version:Date:Message-ID:content-disposition; bh=hkyKr8j3OxoBTrWwgPc9PNlCF0d6AYPRaEfu+FOjftE=; b=MxidANs+F8ZM87gae7J2FlSgNz toNb4BaJOpSIR3tZFT+xC1oEd/EUUR+yK+aXWaA1WGGuq4zTdwS0AIdiKn0O0DsThCLmTbE+nFMFE Xi1lFdCOuq6GPZN421PH28ueyFgv924JEE5k7xHrwWU9WMV3sAd+fX+EFO7vOnG25U1Ncj4T8ZORD RCvaGgFMaID4kWKIetXn6MwollYxbUAeymnKxDjTFEHWJmCWVhXifu0fd1hUDRthhuHGZylFRoLPQ KyfDEIiua8v3we7KGrPIx+bdid2CZD0K0tDaWi27RBPiv3fEsNuKa3dMIPPgOZuew1PVuIUMBWOUw iDoe2QUw==; Received: from s0106a84e3fe8c3f3.cg.shawcable.net ([24.64.144.200] helo=[192.168.0.10]) by ale.deltatee.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1nhZ8U-00DB5J-L7; Thu, 21 Apr 2022 09:54:27 -0600 Message-ID: Date: Thu, 21 Apr 2022 09:54:23 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-CA To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Song Liu , Guoqing Jiang , Stephen Bates , Martin Oliveira , David Sloan References: <20220420195425.34911-1-logang@deltatee.com> <20220420195425.34911-13-logang@deltatee.com> From: Logan Gunthorpe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 24.64.144.200 X-SA-Exim-Rcpt-To: hch@infradead.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, song@kernel.org, guoqing.jiang@linux.dev, sbates@raithlin.com, Martin.Oliveira@eideticom.com, David.Sloan@eideticom.com X-SA-Exim-Mail-From: logang@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=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 Subject: Re: [PATCH v2 12/12] md/raid5: Pivot raid5_make_request() 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 On 2022-04-21 00:43, Christoph Hellwig wrote: > On Wed, Apr 20, 2022 at 01:54:25PM -0600, Logan Gunthorpe wrote: >> struct stripe_request_ctx { >> bool do_flush; >> struct stripe_head *batch_last; >> + sector_t disk_sector_done; >> + sector_t start_disk_sector; > > Very nitpicky, but why use two different naming styles for the sectors > here? > >> + bool first_wrap; >> + sector_t last_sector; > > And especially with the last_sector here a few comments explaining > what each of the sector values mean might be useful. > > I'd also keep the two bool variables together for a better structure > layout. Yeah, this logic has been very tricky to figure out. Thus explaining it was quite difficult. It was a consistent source of bugs for a me for a while until I figured out this little state machine. I'll follow your rough template and rework the comments and try to make a large example comment or something to explain this, and maybe factor it into a helper function. >> + * if new_sector is less than the starting sector. Clear the >> + * boolean once the start sector is hit for the second time. >> + * When first_wrap is set, ignore the disk_sector_done. >> + */ >> + if (ctx->start_disk_sector == MaxSector) { >> + ctx->start_disk_sector = new_sector; >> + } else if (new_sector < ctx->start_disk_sector) { >> + ctx->first_wrap = true; >> + } else if (new_sector == ctx->start_disk_sector) { >> + ctx->first_wrap = false; >> + ctx->start_disk_sector = 0; >> + return STRIPE_SUCCESS; >> + } else if (!ctx->first_wrap && new_sector <= ctx->disk_sector_done) { >> + return STRIPE_SUCCESS; >> + } >> + > > I find this a bit confusing to read. While trying to mentally untangle > it I came up with this version instead, but it could really use some > good comments explaining each of the checks as I found your big comment > to not quite match the logic easily. > > if (ctx->start_disk_sector == MaxSector) { > /* > * First loop iteration, start our state machine. > * > ctx->start_disk_sector = new_sector; > } else { > /* > * We are done if we wrapped around to the same sector. > * (???) > */ > if (new_sector == ctx->start_disk_sector) { > ctx->first_wrap = false; > ctx->start_disk_sector = 0; > return STRIPE_SUCCESS; > } > > /* > * Sector before the start sector? Keep going and wrap > * around. > */ > if (new_sector < ctx->start_disk_sector) { > ctx->first_wrap = true; > } else { > // ??? This is actually the common most important branch that says if we've already done this disk sector to stop and move on. So I'll probably rework it some so that it is not so deeply nested. > if (new_sector <= ctx->disk_sector_done && > !ctx->first_wrap) > return STRIPE_SUCCESS; > } > } No problem cleaning up your other nits. I'll send a v3 in due course. Thanks, Logan