From patchwork Fri Jun 1 12:53:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10443279 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62DBF602BD for ; Fri, 1 Jun 2018 12:54:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5453328D8D for ; Fri, 1 Jun 2018 12:54:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4917828D8F; Fri, 1 Jun 2018 12:54:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5BF028D8D for ; Fri, 1 Jun 2018 12:54:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E71566B0007; Fri, 1 Jun 2018 08:54:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1EA16B000A; Fri, 1 Jun 2018 08:54:12 -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 CE8FF6B000C; Fri, 1 Jun 2018 08:54:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f70.google.com (mail-wm0-f70.google.com [74.125.82.70]) by kanga.kvack.org (Postfix) with ESMTP id 756136B0007 for ; Fri, 1 Jun 2018 08:54:12 -0400 (EDT) Received: by mail-wm0-f70.google.com with SMTP id e26-v6so766958wmh.7 for ; Fri, 01 Jun 2018 05:54:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=7h4KUFAIxKL6qRNxS32cyVNS7Rx61fOv3a36Lfq76Sw=; b=VhyeLqAVCGOkunItOQ61QOacsg6L2di9AEQ3Z6Lz7d0n1cTPjSqZzdSNCrR50CTo/f S5ye3hLWT3yGt8COZfF35mHqaQpklzhShE9ATdZzbvzK7oiq+a6tghPDJGoZud1UV8CW 2KKQMFqIhsDFn/uIBXwMjDqqcpHxMIocAw+5BLSA1uDlWoHpb//PxpeKzws6eVOl2uW5 PVQ9927hRMgO3dTWeVAIjH2vbeAo0rvQV77YPozRFhPgGhN4rA0k35EE11hyzSNCNq6A mIEp8c5n0OwMK4+pHk3YCofP4Mos5ZepWGHiSLAyK+JqQn7seZOa3gaiiPTsNk7imZyw nhMg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Gm-Message-State: ALKqPwcVd5E+3lHba+URXASKzTguZRjMpFLaMETx0EjM8dXCsiXF5Qwm QPCAk9Syl3Ew006HgzmCxJvvVxVDQkrZJ+pdn+A5Dbs8iY7TCfjJywCAE5R7lO2rWu74i3HAZQH 2Cjt8IHBCp20i6OBG8nzJKd+vRl11iBRrsGIidQnWDe28ce6HqgbsF2g5knHVhpecxDEWwdPcyc Tk2bM7EqGdcdx3szsRCVR7t17eMCWU20H3YHAHfXklnSNKh3Q3Z8DQ9Ubn7Q3YBf5hrxu9bM4O7 4SpkNfZRWYaTQgUWBBCsBg8IHlOc/69BqZya+Phkgb67HYk9j3gWUFcheH938zWPnAD1UxuuCbH K+l77dZFct7O6rfZFwOLuNY7mSClur3b3cwan6vuRTpOum1rr9t5IQw2HqCo6hSLruurhPLNVQ= = X-Received: by 2002:adf:9582:: with SMTP id p2-v6mr7881345wrp.16.1527857652050; Fri, 01 Jun 2018 05:54:12 -0700 (PDT) X-Received: by 2002:adf:9582:: with SMTP id p2-v6mr7881292wrp.16.1527857650901; Fri, 01 Jun 2018 05:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527857650; cv=none; d=google.com; s=arc-20160816; b=RLH+ZM+Nd0CFlDLozgYn6ZWYDV7P3QYFQdC6aGDzfvK56lWhAa4LReY1RUEpeml8rA +pGkiTltD0Ytx2EhR5UvDcOStan/RfPLun5g/CUQBpmLKT/plcsTVmm1/FCbVNW/95V4 6xmtDcJObi3Sh50dJ7fiURZFew/fcwCeLI0Nk11kEbhiZi16unl8AqcfasFPvfOq41mk p7ZQTHQKoCPXrOEa7Rph343OZ9yOFkEHn8ap6qf4C4tWGEmSnsVlocQVRHIYtY9rohdv tnXYDuzvTd+E68vOhbE7Wp3aQvTu7lsyKHxR9qDspGG7zoHcLgF8yqUFOtzgRZV0c86h wJSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=7h4KUFAIxKL6qRNxS32cyVNS7Rx61fOv3a36Lfq76Sw=; b=KEQNNfhjqpR6MCNj88lZi8j1RHaj+KBKLKxUZixKc5lsSih4Qua69LdESVlo6N68wL eE3ObSBl+hGgYZ7hdY02mQ05l0BLuXOWgyyoMwDz/pZwUxjlhuEv1XYbc2eeWJvg88gT Njex/l253ILx4ChI014WXZAEI3K7/zBkFg4OMhG/Sqmp99JFjUhLRUBukOpClBE9hU0b vgvwNr86jdIx6m9orIHMTiNkz5rEQ/3dhqDncFiGVxw0BcAEtJHwoULKQl36QVAfP62C 2tHVXtF+YDmTd+jjnrcjwuQOG3UlLkFyF5lYCERcjpWMXWC8gpmzPFNtMTi/bqJPWxaM WzFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i15-v6sor433520wmg.49.2018.06.01.05.54.10 for (Google Transport Security); Fri, 01 Jun 2018 05:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador.vilardaga@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=osalvador.vilardaga@gmail.com X-Google-Smtp-Source: ADUXVKKvC+/RRUwnL/2NhEAZeRGbMiOfaWtCBctsMlnJq9SUgAGdElB2qlSCVPWphiCq8TAZxuwI+A== 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> 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: X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Pavel Tatashin --- 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: