Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2576648rwd; Sun, 28 May 2023 19:26:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68Yk5WU3x68RA97Qyv/rdzwKLdoh/WMXJj2Nd1yIopID0q4nMR3jS1QLrOV8XAIpeae4p6 X-Received: by 2002:a17:903:200b:b0:1a6:b23c:3bf2 with SMTP id s11-20020a170903200b00b001a6b23c3bf2mr7769270pla.10.1685327179275; Sun, 28 May 2023 19:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685327179; cv=none; d=google.com; s=arc-20160816; b=P8OWmziGVRsL0hp2YseOh9Pe8HQESOxweOreXsdyjk1tTTMgn4xHm9pm0qU/hSDvu/ spxz1R/1AIaMPodL4KZrl4pUOPrnaes5EOGu+p2MkY00gL+b4RjRvJ9JUhW2/At2P3C6 prIK9gJ/VoszX1PlytiQQlD3LbzC0uIHOb6SayMp6UciQITqDs8+uE/1eYnMBwNjLE9o oT55b2TQONC0ULj0/XEm520PdO2ba8STyrpkJqAVJ+anp5qaO+k93ruHhU60m9NqF6tg 9BRRTVG3QeFNucLzTpP5bjXT+4n4pCeY4BzS/0Rb/k6WCCatVLkNPLnn7QV4hxoxI9GO p+Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=D/M1bf4CDeEc126Rgxq9a5WFfPKn7E5Yic7C8gWSmfo=; b=VVqViHCUithXqpwkU7exAkQF1DJAELkJewvnn56WAMNlgQLOtAat414eqDv4bjlYZi V71WC3EjjpbOomiOZkydYy9Cu9aVXTQZNk+TXl/XIPiMwoLvwkHKgGSE2GW4/tN+598x 4YlsiMpq5kFWbkmVxgF01WkicDwtZ32NXIRgNnJK4xD9P4HxF3cT0ce+84/X/W4rvK3J Jb/RQ9HQIqcIpwGSsZEpo1+eHEhgoB/GuFfoL9+i9PH3bimi7eFyPgilAov3SpLHJjvJ t8YpJYFMBHLsimjEODYTpI/PYkITpHNCYHafRBMaoAI2TE03Bc+fLNfPHqJ3Ka2qgjdu iifA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jj6-20020a170903048600b001af9d3ca8a9si7269154plb.20.2023.05.28.19.26.04; Sun, 28 May 2023 19:26:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230189AbjE2CT6 (ORCPT + 99 others); Sun, 28 May 2023 22:19:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjE2CT4 (ORCPT ); Sun, 28 May 2023 22:19:56 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A732AC; Sun, 28 May 2023 19:19:54 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QTzkX3Wfcz4f3khv; Mon, 29 May 2023 10:19:48 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP4 (Coremail) with SMTP id gCh0CgD3X7PEC3RkD4rGKQ--.59819S3; Mon, 29 May 2023 10:19:50 +0800 (CST) Subject: Re: [PATCH -next v2 7/7] md/raid1-10: limit the number of plugged bio To: Xiao Ni , Yu Kuai Cc: song@kernel.org, akpm@osdl.org, neilb@suse.de, linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, "yukuai (C)" References: <20230426082031.1299149-1-yukuai1@huaweicloud.com> <20230426082031.1299149-8-yukuai1@huaweicloud.com> From: Yu Kuai Message-ID: <5e9852fe-0d47-92fc-f6a9-16d028d09ad4@huaweicloud.com> Date: Mon, 29 May 2023 10:19:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3X7PEC3RkD4rGKQ--.59819S3 X-Coremail-Antispam: 1UD129KBjvJXoWxXrW7GFyfXF1xZr1fJFyUAwb_yoWrZFW3pa 1Dta4Y9FWUXrWUZw4qq3WUuFyFqw4vgFWUCrZYk3yfAF9rXFyUWa15JFWrWr1DZF9xWFy7 Z3Z8KrZxWFn8tFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4U JVW0owA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kI c2xKxwCYjI0SjxkI62AI1cAE67vIY487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq 3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIda VFxhVjvjDU0xZFpf9x0JUdHUDUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, 在 2023/05/29 10:08, Xiao Ni 写道: > Hi Kuai > > There is a limitation of the memory in your test. But for most > situations, customers should not set this. Can this change introduce a > performance regression against other situations? Noted that this limitation is just to triggered writeback as soon as possible in the test, and it's 100% sure real situations can trigger dirty pages write back asynchronously and continue to produce new dirty pages. If a lot of bio is not plugged, then it's the same as before; if a lot of bio is plugged, noted that before this patchset, these bio will spent quite a long time in plug, and hence I think performance should be better. Thanks, Kuai > > Best Regards > Xiao > > On Wed, Apr 26, 2023 at 4:24 PM Yu Kuai wrote: >> >> From: Yu Kuai >> >> bio can be added to plug infinitely, and following writeback test can >> trigger huge amount of plugged bio: >> >> Test script: >> modprobe brd rd_nr=4 rd_size=10485760 >> mdadm -CR /dev/md0 -l10 -n4 /dev/ram[0123] --assume-clean >> echo 0 > /proc/sys/vm/dirty_background_ratio >> echo 60 > /proc/sys/vm/dirty_ratio >> fio -filename=/dev/md0 -ioengine=libaio -rw=write -bs=4k -numjobs=1 -iodepth=128 -name=test >> >> Test result: >> Monitor /sys/block/md0/inflight will found that inflight keep increasing >> until fio finish writing, after running for about 2 minutes: >> >> [root@fedora ~]# cat /sys/block/md0/inflight >> 0 4474191 >> >> Fix the problem by limiting the number of plugged bio based on the number >> of copies for original bio. >> >> Signed-off-by: Yu Kuai >> --- >> drivers/md/raid1-10.c | 9 ++++++++- >> drivers/md/raid1.c | 2 +- >> drivers/md/raid10.c | 2 +- >> 3 files changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c >> index 98d678b7df3f..35fb80aa37aa 100644 >> --- a/drivers/md/raid1-10.c >> +++ b/drivers/md/raid1-10.c >> @@ -21,6 +21,7 @@ >> #define IO_MADE_GOOD ((struct bio *)2) >> >> #define BIO_SPECIAL(bio) ((unsigned long)bio <= 2) >> +#define MAX_PLUG_BIO 32 >> >> /* for managing resync I/O pages */ >> struct resync_pages { >> @@ -31,6 +32,7 @@ struct resync_pages { >> struct raid1_plug_cb { >> struct blk_plug_cb cb; >> struct bio_list pending; >> + unsigned int count; >> }; >> >> static void rbio_pool_free(void *rbio, void *data) >> @@ -127,7 +129,7 @@ static inline void md_submit_write(struct bio *bio) >> } >> >> static inline bool md_add_bio_to_plug(struct mddev *mddev, struct bio *bio, >> - blk_plug_cb_fn unplug) >> + blk_plug_cb_fn unplug, int copies) >> { >> struct raid1_plug_cb *plug = NULL; >> struct blk_plug_cb *cb; >> @@ -147,6 +149,11 @@ static inline bool md_add_bio_to_plug(struct mddev *mddev, struct bio *bio, >> >> plug = container_of(cb, struct raid1_plug_cb, cb); >> bio_list_add(&plug->pending, bio); >> + if (++plug->count / MAX_PLUG_BIO >= copies) { >> + list_del(&cb->list); >> + cb->callback(cb, false); >> + } >> + >> >> return true; >> } >> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c >> index 639e09cecf01..c6066408a913 100644 >> --- a/drivers/md/raid1.c >> +++ b/drivers/md/raid1.c >> @@ -1562,7 +1562,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio, >> r1_bio->sector); >> /* flush_pending_writes() needs access to the rdev so...*/ >> mbio->bi_bdev = (void *)rdev; >> - if (!md_add_bio_to_plug(mddev, mbio, raid1_unplug)) { >> + if (!md_add_bio_to_plug(mddev, mbio, raid1_unplug, disks)) { >> spin_lock_irqsave(&conf->device_lock, flags); >> bio_list_add(&conf->pending_bio_list, mbio); >> spin_unlock_irqrestore(&conf->device_lock, flags); >> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c >> index bd9e655ca408..7135cfaf75db 100644 >> --- a/drivers/md/raid10.c >> +++ b/drivers/md/raid10.c >> @@ -1306,7 +1306,7 @@ static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio, >> >> atomic_inc(&r10_bio->remaining); >> >> - if (!md_add_bio_to_plug(mddev, mbio, raid10_unplug)) { >> + if (!md_add_bio_to_plug(mddev, mbio, raid10_unplug, conf->copies)) { >> spin_lock_irqsave(&conf->device_lock, flags); >> bio_list_add(&conf->pending_bio_list, mbio); >> spin_unlock_irqrestore(&conf->device_lock, flags); >> -- >> 2.39.2 >> > > . >