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.2 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 D4275C433E0 for ; Mon, 1 Feb 2021 11:20:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83A0B64D7F for ; Mon, 1 Feb 2021 11:20:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233545AbhBALUd (ORCPT ); Mon, 1 Feb 2021 06:20:33 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11994 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233120AbhBALUZ (ORCPT ); Mon, 1 Feb 2021 06:20:25 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DTlmv1FpLzjHQ8; Mon, 1 Feb 2021 19:18:23 +0800 (CST) Received: from [10.174.179.241] (10.174.179.241) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Mon, 1 Feb 2021 19:19:39 +0800 Subject: Re: [PATCH] hugetlbfs: rework calculation code of Hugepage size in hugetlbfs_show_options() To: David Hildenbrand CC: , , , References: <20210201082325.33875-1-linmiaohe@huawei.com> <2bb70cac-b8ef-cdbe-fa4e-db6229587e98@redhat.com> From: Miaohe Lin Message-ID: Date: Mon, 1 Feb 2021 19:19:38 +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: <2bb70cac-b8ef-cdbe-fa4e-db6229587e98@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.179.241] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi: On 2021/2/1 18:56, David Hildenbrand wrote: > On 01.02.21 09:23, Miaohe Lin wrote: >> Rework calculation code of the Hugepage size to make it more readable and >> straightforward. >> >> Signed-off-by: Miaohe Lin >> --- >>   fs/hugetlbfs/inode.c | 9 +++++---- >>   1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c >> index 3a08fbae3b53..1be18de4b537 100644 >> --- a/fs/hugetlbfs/inode.c >> +++ b/fs/hugetlbfs/inode.c >> @@ -1014,11 +1014,12 @@ static int hugetlbfs_show_options(struct seq_file *m, struct dentry *root) >>       if (sbinfo->max_inodes != -1) >>           seq_printf(m, ",nr_inodes=%lu", sbinfo->max_inodes); >>   -    hpage_size /= 1024; >> -    mod = 'K'; >> -    if (hpage_size >= 1024) { >> -        hpage_size /= 1024; >> +    if (hpage_size >= SZ_1M) { >> +        hpage_size /= SZ_1M; >>           mod = 'M'; >> +    } else { >> +        hpage_size /= SZ_1K; >> +        mod = 'K'; >>       } >>       seq_printf(m, ",pagesize=%lu%c", hpage_size, mod); >>       if (spool) { >> > > Looks correct but I am not convinced the old code was that complicated to understand. > The old code is not complicated but I think it may be better to use macro instead of well-known "magic number". Many thanks for review.:)