From patchwork Thu Sep 10 04:27:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tangchen X-Patchwork-Id: 7150871 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2CD62BEEC1 for ; Thu, 10 Sep 2015 04:31:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 468D3209C9 for ; Thu, 10 Sep 2015 04:31:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53962209DB for ; Thu, 10 Sep 2015 04:31:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753224AbbIJEaA (ORCPT ); Thu, 10 Sep 2015 00:30:00 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:60199 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752602AbbIJE3i (ORCPT ); Thu, 10 Sep 2015 00:29:38 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100549494" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 10 Sep 2015 12:32:33 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8A4TNCK014077; Thu, 10 Sep 2015 12:29:23 +0800 Received: from tangchen.g08.fujitsu.local (10.167.226.71) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 10 Sep 2015 12:29:35 +0800 From: Tang Chen To: , , , , , , , , , , , , CC: , , , , , Gu Zheng Subject: [PATCH v2 3/7] x86, gfp: Cache best near node for memory allocation. Date: Thu, 10 Sep 2015 12:27:45 +0800 Message-ID: <1441859269-25831-4-git-send-email-tangchen@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1441859269-25831-1-git-send-email-tangchen@cn.fujitsu.com> References: <1441859269-25831-1-git-send-email-tangchen@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.71] Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gu Zheng In the current kernel, all possible cpus are mapped to the best near online node if they reside in a memory-less node in init_cpu_to_node(). init_cpu_to_node() { ...... for_each_possible_cpu(cpu) { ...... if (!node_online(node)) node = find_near_online_node(node); numa_set_node(cpu, node); } } The reason for doing this is to prevent memory allocation failure if the cpu is online but there is no memory on that node. But since cpuid <-> nodeid mapping is planed to be made static, doing so in initialization pharse makes no sense any more. The best near online node for each cpu has been cached in an array in previous patch. And the reason for doing this is to avoid mapping CPUs on memory-less nodes to other nodes. So in this patch, we get best near online node for CPUs on memory-less nodes inside alloc_pages_node() and alloc_pages_exact_node() to avoid memory allocation failure. Signed-off-by: Gu Zheng Signed-off-by: Tang Chen --- arch/x86/mm/numa.c | 3 +-- include/linux/gfp.h | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c index 8bd7661..e89b9fb 100644 --- a/arch/x86/mm/numa.c +++ b/arch/x86/mm/numa.c @@ -151,6 +151,7 @@ void numa_set_node(int cpu, int node) return; } #endif + per_cpu(x86_cpu_to_node_map, cpu) = node; set_near_online_node(node); @@ -787,8 +788,6 @@ void __init init_cpu_to_node(void) if (node == NUMA_NO_NODE) continue; - if (!node_online(node)) - node = find_near_online_node(node); numa_set_node(cpu, node); } } diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ad35f30..1a1324f 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -307,13 +307,19 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask, if (nid < 0) nid = numa_node_id(); + if (!node_online(nid)) + nid = get_near_online_node(nid); + return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask)); } static inline struct page *alloc_pages_exact_node(int nid, gfp_t gfp_mask, unsigned int order) { - VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES || !node_online(nid)); + VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES); + + if (!node_online(nid)) + nid = get_near_online_node(nid); return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask)); }