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 8806BC433E0 for ; Fri, 22 Jan 2021 06:12:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA252238EE for ; Fri, 22 Jan 2021 06:12:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA252238EE 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 455F06B0008; Fri, 22 Jan 2021 01:12:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 405D86B000A; Fri, 22 Jan 2021 01:12:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F5086B000C; Fri, 22 Jan 2021 01:12:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 16B526B0008 for ; Fri, 22 Jan 2021 01:12:20 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C24B5181AF5D7 for ; Fri, 22 Jan 2021 06:12:19 +0000 (UTC) X-FDA: 77732391198.26.angle19_18182df27569 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 9F1F81806E77E for ; Fri, 22 Jan 2021 06:12:19 +0000 (UTC) X-HE-Tag: angle19_18182df27569 X-Filterd-Recvd-Size: 3643 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Jan 2021 06:12:17 +0000 (UTC) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DMTQw32WRz7Vyx; Fri, 22 Jan 2021 14:11:04 +0800 (CST) Received: from [10.174.177.2] (10.174.177.2) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Fri, 22 Jan 2021 14:12:11 +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> <65c34b40-7c0f-6102-da3b-586551b50453@huawei.com> <9696d9e0-48d7-871c-6ec0-ba6a31c346bd@oracle.com> From: Miaohe Lin Message-ID: <02bc3a85-ca7a-e8a3-587b-7341c390ac74@huawei.com> Date: Fri, 22 Jan 2021 14:12:11 +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: <9696d9e0-48d7-871c-6ec0-ba6a31c346bd@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 13:02, Mike Kravetz wrote: > On 1/21/21 5:42 PM, Miaohe Lin wrote: >> 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 bad! I was looking at code that converts page counts to KB. Sorry. > > Yes, huge_page_size(h) >> 10 is correct. > So I will send v2 with this change. Many thanks.