Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1030306rdh; Mon, 25 Sep 2023 00:33:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGV7l7UfLsEhbjp0nb0wxQGpEga6oaolWV8ava+xMURRP97mY47e1J6zSnFSxmByWAhwATC X-Received: by 2002:a17:903:442:b0:1c6:1d52:277e with SMTP id iw2-20020a170903044200b001c61d52277emr991847plb.40.1695627239442; Mon, 25 Sep 2023 00:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695627239; cv=none; d=google.com; s=arc-20160816; b=OJLnEF6TETrSpGb0/331Rd/bp1rkPP1islcFkeVKi/y+EsERYYYU1e12WVR9/+Vwy2 gpeMIm9d67Lu+WYWKXX9xN9krLgOEdUO3dSgae0CFneznE50n43e5msZ+eh/I8OYiFpQ Zse9RqjbZrsWITiBXuioZKycPo4x+dSusK1vhPGAGN9MKcA26bKzEASAsTWz8P74SY2m /2YXnAQj8Kg6J4JV/1Q6aKwMCmzc/LLZNnPJoVH1057nZ+K25uAF/O5gPnaODQWmO9i+ pto5nuwNaN5Vqln0tN1oPnlAzBWenprPPTB0xPHNjhHtglgthDuMT6I98k56gkGqUCv5 dw2Q== 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=rBYVDv59hkrAfmI0h5SRhnoDO8K6NGX5hpGfXWLtREA=; fh=3AFgu7o3QvEmI/+AtqtfwQ060gFZ/ifEv3zg2LNrUA8=; b=p636F/QeUpUa5pND3ZZUjtHqGRXxFDRFcXKvb1ZsF0/GnL3CdANMh1jRdm/f2svaCy mbbWM/rVZclJyPbjM3bvHZSLZxFQQpfNutqoTA2FFqvZQCixsOuHAVR+XneV95FgUvOR v0boIZJrf6Qmx5UlntNBIqZNLohJnQX0jqUGigLuEc6wDmXKamwnK+vJcivI5/IV/6WN hKiUijVmjleJ9IpnnHXR6+v9rpE6vYycqvD0JLirNVXuHaP9M3g4HV6u5i4icQhVmGB9 DXAzhILH3T36bcRR51yhiJcy+d6AWp64JtZiy3Bhkp4nYv4u3IxVdNjnPM5ieyn73f+U jARg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e9FeroFr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c4-20020a170902d48400b001c382ba4f5bsi10536428plg.434.2023.09.25.00.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 00:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e9FeroFr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id F0614809B743; Mon, 25 Sep 2023 00:25:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbjIYHZC (ORCPT + 99 others); Mon, 25 Sep 2023 03:25:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjIYHZA (ORCPT ); Mon, 25 Sep 2023 03:25:00 -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 23F0AC6 for ; Mon, 25 Sep 2023 00:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695626649; 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=rBYVDv59hkrAfmI0h5SRhnoDO8K6NGX5hpGfXWLtREA=; b=e9FeroFrdAbBkcz9aJ+sD8Atooyn74KFP5pjkLl9q+OST2sIn7o4yxmGT9xeU+oqpiBI+H yQQQJUyphIAdMQLyjl7bRxkZbtm9hPSVrOtackKxQUoKIHTcOEH4bTxKKcc9+nbLWPT9G0 Oic/cSjEQsm6QllV1fVwJThlZgLDQXQ= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-657-nHXeW2WnMVmRtwo5f9ybsg-1; Mon, 25 Sep 2023 03:24:08 -0400 X-MC-Unique: nHXeW2WnMVmRtwo5f9ybsg-1 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2776a4c47c3so435941a91.0 for ; Mon, 25 Sep 2023 00:24:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695626646; x=1696231446; 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=rBYVDv59hkrAfmI0h5SRhnoDO8K6NGX5hpGfXWLtREA=; b=Oi+j8YDQ2EKdmmIYCsxo/iGsaNo/ZvXtBt+WoDJQvtYRzEiWPD64AeQtMtQLGpwGEO /l5tWg4tGwc7E3pAzjUCGH4o4gxS1N1YWZ7OUdmd9XRZf9aeIRXFwruxDv7CdLFvoZFI kTdXbzNmMyk7M4VxlELgda6PmLZgjl2OloL/FZUBMz0GjYJZAswOrEm9qvEh2QmqQZRH qAeyUEqwJxK+rukb/d7Kzo5w96GjNcfPKObe/4frzwmHZzc/PYGOuBv6znsAZCbbOTFO nu0u9j4ZSFu0x1Li0gqmPCtAhsqEB66HSKARX149/Ba0wWJAO6YkBSxeTfoEr3ByGCzT 1iNw== X-Gm-Message-State: AOJu0Yyun0GRDPRzFZqswWDCpZHe/q05+330yOQ38Vb/l1RJW8GC4ojc PBDfgyuXgXxATYPAjRhLH5D8IRxDCdEjXyUo81bYtLJ6/04uTzQmo72oHpLBakErn8FGrZWm6sC i8gik8aaPgL/4ISz0+RbQGFncALuUo50o1U4/cPLV78zvh0JcX08= X-Received: by 2002:a17:90a:bc8f:b0:274:6f67:e7a8 with SMTP id x15-20020a17090abc8f00b002746f67e7a8mr3492882pjr.45.1695626646538; Mon, 25 Sep 2023 00:24:06 -0700 (PDT) X-Received: by 2002:a17:90a:bc8f:b0:274:6f67:e7a8 with SMTP id x15-20020a17090abc8f00b002746f67e7a8mr3492869pjr.45.1695626646245; Mon, 25 Sep 2023 00:24:06 -0700 (PDT) MIME-Version: 1.0 References: <20230828020021.2489641-1-yukuai1@huaweicloud.com> <20230828020021.2489641-4-yukuai1@huaweicloud.com> In-Reply-To: From: Xiao Ni Date: Mon, 25 Sep 2023 15:23:54 +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=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Mon, 25 Sep 2023 00:25:09 -0700 (PDT) On Mon, Sep 25, 2023 at 3:21=E2=80=AFPM Xiao Ni wrote: > > 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 chan= ged; > > > > 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 r= eplaced > > + * 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 re= shape */ > > + > > + 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, bec= ause > > + * other context can't update super_block, and normal io can re= ly 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 progres= s, > > + * allow new reshape to start while waiting for io to be done t= o > > + * 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? Ah, I c, you add the state of active_io to judge if a raid is suspended. Regards Xiao > > 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 re= shape */ > > + > > + 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= deletes > > @@ -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 > >