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 34F4EC433DB for ; Tue, 9 Feb 2021 01:24:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3076964E6C for ; Tue, 9 Feb 2021 01:24:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3076964E6C 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 5EC596B0005; Mon, 8 Feb 2021 20:24:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 59E586B006C; Mon, 8 Feb 2021 20:24:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B42B6B006E; Mon, 8 Feb 2021 20:24:51 -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 2FC8D6B0005 for ; Mon, 8 Feb 2021 20:24:51 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id F072018382485 for ; Tue, 9 Feb 2021 01:24:50 +0000 (UTC) X-FDA: 77796985140.08.moon96_1e1388927603 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id CFCC91819E64A for ; Tue, 9 Feb 2021 01:24:50 +0000 (UTC) X-HE-Tag: moon96_1e1388927603 X-Filterd-Recvd-Size: 3905 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 01:24:50 +0000 (UTC) Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DZQBD0V1BzlHrj; Tue, 9 Feb 2021 09:23:00 +0800 (CST) Received: from [10.174.179.149] (10.174.179.149) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 9 Feb 2021 09:24:43 +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> From: Miaohe Lin Message-ID: Date: Tue, 9 Feb 2021 09:24:43 +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: <3752cc85-06d1-5af7-8baf-2810c98524d3@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.179.149] X-CFilter-Loop: Reflected 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: 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 t= o >> 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 orde= r) >> 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); >=20 > Should we change this to >=20 > huge_page_size(h) / SZ_1K); > > as in hugetlb_report_meminfo above? Or, is that one where it takes a= n > additional instruction to do the divide as opposed to the shift? I wou= ld> rather add the instruction and keep everything consistent. >=20 Yes, it takes an additional instruction to do the divide as opposed to th= e 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 ? Many thanks.