Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1282607pxb; Fri, 27 Aug 2021 05:41:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfP5Qi4gc7gchRfn4CG2m3MbR6dSvABCaPXsxemZCRV0FparR4wmSlbVGaPbAfjQhfzacm X-Received: by 2002:a17:906:fcda:: with SMTP id qx26mr9781955ejb.121.1630068096475; Fri, 27 Aug 2021 05:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630068096; cv=none; d=google.com; s=arc-20160816; b=IVDWa6t1yy/6Ji9J4HPlh36W/F6Rij6a9yoW1w8wg1uveV8dKq/3sU9LL1xQDt+mhf wOPoNNptaWCl0sFyx9N0iMkYzq18iNHVOgg0K0tYiiCNW8yoQGAtLmxeV9lQAzdI7AqF WjOfx6CKcr1TaOU01rmnIvjZ2WsDx4q1cPkUK9oXjffHUM2r9uothIPBW3/BWRpdQ/74 /ol/i3pj/wYKV3m4NnSGYDV9so//OSGAqa0PEFc1ynMlBexfg8FhIvQqGH4dqr8ozCRY PsoQK/OreBz565z2756xxz8cuRKDeBytHABbaxAFC+qc1k7P5V2GpWnPcrLL68czM9Rd DaQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=rSCVAOdTzS6of67hqwXXSt/v4Q5zwDeqrRZRMqtOo4o=; b=qzKbpwzjimoQ87fyPmCVhMFt4hXRDc2jSJRILcGN4mRK1xup8ytOzPWztn8zalBkjo vBkx3S0hMkmx81geK2GNx5uMQX3gD3jmmvErHoo57klTuvtLNsdfDTtquA+dPJCBy01r hfvwsEYnT1GVVk42TiQ2YT4SZ04H25NVxu7ar+5KyLGZp/VMdL5WYIpUuoQWnLyqZ9Pu 0/cJNvvvXEtcZ+1oY82heXxQdGoM9nOSca1PWo3f6V4z3AnlO/q3epTLZGKa3q7OxyUC nwPdWPLpgJoUjrGJBOEj6CmZDITYcOO1Cc2di7t+2syedQGamWV9+G2dfZg3y6sOjL0S G5kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=e1H4CnN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do7si6783357ejc.601.2021.08.27.05.41.09; Fri, 27 Aug 2021 05:41:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ionos.com header.s=google header.b=e1H4CnN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ionos.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245060AbhH0Mkb (ORCPT + 99 others); Fri, 27 Aug 2021 08:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbhH0Mka (ORCPT ); Fri, 27 Aug 2021 08:40:30 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBC1EC061757 for ; Fri, 27 Aug 2021 05:39:41 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id l2so5971288lfp.2 for ; Fri, 27 Aug 2021 05:39:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ionos.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rSCVAOdTzS6of67hqwXXSt/v4Q5zwDeqrRZRMqtOo4o=; b=e1H4CnN0oVEEbKadjd940jNGpQ+4i9Is62sT4sD9RRPkpJVz//9sGynYDjUvr7qOqY 9+KZGi3nY6T3oO/klS2IhsDOR1ubpDzwNM0mGlITPJknlP/5lu5G+jOGUB8w4yh375z8 uUKOkX9MsDLDLQ+nCmgyS3p0++5c4UvqcciD12MAtYATXCJUM2KDAOYv7LLHK5YGTNiZ 7xe/lJg6+6fUoeLam6qlFtW4PTe5pGiTyAbnQ628L/BHbe+2n/o+7BiK1VLvKMxMTRTW tuaOlJ3+A/24VY84DEXxONhu+KShaH4VqtEyFcis1ZvpKPS4XD4TF7G5IF0XmsA+xZMS hlSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rSCVAOdTzS6of67hqwXXSt/v4Q5zwDeqrRZRMqtOo4o=; b=BYSklynCyteVimAA3QdOdFHfan3WAxV7FLkACKoDVSwxnbk0Nxg+DRC7L3Z12npWJF JVp9faY59ooa+7jyYtP4hBPUA5rchUEzhX4pJSaT4jETmzgdsyjlYBvHUcpfUyTmsvII V2ko0xt91bb+60ZTaKULrjCJpzvPPJVprXLloTK+jW1+1D1a+8t8NtQr/xFiMYnf2t8V k69X7gXeYJaOh/xBNmUzZ780HH72ns1J5+OoDdHGe7afCVeFrfUZI0dkLOCM/+lo/jZm hYTD7XlPv8s3o0suiVzb46Xi0yudcXZqKDo8eL9GTMgVCY+67+m1RD3oOrbjsKeBc2kV 2C/A== X-Gm-Message-State: AOAM531KqyQuMUGq6PtjguJs3EWGAq+JePfwLLigTF7H1RxUO1OimjF3 ovNCXamENB7X+C+s+BYnDhP4UW3yeHc6BqpuJP4iFQ== X-Received: by 2002:a19:5f0d:: with SMTP id t13mr6558353lfb.229.1630067979561; Fri, 27 Aug 2021 05:39:39 -0700 (PDT) MIME-Version: 1.0 References: <20210726060855.108250-1-pankaj.gupta.linux@gmail.com> <20210726060855.108250-2-pankaj.gupta.linux@gmail.com> In-Reply-To: From: Pankaj Gupta Date: Fri, 27 Aug 2021 14:39:28 +0200 Message-ID: Subject: Re: [RFC v2 1/2] virtio-pmem: Async virtio-pmem flush To: Dan Williams Cc: Pankaj Gupta , Linux NVDIMM , Linux Kernel Mailing List , jmoyer , David Hildenbrand , "Michael S. Tsirkin" , Cornelia Huck , Vishal L Verma , Dave Jiang , "Weiny, Ira" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > > > > > Implement asynchronous flush for virtio pmem using work queue > > > > > > to solve the preflush ordering issue. Also, coalesce the flush > > > > > > requests when a flush is already in process. > > > > > > > > > > > > Signed-off-by: Pankaj Gupta > > > > > > --- > > > > > > drivers/nvdimm/nd_virtio.c | 72 ++++++++++++++++++++++++++++-------- > > > > > > drivers/nvdimm/virtio_pmem.c | 10 ++++- > > > > > > drivers/nvdimm/virtio_pmem.h | 14 +++++++ > > > > > > 3 files changed, 79 insertions(+), 17 deletions(-) > > > > > > > > > > > > diff --git a/drivers/nvdimm/nd_virtio.c b/drivers/nvdimm/nd_virtio.c > > > > > > index 10351d5b49fa..61b655b583be 100644 > > > > > > --- a/drivers/nvdimm/nd_virtio.c > > > > > > +++ b/drivers/nvdimm/nd_virtio.c > > > > > > @@ -97,29 +97,69 @@ static int virtio_pmem_flush(struct nd_region *nd_region) > > > > > > return err; > > > > > > }; > > > > > > > > > > > > +static void submit_async_flush(struct work_struct *ws); > > > > > > + > > > > > > /* The asynchronous flush callback function */ > > > > > > int async_pmem_flush(struct nd_region *nd_region, struct bio *bio) > > > > > > { > > > > > > - /* > > > > > > - * Create child bio for asynchronous flush and chain with > > > > > > - * parent bio. Otherwise directly call nd_region flush. > > > > > > + /* queue asynchronous flush and coalesce the flush requests */ > > > > > > + struct virtio_device *vdev = nd_region->provider_data; > > > > > > + struct virtio_pmem *vpmem = vdev->priv; > > > > > > + ktime_t req_start = ktime_get_boottime(); > > > > > > + > > > > > > + spin_lock_irq(&vpmem->lock); > > > > > > + /* flush requests wait until ongoing flush completes, > > > > > > + * hence coalescing all the pending requests. > > > > > > */ > > > > > > - if (bio && bio->bi_iter.bi_sector != -1) { > > > > > > - struct bio *child = bio_alloc(GFP_ATOMIC, 0); > > > > > > - > > > > > > - if (!child) > > > > > > - return -ENOMEM; > > > > > > - bio_copy_dev(child, bio); > > > > > > - child->bi_opf = REQ_PREFLUSH; > > > > > > - child->bi_iter.bi_sector = -1; > > > > > > - bio_chain(child, bio); > > > > > > - submit_bio(child); > > > > > > - return 0; > > > > > > + wait_event_lock_irq(vpmem->sb_wait, > > > > > > + !vpmem->flush_bio || > > > > > > + ktime_before(req_start, vpmem->prev_flush_start), > > > > > > + vpmem->lock); > > > > > > + /* new request after previous flush is completed */ > > > > > > + if (ktime_after(req_start, vpmem->prev_flush_start)) { > > > > > > + WARN_ON(vpmem->flush_bio); > > > > > > + vpmem->flush_bio = bio; > > > > > > + bio = NULL; > > > > > > + } > > > > > > > > > > Why the dance with ->prev_flush_start vs just calling queue_work() > > > > > again. queue_work() is naturally coalescing in that if the last work > > > > > request has not started execution another queue attempt will be > > > > > dropped. > > > > > > > > How parent flush request will know when corresponding flush is completed? > > > > > > The eventual bio_endio() is what signals upper layers that the flush > > > completed... > > > > > > > > > Hold on... it's been so long that I forgot that you are copying > > > md_flush_request() here. It would help immensely if that was mentioned > > > in the changelog and at a minimum have a comment in the code that this > > > was copied from md. In fact it would be extra helpful if you > > > > My bad. I only mentioned this in the cover letter. > > Yeah, sorry about that. Having come back to this after so long I just > decided to jump straight into the patches, but even if I had read that > cover I still would have given the feedback that md_flush_request() > heritage should also be noted with a comment in the code. Sure. Thanks, Pankaj