From patchwork Thu Sep 1 08:30:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12962095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25960ECAAD1 for ; Thu, 1 Sep 2022 08:31:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A86D46B0072; Thu, 1 Sep 2022 04:31:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A36918D0001; Thu, 1 Sep 2022 04:31:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D66A6B0074; Thu, 1 Sep 2022 04:31:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7B7EF6B0072 for ; Thu, 1 Sep 2022 04:31:12 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 58AEC1213F8 for ; Thu, 1 Sep 2022 08:31:12 +0000 (UTC) X-FDA: 79862846784.22.7C90678 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf31.hostedemail.com (Postfix) with ESMTP id C62E220065 for ; Thu, 1 Sep 2022 08:31:10 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id j5so12545788plj.5 for ; Thu, 01 Sep 2022 01:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=h9K1JdCkfGUyld5oIiQQ6btcB74MqVy0ViUrjJEnwXc=; b=SCRGIWyselNx78NUYI2j5XKcbA5kANz3bKh54mV1XuswqQunJhY2OyslqIc8AP+TA1 HOijRM9uo7ZA+nlNSAu6U+0Bg98ImbCj6Vf1pkq8gKJHvJdZEjAjmEjAAlpFWPfjE/WA hpKK+LGnkrsyHU9s4lPMbTOqCn7ZOfVTgwfXOc+k8b2//k+lKMuYz0V5xmPT0YOTn725 wF+rG6eCD/jJltU/vWhadu3uzhIhZGvfygDKz8ueBzhkp9t6VF6e/g8LOUpEDuYgVSwv G1AR0w0YeFWvtttpZjSLo+zJGOQDUfjrrvPsoSgnwwdihiE4WisjYWOebM/8+EBBpE8L CAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=h9K1JdCkfGUyld5oIiQQ6btcB74MqVy0ViUrjJEnwXc=; b=iVW2FGd6WH+tW24tpXI4DdOIIlQYUw8SjHVE+vI05L1KjIovPkrnpRi+8T8cyjnGET OycG1vKYkbNKmfi1aH42svSNeNu6ZmxE3AQnO8aG+Xl9GklZPz7hHjLLkWbgRLVN6C7S Sr1rKzxnenCIu8bgc2lo13pGCEhgRli5wzSAQ8H9Ohi9DEOxgiaflUqtJs/CX8JWWVWO nNeRqc4UuAfynl6lS6S5b4GMJLxbx68GQH86JKafz+dzcWdFvcOWtLbwZXh5Iq8WmVFy hyRVMzg9WUbz1111qdD37wPRiF/0UM55RmcUVKG9poiWdyER8KdioD7OHXyuuJL1fCsp aUcQ== X-Gm-Message-State: ACgBeo1eIgDmfHy5e6TiEsPtcqBf8N60rZatBDyFepj2MovV9LLeLg6v bFVY4O7GG2Sm7rGyHGMQY4yxxIB5xidmEr9q X-Google-Smtp-Source: AA6agR7gwi9Ox6nBbUQXNu8ESlA4qDXfc+ORyLUyKeccgLh1pRlns6P3HS//eZlalJOgWuK0cmDSUQ== X-Received: by 2002:a17:903:2cb:b0:171:4f0d:beb6 with SMTP id s11-20020a17090302cb00b001714f0dbeb6mr29255338plk.53.1662021069616; Thu, 01 Sep 2022 01:31:09 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([139.177.225.247]) by smtp.gmail.com with ESMTPSA id 30-20020a630a1e000000b0041d70c03da5sm4666074pgk.60.2022.09.01.01.31.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Sep 2022 01:31:09 -0700 (PDT) From: Muchun Song To: gregkh@linuxfoundation.org, rafael@kernel.org, mike.kravetz@oracle.com, songmuchun@bytedance.com, akpm@linux-foundation.org, osalvador@suse.de, david@redhat.com, ying.huang@intel.com, aneesh.kumar@linux.ibm.com, rientjes@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: hugetlb: eliminate memory-less nodes handling Date: Thu, 1 Sep 2022 16:30:23 +0800 Message-Id: <20220901083023.42319-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.1 (Apple Git-133) MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662021071; a=rsa-sha256; cv=none; b=HktqhSeFtOHKlbX56LjT9qo3NK1e/WXRt8/7GgH7lkpDjfnvKge6fIzEa6YVGQ/Z/zD/d7 1dbpCvBLAL9D6CrHHLqjnnlDCHKQukFnYsU+MroAQuBNxbcO09eVnZK6Hwbf9RdZm2ar5e 5tsjwaVPbZpBJHr1K1ztW6uAwOidak0= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=SCRGIWys; spf=pass (imf31.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662021071; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=h9K1JdCkfGUyld5oIiQQ6btcB74MqVy0ViUrjJEnwXc=; b=gHLevPg2hnncCkLzLQg9rXJbmuvyKBDZnQJ3+BmLPEMWbH3A8R60TFVsuiFqSUgSwQdNv+ HMj7Lf2tWqN+4jBmiv6fWUhqjxL0/N6I0kOrd6/ixE3awVmfSt7fwxBPTfRpk4ZC51XHy5 zrN1mpHmlnwU9Ksg0PKVpRjjoRIpFWA= X-Rspam-User: X-Stat-Signature: zp7911s5fdp68frdfobgki471sti1dpp X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: C62E220065 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=SCRGIWys; spf=pass (imf31.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1662021070-274311 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: The memory-notify-based approach aims to handle meory-less nodes, however, it just adds the complexity of code as pointed by David in thread [1]. The handling of memory-less nodes is introduced by commit 4faf8d950ec4 ("hugetlb: handle memory hot-plug events"). From its commit message, we cannot find any necessity of handling this case. So, we can simply register/unregister sysfs entries in register_node/unregister_node to simlify the code. https://lore.kernel.org/linux-mm/60933ffc-b850-976c-78a0-0ee6e0ea9ef0@redhat.com/ [1] Suggested-by: David Hildenbrand Signed-off-by: Muchun Song Reported-by: kernel test robot --- drivers/base/node.c | 7 +++++-- include/linux/node.h | 5 +++++ mm/hugetlb.c | 37 ++++++++++--------------------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/drivers/base/node.c b/drivers/base/node.c index ed391cb09999..cf115d5a9b8a 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -608,10 +608,12 @@ static int register_node(struct node *node, int num) node->dev.groups = node_dev_groups; error = device_register(&node->dev); - if (error) + if (error) { put_device(&node->dev); - else + } else { + hugetlb_register_node(node); compaction_register_node(node); + } return error; } @@ -625,6 +627,7 @@ static int register_node(struct node *node, int num) */ void unregister_node(struct node *node) { + hugetlb_unregister_node(node); compaction_unregister_node(node); node_remove_accesses(node); node_remove_caches(node); diff --git a/include/linux/node.h b/include/linux/node.h index 427a5975cf40..f5d41498c2bf 100644 --- a/include/linux/node.h +++ b/include/linux/node.h @@ -138,6 +138,11 @@ extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); extern int register_memory_node_under_compute_node(unsigned int mem_nid, unsigned int cpu_nid, unsigned access); + +#ifdef CONFIG_HUGETLBFS +void hugetlb_register_node(struct node *node); +void hugetlb_unregister_node(struct node *node); +#endif #else static inline void node_dev_init(void) { diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d0617d64d718..722e862bb6be 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3898,6 +3898,7 @@ static void __init hugetlb_sysfs_init(void) } #ifdef CONFIG_NUMA +static bool hugetlb_initialized __ro_after_init; /* * node_hstate/s - associate per node hstate attributes, via their kobjects, @@ -3953,7 +3954,7 @@ static struct hstate *kobj_to_node_hstate(struct kobject *kobj, int *nidp) * Unregister hstate attributes from a single node device. * No-op if no hstate attributes attached. */ -static void hugetlb_unregister_node(struct node *node) +void hugetlb_unregister_node(struct node *node) { struct hstate *h; struct node_hstate *nhs = &node_hstates[node->dev.id]; @@ -3983,19 +3984,22 @@ static void hugetlb_unregister_node(struct node *node) * Register hstate attributes for a single node device. * No-op if attributes already registered. */ -static int hugetlb_register_node(struct node *node) +void hugetlb_register_node(struct node *node) { struct hstate *h; struct node_hstate *nhs = &node_hstates[node->dev.id]; int err; + if (!hugetlb_initialized) + return; + if (nhs->hugepages_kobj) - return 0; /* already allocated */ + return; /* already allocated */ nhs->hugepages_kobj = kobject_create_and_add("hugepages", &node->dev.kobj); if (!nhs->hugepages_kobj) - return -ENOMEM; + return; for_each_hstate(h) { err = hugetlb_sysfs_add_hstate(h, nhs->hugepages_kobj, @@ -4005,28 +4009,9 @@ static int hugetlb_register_node(struct node *node) pr_err("HugeTLB: Unable to add hstate %s for node %d\n", h->name, node->dev.id); hugetlb_unregister_node(node); - return -ENOMEM; + break; } } - return 0; -} - -static int __meminit hugetlb_memory_callback(struct notifier_block *self, - unsigned long action, void *arg) -{ - int ret = 0; - struct memory_notify *mnb = arg; - int nid = mnb->status_change_nid; - - if (nid == NUMA_NO_NODE) - return NOTIFY_DONE; - - if (action == MEM_GOING_ONLINE) - ret = hugetlb_register_node(node_devices[nid]); - else if (action == MEM_CANCEL_ONLINE || action == MEM_OFFLINE) - hugetlb_unregister_node(node_devices[nid]); - - return notifier_from_errno(ret); } /* @@ -4038,11 +4023,9 @@ static void __init hugetlb_register_all_nodes(void) { int nid; - get_online_mems(); - hotplug_memory_notifier(hugetlb_memory_callback, 0); + hugetlb_initialized = true; for_each_node_state(nid, N_MEMORY) hugetlb_register_node(node_devices[nid]); - put_online_mems(); } #else /* !CONFIG_NUMA */