From patchwork Fri Jun 22 11:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10481889 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 A15B36023A for ; Fri, 22 Jun 2018 11:19:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C87A28BCD for ; Fri, 22 Jun 2018 11:19:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F84828C03; Fri, 22 Jun 2018 11:19:36 +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 E1BBC28BCD for ; Fri, 22 Jun 2018 11:19:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BC546B000A; Fri, 22 Jun 2018 07:19:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 268956B000D; Fri, 22 Jun 2018 07:19:35 -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 1327A6B000E; Fri, 22 Jun 2018 07:19:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f199.google.com (mail-wr0-f199.google.com [209.85.128.199]) by kanga.kvack.org (Postfix) with ESMTP id A87BA6B000A for ; Fri, 22 Jun 2018 07:19:34 -0400 (EDT) Received: by mail-wr0-f199.google.com with SMTP id d4-v6so4390786wrr.9 for ; Fri, 22 Jun 2018 04:19:34 -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=FwE2DVSw8f3TVzFlTcffGarktS9bl9OK1DspEEDxH8E=; b=OwYB9s55xCPo5TRpM0sJ1knuyawHXaa3NVdu4JJLHg7YYi4JxVDpljRCJG0qBFupkR nYoWo7zDg5c4b3jdc8OnWcTZ0f05WjvqmtjC33MQ8a54yVVyZE5815r/ttJOJyE7Tqac PAD9euIAm0vYqytSpCGw8f/aKmlBry9e8UEVg9a1hJRNBVsqNV0wyTTw1KuyIXQjwMIb JqLTuzYbPkmF50SFr32kT4k7/xurb2Q/2Jqum74gW2aKUe7vF4Vin6tkrrUXS9QwfuRN Nhz2eNYUT8ZZr1J/Za83830MrERT3jWSOJ2txBPvPttEBKb5Qo+JHBetZYlMU9kPkjAD VKew== 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: APt69E11rPnuK5TfA2v781ITgkdq9X57hXuUX2ko0QtELxhbGzlFH5EU n9GeXQC8j3P+MlH5mmN68e29JxG07cQuF7oUEfWuD13QqsDNxHwH3j/xSxKmBnLBvyJGCGRFk8h 4gkZUCnXvvBnD+qmcyyZ38HnlrzXzsiDaCmw77HDey65BRji7XYVBrTV790G5302g6poaE1DAJA OGQ/ShQnJL1dYzd1W/bNu3P4dNMNQ+rZaiNTmrypd4x2DzxaXxnvIQqPdSj+GVFoCkpGLU3nP/1 FfQmccYbLlMKmA3h+en+Eun7i3/HDLgQqnHPgN9tgF7TrbqNztpo6Bl5JS6G74idL8dE/Js3+yi 7gNKH3F+UR7zbgAvIDBWLpNtF1Au7uX7Y+pJleJf+Gsj0FIGKvqk11dxH7AFyObjoyXgsxUdbw= = X-Received: by 2002:a1c:96c8:: with SMTP id y191-v6mr1342066wmd.37.1529666374241; Fri, 22 Jun 2018 04:19:34 -0700 (PDT) X-Received: by 2002:a1c:96c8:: with SMTP id y191-v6mr1342023wmd.37.1529666373359; Fri, 22 Jun 2018 04:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529666373; cv=none; d=google.com; s=arc-20160816; b=cwDaB4fipJV2nlD2EZx1XIRkONPNOGiH3epEr/anKLr68hft3SQeYoZbR/4Lp+GPFg 1u5QFfr5VORh5txN5+l+G4SnBPQmcfRQxxP2PA9zoQ/JMofiWGk0LL9IvZuiTq5s4WPi fshHcE1SP8isd/12qQ4rck8pQONqQxl+5F8IKueSfYubgZvUkrvrWksPC+PHe0Ua3r4c bcJ+whwPBT1rFZUT0ytux1ghSWWuOUnW8WBDawyvykhSszJ+5XOeD8MJCXJFio1tVDuE J9uMs3zc+XNGYlXW19Y86onJDhxgm1JWU0jyJP0Nb4rrb/nfO9WKor1MX1Yjs+7oLC2Y sO8w== 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=FwE2DVSw8f3TVzFlTcffGarktS9bl9OK1DspEEDxH8E=; b=ZRWEcwyEiSq2o0EM/0JxuwJvUnOOWMBcw74JSNUONQM5DWAcmu4q1h9PhV7loZoTOg hw7zEX3mR3fYSBGOHyc7QQPSLx4zbOCh5RZLUzVjdXrBZhsYguIflwWuyxH66i6/ZkVZ Aws1TfPEBw1gjqNm+Xbtefm/M20SGP2ogCYr/YMZfqIxeXQGMsQpOECHurpp9oLSZ2Go 3Ijfyn0slCWXv6kkuxvd86rvIVl/5bWivdgRTgnb6zDYMOZAkZogaB6+u8I7KgM4tmn0 gc10DOUxl1PnwRnPTd7iSGsMH+5qg+SjPd20PEiF0vxOfe5nsENHmEXIpfzrGt1Ahvp8 u1pg== 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 o10-v6sor2753590wrm.36.2018.06.22.04.19.33 for (Google Transport Security); Fri, 22 Jun 2018 04:19:33 -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: ADUXVKLZpn64MaGLgV1JfRJqRMXJRQC7ZW5cPsR/DjGyuctKziehVSZjSG5jM5vRx12McvF/dGYquA== X-Received: by 2002:adf:b3d4:: with SMTP id x20-v6mr1280718wrd.272.1529666373021; Fri, 22 Jun 2018 04:19:33 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id t1-v6sm1723394wmt.40.2018.06.22.04.19.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 04:19:32 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 83C72123759; Fri, 22 Jun 2018 13:19:31 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@suse.cz, pasha.tatashin@oracle.com, Jonathan.Cameron@huawei.com, arbab@linux.vnet.ibm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v2 1/4] mm/memory_hotplug: Make add_memory_resource use __try_online_node Date: Fri, 22 Jun 2018 13:18:36 +0200 Message-Id: <20180622111839.10071-2-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180622111839.10071-1-osalvador@techadventures.net> References: <20180622111839.10071-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 | 67 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7deb49f69e27..504ba120bdfc 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,48 @@ 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. + * + * Returns: + * 1 -> a new node has been allocated + * 0 -> the node is already online + * -ENOMEM -> the node could not be allocated */ -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,9 +1121,7 @@ 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; + bool new_node = false; int ret; start = res->start; @@ -1111,11 +1131,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 +1141,13 @@ 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); + if (ret < 0) + goto error; + new_node = ret; /* call arch's memory hotadd */ ret = arch_add_memory(nid, start, size, NULL, true); - if (ret < 0) goto error; @@ -1180,8 +1191,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: