Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1207111rbb; Mon, 26 Feb 2024 02:04:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX0/cB0imbpFLzECZc6Bw/064lQ+jhuzFUynpkX/l6KSJ6FROBdw+M7WeKdBO009xRRIsELoAemt6PGKzMLdI3/MPdHdcNQfnoOz9ImHw== X-Google-Smtp-Source: AGHT+IFLj98P6+OhcvBchn+4cttxQJQKMhisCAKRuEMn5SphVWDza9t9QErNNYt4TI1RjZtm+LHG X-Received: by 2002:a05:6402:3587:b0:565:a5aa:22e7 with SMTP id y7-20020a056402358700b00565a5aa22e7mr5632384edc.2.1708941865924; Mon, 26 Feb 2024 02:04:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708941865; cv=pass; d=google.com; s=arc-20160816; b=oKUEzheCHqPOxomHb/GhHsGSFcqxc250tao6+QuLib9bPSm7lcohxkzoYmGa7Nt9J5 XmDjLbYu2GK7dXPgkdTSHDcSgsIJ9zQzGYXZanxoSXsQ4ECc10psPUKEqGzAgm3MM/Df 9l7OZA/BfRCaZNNbok27T7E/BInoWssyqJKJBnA6duDAkEqlgbiifrv999ppxt1ndMaR NPPk1eIDdEmASskCsu09ked1YpapY3CQaWYSXI0dQrvT9ENxI4x2M1RYOQBC6kWG8Sf3 pAotK6y0w6YMQkoczNXZD4MBICN2RWarsd3HhDDfqDrLCpFQcuhtQFnbVJxLLRohWrfi xbQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=gdhQzoOSPkQGpx4FLNu1TNF/fcQEZdxq/m6UsACl6i0=; fh=ltmVjLwz+gAs03cEcwuSVm5GoP8NJCsjWUA7jBsZvVA=; b=TbgKU6VEfNXRx1qVrqglSaHu9HOb4oh+K1QC3Zjp6F1VK40EW7B7Hpf05JgFyjVkYs /64dtfg0Av1uVaHTyWlOIrUR05Y+lQrWzjRVGm37Q8El+Shi4AMhkRu7zLV04ue1zZt4 bRNfGgp7SrG/uoJeGTWMxCN588QvWON7oZAZDFy14p1ouRBofr1ZffISu+5pslMGiOcl s7vi1J8m4MOIdbqh1oFLvejxz06r2F8DEKdKPr7Cfx6ls78W/hngC8HE/8G56N4BJV9w xYjQLRxPuWmCrlE9bp7TmXtGAxKdCQ8BFXlnBK/enWIxm3V1wXWB/gHIcoeTnT/GsHyu wxYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-81072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81072-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f10-20020a056402354a00b005659a55527asi1957115edd.532.2024.02.26.02.04.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 02:04:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-81072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81072-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6211E1F21533 for ; Mon, 26 Feb 2024 10:04:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39F215F579; Mon, 26 Feb 2024 09:40:13 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 6815B5F49A; Mon, 26 Feb 2024 09:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708940412; cv=none; b=G4WOjPwexjg5B9G0YsitB2Nw9MnwRCPO9Ge3ekvYNEkk7Pff35QPNh7KleHeFmEb9bzUJcOSOqbgGQgJK2XDa6bXbTUaI4JBCDixh+nxD03a2aScV9/O4PeynBg3bKPbDD0tw/a6KjnWE0OBbvHbo3Ya8DSH/65akQCWerd5eWw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708940412; c=relaxed/simple; bh=SS5aWCEFp88J7+X6Yo4GCAC3/LyWxt3ymokDrhw+bzs=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=c/Sg6BMCnneKWt/f28jAs033CnoCLTGI7fgcr/5gyhkDuJ1V/urKVwVw0o127+hYeg1CK+mlVGLRN4g59t18I1B1hig/uKar8TI3owPQnmtKpOidIaj8/wbh7dxzPmEcHheF8w/0PK/Ud26+3oIl0Zx6WJMJWKgCqa935eUxv3Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TjwZQ5tk9z4f3nVC; Mon, 26 Feb 2024 17:39:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 1C9481A0EBB; Mon, 26 Feb 2024 17:40:06 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgBXKBF1XNxlRaLOFA--.41686S3; Mon, 26 Feb 2024 17:40:05 +0800 (CST) Subject: Re: [PATCH md-6.9 03/10] md/raid1: fix choose next idle in read_balance() To: Xiao Ni , 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)" References: <20240222075806.1816400-1-yukuai1@huaweicloud.com> <20240222075806.1816400-4-yukuai1@huaweicloud.com> <34fbafbe-a510-5193-b86c-91fac69de95f@huaweicloud.com> From: Yu Kuai Message-ID: <05fab111-7111-1dca-57a8-89069a34adc2@huaweicloud.com> Date: Mon, 26 Feb 2024 17:40:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBXKBF1XNxlRaLOFA--.41686S3 X-Coremail-Antispam: 1UD129KBjvJXoW3JrW8WFWkZrWfCr1Dur1xXwb_yoW7Ar4xpr W0qanFyFWUXry5K3s2qw4UXr9aq343JF48uFykJ34Sqr90qFyqqF47KryUuFy8CFs7Jw17 Xr1UGrW7u3W0kFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9Y14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka 0xkIwI1lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWU JwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCT nIWIevJa73UjIFyTuYvjfUF9a9DUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ Hi, 在 2024/02/26 17:24, Xiao Ni 写道: > On Mon, Feb 26, 2024 at 5:12 PM Yu Kuai wrote: >> >> Hi, >> >> 在 2024/02/26 16:55, Xiao Ni 写道: >>> Hi Kuai >>> >>> Thanks for the effort! >>> >>> On Thu, Feb 22, 2024 at 4:04 PM Yu Kuai wrote: >>>> >>>> From: Yu Kuai >>>> >>>> Commit 12cee5a8a29e ("md/raid1: prevent merging too large request") add >>>> the case choose next idle in read_balance(): >>>> >>>> read_balance: >>>> for_each_rdev >>>> if(next_seq_sect == this_sector || disk == 0) >>> >>> typo error: s/disk/dist/g >>> >>>> -> sequential reads >>>> best_disk = disk; >>>> if (...) >>>> choose_next_idle = 1 >>>> continue; >>>> >>>> for_each_rdev >>>> -> iterate next rdev >>>> if (pending == 0) >>>> best_disk = disk; >>>> -> choose the next idle disk >>>> break; >>>> >>>> if (choose_next_idle) >>>> -> keep using this rdev if there are no other idle disk >>>> continue >>>> >>>> However, commit 2e52d449bcec ("md/raid1: add failfast handling for reads.") >>>> remove the code: >>>> >>>> - /* If device is idle, use it */ >>>> - if (pending == 0) { >>>> - best_disk = 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 best >>>> 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 disks >>>> 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, struct 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, struct r1bio *r1_bio, int *max_sect >>>> best_pending_disk = -1; >>>> min_pending = UINT_MAX; >>>> best_good_sectors = 0; >>>> - choose_next_idle = 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, struct r1bio *r1_bio, int *max_sect >>>> int opt_iosize = bdev_io_opt(rdev->bdev) >> 9; >>>> struct raid1_info *mirror = &conf->mirrors[disk]; >>>> >>>> - best_disk = disk; >>>> /* >>>> * If buffered sequential IO size exceeds optimal >>>> * iosize, check if there is idle disk. If yes, choose >>>> @@ -731,15 +728,21 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect >>>> mirror->next_seq_sect > opt_iosize && >>>> mirror->next_seq_sect - opt_iosize >= >>>> mirror->seq_start) { >>>> - choose_next_idle = 1; >>>> - continue; >>>> + /* >>>> + * Add 'pending' to avoid choosing this disk if >>>> + * there is other idle disk. >>>> + * Set 'dist' to 0, so that if there is no other >>>> + * idle disk and all disks are rotational, this >>>> + * disk will still be chosen. >>>> + */ >>>> + pending++; >>>> + dist = 0; >>> >>> There is a problem. If all disks are not idle and there is a disk with >>> dist=0 before the seq disk, it can't read from the seq disk. It will >>> read from the first disk with dist=0. Maybe we can only add the codes >>> which are removed from 2e52d449bcec? >> >> If there is a disk with disk=0, then best_dist_disk will be updated to >> the disk, and best_dist will be updated to 0 already: >> >> // in each iteration >> if (dist < best_dist) { >> best_dist = dist; >> btest_disk_disk = disk; >> } >> >> In this case, best_dist will be set to the first disk with dist=0, and >> at last, the disk will be chosen: >> >> if (best_disk == -1) { >> if (has_nonrot_disk || min_pending == 0) >> best_disk = best_pending_disk; >> else >> best_disk = best_dist_disk; >> -> the first disk with dist=0; >> } >> >> So, the problem that you concerned should not exist. > > Hi Kuai > > Thanks for the explanation. You're right. It chooses the first disk > which has dist==0. In the above, you made the same typo error disk=0 > as the comment. I guess you want to use dist=0, right? Beside this, > this patch is good to me. Yes, and Paul change the name 'best_dist' to 'closest_dist_disk', and 'btest_disk_disk' to 'closest_dist' in the last patch to avoid typo like this. :) Thanks, Kuai > > Best Regards > Xiao >> >> Thanks, >> Kuai >>> >>> Best Regards >>> Xiao >>> >>>> + } else { >>>> + best_disk = disk; >>>> + break; >>>> } >>>> - break; >>>> } >>>> >>>> - if (choose_next_idle) >>>> - continue; >>>> - >>>> if (min_pending > pending) { >>>> min_pending = pending; >>>> best_pending_disk = disk; >>>> -- >>>> 2.39.2 >>>> >>>> >>> >>> . >>> >> > > . >