From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF9D1C432C0 for ; Fri, 29 Nov 2019 13:24:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2ADA20869 for ; Fri, 29 Nov 2019 13:24:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbfK2NYo (ORCPT ); Fri, 29 Nov 2019 08:24:44 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2140 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726871AbfK2NYo (ORCPT ); Fri, 29 Nov 2019 08:24:44 -0500 Received: from lhreml704-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id A7AAE7649D4BA4D02AB0; Fri, 29 Nov 2019 13:24:42 +0000 (GMT) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by lhreml704-cah.china.huawei.com (10.201.108.45) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 29 Nov 2019 13:24:42 +0000 Received: from [127.0.0.1] (10.202.226.46) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 29 Nov 2019 13:24:42 +0000 Subject: Re: [Patch v2 2/3] iommu: optimize iova_magazine_free_pfns() To: Cong Wang , CC: References: <20191129004855.18506-1-xiyou.wangcong@gmail.com> <20191129004855.18506-3-xiyou.wangcong@gmail.com> From: John Garry Message-ID: Date: Fri, 29 Nov 2019 13:24:41 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20191129004855.18506-3-xiyou.wangcong@gmail.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.46] X-ClientProxiedBy: lhreml720-chm.china.huawei.com (10.201.108.71) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 29/11/2019 00:48, Cong Wang wrote: > If the maganize is empty, iova_magazine_free_pfns() should magazine > 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 > Signed-off-by: Cong Wang > --- > 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? Thanks, John > return; > > spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); > @@ -820,16 +830,6 @@ iova_magazine_free_pfns(struct iova_magazine *mag, struct iova_domain *iovad) > mag->size = 0; > } > > -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 unsigned long iova_magazine_pop(struct iova_magazine *mag, > unsigned long limit_pfn) > { >