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=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 76037C433DF for ; Tue, 7 Jul 2020 04:04:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 28FF320702 for ; Tue, 7 Jul 2020 04:04:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28FF320702 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CA9136B0028; Tue, 7 Jul 2020 00:04:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C30F86B0029; Tue, 7 Jul 2020 00:04:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFB5F6B002A; Tue, 7 Jul 2020 00:04:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id 911766B0028 for ; Tue, 7 Jul 2020 00:04:12 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 58BF91EE6 for ; Tue, 7 Jul 2020 04:04:12 +0000 (UTC) X-FDA: 77009937144.26.stamp16_261475226eb1 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 2F9BD1804B656 for ; Tue, 7 Jul 2020 04:04:12 +0000 (UTC) X-HE-Tag: stamp16_261475226eb1 X-Filterd-Recvd-Size: 2741 Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 04:04:11 +0000 (UTC) Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CA0DBDA3F0266F168FF6; Tue, 7 Jul 2020 12:04:03 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.203.253) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.487.0; Tue, 7 Jul 2020 12:03:55 +0800 From: Barry Song To: CC: , , , Barry Song , Mike Kravetz , Jonathan Cameron , Roman Gushchin Subject: [PATCH v3] mm/hugetlb: avoid hardcoding while checking if cma is enable Date: Tue, 7 Jul 2020 16:02:04 +1200 Message-ID: <20200707040204.30132-1-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.203.253] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 2F9BD1804B656 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: hugetlb_cma[0] can be NULL due to various reasons, for example, node0 has no memory. so NULL hugetlb_cma[0] doesn't necessarily mean cma is not enabled. gigantic pages might have been reserved on other nodes. Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages= using cma") Cc: Mike Kravetz Cc: Jonathan Cameron Acked-by: Roman Gushchin Signed-off-by: Barry Song --- -v3: add acked-by; make code more canonical=20 mm/hugetlb.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 57ece74e3aae..d293c823121e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2546,6 +2546,20 @@ static void __init gather_bootmem_prealloc(void) } } =20 +bool __init hugetlb_cma_enabled(void) +{ +#ifdef CONFIG_CMA + int node; + + for_each_online_node(node) { + if (hugetlb_cma[node]) + return true; + } +#endif + + return false; +} + static void __init hugetlb_hstate_alloc_pages(struct hstate *h) { unsigned long i; @@ -2571,7 +2585,7 @@ static void __init hugetlb_hstate_alloc_pages(struc= t hstate *h) =20 for (i =3D 0; i < h->max_huge_pages; ++i) { if (hstate_is_gigantic(h)) { - if (IS_ENABLED(CONFIG_CMA) && hugetlb_cma[0]) { + if (hugetlb_cma_enabled()) { pr_warn_once("HugeTLB: hugetlb_cma is enabled, skip boot time alloca= tion\n"); break; } --=20 2.27.0