Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1313069rbb; Mon, 26 Feb 2024 05:47:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU7Xf24F3NqrVUp83gbbTYtFbzqLhho3P+KgmOgQr5Sinp0sFyKGNylxiUUTq+jNkSoM80v94mJjrT6h7QZS/Lgb7C4MXvoJIvtkd+GcA== X-Google-Smtp-Source: AGHT+IG1d2i/8dbuXI5PXSgp8EPpCM6CPODWhlqCCot9RKUivPtyC/DE4vmyULfXyEGZcMpSQqg1 X-Received: by 2002:a0c:e44d:0:b0:68f:cbfa:6876 with SMTP id d13-20020a0ce44d000000b0068fcbfa6876mr7283492qvm.38.1708955242343; Mon, 26 Feb 2024 05:47:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708955242; cv=pass; d=google.com; s=arc-20160816; b=aXu7iC/QlgzD3N5VgBqr4aH7mkXMkFRAOHJSTex6RNnNQFTgdBmRgheTinPF03YST6 pMEaWYrlvzBO/YK8LJ5vgqRr3GyKpruFyU6do70ZahXEm+WmOp6q49bHQx0/lXxcBvGX tiJv0kubUq3LeUNwtObj03Kmxdpq9RU2DVmniVi/zS18+GWpmwgpc5VcJeh9Wi6ULe4c 9M6xrbEDimvLqFcJNT/YsuvJ1DjtBcJmuqZ9w4zRfPXKv6TNRt9ZEf60c8xP1xAG/bui rDp3tUP9J3IW2iJMPeRusWF82XXYMlBmAYXcPyzK0r6r88BM8ScHCVYeQPjFgRFHdVX7 sdmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=USZoAZmeJUCkk8eKkEZ4nGh7Q9sDulz8ByqxvL+GExk=; fh=h+tVC/3VUtSnSmcs8NP+h62PtIPamva/fuQFEToV9mc=; b=EExqw4Pl8g8b7GUkgRdc8mxoZoWdwd2dEu2OO8VgVIyueGSX+MmbdhU38a3I48FqSj 8Ewyll396mPtX7AqaujXBI162UNpAJFaVmWN1nkm8LnmIHiWzFvtMAjeEU7i+AF1I+4v lqqFV+3nVTvteXLSuY6gAHVHy+Ka7KUOG0F2Z6BUXr20H0aTYBkW6Wd4piJTLIUuG58x iI1+cUGFy5t5JdnoL8LAkQX28U7rmpya4a4bMofvlJlLmomT4Htiirj+y9lJeIXKV3SK tcv4wHUaFW7R3OUZPscVu+kcm5qbEoJVy1FJSRVNMNIXWR8yCK5dHgRL/CXUkn8yVVOa l62A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TvwZ1BLx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-81526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id gw12-20020a0562140f0c00b00690062e6bf9si2635929qvb.597.2024.02.26.05.47.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:47:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TvwZ1BLx; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-81526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0BA531C22D64 for ; Mon, 26 Feb 2024 13:47:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29316129A6D; Mon, 26 Feb 2024 13:47:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TvwZ1BLx" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02E93129A8F for ; Mon, 26 Feb 2024 13:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708955227; cv=none; b=V3F56R/V8W9ZGJ9xXVAWVtaD2H8P+vLp6BIKiiHvcrYhE1xqOGT2dUtnowo1dsc0jYwkqT6c7Wr9taErVgMxt5j6F/1oKgILAiYbkXxmdP0GgmW3iBEJa1YESx4rCVeXuISKXGsbq8QbfHi3mCBgdXxBxTLRx+ooOjc+i3OL4Tg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708955227; c=relaxed/simple; bh=81sdhCcN9wporVYbJerD7h86zygDNdYtXMFH1Wo/mCU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=oYT0ugZliMHzApq6YgJ4tQEGQ8brm0nO49/Z19PQ/DMDDguW5qt4dNJPdr3PTQpJFX54KnCEM9UL1lQ5TakgYZj38P7j5+lgxiD9KCtpSCSyQDOAGsfYjPvY3uTh/DukipYjpSfsVo4mFg+CYV2p4cDJIMtnV3Kj4Hn1dospzJ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TvwZ1BLx; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708955223; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=USZoAZmeJUCkk8eKkEZ4nGh7Q9sDulz8ByqxvL+GExk=; b=TvwZ1BLxoGYk0azePVOnmuwR54OsGu5r5yfpx2IZkKEQvVvp7HWPb91YLsLK00uVLB+uKu O3VAxULgfdpKDeJyH5u9ZFCa9lWvbdL1C03V5Gmfeka0ElotugNkBTREj3B5oJJ0TB7Bjz y7Bdzkc+umRD1iZEbCrC9GlKPoizTig= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-544-8EmOiJJCPEW5nRNu9zlqJA-1; Mon, 26 Feb 2024 08:47:02 -0500 X-MC-Unique: 8EmOiJJCPEW5nRNu9zlqJA-1 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-1dc30bbb7b6so34698125ad.1 for ; Mon, 26 Feb 2024 05:47:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708955221; x=1709560021; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USZoAZmeJUCkk8eKkEZ4nGh7Q9sDulz8ByqxvL+GExk=; b=OqGqPcJiLHRTh4zPzQKOY77NIsSyyTxXM9RPyKuixHrsIQWYsSib33/VsWZ1QLPNVL 4FF7aIp8zQfOOibkHP2TvOn3u4uAn5IGPosbVyZyP2BIOvKsme+0Cub15hPwIsXFEcG9 kttKdmiNmYDjyEIOCSOmM7kM7nwRLDd0GjXX4mw2h/99nBpwE0WHy3vpq/kD+gumcgR9 hh1Jpn7bsb1pUT+U0iu+NI2GnNKty1PHb1TkLWOtQGUOoncNSlmmDAsjn0fNzt6bMpdi ScoyjvFZjvMWNnNk36orKiwVfQNwfdUFws1RGuzqxitXsAloxry/GG+f++OYZ34lKA+7 bY0Q== X-Forwarded-Encrypted: i=1; AJvYcCVsFXrGlvyqIzCC+EQ9E/7V2H8yhmUo4c6j3SL2sADfc2YUKIg8wq9D8ZZVdOsKPU3SXBujvkn8kFVbIVNFRopTU8eFGxT/wXsEnp9i X-Gm-Message-State: AOJu0YwgpLcGUbU3DBjY65T1qoqN+xPiOHS3cOuIA5NVoTfmszMfgQnO X64BU4lnPO9vGuv6Nld8KOLOh4n+qYJfwvcukxyHKnoS6TVgk8EWFDZF1+VamQVxaUpSbQ81I8x q+YFvXt8HlvsqVmP4mIB3gA96CcMjx/PVhL67nUfTy/I/qLKnkcNxoLGY2a+dHtBZ8lfD/tWmhL c5HllZTpdG80FKz7jOAreKimvurHGm3/+LVj+w X-Received: by 2002:a17:902:ec82:b0:1dc:7719:7095 with SMTP id x2-20020a170902ec8200b001dc77197095mr11309440plg.60.1708955221377; Mon, 26 Feb 2024 05:47:01 -0800 (PST) X-Received: by 2002:a17:902:ec82:b0:1dc:7719:7095 with SMTP id x2-20020a170902ec8200b001dc77197095mr11309407plg.60.1708955221062; Mon, 26 Feb 2024 05:47:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240222075806.1816400-1-yukuai1@huaweicloud.com> <20240222075806.1816400-6-yukuai1@huaweicloud.com> In-Reply-To: <20240222075806.1816400-6-yukuai1@huaweicloud.com> From: Xiao Ni Date: Mon, 26 Feb 2024 21:46:49 +0800 Message-ID: Subject: Re: [PATCH md-6.9 05/10] md/raid1-10: factor out a new helper raid1_should_read_first() To: Yu Kuai Cc: paul.e.luse@linux.intel.com, song@kernel.org, neilb@suse.com, shli@fb.com, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, yangerkun@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 22, 2024 at 4:05=E2=80=AFPM Yu Kuai w= rote: > > From: Yu Kuai > > If resync is in progress, read_balance() should find the first usable > disk, otherwise, data could be inconsistent after resync is done. raid1 > and raid10 implement the same checking, hence factor out the checking > to make code cleaner. > > Noted that raid1 is using 'mddev->recovery_cp', which is updated after > all resync IO is done, while raid10 is using 'conf->next_resync', which > is inaccurate because raid10 update it before submitting resync IO. > Fortunately, raid10 read IO can't concurrent with resync IO, hence there > is no problem. And this patch also switch raid10 to use > 'mddev->recovery_cp'. > > Co-developed-by: Paul Luse > Signed-off-by: Paul Luse > Signed-off-by: Yu Kuai > --- > drivers/md/raid1-10.c | 20 ++++++++++++++++++++ > drivers/md/raid1.c | 15 ++------------- > drivers/md/raid10.c | 13 ++----------- > 3 files changed, 24 insertions(+), 24 deletions(-) > > diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c > index 9bc0f0022a6c..2ea1710a3b70 100644 > --- a/drivers/md/raid1-10.c > +++ b/drivers/md/raid1-10.c > @@ -276,3 +276,23 @@ static inline int raid1_check_read_range(struct md_r= dev *rdev, > *len =3D first_bad + bad_sectors - this_sector; > return 0; > } > + > +/* > + * Check if read should choose the first rdev. > + * > + * Balance on the whole device if no resync is going on (recovery is ok)= or > + * below the resync window. Otherwise, take the first readable disk. > + */ > +static inline bool raid1_should_read_first(struct mddev *mddev, > + sector_t this_sector, int len) > +{ > + if ((mddev->recovery_cp < this_sector + len)) > + return true; > + > + if (mddev_is_clustered(mddev) && > + md_cluster_ops->area_resyncing(mddev, READ, this_sector, > + this_sector + len)) > + return true; > + > + return false; > +} > diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c > index d0bc67e6d068..8089c569e84f 100644 > --- a/drivers/md/raid1.c > +++ b/drivers/md/raid1.c > @@ -605,11 +605,6 @@ static int read_balance(struct r1conf *conf, struct = r1bio *r1_bio, int *max_sect > struct md_rdev *rdev; > int choose_first; > > - /* > - * Check if we can balance. We can balance on the whole > - * device if no resync is going on, or below the resync window. > - * We take the first readable disk when above the resync window. > - */ > retry: > sectors =3D r1_bio->sectors; > best_disk =3D -1; > @@ -618,16 +613,10 @@ static int read_balance(struct r1conf *conf, struct= r1bio *r1_bio, int *max_sect > best_pending_disk =3D -1; > min_pending =3D UINT_MAX; > best_good_sectors =3D 0; > + choose_first =3D raid1_should_read_first(conf->mddev, this_sector= , > + sectors); > clear_bit(R1BIO_FailFast, &r1_bio->state); > > - if ((conf->mddev->recovery_cp < this_sector + sectors) || > - (mddev_is_clustered(conf->mddev) && > - md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector= , > - this_sector + sectors))) > - choose_first =3D 1; > - else > - choose_first =3D 0; > - > for (disk =3D 0 ; disk < conf->raid_disks * 2 ; disk++) { > sector_t dist; > sector_t first_bad; > diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c > index 1f6693e40e12..22bcc3ce11d3 100644 > --- a/drivers/md/raid10.c > +++ b/drivers/md/raid10.c > @@ -747,17 +747,8 @@ static struct md_rdev *read_balance(struct r10conf *= conf, > best_good_sectors =3D 0; > do_balance =3D 1; > clear_bit(R10BIO_FailFast, &r10_bio->state); > - /* > - * Check if we can balance. We can balance on the whole > - * device if no resync is going on (recovery is ok), or below > - * the resync window. We take the first readable disk when > - * above the resync window. > - */ > - if ((conf->mddev->recovery_cp < MaxSector > - && (this_sector + sectors >=3D conf->next_resync)) || > - (mddev_is_clustered(conf->mddev) && > - md_cluster_ops->area_resyncing(conf->mddev, READ, this_secto= r, > - this_sector + sectors))) > + > + if (raid1_should_read_first(conf->mddev, this_sector, sectors)) > do_balance =3D 0; > > for (slot =3D 0; slot < conf->copies ; slot++) { > -- > 2.39.2 > > This patch looks good to me. Reviewed-by: Xiao Ni