From patchwork Wed Aug 15 14:42: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: 10566673 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 8D65415E2 for ; Wed, 15 Aug 2018 14:42:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B4C42A902 for ; Wed, 15 Aug 2018 14:42:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FB9F2A905; Wed, 15 Aug 2018 14:42:40 +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 D9AB72A902 for ; Wed, 15 Aug 2018 14:42:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33A086B000C; Wed, 15 Aug 2018 10:42:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 26C456B000D; Wed, 15 Aug 2018 10:42:33 -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 10E896B000E; Wed, 15 Aug 2018 10:42:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id 9E8746B000D for ; Wed, 15 Aug 2018 10:42:32 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id z16-v6so1000653wrs.22 for ; Wed, 15 Aug 2018 07:42:32 -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=I2UQDafRhlwWSGUrQN/8rcLHamOMjqaMdDg6JvlZSrA=; b=VWCQC4hyva/5LpAzwLH7DSgdDwek41A806qegrKar3Txv7uWohSbOCl+T6mvKNEzYA 6as8+e03tsl8BmctnqpkNHx/oeVJw14zL12gwgDmihWvKY3JepPR9O5wS172JnzUoAJY QQq5fvlCj6C+gzTkfopibUD8LNJKrSqdE70pIcSfmkEUumuQn1QPB+QqxxbgBCFCajGV EVbe6EvmXVEma55OUsllsP04KqgV0AJwGFRNrIKCx69Qg0mBXts25RlGSTTW42SpA68J NPMAwP/W4q9R8rYiLAmVwlZCTIZPVo/RPhnXbLxZc3kbZV2+tFB4spXumMYFEjIxR5tU i9fA== 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: AOUpUlHfBFsG2sI67hwUL91Z63xtaYNRrIRVzp4gEStsBpy6yKfSurW1 0J2FVfxGPCMF+9D5IcgWQG0hZx2BO/t6LgZP08XpoAesfaLYII2QR1Hq5PkR4rVHpERnwztpGEn CGiQLTfCWHUcKw2ygQGgX0vxLw7MtFCWPRvNX5w4NJw1A8IV7ysIcy5EbBSHlKfS8O9cgiRtf0F DRn9iRGXPv8v+/NOFDDNmzRsmEku3KztvVoSwGs5LSmErx5yLIgyDh8NCe8xDlpMYBMdz3QKFoB VNDpB8RlhgvLmy/ma/RDWc8t/a172uMYk9vosaFod7jrO7/nwnR9OR9fx3XzGtvm1dY20MXMBeq zD9zzgqdYV5s9XiUD3RBP2+csbxyIJAV80qIQzsPupbtcOU8ak61+F+/0cfRfFXjZn39igxOaw= = X-Received: by 2002:a5d:4c4c:: with SMTP id n12-v6mr17032707wrt.71.1534344152169; Wed, 15 Aug 2018 07:42:32 -0700 (PDT) X-Received: by 2002:a5d:4c4c:: with SMTP id n12-v6mr17032663wrt.71.1534344151296; Wed, 15 Aug 2018 07:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534344151; cv=none; d=google.com; s=arc-20160816; b=MwTiIbaQ6O4J+p9eEfOtHmhUfUhT6ZFVNpAlrsWPBVp57BAA5xnS4o9zcSEeV6FTV5 80UAp6FF5ijMruph57K4T3RMkp7DbBRbzIMJSejeYZjXHaIAp2bQO/934ghxRtsCCcU/ 3QFoxxMB7fLbxYcwLV2lksO8DWqWG8v2aqje+ejpgiRINspE/5UxWV2B1wEPMKbmGkto 7X3bFEXyS228BdF7oqOj1ltgg1R57QbI3pFu7h72AVZIwFzFzyRy/A1ZIqNcJbQTLBZI 2NLmsEXjLMsFmlZX0DhTUO8PePZshmJdeG823p6sxSJ8m+Jzm+x0EgBzPW37a2T4a55z B0dg== 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=I2UQDafRhlwWSGUrQN/8rcLHamOMjqaMdDg6JvlZSrA=; b=F5leszZfIX64/UMMMoxi2RKP1p6dE9xf2UMiHBDgzJVulaSrCvTESMDx8XwjMQfokt g10YR8BAAcbZLcYpsCqfX9W9W0wl4GkW9IkIhGCeccCcREU2MdyYw7pMt0h3mQ/0tPY7 H6k5gAPS2aRGey2huS89yt35iwxr+Ky3GZq11eHlKGoQ+HHBo6tGB+jm0/LUMGMl1VV3 D0mbB9XGEvvrXmF/XW5vKgFe/TCBkzUEFpjc1uSPtPgfrHJf8BBw8isL9fbagHeB6EyA 9TOoDsydn/8cpXlqdx5qcx04EK/Zqsax350EIDbAWmzR6uoNyX4XzUYpVyTjDbif23tN j9jQ== 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 64-v6sor483504wmb.42.2018.08.15.07.42.31 for (Google Transport Security); Wed, 15 Aug 2018 07:42:31 -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+uWPx/kdcTnwJNZ7FDSoD2iP1vX9rmS1W+o1C2niNfRK8QGiwxfKx89NWS11r1ua3TiOOwbTY7nA== X-Received: by 2002:a1c:b84e:: with SMTP id i75-v6mr12853566wmf.158.1534344150952; Wed, 15 Aug 2018 07:42:30 -0700 (PDT) Received: from techadventures.net (techadventures.net. [62.201.165.239]) by smtp.gmail.com with ESMTPSA id d123-v6sm3189039wmd.9.2018.08.15.07.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Aug 2018 07:42:29 -0700 (PDT) Received: from d104.suse.de (charybdis-ext.suse.de [195.135.221.2]) by techadventures.net (Postfix) with ESMTPA id 7C6CF1248A0; Wed, 15 Aug 2018 16:42:28 +0200 (CEST) From: Oscar Salvador 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, Pavel.Tatashin@microsoft.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Oscar Salvador Subject: [PATCH v3 3/4] mm/memory_hotplug: Refactor unregister_mem_sect_under_nodes Date: Wed, 15 Aug 2018 16:42:18 +0200 Message-Id: <20180815144219.6014-4-osalvador@techadventures.net> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180815144219.6014-1-osalvador@techadventures.net> References: <20180815144219.6014-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 unregister_mem_sect_under_nodes() tries to allocate a nodemask_t in order to check whithin the loop which nodes have already been unlinked, so we do not repeat the operation on them. NODEMASK_ALLOC calls kmalloc() if NODES_SHIFT > 8, otherwise it just declares a nodemask_t variable whithin the stack. Since kamlloc() can fail, we actually check whether NODEMASK_ALLOC failed or not, and we return -ENOMEM accordingly. remove_memory_section() does not check for the return value though. The problem with this is that if we return -ENOMEM, it means that unregister_mem_sect_under_nodes will not be able to remove the symlinks, but since we do not check the return value, we go ahead and we call unregister_memory(), which will remove all the mem_blks directories. This will leave us with dangled symlinks. The easiest way to overcome this is to fallback by calling sysfs_remove_link() unconditionally in case NODEMASK_ALLOC failed. This means that we will call sysfs_remove_link on nodes that have been already unlinked, but nothing wrong happens as sysfs_remove_link() backs off somewhere down the chain in case the link has already been removed. I think that this is better than a) dangled symlinks b) having to recovery from such error in remove_memory_section Since from now on we will not need to care about return values, we can make the function void. As we have a safe fallback, one thing that could also be done is to add __GFP_NORETRY in the flags when calling NODEMASK_ALLOC, so we do not retry. Signed-off-by: Oscar Salvador --- drivers/base/node.c | 23 +++++++++++++++-------- include/linux/node.h | 5 ++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index dd3bdab230b2..81b27b5b1f15 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -449,35 +449,42 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg) } /* unregister memory section under all nodes that it spans */ -int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, +void 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); + if (unlinked_nodes) + nodes_clear(*unlinked_nodes); 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 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)) + /* + * It is possible that NODEMASK_ALLOC fails due to memory + * pressure. + * If that happens, we fallback to call sysfs_remove_link + * unconditionally. + * Nothing wrong will happen as sysfs_remove_link will back off + * somewhere down the chain in case the link has already been + * removed. + */ + if (unlinked_nodes && 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)); } NODEMASK_FREE(unlinked_nodes); - return 0; } int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn) diff --git a/include/linux/node.h b/include/linux/node.h index 257bb3d6d014..1203378e596a 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -72,7 +72,7 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); extern int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg); -extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, +extern void unregister_mem_sect_under_nodes(struct memory_block *mem_blk, unsigned long phys_index); #ifdef CONFIG_HUGETLBFS @@ -105,10 +105,9 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk, { return 0; } -static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, +static inline void unregister_mem_sect_under_nodes(struct memory_block *mem_blk, unsigned long phys_index) { - return 0; } static inline void register_hugetlbfs_with_node(node_registration_func_t reg,