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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 34C51C433E0 for ; Tue, 7 Jul 2020 07:37:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ECE5C20708 for ; Tue, 7 Jul 2020 07:37:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="HiyY7dVT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECE5C20708 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5EC0A6B0037; Tue, 7 Jul 2020 03:37:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59DB46B0055; Tue, 7 Jul 2020 03:37:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48B676B005A; Tue, 7 Jul 2020 03:37:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 311A56B0037 for ; Tue, 7 Jul 2020 03:37:44 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 403868248D7C for ; Tue, 7 Jul 2020 07:37:42 +0000 (UTC) X-FDA: 77010475164.26.neck77_19093aa26eb2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 243091804B661 for ; Tue, 7 Jul 2020 07:37:42 +0000 (UTC) X-HE-Tag: neck77_19093aa26eb2 X-Filterd-Recvd-Size: 3680 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 07:37:41 +0000 (UTC) Received: from kernel.org (unknown [87.71.40.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D2286206E2; Tue, 7 Jul 2020 07:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594107460; bh=BF/9d7raiGWUHJ5VCEYHildUE4Bc46UC4HFzLOSAoDQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HiyY7dVThrJzbTOWbbKMgtRYXguD5FReKSYQajzHKozoRHrziwsBDkEkSDkf7ExXJ C3Y9jrDr4Q//FWhZVVoz56Vlv+2LB52CWofjh/aB+Mu+AsLsIS4YCf3QMVlZrfezNP zv+AVhV1bcd66K4falGbYYyghdvOImy7emAw6nr8= Date: Tue, 7 Jul 2020 10:37:35 +0300 From: Mike Rapoport To: Roman Gushchin Cc: Barry Song , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, Mike Kravetz , Jonathan Cameron Subject: Re: [PATCH v2] mm/hugetlb: avoid hardcoding while checking if cma is enable Message-ID: <20200707073735.GB9449@kernel.org> References: <20200707031156.29932-1-song.bao.hua@hisilicon.com> <20200707033631.GA164297@carbon.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200707033631.GA164297@carbon.dhcp.thefacebook.com> X-Rspamd-Queue-Id: 243091804B661 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 Mon, Jul 06, 2020 at 08:36:31PM -0700, Roman Gushchin wrote: > On Tue, Jul 07, 2020 at 03:11:56PM +1200, Barry Song wrote: > > 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: Roman Gushchin > > Cc: Mike Kravetz > > Cc: Jonathan Cameron > > Signed-off-by: Barry Song > > --- > > -v2: add hugetlb_cma_enabled() helper to improve readability according to Roman > > > > mm/hugetlb.c | 16 +++++++++++++++- > > 1 file changed, 15 insertions(+), 1 deletion(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 57ece74e3aae..d5e98ed86bb9 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -2546,6 +2546,20 @@ static void __init gather_bootmem_prealloc(void) > > } > > } > > > > +bool __init hugetlb_cma_enabled(void) > > +{ > > + if (IS_ENABLED(CONFIG_CMA)) { > > + int node; > > + > > + for_each_online_node(node) { > > + if (hugetlb_cma[node]) > > + return true; > > + } > > + } > > + > > + return false; > > +} > > + > > Can you, please, change it to a more canonical > > #ifdef CONFIG_CMA > bool __init hugetlb_cma_enabled(void) > { > int node; > > for_each_online_node(node) > if (hugetlb_cma[node]) > return true; > > return false; > } > #else > bool __init hugetlb_cma_enabled(void) > { > return false; > } > #endif > > or maybe just > > 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; > } This one please. > ? > > Please, feel free to add > Acked-by: Roman Gushchin after that. > > Thank you! > -- Sincerely yours, Mike.