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=unavailable 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 31175C433E6 for ; Fri, 22 Jan 2021 06:13:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAD67239D1 for ; Fri, 22 Jan 2021 06:13:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726574AbhAVGNA (ORCPT ); Fri, 22 Jan 2021 01:13:00 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:11847 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726019AbhAVGM4 (ORCPT ); Fri, 22 Jan 2021 01:12:56 -0500 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.