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=-15.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 3AF72C433E0 for ; Fri, 15 Jan 2021 02:04:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4145F23A5B for ; Fri, 15 Jan 2021 02:04:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4145F23A5B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 411608D0137; Thu, 14 Jan 2021 21:04:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C2658D00F0; Thu, 14 Jan 2021 21:04:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D8238D0137; Thu, 14 Jan 2021 21:04:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1C6048D00F0 for ; Thu, 14 Jan 2021 21:04:29 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D616B181AEF23 for ; Fri, 15 Jan 2021 02:04:28 +0000 (UTC) X-FDA: 77706365016.10.beast73_3615f1c2752b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id B336B16A4CA for ; Fri, 15 Jan 2021 02:04:28 +0000 (UTC) X-HE-Tag: beast73_3615f1c2752b X-Filterd-Recvd-Size: 3325 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 02:04:27 +0000 (UTC) Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DH4G04rtLzMKKS; Fri, 15 Jan 2021 10:03:04 +0800 (CST) Received: from [10.174.176.197] (10.174.176.197) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Fri, 15 Jan 2021 10:04:19 +0800 Subject: Re: [PATCH] mm/hugetlb: avoid unnecessary hugetlb_acct_memory() call To: Mike Kravetz , David Hildenbrand CC: , , Andrew Morton References: <20210114113140.23069-1-linmiaohe@huawei.com> <853d6aa4-b84c-7ac2-00d4-402893fcf6b3@redhat.com> From: Miaohe Lin Message-ID: <9841241e-eb8f-9b49-8d2d-d84effda8ba4@huawei.com> Date: Fri, 15 Jan 2021 10:04:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.176.197] X-CFilter-Loop: Reflected X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi: On 2021/1/15 3:16, Mike Kravetz wrote: > On 1/14/21 4:32 AM, David Hildenbrand wrote: >> On 14.01.21 12:31, Miaohe Lin wrote: >>> When gbl_reserve is 0, hugetlb_acct_memory() will do nothing except holding >>> and releasing hugetlb_lock. >> >> So, what's the deal then? Adding more code? >> >> If this is a performance improvement, we should spell it out. Otherwise >> I don't see a real benefit of this patch. >> > > Thanks for finding/noticing this. > > As David points out, the commit message should state that this is a > performance improvement. Mention that such a change avoids an unnecessary > hugetlb_lock lock/unlock cycle. You can also mention that this unnecessary > lock cycle is happening on 'most' hugetlb munmap operations. > My bad. I should spell this out explicitly. Many thanks for both of you. >>> >>> Signed-off-by: Miaohe Lin >>> --- >>> mm/hugetlb.c | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >>> index 737b2dce19e6..fe2da9ad6233 100644 >>> --- a/mm/hugetlb.c >>> +++ b/mm/hugetlb.c >>> @@ -5241,7 +5241,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end, >>> * reservations to be released may be adjusted. >>> */ >>> gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed)); >>> - hugetlb_acct_memory(h, -gbl_reserve); >>> + if (gbl_reserve) >>> + hugetlb_acct_memory(h, -gbl_reserve); > > It is true that gbl_reserve is likely to be 0 in this code path. However, > there are other code paths where hugetlb_acct_memory is called with a delta > value of 0 as well. I would rather see a simple check at the beginning of > hugetlb_acct_memory like. > > if (!delta) > return 0; > Sounds good. Will do it in v2. Many thanks again.