From patchwork Fri Aug 10 15:29:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 10562847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4A931390 for ; Fri, 10 Aug 2018 15:29:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 945042BCDE for ; Fri, 10 Aug 2018 15:29:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88BB32BCD9; Fri, 10 Aug 2018 15:29:45 +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 204972BCD2 for ; Fri, 10 Aug 2018 15:29:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C0176B0006; Fri, 10 Aug 2018 11:29:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 672216B000C; Fri, 10 Aug 2018 11:29:39 -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 3144B6B000A; Fri, 10 Aug 2018 11:29:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by kanga.kvack.org (Postfix) with ESMTP id B33A16B0006 for ; Fri, 10 Aug 2018 11:29:38 -0400 (EDT) Received: by mail-wr1-f71.google.com with SMTP id q18-v6so7250820wrr.12 for ; Fri, 10 Aug 2018 08:29:38 -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=DThuzYFgA226wgydxOLHMV8CyK7W76Ue8dyps4MED5o=; b=ayLRU7oHZpXQePAESFvAY6mNLTXi2Bt/liSwc7GNmJsARd2J+WaF85fEjAeCZBo5h3 kuXsAd1UCGIpSGx2AFOss21w9cLS4IVLKDx0Fg6Se8OlyBk3lpNfnmHqTG/FIpYeqFOD ZwPOM2h2hWQtGVSFdX15thWOH7bXKzKZCTa687V0o1YWIAa9ILy0R4D8H1yNBdAEtjNe fl7RMx0qj2d4fr0akJuFr/0613Cwdde4ZPWMG/0bhyG2hlx7O018eVzMfNLRwJi13Gxg WpvfLkjg7nF8q8n06r3lBI/BII2rzHOJ9efphJbsZY5lbmSfsT+/2SPieqOhzEeqtRRt 7bLw== 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: AOUpUlH7z/BFNEKEFtqOUopEH/GPD3MuIJQlDy34M20HeyBPy2P0amcp E5SaccSS0rwNQgyspW73ndjmb/41JOTQfC5bzyr2E4e/D9C3JGZNCrvBjaZ9RXBOZKOlGpHPcSw CbZ3EsN75gHvA9nqdf01HjTeSm81OsooOR1ejuurRRfxtkis7ltHc20co1HP2xorVpOCcIYfMHS xye9YG2y/5UA/tqCCmK+PpmMvmV0DA6sQcrBQLp4hSMBA1MLAE5yvB67+4PNRtEdGm0TEXfe+f+ vzI0FGybYpSf5bD/jWiK579N1vlvPOSOr65CcJ1Vih5hEvtT5Uv9Fy3PFMoBsigKp+/DLQ7Jmqx Xsuw4pt89AJ8CvuaOx8TncHXiSEampiWrHZWfSo0IauPX6xWxoWlubA1WvmUknrMCoDym92BnA= = X-Received: by 2002:a1c:dacb:: with SMTP id r194-v6mr1798056wmg.56.1533914978285; Fri, 10 Aug 2018 08:29:38 -0700 (PDT) X-Received: by 2002:a1c:dacb:: with SMTP id r194-v6mr1798021wmg.56.1533914977324; Fri, 10 Aug 2018 08:29:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533914977; cv=none; d=google.com; s=arc-20160816; b=Shr2Q7q/gSR8KGgYdWmk7sdoq7x4zK4Q1JtktTzefHFrAC8OvgRS4xyrVKz79LP35+ ELv/TB5opJUK1WJcaLz5dV4nZPpBPOCkqD7x6jXweWVsxh8qXSbBB9GiP8qpQRqG1JpW fHEr/X9VUvdLeEPPKFIkGPEYn3C4Ud2HWu5ZoAAtyAwqg5lVdXTVl8Eab/F/sHBV7a06 Wohwjwq8eGmKXw08tEyY2dLbqLbpoRq1zBHLeXrggViaZXe5jmOE/YwKCvMujLsVGR3j Vl8cfhiTBsJn+EsRgWkwq1wZSDKu0UaVCjJEyldQ9NuBISQpocbAn5CQfXueMNt+0krt Ld+w== 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=DThuzYFgA226wgydxOLHMV8CyK7W76Ue8dyps4MED5o=; b=uNijlRpCB3HjDx0hSH8c40icW8NMdCvGWvybt55yaOzFQZXTxDCr+RqSH0cOWiwilJ 7wvZiywJNA9TQOAYmr1cWjBQOrAF/P8HJpF08/DDhsSBmzEHX4rqPdDAN2wgV+jbkRQm ryCAINVnzVtKslYYIpf1EcAWoZ4AV81NqwJq13XemqPyqKHaVuAWY2y6KQ35uel90/pB OCJShOOT+WpzTb5n51uHIZdJmdpjQLiVHaOLcUlYwsDQFvPU3rDQ7utzOr3J2c+DfgpZ Vv/VC0E3NVk79iR/W2v+NvM3gK/nN8+Th8xrIDr4rxE2BDCRKD4B5GQ5eO/378srgaiI ta8w== 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 16-v6sor292153wms.81.2018.08.10.08.29.37 for (Google Transport Security); Fri, 10 Aug 2018 08:29:37 -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: AA+uWPzbs36MxCTUWcZ9pj2HjX2ZyzIipgHJh9Tm0gNRoWHVIbPlItS90THDEvmfRh2AMypOByfCDA== X-Received: by 2002:a1c:b45:: with SMTP id 66-v6mr1816958wml.45.1533914977055; Fri, 10 Aug 2018 08:29:37 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id n7-v6sm8811166wrr.35.2018.08.10.08.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 Aug 2018 08:29:35 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id B0EA412481F; Fri, 10 Aug 2018 17:29:34 +0200 (CEST) From: osalvador@techadventures.net To: akpm@linux-foundation.org Cc: mhocko@suse.com, vbabka@suse.cz, dan.j.williams@intel.com, yasu.isimatu@gmail.com, jonathan.cameron@huawei.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH 3/3] mm/memory_hotplug: Cleanup unregister_mem_sect_under_nodes Date: Fri, 10 Aug 2018 17:29:31 +0200 Message-Id: <20180810152931.23004-4-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180810152931.23004-1-osalvador@techadventures.net> References: <20180810152931.23004-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 With the assumption that the relationship between memory_block <-> node is 1:1, we can refactor this function a bit. This assumption is being taken from register_mem_sect_under_node() code. register_mem_sect_under_node() takes the mem_blk's nid, and compares it to the pfn's nid we are checking. If they match, we go ahead and link both objects. Once done, we just return. So, the relationship between memory_block <-> node seems to stand. Currently, unregister_mem_sect_under_nodes() defines a nodemask_t which is being checked in the loop to see if we have already unliked certain node. But since a memory_block can only belong to a node, we can drop the nodemask and the check within the loop. If we find a match between the mem_block->nid and the nid of the pfn we are checking, we unlink the objects and return, as unlink the objects once is enough. Signed-off-by: Oscar Salvador --- drivers/base/node.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index dd3bdab230b2..0657ed70bddd 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -448,35 +448,27 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) return 0; } -/* unregister memory section under all nodes that it spans */ +/* unregister memory section from the node it belongs to */ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, unsigned long phys_index) { - NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); unsigned long pfn, sect_start_pfn, sect_end_pfn; - - if (!unlinked_nodes) - return -ENOMEM; - nodes_clear(*unlinked_nodes); + int nid = mem_blk->nid; sect_start_pfn = section_nr_to_pfn(phys_index); sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { - int nid; + int page_nid = get_nid_for_pfn(pfn); - nid = get_nid_for_pfn(pfn); - if (nid < 0) - continue; - if (!node_online(nid)) - continue; - if (node_test_and_set(nid, *unlinked_nodes)) - continue; - sysfs_remove_link(&node_devices[nid]->dev.kobj, - kobject_name(&mem_blk->dev.kobj)); - sysfs_remove_link(&mem_blk->dev.kobj, - kobject_name(&node_devices[nid]->dev.kobj)); + if (page_nid >= 0 && page_nid == nid) { + sysfs_remove_link(&node_devices[nid]->dev.kobj, + kobject_name(&mem_blk->dev.kobj)); + sysfs_remove_link(&mem_blk->dev.kobj, + kobject_name(&node_devices[nid]->dev.kobj)); + break; + } } - NODEMASK_FREE(unlinked_nodes); + return 0; }