Skip to contentSkip to conversation

mm: hugetlb: eliminate memory-less nodes handling

PATCH In review Muchun Song 3 participants 3 messages Sep 8, 2022 – Sep 13, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mm: hugetlb: eliminate memory-less nodes handling

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.

BTW, hotplug callback added because in hugetlb_register_all_nodes() we register sysfs nodes only for N_MEMORY nodes, seeing commit 9b5e5d0fdc91, which said it was a preparation for handling memory-less nodes via memory hotplug. Since we want to remove memory hotplug, so make sure we only register per-node sysfs for online (N_ONLINE) nodes in hugetlb_register_all_nodes().

https://lore.kernel.org/linux-mm/[email protected]/ [1]

---
v3:
- Fix 'struct node' is not declared reported by LTP.

v2:
- Move declaration of function related to hugetlb to hugetlb.h (David).
- Introduce hugetlb_sysfs_initialized() and call it from hugetlb_sysfs_init() (David).
- Move hugetlb_register_all_nodes() into hugetlb_sysfs_init() (David).
- Fix implicit-function-declaration reported by LKP.
- Register per-node sysfs for online (N_ONLINE) nodes instead of N_MEMORY (Aneesh).

 drivers/base/node.c     |  8 +++--
 include/linux/hugetlb.h | 14 +++++++++
 mm/hugetlb.c            | 81 ++++++++++++++++++++++---------------------------
 3 files changed, 57 insertions(+), 46 deletions(-)
drivers/base/node.c +6 -2
index ed391cb09999..80b1e91b9608 100644
@@ -20,6 +20,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/swap.h>
 #include <linux/slab.h>
+#include <linux/hugetlb.h>
 
 static struct bus_type node_subsys = {
 	.name = "node",
@@ -608,10 +609,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 +628,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);
include/linux/hugetlb.h +14 -0
index 852f911d676e..2d98d0ac4a48 100644
@@ -16,6 +16,7 @@
 struct ctl_table;
 struct user_struct;
 struct mmu_gather;
+struct node;
 
 #ifndef is_hugepd
 typedef struct { unsigned long pd; } hugepd_t;
@@ -967,6 +968,11 @@ static inline void huge_ptep_modify_prot_commit(struct vm_area_struct *vma,
 }
 #endif
 
+#ifdef CONFIG_NUMA
+void hugetlb_register_node(struct node *node);
+void hugetlb_unregister_node(struct node *node);
+#endif
+
 #else	/* CONFIG_HUGETLB_PAGE */
 struct hstate {};
 
@@ -1141,6 +1147,14 @@ static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
 				   pte_t *ptep, pte_t pte)
 {
 }
+
+static inline void hugetlb_register_node(struct node *node)
+{
+}
+
+static inline void hugetlb_unregister_node(struct node *node)
+{
+}
 #endif	/* CONFIG_HUGETLB_PAGE */
 
 static inline spinlock_t *huge_pte_lock(struct hstate *h,
mm/hugetlb.c +37 -44

141 lines not on this page · raw message

Signature · 1 line
2.11.0
Acked-by on v3 1/1
#1 lore raw
Quoted 51 lines · Muchun Song

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.

BTW, hotplug callback added because in hugetlb_register_all_nodes() we register sysfs nodes only for N_MEMORY nodes, seeing commit 9b5e5d0fdc91, which said it was a preparation for handling memory-less nodes via memory hotplug. Since we want to remove memory hotplug, so make sure we only register per-node sysfs for online (N_ONLINE) nodes in hugetlb_register_all_nodes().

https://lore.kernel.org/linux-mm/[email protected]/ [1]

---
v3:
- Fix 'struct node' is not declared reported by LTP.

v2:
- Move declaration of function related to hugetlb to hugetlb.h (David).
- Introduce hugetlb_sysfs_initialized() and call it from hugetlb_sysfs_init() (David).
- Move hugetlb_register_all_nodes() into hugetlb_sysfs_init() (David).
- Fix implicit-function-declaration reported by LKP.
- Register per-node sysfs for online (N_ONLINE) nodes instead of N_MEMORY (Aneesh).

  drivers/base/node.c     |  8 +++--
  include/linux/hugetlb.h | 14 +++++++++
  mm/hugetlb.c            | 81 ++++++++++++++++++++++---------------------------
  3 files changed, 57 insertions(+), 46 deletions(-)
mm/hugetlb.c +2 -8
@@ -3880,24 +3880,14 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
  	return 0;
  }
 
