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 7ABA6C433DB for ; Tue, 9 Feb 2021 01:57:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DD9964E75 for ; Tue, 9 Feb 2021 01:57:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6DD9964E75 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 E21916B006C; Mon, 8 Feb 2021 20:57:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2616B006E; Mon, 8 Feb 2021 20:57:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE7D98D0001; Mon, 8 Feb 2021 20:57:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id BA57A6B006C for ; Mon, 8 Feb 2021 20:57:37 -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 7862A18410DE2 for ; Tue, 9 Feb 2021 01:57:37 +0000 (UTC) X-FDA: 77797067754.26.0F09004 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf05.hostedemail.com (Postfix) with ESMTP id B7849E0001A9 for ; Tue, 9 Feb 2021 01:57:34 +0000 (UTC) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DZQw31DJzzMX5x; Tue, 9 Feb 2021 09:55:47 +0800 (CST) Received: from [10.174.179.149] (10.174.179.149) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.498.0; Tue, 9 Feb 2021 09:57:30 +0800 Subject: Re: [PATCH] mm/hugetlb: use helper huge_page_size() to get hugepage size To: Mike Kravetz , CC: , References: <20210208082450.15716-1-linmiaohe@huawei.com> <3752cc85-06d1-5af7-8baf-2810c98524d3@oracle.com> <4fac6900-3685-abd6-964f-8fa436f97c43@oracle.com> From: Miaohe Lin Message-ID: <8ba00fe0-fc0c-9304-ae6d-5d9ecaca489a@huawei.com> Date: Tue, 9 Feb 2021 09:57:26 +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: <4fac6900-3685-abd6-964f-8fa436f97c43@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.179.149] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B7849E0001A9 X-Stat-Signature: mi8d4h7tthxgwsnicrut4xbntmjez7wg Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=szxga05-in.huawei.com; client-ip=45.249.212.191 X-HE-DKIM-Result: none/none X-HE-Tag: 1612835854-980458 Content-Transfer-Encoding: quoted-printable 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: On 2021/2/9 9:36, Mike Kravetz wrote: > On 2/8/21 5:24 PM, Miaohe Lin wrote: >> Hi=EF=BC=9A >> On 2021/2/9 8:45, Mike Kravetz wrote: >>> On 2/8/21 12:24 AM, Miaohe Lin wrote: >>>> We can use helper huge_page_size() to get the hugepage size directly= to >>>> simplify the code slightly. >>>> >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/hugetlb.c | 14 ++++++-------- >>>> 1 file changed, 6 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/mm/hugetlb.c b/mm/hugetlb.c >>>> index 18628f8dbfb0..6cdb59d8f663 100644 >>>> --- a/mm/hugetlb.c >>>> +++ b/mm/hugetlb.c >>>> @@ -3199,7 +3199,7 @@ void __init hugetlb_add_hstate(unsigned int or= der) >>>> BUG_ON(order =3D=3D 0); >>>> h =3D &hstates[hugetlb_max_hstate++]; >>>> h->order =3D order; >>>> - h->mask =3D ~((1ULL << (order + PAGE_SHIFT)) - 1); >>>> + h->mask =3D ~(huge_page_size(h) - 1); >>>> for (i =3D 0; i < MAX_NUMNODES; ++i) >>>> INIT_LIST_HEAD(&h->hugepage_freelists[i]); >>>> INIT_LIST_HEAD(&h->hugepage_activelist); >>>> @@ -3474,7 +3474,7 @@ void hugetlb_report_meminfo(struct seq_file *m= ) >>>> for_each_hstate(h) { >>>> unsigned long count =3D h->nr_huge_pages; >>>> =20 >>>> - total +=3D (PAGE_SIZE << huge_page_order(h)) * count; >>>> + total +=3D huge_page_size(h) * count; >>>> =20 >>>> if (h =3D=3D &default_hstate) >>>> seq_printf(m, >>>> @@ -3487,10 +3487,10 @@ void hugetlb_report_meminfo(struct seq_file = *m) >>>> h->free_huge_pages, >>>> h->resv_huge_pages, >>>> h->surplus_huge_pages, >>>> - (PAGE_SIZE << huge_page_order(h)) / 1024); >>>> + huge_page_size(h) / SZ_1K); >>>> } >>>> =20 >>>> - seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024); >>>> + seq_printf(m, "Hugetlb: %8lu kB\n", total / SZ_1K); >>>> } >>>> =20 >>>> int hugetlb_report_node_meminfo(char *buf, int len, int nid) >>>> @@ -3524,7 +3524,7 @@ void hugetlb_show_meminfo(void) >>>> h->nr_huge_pages_node[nid], >>>> h->free_huge_pages_node[nid], >>>> h->surplus_huge_pages_node[nid], >>>> - 1UL << (huge_page_order(h) + PAGE_SHIFT - 10)); >>>> + huge_page_size(h) >> 10); >>> >>> Should we change this to >>> >>> huge_page_size(h) / SZ_1K); >>>> as in hugetlb_report_meminfo above? Or, is that one where it takes = an >>> additional instruction to do the divide as opposed to the shift? I w= ould> rather add the instruction and keep everything consistent. >>> >> >> Yes, it takes an additional instruction to do the divide as opposed to= the shift. So I did not >> change this. But it seems keeping everything consistent in a function = is more important. So should >> I send a V2 to change this or Andrew would kindly handle this ? >=20 > I would go ahead and put together a v2 and let Andrew decide how he wan= ts > to handle it. You can include, >=20 Will do. Thanks a lot. > Reviewed-by: Mike Kravetz >=20 > Thanks >=20