Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1711197rbb; Mon, 26 Feb 2024 20:49:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVFBFB1255+rkz+9VmbuOrYnEbXnOwvR6C4WYhZ5EpFoLbpjQ12RxCzsiib01xFuj4R4qL3wtZ17olbcKGjqANjK60L4JFe2I3hqq+dwQ== X-Google-Smtp-Source: AGHT+IHu8/Bui0KNqOR9ewQ7WpFyzJmbNrrV/6FRPfnLVhQh+2iwqyPIeORTsO+ayIpeyhWwIKRq X-Received: by 2002:ad4:40c4:0:b0:68f:de5f:44b4 with SMTP id x4-20020ad440c4000000b0068fde5f44b4mr1756830qvp.10.1709009392124; Mon, 26 Feb 2024 20:49:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709009392; cv=pass; d=google.com; s=arc-20160816; b=sH34bb3WFkLZH6eE21vSysBvx/NhSeQ3Nb9wNy6yjrC/3ixOsPeRAIVZgnlTlpSUra cnXzkcCLwrMLLCxdLVGEMeA1F3GFSOjfLE72cwFy0fWTPmt3+0psav+Ni9+dlnnTIkRQ hkY9s0k1MJxMw5Ptn32ffpFtIZGJQAlhpi7eB5NSBH+odMYGIlA8Uod2MgR0NXN34bM2 zjF5yT+aNY1sE8f0aQqq4Sa8A26xjB93zqDJqVqtU09R8CTwX3osh9kWaugWCX8Fdy/O vpmnJIEGV0iS0umg8IuTvt+JNnxjA9j9hLE1MLTUvWRUjF+wN5z12EtLBiAfjO93JUiw rs7A== 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=w/eq9c918teT3asFeHzf8cTm6jZIDfMNRa5Rd6esSYg=; fh=6LSVS/ST9xZpPpI1zFmF9s6zZyL5Y/Hraqf5Mwy0leM=; b=ZwGiqu00OlqKNPTdOiHFmKcPVertDK16palUtyz8yeefKUBwLaNy+G0gHCJzywNbQJ rg6Jt0tHKbLZACF9pRZcpjjv7HbxUeYb1Pu/05VDhR6I532AJth1+x0pKsP2WMqihw6G FNV5IQln3QP8cvg9VxmlcCS0FIeoNQI4mBCLrOCvILb9YXw1LZj0Y14I4gvH2Pz5U5U0 bPugbPgRmGmEth8Cu7GFh4lCBp61Z8MoUHJ+VvFQHBGGwVUeUZp3bVOq6R03vcUFOd7i FqHcOal5e4w+GjKF1BSBauuf1IDivt710A+btOMflCecQGmWv3dnldmJqiED9VdJRQgv pXMQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="h6ExSm/S"; 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-82709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82709-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 d20-20020ac847d4000000b0042e66cbc8f7si6334174qtr.319.2024.02.26.20.49.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 20:49:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82709-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="h6ExSm/S"; 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-82709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82709-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 CECB91C22821 for ; Tue, 27 Feb 2024 04:49:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40ABB52F7A; Tue, 27 Feb 2024 04:49:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h6ExSm/S" 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 91A3151C5B for ; Tue, 27 Feb 2024 04:49:40 +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=1709009382; cv=none; b=dXn1Rxsvi0DEABn68JjKhW749SGVzwTAWSGG+DLAUqbqe+MMQw9Pmhp8HJZfJ0DzPZdBR2Y0zE0P4IAQAi7MpHJMki395QwGkaTwVDe13Pvvg0rYyxAr8dzDDhJ3bF783YGBk5jPurovQsWWtcty4SLgQQBMWQ0/IXJP+QQHuuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709009382; c=relaxed/simple; bh=FuHYOldpPnqbaKrdQRI+3loAuTSXbdWRUieVFpn6n6g=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NWhdNKLKrWj4Hpm4uTzbHEm3xQsdSwuwlHDkWuKtjcbbTR571CMDltWupZpdZNJ17XDgoCt/YDTca7nUobJhzieP4euGmqyPoXhnPAAJcEwNFDUzYkuJ3SRn31JX1Jcp2oJsXpRGrkotA8+o4gj5h6mr2UF29WOrB1j6siwwn7w= 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=h6ExSm/S; 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=1709009379; 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=w/eq9c918teT3asFeHzf8cTm6jZIDfMNRa5Rd6esSYg=; b=h6ExSm/SFwtRrLNw1Pc20mQt/c83XeUYFLS6i8C/SSk2912oRgBN9T6kfM06IyPw40jGEx Y45GQsAxwUAy/IBduU/zbrvyP8ggIeAuxktpS+3mg6JrnrXsA/q/7bXnxvZvFpJFal4zmx YhvlT2nzL6lv/229D2dLKg4kkIoZ4H8= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-xmhmA6uMM227UzaBKMwr5g-1; Mon, 26 Feb 2024 23:49:15 -0500 X-MC-Unique: xmhmA6uMM227UzaBKMwr5g-1 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-1dc6b99b045so21736055ad.0 for ; Mon, 26 Feb 2024 20:49:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709009354; x=1709614154; 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=w/eq9c918teT3asFeHzf8cTm6jZIDfMNRa5Rd6esSYg=; b=xFjbKPsjCnY36Ml+niD3irwOW1+xfibNYhkTk8vI0K82Frmv3h/JggXtdB30NCvwpX Yk5z3q2QAsARbe1C2fn3ZKQCQ8ay/fNo5TqcCfB4qYBWqp78r/FuobTQPzJQN0IxfZ1V bSjwEM09J+WkuraB3flcVSq3gKIh8hWnHQXuBAcpAiQ0peARSitXD+aP6N9bOwtMzR5K bUCPBRJFPrjyFtnMD3rEEZNRnE09BCIcyJfL9XKF1VesXfi1j39ScJqIEb/qnNAC1ZFz pmKmkmyu5kXQPU7Md+W1481gUbnm6K3LbW5xS2Ht2mEjYg0ygrV6nAnXdmIIVzA43KJU SOmA== X-Forwarded-Encrypted: i=1; AJvYcCV+ifXRJrBK3tuqeewpOvgSV5VlSLGhcb9YfkgtDa3xr95XN6QYSU92HB97GeZ4SyS6rxC5ZwXGF8fggXDLps0++33I01xSDuklaned X-Gm-Message-State: AOJu0YxJh8+R+5Jz9AgfX5UKvXjwV90QeU8Q+yF20mueEvnGkuFw4y4S qVDdLuDGIGVrp7UmJp6IU4WDpdIBffgbbPoyqKSvT8JMqEX8b3Yk/x8yHmk9U67b5L19/PGQC7G 4Dd0mOFAHUpZgPv8b4lUxwbpCcabhVzAtDdROTePqX98EUZjutBJzqtebN8mSJ7BHjWdUd7nFAN ouekmqescl7GsoC0CP2DvxHwV9SV+NetBjXYlD X-Received: by 2002:a17:902:c404:b0:1d7:836d:7b3f with SMTP id k4-20020a170902c40400b001d7836d7b3fmr12471168plk.9.1709009354661; Mon, 26 Feb 2024 20:49:14 -0800 (PST) X-Received: by 2002:a17:902:c404:b0:1d7:836d:7b3f with SMTP id k4-20020a170902c40400b001d7836d7b3fmr12471157plk.9.1709009354330; Mon, 26 Feb 2024 20:49:14 -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-4-yukuai1@huaweicloud.com> <6114e6f5-87a6-216e-027d-cbb0a7e8e429@huaweicloud.com> In-Reply-To: <6114e6f5-87a6-216e-027d-cbb0a7e8e429@huaweicloud.com> From: Xiao Ni Date: Tue, 27 Feb 2024 12:49:03 +0800 Message-ID: Subject: Re: [PATCH md-6.9 03/10] md/raid1: fix choose next idle in read_balance() 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, yi.zhang@huawei.com, yangerkun@huawei.com, "yukuai (C)" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 27, 2024 at 10:38=E2=80=AFAM Yu Kuai = wrote: > > Hi, > > =E5=9C=A8 2024/02/27 10:23, Xiao Ni =E5=86=99=E9=81=93: > > On Thu, Feb 22, 2024 at 4:04=E2=80=AFPM Yu Kuai wrote: > >> > >> From: Yu Kuai > >> > >> Commit 12cee5a8a29e ("md/raid1: prevent merging too large request") ad= d > >> the case choose next idle in read_balance(): > >> > >> read_balance: > >> for_each_rdev > >> if(next_seq_sect =3D=3D this_sector || disk =3D=3D 0) > >> -> sequential reads > >> best_disk =3D disk; > >> if (...) > >> choose_next_idle =3D 1 > >> continue; > >> > >> for_each_rdev > >> -> iterate next rdev > >> if (pending =3D=3D 0) > >> best_disk =3D disk; > >> -> choose the next idle disk > >> break; > >> > >> if (choose_next_idle) > >> -> keep using this rdev if there are no other idle disk > >> contine > >> > >> However, commit 2e52d449bcec ("md/raid1: add failfast handling for rea= ds.") > >> remove the code: > >> > >> - /* If device is idle, use it */ > >> - if (pending =3D=3D 0) { > >> - best_disk =3D disk; > >> - break; > >> - } > >> > >> Hence choose next idle will never work now, fix this problem by > >> following: > >> > >> 1) don't set best_disk in this case, read_balance() will choose the be= st > >> disk after iterating all the disks; > >> 2) add 'pending' so that other idle disk will be chosen; > >> 3) set 'dist' to 0 so that if there is no other idle disk, and all dis= ks > >> are rotational, this disk will still be chosen; > >> > >> Fixes: 2e52d449bcec ("md/raid1: add failfast handling for reads.") > >> Co-developed-by: Paul Luse > >> Signed-off-by: Paul Luse > >> Signed-off-by: Yu Kuai > >> --- > >> drivers/md/raid1.c | 21 ++++++++++++--------- > >> 1 file changed, 12 insertions(+), 9 deletions(-) > >> > >> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c > >> index c60ea58ae8c5..d0bc67e6d068 100644 > >> --- a/drivers/md/raid1.c > >> +++ b/drivers/md/raid1.c > >> @@ -604,7 +604,6 @@ static int read_balance(struct r1conf *conf, struc= t r1bio *r1_bio, int *max_sect > >> unsigned int min_pending; > >> struct md_rdev *rdev; > >> int choose_first; > >> - int choose_next_idle; > >> > >> /* > >> * Check if we can balance. We can balance on the whole > >> @@ -619,7 +618,6 @@ static int read_balance(struct r1conf *conf, struc= t r1bio *r1_bio, int *max_sect > >> best_pending_disk =3D -1; > >> min_pending =3D UINT_MAX; > >> best_good_sectors =3D 0; > >> - choose_next_idle =3D 0; > >> clear_bit(R1BIO_FailFast, &r1_bio->state); > >> > >> if ((conf->mddev->recovery_cp < this_sector + sectors) || > >> @@ -712,7 +710,6 @@ static int read_balance(struct r1conf *conf, struc= t r1bio *r1_bio, int *max_sect > >> int opt_iosize =3D bdev_io_opt(rdev->bdev) >>= 9; > >> struct raid1_info *mirror =3D &conf->mirrors[= disk]; > >> > >> - best_disk =3D disk; > >> /* > >> * If buffered sequential IO size exceeds opt= imal > >> * iosize, check if there is idle disk. If ye= s, choose > >> @@ -731,15 +728,21 @@ static int read_balance(struct r1conf *conf, str= uct r1bio *r1_bio, int *max_sect > >> mirror->next_seq_sect > opt_iosize && > >> mirror->next_seq_sect - opt_iosize >=3D > >> mirror->seq_start) { > >> - choose_next_idle =3D 1; > >> - continue; > >> + /* > >> + * Add 'pending' to avoid choosing thi= s disk if > >> + * there is other idle disk. > >> + * Set 'dist' to 0, so that if there i= s no other > >> + * idle disk and all disks are rotatio= nal, this > >> + * disk will still be chosen. > >> + */ > >> + pending++; > >> + dist =3D 0; > >> + } else { > >> + best_disk =3D disk; > >> + break; > >> } > >> - break; > >> } > > > > Hi Kuai > > > > I noticed something. In patch 12cee5a8a29e, it sets best_disk if it's > > a sequential read. If there are no other idle disks, it will read from > > the sequential disk. With this patch, it reads from the > > best_pending_disk even min_pending is not 0. It looks like a wrong > > behaviour? > > Yes, nice catch, I didn't notice this yet... So there is a hidden > logical, sequential IO priority is higher than minimal 'pending' > selection, it's only less than 'choose_next_idle' where idle disk > exist. Yes. > > Looks like if we want to keep this behaviour, we can add a 'sequential > disk': > > if (is_sequential()) > if (!should_choose_next()) > return disk; > ctl.sequential_disk =3D disk; > > ... > > if (ctl.min_pending !=3D 0 && ctl.sequential_disk !=3D -1) > return ctl.sequential_disk; Agree with this, thanks :) Best Regards Xiao > > Thanks, > Kuai > > > > > Best Regards > > Xiao > >> > >> - if (choose_next_idle) > >> - continue; > >> - > >> if (min_pending > pending) { > >> min_pending =3D pending; > >> best_pending_disk =3D disk; > >> -- > >> 2.39.2 > >> > >> > > > > . > > >