Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1109572rdh; Mon, 25 Sep 2023 03:42:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFoKKeKLZ5Td6BAnrI3psyY9j8ku+ocirMH7x5XPyz17LPA7f8v8PYNvkVZYdHHMCJqxA6f X-Received: by 2002:a05:6358:c12a:b0:142:e3ff:ed76 with SMTP id fh42-20020a056358c12a00b00142e3ffed76mr4348504rwb.3.1695638577320; Mon, 25 Sep 2023 03:42:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695638577; cv=none; d=google.com; s=arc-20160816; b=XfOjkVR1BNlKxwPsbrcFJdXMVR9zLgl1ObVhGYT+omzy3DWBU19vHgTOoOhsU9qXns Ps2o/OSjcTjAA1B85PIpT5DjqXwXyFa492wNcvJf93ZJ2nbkM3o3V41WYhd7vO20SI7Z nxSddNHX0NBmyaJfTATtj6/NvNLeroz/cdjCTl1RCrTrklg+HUlM2hPqGKc+BJIsrNoB FC6V6nneNnbBT76xhzYkwPzn7uZibb0kypJ8PLepGR+j97i5jjGadthQLL3sQpT+QslY xcrmqDfDMN8GeIafrea873uWIWRF671ltfMVhHlSix+mKSj5ckU+KxyEc2gwqt4yCpWj khPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gzztqiTccNd/WUIopmBC+PbliphbDEU0hH26bTuwFVE=; fh=3AFgu7o3QvEmI/+AtqtfwQ060gFZ/ifEv3zg2LNrUA8=; b=0xFUqJUX0Jo3ixhGjnlg0cwSzMWKG12xIyZgSljGQa2UkcZum4IWDOO+3Ntm+fByKb igE6rqI4ev7K3XnA0OgOFEpsw16G8MK7IyRuyv3FhEWAVyaQiRD45fo+BHgTeH5fPINO 0k5GHzanQ0mr1HM1XK91z1m6NrsXIirgG9J6zFIMIfi72ls8IoMTTnHKXWrbBCCW8/OI puGc0yrXPywrPV18EHA8Oacx1jRmoBq11AWAeSW3bzDOXYgTNl07ilXg9sElmS88p2hW XOM15f28ZwT+k6mICyb8PicnsOPezmhvQfUe5VOfNLlwjNOmOuOKZBRSSbidatxLoWkO 506A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JstlfAO3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v70-20020a638949000000b00577a9ed62edsi9886544pgd.419.2023.09.25.03.42.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 03:42:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JstlfAO3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id A1982802DD15; Mon, 25 Sep 2023 00:23:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230418AbjIYHXM (ORCPT + 99 others); Mon, 25 Sep 2023 03:23:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231816AbjIYHW7 (ORCPT ); Mon, 25 Sep 2023 03:22:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A1FCC1 for ; Mon, 25 Sep 2023 00:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695626519; 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=gzztqiTccNd/WUIopmBC+PbliphbDEU0hH26bTuwFVE=; b=JstlfAO3GcJ1DmIg11x9J54fmqC3CtU4Y04dyjk9KGbytqL8UjaSKJR1Ay8a+fcSwFZJSU DS0i3880IwB7ZQjJuecXObygUvXmerRHuO/i5seq+Wt6jWFmJpFlQIM2yjJfNEhPSsay4P jdERT4Y+VLoYpjFsH+OiIHiDUICxMjM= Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-PCdRBHgWNq6mmCV6ZPuwTA-1; Mon, 25 Sep 2023 03:21:58 -0400 X-MC-Unique: PCdRBHgWNq6mmCV6ZPuwTA-1 Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-692b5134675so4358229b3a.2 for ; Mon, 25 Sep 2023 00:21:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695626517; x=1696231317; 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=gzztqiTccNd/WUIopmBC+PbliphbDEU0hH26bTuwFVE=; b=rxtJ4NRRsK5t0DCL0TG6p1GlzqwmbY03+9jFZjjzR0hqz67P/h1rg/xzFW2QKtC6Zy Bqk8JK7pCWXHWyAiT02SOe0bayMLoUAXtzhhN00Za0JJd2o6uCz22t83CSb68CudhXae yTVyUtdQ9yBiguZiaXRtQ2KfcfY6EVLCmCNtfgTGwORgUgMBjBZHlx88IBFm/TuW8kMF 8h4iynUKWS9yW5c761Lhv+itq35o867/QC4hLQYQFx9GTFI2lKjHnzmfsQAhGN15PYD+ H20Uv6IZhPfonYSIKXqiGYxDtyU42wmKpmV4NCYwz/T2h5SWCFX2B61TQatCBuvetCFk TCIw== X-Gm-Message-State: AOJu0Yya+WynKWam8KGS7J7vPk4EHvc2ipQwu59GHILmejVjAMgvt6q3 sXxiA/OSVyOYnmrPgXXjV6TefQkjrpiyXIclWt1XXdxadgjZOTbPXxTXh7TtowwwqwAMn7Iru7Z jifNW6mCQyo4oW3p2wbtrsOixx4f5PGFQqAddc939 X-Received: by 2002:a05:6a20:f392:b0:14d:396e:6e1c with SMTP id qr18-20020a056a20f39200b0014d396e6e1cmr3937739pzb.28.1695626517216; Mon, 25 Sep 2023 00:21:57 -0700 (PDT) X-Received: by 2002:a05:6a20:f392:b0:14d:396e:6e1c with SMTP id qr18-20020a056a20f39200b0014d396e6e1cmr3937728pzb.28.1695626516919; Mon, 25 Sep 2023 00:21:56 -0700 (PDT) MIME-Version: 1.0 References: <20230828020021.2489641-1-yukuai1@huaweicloud.com> <20230828020021.2489641-4-yukuai1@huaweicloud.com> In-Reply-To: <20230828020021.2489641-4-yukuai1@huaweicloud.com> From: Xiao Ni Date: Mon, 25 Sep 2023 15:21:45 +0800 Message-ID: Subject: Re: [PATCH -next v2 03/28] md: add new helpers to suspend/resume array To: Yu Kuai Cc: agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com, song@kernel.org, linux-kernel@vger.kernel.org, linux-raid@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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 00:23:11 -0700 (PDT) On Mon, Aug 28, 2023 at 10:04=E2=80=AFAM Yu Kuai = wrote: > > From: Yu Kuai > > Advantages for new apis: > - reconfig_mutex is not required; > - the weird logical that suspend array hold 'reconfig_mutex' for > mddev_check_recovery() to update superblock is not needed; > - the specail handling, 'pers->prepare_suspend', for raid456 is not > needed; > - It's safe to be called at any time once mddev is allocated, and it's > designed to be used from slow path where array configuration is change= d; > > Signed-off-by: Yu Kuai > --- > drivers/md/md.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++-- > drivers/md/md.h | 3 ++ > 2 files changed, 86 insertions(+), 2 deletions(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 7fa311a14317..6236e2e395c1 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -443,12 +443,22 @@ void mddev_suspend(struct mddev *mddev) > lockdep_is_held(&mddev->reconfig_mutex)); > > WARN_ON_ONCE(thread && current =3D=3D thread->tsk); > - if (mddev->suspended++) > + > + /* can't concurrent with __mddev_suspend() and __mddev_resume() *= / > + mutex_lock(&mddev->suspend_mutex); > + if (mddev->suspended++) { > + mutex_unlock(&mddev->suspend_mutex); > return; > + } > + > wake_up(&mddev->sb_wait); > set_bit(MD_ALLOW_SB_UPDATE, &mddev->flags); > percpu_ref_kill(&mddev->active_io); > > + /* > + * TODO: cleanup 'pers->prepare_suspend after all callers are rep= laced > + * by __mddev_suspend(). > + */ > if (mddev->pers && mddev->pers->prepare_suspend) > mddev->pers->prepare_suspend(mddev); > > @@ -459,14 +469,21 @@ void mddev_suspend(struct mddev *mddev) > del_timer_sync(&mddev->safemode_timer); > /* restrict memory reclaim I/O during raid array is suspend */ > mddev->noio_flag =3D memalloc_noio_save(); > + > + mutex_unlock(&mddev->suspend_mutex); > } > EXPORT_SYMBOL_GPL(mddev_suspend); > > void mddev_resume(struct mddev *mddev) > { > lockdep_assert_held(&mddev->reconfig_mutex); > - if (--mddev->suspended) > + > + /* can't concurrent with __mddev_suspend() and __mddev_resume() *= / > + mutex_lock(&mddev->suspend_mutex); > + if (--mddev->suspended) { > + mutex_unlock(&mddev->suspend_mutex); > return; > + } > > /* entred the memalloc scope from mddev_suspend() */ > memalloc_noio_restore(mddev->noio_flag); > @@ -477,9 +494,72 @@ void mddev_resume(struct mddev *mddev) > set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); > md_wakeup_thread(mddev->thread); > md_wakeup_thread(mddev->sync_thread); /* possibly kick off a resh= ape */ > + > + mutex_unlock(&mddev->suspend_mutex); > } > EXPORT_SYMBOL_GPL(mddev_resume); > > +void __mddev_suspend(struct mddev *mddev) > +{ > + > + /* > + * hold reconfig_mutex to wait for normal io will deadlock, becau= se > + * other context can't update super_block, and normal io can rely= on > + * updating super_block. > + */ > + lockdep_assert_not_held(&mddev->reconfig_mutex); > + > + mutex_lock(&mddev->suspend_mutex); > + > + if (mddev->suspended) { > + WRITE_ONCE(mddev->suspended, mddev->suspended + 1); > + mutex_unlock(&mddev->suspend_mutex); > + return; > + } > + > + percpu_ref_kill(&mddev->active_io); > + wait_event(mddev->sb_wait, percpu_ref_is_zero(&mddev->active_io))= ; > + > + /* > + * For raid456, io might be waiting for reshape to make progress, > + * allow new reshape to start while waiting for io to be done to > + * prevent deadlock. > + */ > + WRITE_ONCE(mddev->suspended, mddev->suspended + 1); It changes the order of setting suspended and checking active_io. suspended is used to stop I/O. Now it checks active_io first and then adds suspended, if the i/o doesn't stop, it looks like active_io can't be 0. So it will stuck at waiting active_io to be 0? Best Regards Xiao > + > + del_timer_sync(&mddev->safemode_timer); > + /* restrict memory reclaim I/O during raid array is suspend */ > + mddev->noio_flag =3D memalloc_noio_save(); > + > + mutex_unlock(&mddev->suspend_mutex); > +} > +EXPORT_SYMBOL_GPL(__mddev_suspend); > + > +void __mddev_resume(struct mddev *mddev) > +{ > + lockdep_assert_not_held(&mddev->reconfig_mutex); > + > + mutex_lock(&mddev->suspend_mutex); > + WRITE_ONCE(mddev->suspended, mddev->suspended - 1); > + if (mddev->suspended) { > + mutex_unlock(&mddev->suspend_mutex); > + return; > + } > + > + /* entred the memalloc scope from __mddev_suspend() */ > + memalloc_noio_restore(mddev->noio_flag); > + > + percpu_ref_resurrect(&mddev->active_io); > + wake_up(&mddev->sb_wait); > + > + set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); > + md_wakeup_thread(mddev->thread); > + md_wakeup_thread(mddev->sync_thread); /* possibly kick off a resh= ape */ > + > + mutex_unlock(&mddev->suspend_mutex); > +} > +EXPORT_SYMBOL_GPL(__mddev_resume); > + > /* > * Generic flush handling for md > */ > @@ -667,6 +747,7 @@ int mddev_init(struct mddev *mddev) > mutex_init(&mddev->open_mutex); > mutex_init(&mddev->reconfig_mutex); > mutex_init(&mddev->sync_mutex); > + mutex_init(&mddev->suspend_mutex); > mutex_init(&mddev->bitmap_info.mutex); > INIT_LIST_HEAD(&mddev->disks); > INIT_LIST_HEAD(&mddev->all_mddevs); > diff --git a/drivers/md/md.h b/drivers/md/md.h > index fb3b123f16dd..1103e6b08ad9 100644 > --- a/drivers/md/md.h > +++ b/drivers/md/md.h > @@ -316,6 +316,7 @@ struct mddev { > unsigned long sb_flags; > > int suspended; > + struct mutex suspend_mutex; > struct percpu_ref active_io; > int ro; > int sysfs_active; /* set when sysfs d= eletes > @@ -811,6 +812,8 @@ extern void md_rdev_clear(struct md_rdev *rdev); > extern void md_handle_request(struct mddev *mddev, struct bio *bio); > extern void mddev_suspend(struct mddev *mddev); > extern void mddev_resume(struct mddev *mddev); > +extern void __mddev_suspend(struct mddev *mddev); > +extern void __mddev_resume(struct mddev *mddev); > > extern void md_reload_sb(struct mddev *mddev, int raid_disk); > extern void md_update_sb(struct mddev *mddev, int force); > -- > 2.39.2 >