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.3 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 B3CE7C433DB for ; Fri, 22 Jan 2021 01:42:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C71DF22B43 for ; Fri, 22 Jan 2021 01:42:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C71DF22B43 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 E508C6B0006; Thu, 21 Jan 2021 20:42:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD96C6B0007; Thu, 21 Jan 2021 20:42:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEEB06B0008; Thu, 21 Jan 2021 20:42:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id B54066B0006 for ; Thu, 21 Jan 2021 20:42:16 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 80D9F181AF5C2 for ; Fri, 22 Jan 2021 01:42:16 +0000 (UTC) X-FDA: 77731710672.27.actor19_5604b4b27567 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 6741F3D663 for ; Fri, 22 Jan 2021 01:42:16 +0000 (UTC) X-HE-Tag: actor19_5604b4b27567 X-Filterd-Recvd-Size: 3288 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 01:42:15 +0000 (UTC) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DMMRb540xzj9jy; Fri, 22 Jan 2021 09:41:15 +0800 (CST) Received: from [10.174.177.2] (10.174.177.2) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Fri, 22 Jan 2021 09:42:09 +0800 Subject: Re: [PATCH] hugetlbfs: make hugepage size conversion more readable To: Mike Kravetz CC: , , Andrew Morton References: <20210120092348.13811-1-linmiaohe@huawei.com> <668845df-e654-ecdc-c32a-b50a22098333@oracle.com> From: Miaohe Lin Message-ID: <65c34b40-7c0f-6102-da3b-586551b50453@huawei.com> Date: Fri, 22 Jan 2021 09:42:08 +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: <668845df-e654-ecdc-c32a-b50a22098333@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.2] 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/22 3:00, Mike Kravetz wrote: > On 1/20/21 1:23 AM, Miaohe Lin wrote: >> The calculation 1U << (h->order + PAGE_SHIFT - 10) is actually equal to >> (PAGE_SHIFT << (h->order)) >> 10. So we can make it more readable by >> replace it with huge_page_size(h) / SZ_1K. >> >> Signed-off-by: Miaohe Lin >> --- >> fs/hugetlbfs/inode.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c >> index 25c1857ff45d..f94b8f6553fa 100644 >> --- a/fs/hugetlbfs/inode.c >> +++ b/fs/hugetlbfs/inode.c >> @@ -1519,8 +1519,8 @@ static struct vfsmount *__init mount_one_hugetlbfs(struct hstate *h) >> put_fs_context(fc); >> } >> if (IS_ERR(mnt)) >> - pr_err("Cannot mount internal hugetlbfs for page size %uK", >> - 1U << (h->order + PAGE_SHIFT - 10)); >> + pr_err("Cannot mount internal hugetlbfs for page size %luK", >> + huge_page_size(h) / SZ_1K); > > I appreciate the effort to make the code more readable. The existing > calculation does take a minute to understand. However, it is correct and > anyone modifying the code should be able to understand. > > With my compiler, your proposed change adds an additional instruction to > the routine mount_one_hugetlbfs. I know this is not significant, but still I thought compiler would generate the same code... > it does increase the kernel size for a change that is of questionable value. > > In the kernel, size in KB is often calculated as (size << (PAGE_SHIFT - 10)). > If you change the calculation in the hugetlb code to be: > > huge_page_size(h) << (PAGE_SHIFT - 10) I'am sorry but this looks not really correct. I think the calculation shoud be huge_page_size(h) >> 10. What do you think? > > my compiler will actually reduce the size of the routine by one instruction. > Many thanks.