From patchwork Mon May 28 07:52:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10430017 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 BAF53602CB for ; Mon, 28 May 2018 07:53:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8CE728B56 for ; Mon, 28 May 2018 07:53:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B3FF28B73; Mon, 28 May 2018 07:53:04 +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 ED72228B56 for ; Mon, 28 May 2018 07:53:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0FD56B0005; Mon, 28 May 2018 03:53:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BBDA46B0006; Mon, 28 May 2018 03:53:02 -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 AAD056B0007; Mon, 28 May 2018 03:53:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wm0-f69.google.com (mail-wm0-f69.google.com [74.125.82.69]) by kanga.kvack.org (Postfix) with ESMTP id 55F086B0005 for ; Mon, 28 May 2018 03:53:02 -0400 (EDT) Received: by mail-wm0-f69.google.com with SMTP id h81-v6so4144503wmf.6 for ; Mon, 28 May 2018 00:53:02 -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=pReb2KCo8THOkXXhg0w3A+jScDTaR/QBPeFcnPqaANM=; b=dRBru/U2rSg1ewdh16esUSiN0v/nlCbiLxfAvWpAZn8OMf+zDU+LIrw9nQATjkB7+C tWJTAKBbFRCQhL/Z7Qo541inxJNBCP7ep3SZoAhOTiWimSAJNUHA3sJnITfQQ8/++Q34 +WcSI8wFxhCra+X+bHJiGG73Vd/5PfrSSm+5mY8acxz4rPiRZUIAz1WUuXitU15iExTP rPpboDkZUSgsZP3BvAoYTgilsoOfP1CiBFkDJja0+ijeeUSoUHdG6jjLVS9kdI/4slDO tbYV7g7WwGbCZs136D0JVTpSCdDkdbl3et2IoXcVvwRVDT52h73/cfH42dh7WJqWQMHK 81RA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@techadventures.net designates 62.201.165.239 as permitted sender) smtp.mailfrom=osalvador@techadventures.net X-Gm-Message-State: ALKqPweVFdlF8zi+wRAHY2JUWA+PJnDYa4Kupk4Bv67yj6PXmI0kNbyX OmVKJZWPU38IhhjvU7SFEn/S87TdsqFKvdcMUL5RZZcGliHapyZRPcxHfJpVe65tHytbUDvvtFw ho4/hCWBzAKYPNI1NlIF31iAlGQk8tjtksgu6K5TtiFF9vBr6iuezGwzPFFiJHdaYPw== X-Received: by 2002:adf:dc8b:: with SMTP id r11-v6mr8414087wrj.263.1527493981876; Mon, 28 May 2018 00:53:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoqE7mGdlYNc7JO02++0iEh9brTBg/di/6RBnnFGwA782kkkQ3y8ZLJYdD6NTb2Ou8z8FJc X-Received: by 2002:adf:dc8b:: with SMTP id r11-v6mr8414064wrj.263.1527493981259; Mon, 28 May 2018 00:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527493981; cv=none; d=google.com; s=arc-20160816; b=J6m0RsPA0iHbTVAG6LVrZjkwWY8Q+Tg3v7Pa+XWeOA/XOPaBu9165wxnBudCqjnEWD +3Lxlu1S10JSPoyMiKA3MVRSd78aHEuJDMeJou4GROlmwEteE7apEyPzs72lYwqot26z ZJqNae8p3GOUy2MC41OKQbK0ol37TGTd/vbsavE4XRWuzjqn+sEvTK1Z8TXwudeG1EYa PTUBhqybcu81JtYUo6bsu7pPmxsBT41TaUrPkeNV8/LJ6mWTT1bYEHOvUi0KEkCNrQ8T n1y1r4IF2iFxZpE2IiTn8VwsVIC5/h7vqP0G0GmvjHUIXksr5l6X89oDvVD1dyg8+015 5EaQ== 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=pReb2KCo8THOkXXhg0w3A+jScDTaR/QBPeFcnPqaANM=; b=lVjM8jVAYYqa3RQ5fd1iwoUFDdJ7prNb22vD6UKFtFmVkZzr/cZVblyA6SZfXiZcDL s2Pd1sL6Ot/sDAPxBLXlmxbt5k0ponUKwQDcBVFf3Y+lf/x3kvIUgYk3WDzawQxXg0Ab /IqESpYeIwgMMCGBq1oUPOkRbJpFWHWWTmR5XiuEG7prMUuyNGglr9/KzSdr7qX4bv6a 0IiLhCGG2XHZ1ZDZRopjVqNqXBGq+Rp3NfddDG/mF4oBasMMpGTGcsgHKSvXyP5KfaAn 9wrQLay9D3Qz4W8UEd1vFidEPIlHwQjJghLJyz/JOWUZ/L2S/3i+u4I6tLIH2j73JK0t RyUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of osalvador@techadventures.net designates 62.201.165.239 as permitted sender) smtp.mailfrom=osalvador@techadventures.net Received: from techadventures.net (techadventures.net. [62.201.165.239]) by mx.google.com with ESMTP id u18-v6si25657986wra.387.2018.05.28.00.53.01 for ; Mon, 28 May 2018 00:53:01 -0700 (PDT) Received-SPF: pass (google.com: domain of osalvador@techadventures.net designates 62.201.165.239 as permitted sender) client-ip=62.201.165.239; Authentication-Results: mx.google.com; spf=pass (google.com: domain of osalvador@techadventures.net designates 62.201.165.239 as permitted sender) smtp.mailfrom=osalvador@techadventures.net Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id D298C122FB8; Mon, 28 May 2018 09:53:00 +0200 (CEST) From: osalvador@techadventures.net To: linux-mm@kvack.org Cc: mhocko@suse.com, vbabka@suse.cz, pasha.tatashin@oracle.com, akpm@linux-foundation.org, Oscar Salvador Subject: [RFC PATCH 1/3] mm/memory_hotplug: Make add_memory_resource use __try_online_node Date: Mon, 28 May 2018 09:52:35 +0200 Message-Id: <20180528075237.18105-2-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180528075237.18105-1-osalvador@techadventures.net> References: <20180528075237.18105-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. try_online_node has most of the code to do this, so 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: