Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp558304imm; Fri, 1 Jun 2018 05:56:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLdRClFHTkGGDu1BsmCTW/EcEMDv3oWmMzWyfruuZGaLm2gNfDwqfM85OMFNXbVc/R+WA5N X-Received: by 2002:a17:902:600a:: with SMTP id r10-v6mr10852599plj.70.1527857776959; Fri, 01 Jun 2018 05:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527857776; cv=none; d=google.com; s=arc-20160816; b=dVirJfbXcinI3Yd6Pp4DZehTrbvA8v4vnEcBYJMek42rRsUUUL9Ig9fKzzujkwOc0G XNyJX1pcFPUyIGKrWUkyE38MCp7sa3Lr278EMnYlK8PgiLpHOD1Er9Qw0Nb7CzI3VXkH W5RKz8Dr0FLY7uzcNxDbJv5Jzpnn3o3VANS8ZWUg2NIEXhkKpXBhLIcC9hpvUNRcQzeM qACJV0aG2ZWNs/cH+iwOCYzcafjgYWIoh0yTNqYaw3pcgD4b1goEzOUu7Wv9O8RIjpnV e03NR78FHlJDoVASOHgiEo+fadIDgA6mfJFYSeVlHtsMnfoW10zZ8isBolXjN/PaSt/p tyaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=7h4KUFAIxKL6qRNxS32cyVNS7Rx61fOv3a36Lfq76Sw=; b=vnL8o1bwzrbc8jtZZs280hRwD47nKMQUyDv3O9xhu/it5p4ExSdb8a7HmO4qTmBQF3 YVtVu06vprUX4Bta8NmKSttOciGYKeRiF44AvqEIW9nnJ2zYwlvfKhlGpB1L8H9GEFJ1 fFZouv90rZYZq5Z8/Y/IkgeE8gvSROLU/s+eLO4Z5AbwdsXJiZZ6MCL3V9zC+Fw3jDcb kvD6UCNQco99P8fl7RZ5qGGcHVRXdHZ67jWS/sh3ejy325w+vjadBPJZvFc8B7xqrEAX DRx/T0ZnCmYyghLxCz0G+bzcjWI+/0msM44RV3d0cc6f/AgHatYliOuMRKp6ffmCq615 h02g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12-v6si9921387pgp.565.2018.06.01.05.56.02; Fri, 01 Jun 2018 05:56:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752464AbeFAMyT (ORCPT + 99 others); Fri, 1 Jun 2018 08:54:19 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:53036 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752167AbeFAMyL (ORCPT ); Fri, 1 Jun 2018 08:54:11 -0400 Received: by mail-wm0-f65.google.com with SMTP id 18-v6so2869228wml.2 for ; Fri, 01 Jun 2018 05:54:10 -0700 (PDT) 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:in-reply-to :references; bh=7h4KUFAIxKL6qRNxS32cyVNS7Rx61fOv3a36Lfq76Sw=; b=IxUZTzyekoxFDfr+iQCFmDbgVL/1bBRsv6vrT/nIusDAHO/eAtXdt1WEl7BJ5yVaNZ pic/MkjlPe30B25MwVEsFcpJBqKAakZDMyTlCv+qxnx3a0B8CAy7ywWErmMPTmLH7zaU y25VoJXONtR8CWeRx9ACfljnSJQTsEdW8CBsV59YwgIeRKwgx4mkbwz0Wt/224tzDfiT I3Ml2v+tkuJLKam4fup/msE+yxsZKpOIBMhVg6SRsGibQMU+V0+Bhb9s56Db/TVEkLBq mIhYFqaL5QuXAwXYBRC25jDKH7hkSR7wYUySplJzk2s/owWsY5EpIJMID33AHtS/DFIx H6PA== X-Gm-Message-State: APt69E3yZRISx1UiTRJcc+m2U/B48TIAJ2h0gwNoueoGrXVsgbvd3Gof 8OPSZKL+uyhcuF5vWWQ/VRs= X-Received: by 2002:a1c:e48a:: with SMTP id b132-v6mr2576985wmh.129.1527857650251; Fri, 01 Jun 2018 05:54:10 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id p5-v6sm24974062wre.83.2018.06.01.05.54.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jun 2018 05:54:09 -0700 (PDT) Received: from d104.suse.de (nat.nue.novell.com [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id AF98F123175; Fri, 1 Jun 2018 14:54:08 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@suse.cz, pasha.tatashin@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH 1/4] mm/memory_hotplug: Make add_memory_resource use __try_online_node Date: Fri, 1 Jun 2018 14:53:18 +0200 Message-Id: <20180601125321.30652-2-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180601125321.30652-1-osalvador@techadventures.net> References: <20180601125321.30652-1-osalvador@techadventures.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Oscar Salvador add_memory_resource() contains code to allocate a new node in case it is necessary. Since try_online_node() also hast some code for this purpose, let us make use of that and remove duplicate code. This introduces __try_online_node(), which is called by add_memory_resource() and try_online_node(). __try_online_node() has two new parameters, start_addr of the node, and if the node should be onlined and registered right away. This is always wanted if we are calling from do_cpu_up(), but not when we are calling from memhotplug code. Nothing changes from the point of view of the users of try_online_node(), since try_online_node passes start_addr=0 and online_node=true to __try_online_node(). Signed-off-by: Oscar Salvador --- mm/memory_hotplug.c | 61 +++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7deb49f69e27..29a5fc89bdb1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1034,8 +1034,10 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) return pgdat; } -static void rollback_node_hotadd(int nid, pg_data_t *pgdat) +static void rollback_node_hotadd(int nid) { + pg_data_t *pgdat = NODE_DATA(nid); + arch_refresh_nodedata(nid, NULL); free_percpu(pgdat->per_cpu_nodestats); arch_free_nodedata(pgdat); @@ -1046,28 +1048,43 @@ static void rollback_node_hotadd(int nid, pg_data_t *pgdat) /** * try_online_node - online a node if offlined * @nid: the node ID - * + * @start: start addr of the node + * @set_node_online: Whether we want to online the node * called by cpu_up() to online a node without onlined memory. */ -int try_online_node(int nid) +static int __try_online_node(int nid, u64 start, bool set_node_online) { - pg_data_t *pgdat; - int ret; + pg_data_t *pgdat; + int ret = 1; if (node_online(nid)) return 0; - mem_hotplug_begin(); - pgdat = hotadd_new_pgdat(nid, 0); + pgdat = hotadd_new_pgdat(nid, start); if (!pgdat) { pr_err("Cannot online node %d due to NULL pgdat\n", nid); ret = -ENOMEM; goto out; } - node_set_online(nid); - ret = register_one_node(nid); - BUG_ON(ret); + + if (set_node_online) { + node_set_online(nid); + ret = register_one_node(nid); + BUG_ON(ret); + } out: + return ret; +} + +/* + * Users of this function always want to online/register the node + */ +int try_online_node(int nid) +{ + int ret; + + mem_hotplug_begin(); + ret = __try_online_node (nid, 0, true); mem_hotplug_done(); return ret; } @@ -1099,8 +1116,6 @@ static int online_memory_block(struct memory_block *mem, void *arg) int __ref add_memory_resource(int nid, struct resource *res, bool online) { u64 start, size; - pg_data_t *pgdat = NULL; - bool new_pgdat; bool new_node; int ret; @@ -1111,11 +1126,6 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) if (ret) return ret; - { /* Stupid hack to suppress address-never-null warning */ - void *p = NODE_DATA(nid); - new_pgdat = !p; - } - mem_hotplug_begin(); /* @@ -1126,17 +1136,14 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) */ memblock_add_node(start, size, nid); - new_node = !node_online(nid); - if (new_node) { - pgdat = hotadd_new_pgdat(nid, start); - ret = -ENOMEM; - if (!pgdat) - goto error; - } + ret = __try_online_node (nid, start, false); + new_node = !!(ret > 0); + if (ret < 0) + goto error; + /* call arch's memory hotadd */ ret = arch_add_memory(nid, start, size, NULL, true); - if (ret < 0) goto error; @@ -1180,8 +1187,8 @@ int __ref add_memory_resource(int nid, struct resource *res, bool online) error: /* rollback pgdat allocation and others */ - if (new_pgdat && pgdat) - rollback_node_hotadd(nid, pgdat); + if (new_node) + rollback_node_hotadd(nid); memblock_remove(start, size); out: -- 2.13.6