iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: John Garry <john.garry@huawei.com>
Cc: iommu@lists.linux-foundation.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [Patch v2 2/3] iommu: optimize iova_magazine_free_pfns()
Date: Tue, 3 Dec 2019 11:40:34 -0800	[thread overview]
Message-ID: <CAM_iQpX+V=Hv+3QQU-FrsRKm=75cghSTx-ip2oU=Mn1tdXywjA@mail.gmail.com> (raw)
In-Reply-To: <9996d30c-e063-e74d-925f-4181c36ca764@huawei.com>

On Mon, Dec 2, 2019 at 2:02 AM John Garry <john.garry@huawei.com> wrote:
>
> On 30/11/2019 06:02, Cong Wang wrote:
> > On Fri, Nov 29, 2019 at 5:24 AM John Garry <john.garry@huawei.com> wrote:
> >>
> >> On 29/11/2019 00:48, Cong Wang wrote:
> >>> If the maganize is empty, iova_magazine_free_pfns() should
> >>
> >> magazine
> >
> > Good catch!
> >
> >>
> >>> be a nop, however it misses the case of mag->size==0. So we
> >>> should just call iova_magazine_empty().
> >>>
> >>> This should reduce the contention on iovad->iova_rbtree_lock
> >>> a little bit.
> >>>
> >>> Cc: Joerg Roedel <joro@8bytes.org>
> >>> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> >>> ---
> >>>    drivers/iommu/iova.c | 22 +++++++++++-----------
> >>>    1 file changed, 11 insertions(+), 11 deletions(-)
> >>>
> >>> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
> >>> index cb473ddce4cf..184d4c0e20b5 100644
> >>> --- a/drivers/iommu/iova.c
> >>> +++ b/drivers/iommu/iova.c
> >>> @@ -797,13 +797,23 @@ static void iova_magazine_free(struct iova_magazine *mag)
> >>>        kfree(mag);
> >>>    }
> >>>
> >>> +static bool iova_magazine_full(struct iova_magazine *mag)
> >>> +{
> >>> +     return (mag && mag->size == IOVA_MAG_SIZE);
> >>> +}
> >>> +
> >>> +static bool iova_magazine_empty(struct iova_magazine *mag)
> >>> +{
> >>> +     return (!mag || mag->size == 0);
> >>> +}
> >>> +
> >>>    static void
> >>>    iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad)
> >>>    {
> >>>        unsigned long flags;
> >>>        int i;
> >>>
> >>> -     if (!mag)
> >>> +     if (iova_magazine_empty(mag))
> >>
> >> The only hot path we this call is
> >> __iova_rcache_insert()->iova_magazine_free_pfns(mag_to_free) and
> >> mag_to_free is full in this case, so I am sure how the additional check
> >> helps, right?
> >
> > This is what I mean by "a little bit" in changelog, did you miss it or
> > misunderstand it? :)
>
> I was concerned that in the fastpath we actually make things very
> marginally slower by adding a check which will fail.

The check is done without any locking, so it is cheap. And it is a
common pattern that we do a check without lock and do a second same
check with lock:

https://en.wikipedia.org/wiki/Double-checked_locking

Thanks.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2019-12-03 19:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29  0:48 [Patch v2 0/3] iommu: reduce spinlock contention on fast path Cong Wang
2019-11-29  0:48 ` [Patch v2 1/3] iommu: match the original algorithm Cong Wang
2019-11-29 14:43   ` John Garry
2019-11-30  5:58     ` Cong Wang
2019-12-02 10:55       ` John Garry
2019-12-03 19:26         ` Cong Wang
2019-12-02 16:58   ` Christoph Hellwig
2019-12-03 19:24     ` Cong Wang
2019-11-29  0:48 ` [Patch v2 2/3] iommu: optimize iova_magazine_free_pfns() Cong Wang
2019-11-29 13:24   ` John Garry
2019-11-30  6:02     ` Cong Wang
2019-12-02 10:02       ` John Garry
2019-12-03 19:40         ` Cong Wang [this message]
2019-12-02 16:59   ` Christoph Hellwig
2019-12-03 19:28     ` Cong Wang
2019-11-29  0:48 ` [Patch v2 3/3] iommu: avoid taking iova_rbtree_lock twice Cong Wang
2019-11-29 13:34   ` John Garry
2019-11-30  6:03     ` Cong Wang
2019-12-17  9:43 ` [Patch v2 0/3] iommu: reduce spinlock contention on fast path Joerg Roedel
2019-12-18  4:32   ` Cong Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAM_iQpX+V=Hv+3QQU-FrsRKm=75cghSTx-ip2oU=Mn1tdXywjA@mail.gmail.com' \
    --to=xiyou.wangcong@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=john.garry@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).