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=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 4F649C433E6 for ; Tue, 1 Sep 2020 13:41:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 14CC0206EB for ; Tue, 1 Sep 2020 13:41:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 14CC0206EB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A069A6B0003; Tue, 1 Sep 2020 09:41:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B7846B0055; Tue, 1 Sep 2020 09:41:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F53F6B005A; Tue, 1 Sep 2020 09:41:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 54B226B0003 for ; Tue, 1 Sep 2020 09:41:22 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1777E180AD801 for ; Tue, 1 Sep 2020 13:41:22 +0000 (UTC) X-FDA: 77214604404.02.snail67_37138f127098 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id DDE8810097AA1 for ; Tue, 1 Sep 2020 13:41:21 +0000 (UTC) X-HE-Tag: snail67_37138f127098 X-Filterd-Recvd-Size: 4242 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 13:41:21 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8EA34ADE1; Tue, 1 Sep 2020 13:41:20 +0000 (UTC) Date: Tue, 1 Sep 2020 15:41:19 +0200 From: Michal Hocko To: Mike Kravetz Cc: Li Xinhai , linux-mm@kvack.org, akpm@linux-foundation.org, Roman Gushchin Subject: Re: [PATCH] mm/hugetlb: try preferred node first when alloc gigantic page from cma Message-ID: <20200901134119.GE16650@dhcp22.suse.cz> References: <20200830140418.605627-1-lixinhai.lxh@gmail.com> <640ddf82-26b1-3e38-5245-df481bc0756e@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <640ddf82-26b1-3e38-5245-df481bc0756e@oracle.com> X-Rspamd-Queue-Id: DDE8810097AA1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 31-08-20 14:44:40, Mike Kravetz wrote: > On 8/30/20 7:04 AM, Li Xinhai wrote: > > Since commit cf11e85fc08cc6a4 ("mm: hugetlb: optionally allocate gigantic > > hugepages using cma"), the gigantic page would be allocated from node > > which is not the preferred node, although there are pages available from > > that node. The reason is that the nid parameter has been ignored in > > alloc_gigantic_page(). > > > > After this patch, the preferred node is tried first before other allowed > > nodes. > > Thank you! > This is an issue that needs to be fixed. > > > Fixes: cf11e85fc08cc6a4 ("mm: hugetlb: optionally allocate gigantic hugepages using cma") > > Cc: Roman Gushchin > > Cc: Mike Kravetz > > Cc: Michal Hocko > > Signed-off-by: Li Xinhai > > --- > > mm/hugetlb.c | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index a301c2d672bf..4a28b8853d47 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -1256,8 +1256,15 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask, > > struct page *page; > > int node; > > > > + if (hugetlb_cma[nid]) { > > + page = cma_alloc(hugetlb_cma[nid], nr_pages, > > + huge_page_order(h), true); > > + if (page) > > + return page; > > + } > > + > > When looking at your changes, I noticed that this code for allocation > from CMA does not take gfp_mask into account. The 'normal' use case > is to allocate pool pages with something similar to: > > echo 16 > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages > > The routine alloc_pool_huge_page will try to interleave pages among nodes: > > ... > gfp_t gfp_mask = htlb_alloc_mask(h) | __GFP_THISNODE; > > for_each_node_mask_to_alloc(h, nr_nodes, node, nodes_allowed) { > ... > > which will eventually call alloc_gigantic_page. If __GFP_THISNODE is > set we really do not want to execute the below for loop in alloc_gigantic_page. Yes, this is the case indeed. > I think the convention in the mm code is that only the lowest level > allocation routines should interpret the GFP flags. We may need to make > an exception here and check for __GFP_THISNODE. Yes this is true, But alloc_gigantic_page is actually low level allocation routine in fact. I would go with the following diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a301c2d672bf..124754240b56 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1256,6 +1256,16 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask, struct page *page; int node; + if (nid != NUMA_NO_NODE && hugetlb_cma[nid]) { + page = cma_alloc(hugetlb_cma[nid], nr_pages, + huge_page_order(h), true); + if (page) + return page; + } + + if (gfp_mask & __GFP_THISNODE) + return NULL; + for_each_node_mask(node, *nodemask) { if (!hugetlb_cma[node]) continue; I do not think we actually do have an explicit NUMA_NO_NODE user but it is safer to not asume that here. -- Michal Hocko SUSE Labs