From patchwork Wed Sep 2 02:50:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11749651 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84F981575 for ; Wed, 2 Sep 2020 02:50:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 488C0206F0 for ; Wed, 2 Sep 2020 02:50:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ux4p78JP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 488C0206F0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 529A48E0003; Tue, 1 Sep 2020 22:50:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4B3368E0001; Tue, 1 Sep 2020 22:50:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37AEA8E0003; Tue, 1 Sep 2020 22:50:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 1DC908E0001 for ; Tue, 1 Sep 2020 22:50:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DA1CF181AEF10 for ; Wed, 2 Sep 2020 02:50:28 +0000 (UTC) X-FDA: 77216592936.25.hall89_37137582709d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id A39DB1804E3A8 for ; Wed, 2 Sep 2020 02:50:28 +0000 (UTC) X-Spam-Summary: 1,0,0,bd3b68859b3c8c02,d41d8cd98f00b204,lixinhai.lxh@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1437:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:2898:2911:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3874:4321:4425:5007:6119:6120:6261:6653:7514:7901:7903:9413:9592:10004:11026:11473:11658:11914:12296:12297:12517:12519:12555:12679:12895:13141:13230:13255:14093:14181:14394:14687:14721:14819:21080:21444:21451:21627:21666:21795:21990:30051:30054:30064:30070,0,RBL:209.85.167.66:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y898up61rngc1ywrkipnthcqryxypxxouu71p4oiirfghg38w1u5tasexcckr.1z9exjh74e7k9apffourmzsxux6zr496bhuqif85xbbuxd3ajxmx45naygtozwb.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: hall89_37137582709d X-Filterd-Recvd-Size: 5062 Received: from mail-lf1-f66.google.com (mail-lf1-f66.google.com [209.85.167.66]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Sep 2020 02:50:28 +0000 (UTC) Received: by mail-lf1-f66.google.com with SMTP id y11so1945485lfl.5 for ; Tue, 01 Sep 2020 19:50:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=0l3pFmps8jpjwcO5xOTOjfAZNXjLmooeghsmkIf1DDs=; b=ux4p78JPgljwtSHgdzBB6nQc9LSkdb0ZkrdCJ5kh5ielCsjPIiopBqbtwd34rY6Oz/ Ujqru+y1FgbI7laIMj8ir/wE1oYTwN/4Rna1ECJlssee3rrBSRsM2qzP+YPxPgykaxNd aoXSRRRhpoov+u9Bp/tJ4f0urV3lxFVzEdLohEVbqoAoa/0+fkZejNY74D89GcfflIea YHd2jSICtMmm9dJPlNYZDpvckRX2/ET3hE2rCE0GzU/K2BI9dLr1npB/yeRtpuMRXLIZ Ud5ifMKv5wOqHS4nKrFwu06duJxUImCJhDawcXpSrXBuzpDav8vL4I78PqMI8S4DtcPW Rdng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=0l3pFmps8jpjwcO5xOTOjfAZNXjLmooeghsmkIf1DDs=; b=ICMncwvoouA0dVCFgB1ljLjddpszjc2zH8ITUeiapzvYkyDyiSPSrznKBEeTQcMbLL +mCjZAjVUNvUDIFszyTTyV3R1O7xaCz8txkhtsp0I3u7tVdQWW4kYr1VFucsKtPeXkx5 kCOfMZttaReb4W3ez1gHLyF7/X6Z83mGRtvvGBUyi2+TX1u4L0Y5dkoJxGiizSSlDu9I bfBeyuKPdXGpGAQIrypipxdppS46ncb4jrdncmDe+8FnEYOd+oxtUGnow6yQ/f9krqPh SHtr8ZnKbaZh2ilf/P20BerapYAasqr/nKPP8+sGasaZCSxyjrRRs949meS/3cJnnX0u BSRw== X-Gm-Message-State: AOAM531s0eGqCDbY7hRtD1VYrYieQLkiXbDdeh0wzSZykEbNjn1yaEjM 8bhzgqRNZNvc9iJ7dUWauWEUWFR2C0E= X-Google-Smtp-Source: ABdhPJyQNLwrDAS2Ei17rnhdoEiHAKjCDPayAa5/G6/4UGO+BYYp3Al0NwdPt6QlTPHCYoAzSEmmHg== X-Received: by 2002:a05:6512:3185:: with SMTP id i5mr2107153lfe.205.1599015026293; Tue, 01 Sep 2020 19:50:26 -0700 (PDT) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id o15sm654784ljp.29.2020.09.01.19.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 19:50:25 -0700 (PDT) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Roman Gushchin , Mike Kravetz , Michal Hocko Subject: [PATCH V3] mm/hugetlb: try preferred node first when alloc gigantic page from cma Date: Wed, 2 Sep 2020 10:50:16 +0800 Message-Id: <20200902025016.697260-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 X-Rspamd-Queue-Id: A39DB1804E3A8 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: 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(). Besides, the __GFP_THISNODE also need be checked if user required to alloc only from the preferred node. After this patch, the preferred node is tried first before other allowed nodes, and don't try to allocate from other nodes if __GFP_THISNODE is specified. If user don't specify the preferred node, the current node will be used as preferred node, which makes sure consistent behavior of allocating gigantic and non-gigantic hugetlb page. Fixes: cf11e85fc08cc6a4 ("mm: hugetlb: optionally allocate gigantic hugepages using cma") Cc: Roman Gushchin Cc: Mike Kravetz Cc: Michal Hocko Signed-off-by: Li Xinhai Acked-by: Michal Hocko Reviewed-by: Mike Kravetz --- v2->V3 Consider current node as preferred node if nid is NUMA_NO_NODE, thanks Mike. v1->v2: With review by Mike and Michal, need to check __GFP_THISNODE to avoid allocate from other nodes. mm/hugetlb.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a301c2d672bf..5957dc80ebb1 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1250,21 +1250,32 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask, int nid, nodemask_t *nodemask) { unsigned long nr_pages = 1UL << huge_page_order(h); + if (nid == NUMA_NO_NODE) + nid = numa_mem_id(); #ifdef CONFIG_CMA { struct page *page; int node; - for_each_node_mask(node, *nodemask) { - if (!hugetlb_cma[node]) - continue; - - page = cma_alloc(hugetlb_cma[node], nr_pages, - huge_page_order(h), true); + if (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)) { + for_each_node_mask(node, *nodemask) { + if (node == nid || !hugetlb_cma[node]) + continue; + + page = cma_alloc(hugetlb_cma[node], nr_pages, + huge_page_order(h), true); + if (page) + return page; + } + } } #endif