From patchwork Tue Sep 1 14:49:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 11748523 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 9C27813B6 for ; Tue, 1 Sep 2020 14:49:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 699C721D6C for ; Tue, 1 Sep 2020 14:49:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sbdKyf6g" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 699C721D6C 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 9F3566B007E; Tue, 1 Sep 2020 10:49:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A4806B0080; Tue, 1 Sep 2020 10:49:39 -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 8E1F96B0081; Tue, 1 Sep 2020 10:49:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 773A36B007E for ; Tue, 1 Sep 2020 10:49:39 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6C297362B for ; Tue, 1 Sep 2020 14:49:37 +0000 (UTC) X-FDA: 77214776394.14.pets01_3109fe427099 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 56FAA18229837 for ; Tue, 1 Sep 2020 14:49:36 +0000 (UTC) X-Spam-Summary: 1,0,0,e82889292a6bf93f,d41d8cd98f00b204,lixinhai.lxh@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2898:2911:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3874:4321:4425:5007:6119:6120:6261:6653:7514:7901:7903:9413:9592:10004:11026:11473:11658:11914:12297:12517:12519:12555:12679:12895:12986:13069:13141:13230:13255:13311:13357:14093:14181:14384:14394:14687:14721:14819:21080:21444:21451:21627:21666:21795:21990:30051:30054:30064:30070,0,RBL:209.85.208.194:@gmail.com:.lbl8.mailshell.net-62.18.84.100 66.100.201.100;04ygqramk5pkzjbgb31td9ff8z39iocnshwwb4m8aiirfghg386sr3ikksjsoti.cifms6tqe8dycmeaq9y16nhbhz37kh9d5k66f4qrqsdo7zf71ady9x7145i7i4n.q-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:27,LUA_SUMMARY:none X-HE-Tag: pets01_3109fe427099 X-Filterd-Recvd-Size: 4634 Received: from mail-lj1-f194.google.com (mail-lj1-f194.google.com [209.85.208.194]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 14:49:35 +0000 (UTC) Received: by mail-lj1-f194.google.com with SMTP id v12so1848412ljc.10 for ; Tue, 01 Sep 2020 07:49:35 -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=k8MG7uPDkNe5gsEf63TdNlQB0TpyGOf/Jh0ZLqp4syI=; b=sbdKyf6gpC13RVG5iO7kGJBzxIxc18V7+htL93q+yFTUPcDq1vaAh31broaU7owahb 1QUbom0ZzLeg2nergoX0D3WF6C48ouK57FijMPRwis1MdCqUSjnhv0Q3KUhdspOM9tIS bL7ibIsdRuMSRUHsYwHkHK017lrhIyqYzsb1W1S2T7Q0yXYIzswDxMYR7jxi/Zhf8aWD LsAfUT0QQcuymV56aaTLK59k75y0d4/0rwCwiWnnT+tFf+a2NkepuLheyGQ0nHnRU5Uq f9k+4ZuRMYEMlKOMXrovSoboC4vOOFDhG2dfehoxnJriCHx1+U4IzfA9TKmwfDQJEyB4 fiFA== 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=k8MG7uPDkNe5gsEf63TdNlQB0TpyGOf/Jh0ZLqp4syI=; b=soOchoJBnK3bhpI7mYjpQgXjcFI9pe9dBkLKCnkpfUu19e2Ud2wUk9Q9AMmt7q2Vis GAEokX8G8yOgoCwJQ0HfFYKoUgB/vRD+G+fMqDkmF6Q0ss+8lNs2rxXrwGtudAlpwDyU t0VJEX7WwKMFuVeRijSTKyAnF2XAjm2xuX2DsHJJFMYWQPBvtIWoDtQMC0z0ZaWC+NlB zeOVq/xjyExQV+q/CtugsK6cSNtF7TE0EjRhRuV4/FFCEXzjSAN+lYgKW81q0FXMyodi T8cXLfOMfG6HGWrzZqXZDu+X2y4hVIR/gwFYWHq3ySFoZk5svNH52Hv0TowRPU37vD8V 04xQ== X-Gm-Message-State: AOAM531ccM5X4p2X3zzhJ2/OZXFg+IQLKz77eygB9sv+j5x2+RusCKuN FKMLdaA8jk8A9FKAXtHe8u8EArhyCso= X-Google-Smtp-Source: ABdhPJyFuQu/y2sF4bXw5lYt1I9uxpFUQObQee2zvTMsvwGqE5KAdRyfzlynxpjQy485wMkD4k7TzA== X-Received: by 2002:a2e:3506:: with SMTP id z6mr770908ljz.418.1598971774051; Tue, 01 Sep 2020 07:49:34 -0700 (PDT) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id x73sm329201lfa.94.2020.09.01.07.49.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 07:49:33 -0700 (PDT) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Roman Gushchin , Mike Kravetz , Michal Hocko Subject: [PATCH V2] mm/hugetlb: try preferred node first when alloc gigantic page from cma Date: Tue, 1 Sep 2020 22:49:24 +0800 Message-Id: <20200901144924.678195-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.18.4 X-Rspamd-Queue-Id: 56FAA18229837 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. 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 Acked-by: Roman Gushchin --- v1->v2: With review by Mike and Michal, need to check __GFP_THISNODE to avoid allocate from other nodes. mm/hugetlb.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a301c2d672bf..d24986145087 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1256,15 +1256,24 @@ static struct page *alloc_gigantic_page(struct hstate *h, gfp_t gfp_mask, 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 (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)) { + 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