From patchwork Fri Apr 24 09:58:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Zheng X-Patchwork-Id: 6267491 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D84AB9F1C4 for ; Fri, 24 Apr 2015 10:18:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 015E3202E5 for ; Fri, 24 Apr 2015 10:18:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1ABF6202BE for ; Fri, 24 Apr 2015 10:18:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753103AbbDXKSF (ORCPT ); Fri, 24 Apr 2015 06:18:05 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:18277 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752668AbbDXKRx (ORCPT ); Fri, 24 Apr 2015 06:17:53 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91182296" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Apr 2015 18:13:53 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t3OAGVej026162; Fri, 24 Apr 2015 18:16:31 +0800 Received: from localhost.localdomain (10.167.226.100) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Fri, 24 Apr 2015 18:17:45 +0800 From: Gu Zheng To: CC: , , , , , , , , , , , , Subject: [RESEND RFC PATCH 2/2] gfp: use the best near online node if the target node is offline Date: Fri, 24 Apr 2015 17:58:33 +0800 Message-ID: <1429869513-2906-2-git-send-email-guz.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.7.7 In-Reply-To: <1429869513-2906-1-git-send-email-guz.fnst@cn.fujitsu.com> References: <1429869513-2906-1-git-send-email-guz.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.100] 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=ham 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 Since the change to the cpu <--> mapping (map the cpu to the physical node for all possible at the boot), the node of cpu may be not present, so we use the best near online node if the node is not present in the low level allocation APIs. Signed-off-by: Gu Zheng --- include/linux/gfp.h | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 97a9373..19684a8 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -298,9 +298,31 @@ __alloc_pages(gfp_t gfp_mask, unsigned int order, return __alloc_pages_nodemask(gfp_mask, order, zonelist, NULL); } +static int find_near_online_node(int node) +{ + int n, val; + int min_val = INT_MAX; + int best_node = -1; + + for_each_online_node(n) { + val = node_distance(node, n); + + if (val < min_val) { + min_val = val; + best_node = n; + } + } + + return best_node; +} + static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask, unsigned int order) { + /* Offline node, use the best near online node */ + if (!node_online(nid)) + nid = find_near_online_node(nid); + /* Unknown node is current node */ if (nid < 0) nid = numa_node_id(); @@ -311,7 +333,11 @@ static inline struct page *alloc_pages_node(int nid, gfp_t 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)); + /* Offline node, use the best near online node */ + if (!node_online(nid)) + nid = find_near_online_node(nid); + + VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES); return __alloc_pages(gfp_mask, order, node_zonelist(nid, gfp_mask)); }