Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp25983pxb; Wed, 27 Jan 2021 00:46:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQcApM3/gouplhH5QleuvRQb4qOt9ZRxq8X1SAZ2mHIJ2bubTQkylHL7vLWWDASSFdNi/3 X-Received: by 2002:a17:906:9381:: with SMTP id l1mr6341148ejx.433.1611737194827; Wed, 27 Jan 2021 00:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611737194; cv=none; d=google.com; s=arc-20160816; b=XizhCq94UuoNrSU+qZbZucA/z+H26opr8m662v732iOUEvKDs4NfTKteVjgOGced4I IVp2v704D1nukln8ik8G+RNjZT+SAPl6S4ABwyMRJKGwXExoXzZpZpWv/AJ23g5gvkCr hEQ2rFPjqlBm+Bsf2uyqE6gJLShvMUH/bjcNthKc2a5VSnhZnh6M7ZkZRM6394OtNjlx 94UTvI1dMKFAY6B/3w6VV9RMR4PHmfQBZZttpRsw09HmcBgHP0v2EZTM8t6mqvuyKepU aNSCx8+vvU10F5+KgTaRlb6bwXcwzvxKw78Las7goc3hRj54VijyvCFY6fkypdHn0x8u Dpqw== 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=i4cSXHHR4Py00rpJbf3wI2gkC/FS09xHyRE0JV+nuS4=; b=JkUjQgSsSz7y/aqz4ELrjZbSdEvswjUOBTCVK21EOTz/79IXNXqd+q+tIykowtpHaX +ODsJU4ncQpNIZQuMERjwh8e/Nfs+vD6eT0j9BWRBomGnd/d4ZQJDwrI3UGjsvZyZ1y7 dGQCtTOYOLVnRelxoonR3lyizun1DjLlz4vytMSdynj/ntpKvWB46zF0mPRSK766IDkh MKdOGHw4oQDeY7s2pSGh1OGx2OdC46SPr4l2tdA2zf89pYVNPrOKNcPVNAulTeHX2g0q j2t7Q2PzyV4UWQqlKgM42J/rxHrgwoi51/C6ys1VjuDbVtfW7jTWGhMYB2Hl44gABacF pXGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YwAkJqJB; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q14si669872edw.313.2021.01.27.00.45.39; Wed, 27 Jan 2021 00:46:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YwAkJqJB; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-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 S233358AbhA0HTn (ORCPT + 99 others); Wed, 27 Jan 2021 02:19:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:47124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbhA0HQr (ORCPT ); Wed, 27 Jan 2021 02:16:47 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A14A22073A; Wed, 27 Jan 2021 07:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611731766; bh=roeH+S42no3Sboc4a7IJP429EgMi3Brd/syWUAT1emI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=YwAkJqJB5KFzCdu4e+4xCNTp5SGGkGySjdzbItm+79z64FYD48iciemcPnv9Mlnh2 fQe/1cHafViGhPE5p2SUGGk7l2Vhny6UH/75EGwWZ3nK0+HnxUNWUmWGRosC2xio9O dRi+UbUKyDXe8JCUdmtUZW0806oZFEhVUm2J2GGpN8AlBtCoUdYBvDoW9GI5hoFou2 3xjIKrj9pkB94a6Kv5TBwDw6939ekhvFTRuKbb7P+RY+RabHAYJmGrLgripNRJJX3W Raf3XxHZrQEIZAvG4133epfOMyH9k3RvBZMOilB6mOoVuQkWm455KOkyOh/K8Y5DFv MHtESQFL6GhMA== Received: by mail-lf1-f50.google.com with SMTP id f1so1249639lfu.3; Tue, 26 Jan 2021 23:16:05 -0800 (PST) X-Gm-Message-State: AOAM530hTGoI/NZEUqRnpztQG0Cn43JQoq4V3v2LqhN1rQpHFale6zgN YHpuyXJcRDV06hRuJQEI2t3QbwUHSclvuTQlo4w= X-Received: by 2002:a05:6512:b1b:: with SMTP id w27mr4506047lfu.10.1611731763892; Tue, 26 Jan 2021 23:16:03 -0800 (PST) MIME-Version: 1.0 References: <20210126145247.1964410-1-hch@lst.de> <20210126145247.1964410-15-hch@lst.de> In-Reply-To: <20210126145247.1964410-15-hch@lst.de> From: Song Liu Date: Tue, 26 Jan 2021 23:15:52 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 14/17] md/raid6: refactor raid5_read_one_chunk To: Christoph Hellwig Cc: Jens Axboe , Jaegeuk Kim , Chao Yu , Philipp Reisner , Lars Ellenberg , Coly Li , Mike Snitzer , Josef Bacik , David Sterba , Damien Le Moal , Naohiro Aota , Andrew Morton , Ryusuke Konishi , linux-nilfs@vger.kernel.org, dm-devel@redhat.com, linux-f2fs-devel@lists.sourceforge.net, linux-block@vger.kernel.org, drbd-dev@lists.linbit.com, linux-bcache@vger.kernel.org, linux-raid , Linux-Fsdevel , linux-btrfs@vger.kernel.org, linux-nfs@vger.kernel.org, Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Tue, Jan 26, 2021 at 7:19 AM Christoph Hellwig wrote: > > Refactor raid5_read_one_chunk so that all simple checks are done > before allocating the bio. > > Signed-off-by: Christoph Hellwig Acked-by: Song Liu Thanks for the clean-up! > --- > drivers/md/raid5.c | 108 +++++++++++++++++++-------------------------- > 1 file changed, 45 insertions(+), 63 deletions(-) > > diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c > index f411b9e5c332f4..a348b2adf2a9f9 100644 > --- a/drivers/md/raid5.c > +++ b/drivers/md/raid5.c > @@ -5393,90 +5393,72 @@ static void raid5_align_endio(struct bio *bi) > static int raid5_read_one_chunk(struct mddev *mddev, struct bio *raid_bio) > { > struct r5conf *conf = mddev->private; > - int dd_idx; > - struct bio* align_bi; > + struct bio *align_bio; > struct md_rdev *rdev; > - sector_t end_sector; > + sector_t sector, end_sector, first_bad; > + int bad_sectors, dd_idx; > > if (!in_chunk_boundary(mddev, raid_bio)) { > pr_debug("%s: non aligned\n", __func__); > return 0; > } > - /* > - * use bio_clone_fast to make a copy of the bio > - */ > - align_bi = bio_clone_fast(raid_bio, GFP_NOIO, &mddev->bio_set); > - if (!align_bi) > - return 0; > - /* > - * set bi_end_io to a new function, and set bi_private to the > - * original bio. > - */ > - align_bi->bi_end_io = raid5_align_endio; > - align_bi->bi_private = raid_bio; > - /* > - * compute position > - */ > - align_bi->bi_iter.bi_sector = > - raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, > - 0, &dd_idx, NULL); > > - end_sector = bio_end_sector(align_bi); > + sector = raid5_compute_sector(conf, raid_bio->bi_iter.bi_sector, 0, > + &dd_idx, NULL); > + end_sector = bio_end_sector(raid_bio); > + > rcu_read_lock(); > + if (r5c_big_stripe_cached(conf, sector)) > + goto out_rcu_unlock; > + > rdev = rcu_dereference(conf->disks[dd_idx].replacement); > if (!rdev || test_bit(Faulty, &rdev->flags) || > rdev->recovery_offset < end_sector) { > rdev = rcu_dereference(conf->disks[dd_idx].rdev); > - if (rdev && > - (test_bit(Faulty, &rdev->flags) || > + if (!rdev) > + goto out_rcu_unlock; > + if (test_bit(Faulty, &rdev->flags) || > !(test_bit(In_sync, &rdev->flags) || > - rdev->recovery_offset >= end_sector))) > - rdev = NULL; > + rdev->recovery_offset >= end_sector)) > + goto out_rcu_unlock; > } > > - if (r5c_big_stripe_cached(conf, align_bi->bi_iter.bi_sector)) { > - rcu_read_unlock(); > - bio_put(align_bi); > + atomic_inc(&rdev->nr_pending); > + rcu_read_unlock(); > + > + align_bio = bio_clone_fast(raid_bio, GFP_NOIO, &mddev->bio_set); > + bio_set_dev(align_bio, rdev->bdev); > + align_bio->bi_end_io = raid5_align_endio; > + align_bio->bi_private = raid_bio; > + align_bio->bi_iter.bi_sector = sector; > + > + raid_bio->bi_next = (void *)rdev; > + > + if (is_badblock(rdev, sector, bio_sectors(align_bio), &first_bad, > + &bad_sectors)) { > + bio_put(align_bio); > + rdev_dec_pending(rdev, mddev); > return 0; > } > > - if (rdev) { > - sector_t first_bad; > - int bad_sectors; > - > - atomic_inc(&rdev->nr_pending); > - rcu_read_unlock(); > - raid_bio->bi_next = (void*)rdev; > - bio_set_dev(align_bi, rdev->bdev); > - > - if (is_badblock(rdev, align_bi->bi_iter.bi_sector, > - bio_sectors(align_bi), > - &first_bad, &bad_sectors)) { > - bio_put(align_bi); > - rdev_dec_pending(rdev, mddev); > - return 0; > - } > + /* No reshape active, so we can trust rdev->data_offset */ > + align_bio->bi_iter.bi_sector += rdev->data_offset; > > - /* No reshape active, so we can trust rdev->data_offset */ > - align_bi->bi_iter.bi_sector += rdev->data_offset; > + spin_lock_irq(&conf->device_lock); > + wait_event_lock_irq(conf->wait_for_quiescent, conf->quiesce == 0, > + conf->device_lock); > + atomic_inc(&conf->active_aligned_reads); > + spin_unlock_irq(&conf->device_lock); > > - spin_lock_irq(&conf->device_lock); > - wait_event_lock_irq(conf->wait_for_quiescent, > - conf->quiesce == 0, > - conf->device_lock); > - atomic_inc(&conf->active_aligned_reads); > - spin_unlock_irq(&conf->device_lock); > + if (mddev->gendisk) > + trace_block_bio_remap(align_bio, disk_devt(mddev->gendisk), > + raid_bio->bi_iter.bi_sector); > + submit_bio_noacct(align_bio); > + return 1; > > - if (mddev->gendisk) > - trace_block_bio_remap(align_bi, disk_devt(mddev->gendisk), > - raid_bio->bi_iter.bi_sector); > - submit_bio_noacct(align_bi); > - return 1; > - } else { > - rcu_read_unlock(); > - bio_put(align_bi); > - return 0; > - } > +out_rcu_unlock: > + rcu_read_unlock(); > + return 0; > } > > static struct bio *chunk_aligned_read(struct mddev *mddev, struct bio *raid_bio) > -- > 2.29.2 >