-static void __init hugetlb_sysfs_init(void)
-{
-	struct hstate *h;
-	int err;
-
-	hugepages_kobj = kobject_create_and_add("hugepages", mm_kobj);
-	if (!hugepages_kobj)
-		return;
+#ifdef CONFIG_NUMA
+static bool hugetlb_sysfs_initialized __ro_after_init;
 

mm/hugetlb.c static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, · line 3889

Quoted 10 lines
mm/hugetlb.c +3 -6
-	for_each_hstate(h) {
-		err = hugetlb_sysfs_add_hstate(h, hugepages_kobj,
-					 hstate_kobjs, &hstate_attr_group);
-		if (err)
-			pr_err("HugeTLB: Unable to add hstate %s", h->name);
-	}
+static inline void hugetlb_mark_sysfs_initialized(void)
+{
+	hugetlb_sysfs_initialized = true;
  }

Do we really need a separate function for this? Why not simply always set that from hugetlb_sysfs_init() ?

I'm also not sure if we really want to optimize out one variable for !CONFIG_NUMA.

Anyhow, in general

Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#2 lore raw
Quoted 54 lines · David Hildenbrand
Quoted 49 lines · Muchun Song

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.
BTW, hotplug callback added because in hugetlb_register_all_nodes() we register sysfs nodes only for N_MEMORY nodes, seeing commit 9b5e5d0fdc91, which said it was a preparation for handling memory-less nodes via memory hotplug. Since we want to remove memory hotplug, so make sure we only register per-node sysfs for online (N_ONLINE) nodes in hugetlb_register_all_nodes().
https://lore.kernel.org/linux-mm/[email protected]/ [1]

---
v3:
- Fix 'struct node' is not declared reported by LTP.
v2:
- Move declaration of function related to hugetlb to hugetlb.h (David).
- Introduce hugetlb_sysfs_initialized() and call it from hugetlb_sysfs_init() (David).
- Move hugetlb_register_all_nodes() into hugetlb_sysfs_init() (David).
- Fix implicit-function-declaration reported by LKP.
- Register per-node sysfs for online (N_ONLINE) nodes instead of N_MEMORY (Aneesh).

 drivers/base/node.c     |  8 +++--
 include/linux/hugetlb.h | 14 +++++++++
 mm/hugetlb.c            | 81 ++++++++++++++++++++++---------------------------
 3 files changed, 57 insertions(+), 46 deletions(-)
mm/hugetlb.c +2 -10
@@ -3880,24 +3880,14 @@ static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent,
 	return 0;
 }
 -static void __init hugetlb_sysfs_init(void)
-{
-	struct hstate *h;
-	int err;
-
-	hugepages_kobj = kobject_create_and_add("hugepages", mm_kobj);
-	if (!hugepages_kobj)
-		return;
+#ifdef CONFIG_NUMA
+static bool hugetlb_sysfs_initialized __ro_after_init;
 -	for_each_hstate(h) {
-		err = hugetlb_sysfs_add_hstate(h, hugepages_kobj,
-					 hstate_kobjs, &hstate_attr_group);
-		if (err)
Quoted 8 lines

mm/hugetlb.c static int hugetlb_sysfs_add_hstate(struct hstate *h, struct kobject *parent, · line 3889

Quoted 6 lines
mm/hugetlb.c +3 -2
-			pr_err("HugeTLB: Unable to add hstate %s", h->name);
-	}
+static inline void hugetlb_mark_sysfs_initialized(void)
+{
+	hugetlb_sysfs_initialized = true;
 }

Do we really need a separate function for this? Why not simply always set that from hugetlb_sysfs_init() ?

I can remove this helper.

Quoted 2 lines

I'm also not sure if we really want to optimize out one variable for !CONFIG_NUMA.

Either is fine to me. I think the optimization does not bring any complexity. So I’ll keep it the same in the next version unless anyone is against this.

Quoted 4 lines

Anyhow, in general

Thanks David.

Quoted 7 lines
Signature · 4 lines
-- 
Thanks,

David / dhildenb