Message ID | 20220906034239.69436-1-songmuchun@bytedance.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] mm: hugetlb: eliminate memory-less nodes handling | expand |
Hi Muchun, I love your patch! Perhaps something to improve: [auto build test WARNING on next-20220901] [cannot apply to akpm-mm/mm-everything driver-core/driver-core-testing linus/master v6.0-rc4 v6.0-rc3 v6.0-rc2 v6.0-rc4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Muchun-Song/mm-hugetlb-eliminate-memory-less-nodes-handling/20220906-114538 base: e47eb90a0a9ae20b82635b9b99a8d0979b757ad8 config: um-i386_defconfig compiler: gcc-11 (Debian 11.3.0-5) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/ec1575c86ce4904a7134d2fef8e231ecd50ffc75 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Muchun-Song/mm-hugetlb-eliminate-memory-less-nodes-handling/20220906-114538 git checkout ec1575c86ce4904a7134d2fef8e231ecd50ffc75 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=um SUBARCH=i386 SHELL=/bin/bash fs/proc/ If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from fs/proc/array.c:74: >> include/linux/hugetlb.h:1150:49: warning: 'struct node' declared inside parameter list will not be visible outside of this definition or declaration 1150 | static inline void hugetlb_register_node(struct node *node) | ^~~~ include/linux/hugetlb.h:1154:51: warning: 'struct node' declared inside parameter list will not be visible outside of this definition or declaration 1154 | static inline void hugetlb_unregister_node(struct node *node) | ^~~~ -- In file included from fs/proc/meminfo.c:6: >> include/linux/hugetlb.h:1150:49: warning: 'struct node' declared inside parameter list will not be visible outside of this definition or declaration 1150 | static inline void hugetlb_register_node(struct node *node) | ^~~~ include/linux/hugetlb.h:1154:51: warning: 'struct node' declared inside parameter list will not be visible outside of this definition or declaration 1154 | static inline void hugetlb_unregister_node(struct node *node) | ^~~~ fs/proc/meminfo.c:22:28: warning: no previous prototype for 'arch_report_meminfo' [-Wmissing-prototypes] 22 | void __attribute__((weak)) arch_report_meminfo(struct seq_file *m) | ^~~~~~~~~~~~~~~~~~~ vim +1150 include/linux/hugetlb.h 1149 > 1150 static inline void hugetlb_register_node(struct node *node) 1151 { 1152 } 1153
Hi Muchun, I love your patch! Perhaps something to improve: [auto build test WARNING on next-20220901] [cannot apply to akpm-mm/mm-everything driver-core/driver-core-testing linus/master v6.0-rc4 v6.0-rc3 v6.0-rc2 v6.0-rc4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Muchun-Song/mm-hugetlb-eliminate-memory-less-nodes-handling/20220906-114538 base: e47eb90a0a9ae20b82635b9b99a8d0979b757ad8 config: arm-randconfig-r023-20220906 (https://download.01.org/0day-ci/archive/20220906/202209062036.1eQ3lYsX-lkp@intel.com/config) compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project c55b41d5199d2394dd6cdb8f52180d8b81d809d4) reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # install arm cross compiling tool for clang build # apt-get install binutils-arm-linux-gnueabi # https://github.com/intel-lab-lkp/linux/commit/ec1575c86ce4904a7134d2fef8e231ecd50ffc75 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Muchun-Song/mm-hugetlb-eliminate-memory-less-nodes-handling/20220906-114538 git checkout ec1575c86ce4904a7134d2fef8e231ecd50ffc75 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): In file included from mm/folio-compat.c:7: In file included from include/linux/migrate.h:8: >> include/linux/hugetlb.h:1150:49: warning: declaration of 'struct node' will not be visible outside of this function [-Wvisibility] static inline void hugetlb_register_node(struct node *node) ^ include/linux/hugetlb.h:1154:51: warning: declaration of 'struct node' will not be visible outside of this function [-Wvisibility] static inline void hugetlb_unregister_node(struct node *node) ^ 2 warnings generated. vim +1150 include/linux/hugetlb.h 1149 > 1150 static inline void hugetlb_register_node(struct node *node) 1151 { 1152 } 1153
diff --git a/drivers/base/node.c b/drivers/base/node.c index ed391cb09999..80b1e91b9608 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -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); diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 852f911d676e..3b3d23bcad09 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -967,6 +967,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 +1146,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, diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d0617d64d718..06ac469582da 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -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) - pr_err("HugeTLB: Unable to add hstate %s", h->name); - } +static inline void hugetlb_mark_sysfs_initialized(void) +{ + hugetlb_sysfs_initialized = true; } -#ifdef CONFIG_NUMA /* * node_hstate/s - associate per node hstate attributes, via their kobjects, @@ -3953,7 +3943,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 +3973,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_sysfs_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 +3998,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 +4012,8 @@ static void __init hugetlb_register_all_nodes(void) { int nid; - get_online_mems(); - hotplug_memory_notifier(hugetlb_memory_callback, 0); - for_each_node_state(nid, N_MEMORY) + for_each_online_node(nid) hugetlb_register_node(node_devices[nid]); - put_online_mems(); } #else /* !CONFIG_NUMA */ @@ -4056,8 +4027,31 @@ static struct hstate *kobj_to_node_hstate(struct kobject *kobj, int *nidp) static void hugetlb_register_all_nodes(void) { } +static inline void hugetlb_mark_sysfs_initialized(void) +{ +} #endif +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; + + 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); + } + + hugetlb_mark_sysfs_initialized(); + hugetlb_register_all_nodes(); +} + static int __init hugetlb_init(void) { int i; @@ -4112,7 +4106,6 @@ static int __init hugetlb_init(void) report_hugepages(); hugetlb_sysfs_init(); - hugetlb_register_all_nodes(); hugetlb_cgroup_file_init(); #ifdef CONFIG_SMP
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, make sure we only register per-node sysfs for online (N_ONLINE) nodes in hugetlb_register_all_nodes(). https://lore.kernel.org/linux-mm/60933ffc-b850-976c-78a0-0ee6e0ea9ef0@redhat.com/ [1] Suggested-by: David Hildenbrand <david@redhat.com> Signed-off-by: Muchun Song <songmuchun@bytedance.com> --- 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 | 13 ++++++++ mm/hugetlb.c | 81 ++++++++++++++++++++++--------------------------- 3 files changed, 56 insertions(+), 46 deletions(-)