aboutsummaryrefslogtreecommitdiffstats
path: root/mm/hugetlb.c
diff options
context:
space:
mode:
authorMuchun Song <songmuchun@bytedance.com>2022-09-14 15:26:02 +0800
committerAndrew Morton <akpm@linux-foundation.org>2022-10-03 14:03:15 -0700
commitb958d4d08fbfe938af24ea06ebbf839b48fa18a9 (patch)
tree0fdb7c2c654efc2ee572d7b0a40ce81871050964 /mm/hugetlb.c
parentmm/mempolicy: use PAGE_ALIGN instead of open-coding it (diff)
downloadlinux-dev-b958d4d08fbfe938af24ea06ebbf839b48fa18a9.tar.xz
linux-dev-b958d4d08fbfe938af24ea06ebbf839b48fa18a9.zip
mm: hugetlb: simplify per-node sysfs creation and removal
Patch series "simplify handling of per-node sysfs creation and removal", v4. This patch (of 2): The following commit offload per-node sysfs creation and removal to a kworker and did not say why it is needed. And it also said "I don't know that this is absolutely required". It seems like the author was not sure as well. Since it only complicates the code, this patch will revert the changes to simplify the code. 39da08cb074c ("hugetlb: offload per node attribute registrations") We could use memory hotplug notifier to do per-node sysfs creation and removal instead of inserting those operations to node registration and unregistration. Then, it can reduce the code coupling between node.c and hugetlb.c. Also, it can simplify the code. Link: https://lkml.kernel.org/r/20220914072603.60293-1-songmuchun@bytedance.com Link: https://lkml.kernel.org/r/20220914072603.60293-2-songmuchun@bytedance.com Signed-off-by: Muchun Song <songmuchun@bytedance.com> Acked-by: Mike Kravetz <mike.kravetz@oracle.com> Acked-by: David Hildenbrand <david@redhat.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Muchun Song <songmuchun@bytedance.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Rafael J. Wysocki <rafael@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/hugetlb.c')
-rw-r--r--mm/hugetlb.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 6af123374e98..397f2988c37f 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -33,6 +33,7 @@
#include <linux/migrate.h>
#include <linux/nospec.h>
#include <linux/delayacct.h>
+#include <linux/memory.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
@@ -4000,6 +4001,23 @@ static void hugetlb_register_node(struct node *node)
}
}
+static int __meminit hugetlb_memory_callback(struct notifier_block *self,
+ unsigned long action, void *arg)
+{
+ struct memory_notify *mnb = arg;
+ int nid = mnb->status_change_nid;
+
+ if (nid == NUMA_NO_NODE)
+ return NOTIFY_DONE;
+
+ if (action == MEM_GOING_ONLINE)
+ hugetlb_register_node(node_devices[nid]);
+ else if (action == MEM_CANCEL_ONLINE || action == MEM_OFFLINE)
+ hugetlb_unregister_node(node_devices[nid]);
+
+ return NOTIFY_OK;
+}
+
/*
* hugetlb init time: register hstate attributes for all registered node
* devices of nodes that have memory. All on-line nodes should have
@@ -4009,18 +4027,11 @@ static void __init hugetlb_register_all_nodes(void)
{
int nid;
- for_each_node_state(nid, N_MEMORY) {
- struct node *node = node_devices[nid];
- if (node->dev.id == nid)
- hugetlb_register_node(node);
- }
-
- /*
- * Let the node device driver know we're here so it can
- * [un]register hstate attributes on node hotplug.
- */
- register_hugetlbfs_with_node(hugetlb_register_node,
- hugetlb_unregister_node);
+ get_online_mems();
+ hotplug_memory_notifier(hugetlb_memory_callback, 0);
+ for_each_node_state(nid, N_MEMORY)
+ hugetlb_register_node(node_devices[nid]);
+ put_online_mems();
}
#else /* !CONFIG_NUMA */