hugetlbfs: Extend the definition of hugepages parameter to support node allocation
Subsystems (5)
PATCH v8 1/1 hugetlbfs: Extend the definition of hugepages parameter to support node allocation
We can specify the number of hugepages to allocate at boot. But the hugepages is balanced in all nodes at present. In some scenarios, we only need hugepages in one node. For example: DPDK needs hugepages which are in the same node as NIC.
If DPDK needs four hugepages of 1G size in node1 and system has 16 numa nodes we must reserve 64 hugepages on the kernel cmdline. But only four hugepages are used. The others should be free after boot. If the system memory is low(for example: 64G), it will be an impossible task.
So extend the hugepages parameter to support specifying hugepages on a specific node. For example add following parameter:
hugepagesz=1G hugepages=0:1,1:3
It will allocate 1 hugepage in node0 and 3 hugepages in node1.
---v7->v8 changes:
- fix smatch warning.
- rename node_specific_alloc_support to hugetlb_node_alloc_supported.
- fix clang warning.
- remove useless codes.v6->v7 changes:
- replace nodes_weight(node_states[N_MEMORY] with nr_online_nodes.v5->v6 changes:
- Remove v5 codes: using return value to disable node specific alloc.
- Add node_specific_alloc_support weak function to disable node specific alloc when arch can't support it.
- Remove useless variable addr in alloc_bootmem_huge_page.
- Add powerpc version of node_specific_alloc_support when CONFIG_PPC_BOOK3S_64 is defined.v4->v5 changes:
- remove BUG_ON in __alloc_bootmem_huge_page.
- add nid parameter in __alloc_bootmem_huge_page to support called in both specific node alloc and normal alloc.
- do normal alloc if architecture can't support node specific alloc.
- return -1 in powerpc version of alloc_bootmem_huge_page when nid is not NUMA_NO_NODE.v3->v4 changes:
- fix wrong behavior for parameter:
hugepages=0:1,1:3 default_hugepagesz=1G
- make the change of documentation more reasonable.v2->v3 changes:
- Skip gigantic hugepages allocation if hugetlb_cma is enabled.
- Fix wrong behavior for parameter:
hugepagesz=2M hugepages=2 hugepages=5.
- Update hugetlbpage.rst.
- Fix side effects which v2 brings in.
- add cond_resched in hugetlb_hstate_alloc_pages_onenode.v1->v2 changes:
- add checking for max node to avoid array out of bounds.
- fix wrong max_huge_pages after failed allocation.
- fix wrong behavior when parsing parameter: hugepages=0:1,2,3:4.
- return 0 when parsing invalid parameter in hugepages_setup
--- .../admin-guide/kernel-parameters.txt | 8 +- Documentation/admin-guide/mm/hugetlbpage.rst | 12 +- arch/powerpc/mm/hugetlbpage.c | 9 +- include/linux/hugetlb.h | 6 +- mm/hugetlb.c | 153 +++++++++++++++--- 5 files changed, 155 insertions(+), 33 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -3
@@ -1599,9 +1599,11 @@ the number of pages of hugepagesz to be allocated. If this is the first HugeTLB parameter on the command line, it specifies the number of pages to allocate for - the default huge page size. See also - Documentation/admin-guide/mm/hugetlbpage.rst. - Format: <integer> + the default huge page size. If using node format, the + number of pages to allocate per-node can be specified. + See also Documentation/admin-guide/mm/hugetlbpage.rst. + Format: <integer> or (node format) + <node>:<integer>[,<node>:<integer>] hugepagesz= [HW] The size of the HugeTLB pages. This is used in
Documentation/admin-guide/mm/hugetlbpage.rst +11 -1
@@ -128,7 +128,9 @@ hugepages implicitly specifies the number of huge pages of default size to allocate. If the number of huge pages of default size is implicitly specified, it can not be overwritten by a hugepagesz,hugepages - parameter pair for the default size. + parameter pair for the default size. This parameter also has a + node format. The node format specifies the number of huge pages + to allocate on specific nodes. For example, on an architecture with 2M default huge page size::
@@ -138,6 +140,14 @@ hugepages indicating that the hugepages=512 parameter is ignored. If a hugepages parameter is preceded by an invalid hugepagesz parameter, it will be ignored. + + Node format example:: + + hugepagesz=2M hugepages=0:1,1:2 + + It will allocate 1 2M hugepage on node0 and 2 2M hugepages on node1. + If the node number is invalid, the parameter will be ignored. + default_hugepagesz Specify the default huge page size. This parameter can only be specified once on the command line. default_hugepagesz can
arch/powerpc/mm/hugetlbpage.c +7 -2
@@ -229,17 +229,22 @@ static int __init pseries_alloc_bootmem_huge_page(struct hstate *hstate) m->hstate = hstate; return 1; } + +bool __init hugetlb_node_alloc_supported (void ) +{ +return false; +}#endif -int __init alloc_bootmem_huge_page (struct hstate *h) +int __init alloc_bootmem_huge_page (struct hstate *h,int nid) {#ifdef CONFIG_PPC_BOOK3S_64 if (firmware_has_feature (FW_FEATURE_LPAR ) && !radix_enabled ())return pseries_alloc_bootmem_huge_page (h);#endif -return __alloc_bootmem_huge_page (h); +return __alloc_bootmem_huge_page (h, nid); }#ifndef CONFIG_PPC_BOOK3S_64
include/linux/hugetlb.h +4 -2
@@ -605,6 +605,7 @@ struct hstate {unsigned long nr_overcommit_huge_pages;struct list_head hugepage_activelist;struct list_head hugepage_freelists[MAX_NUMNODES ]; +unsigned int max_huge_pages_node[MAX_NUMNODES ];unsigned int nr_huge_pages_node[MAX_NUMNODES ];unsigned int free_huge_pages_node[MAX_NUMNODES ];unsigned int surplus_huge_pages_node[MAX_NUMNODES ];
@@ -637,8 +638,9 @@ void restore_reserve_on_error(struct hstate *h, struct vm_area_struct *vma, unsigned long address, struct page *page);/* arch callback */ -int __init __alloc_bootmem_huge_page (struct hstate *h); -int __init alloc_bootmem_huge_page (struct hstate *h); +int __init __alloc_bootmem_huge_page (struct hstate *h,int nid); +int __init alloc_bootmem_huge_page (struct hstate *h,int nid); +bool __init hugetlb_node_alloc_supported (void );void __init hugetlb_add_hstate (unsigned order);bool __init arch_hugetlb_valid_size (unsigned long size);
mm/hugetlb.c +128 -25
241 lines not on this page · raw message
Signature · 1 line
2.27.0
Quoted 13 lines · Zhenguo Yao
We can specify the number of hugepages to allocate at boot. But the hugepages is balanced in all nodes at present. In some scenarios, we only need hugepages in one node. For example: DPDK needs hugepages which are in the same node as NIC.
If DPDK needs four hugepages of 1G size in node1 and system has 16 numa nodes we must reserve 64 hugepages on the kernel cmdline. But only four hugepages are used. The others should be free after boot. If the system memory is low(for example: 64G), it will be an impossible task.
So extend the hugepages parameter to support specifying hugepages on a specific node. For example add following parameter:
Quoted 6 lines
hugepagesz=1G hugepages=0:1,1:3
It will allocate 1 hugepage in node0 and 3 hugepages in node1.
Signed-off-by Zhenguo Yao <[email protected]>Reviewed-by Mike Kravetz <[email protected]>
Looks good. Thank you!
Signature · 1 line
Mike Kravetz