hugetlbfs: add hugepages_node kernel parameter
Subsystems (3)
PATCH 1/1 hugetlbfs: add hugepages_node kernel parameter
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add hugepages_node kernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
--- .../admin-guide/kernel-parameters.txt | 6 + include/linux/hugetlb.h | 1 + mm/hugetlb.c | 109 +++++++++++++++++- 3 files changed, 110 insertions(+), 6 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +6 -0
@@ -1583,6 +1583,12 @@ hugepages using the CMA allocator. If enabled, the boot-time allocation of gigantic hugepages is skipped. + hugepages_node= [HW] Node number of hugepages to allocate at boot. + This is used in conjunction with hugepages (below), + The pair hugepages_node=X hugepages=Y can be specified + for number of hugepages in numa node X. + Format: <integer> + hugepages= [HW] Number of HugeTLB pages to allocate at boot. If this follows hugepagesz (below), it specifies the number of pages of hugepagesz to be allocated.
include/linux/hugetlb.h +1 -0
@@ -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 ];
mm/hugetlb.c +103 -6
168 lines not on this page · raw message
Signature · 1 line
2.27.0
Andrew Morton
maintainerQuoted 11 lines · On Fri, 20 Aug 2021 11:05:36 +0800 yaozhenguo <[email protected]> wrote:
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add
hugepages_nodekernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:
Quoted 3 lines
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
If were going to do this, shouldn't we permit more than one node?
hugepages_nodes=1,2,5
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Fri, 20 Aug 2021 11:05:36 +0800 yaozhenguo <[email protected]> wrote:
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add
hugepages_nodekernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:
Quoted 7 lines
Quoted 3 lines
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
If were going to do this, shouldn't we permit more than one node?
hugepages_nodes=1,2,5
I'd think we'd be better off expanding the definition of hugepages. eg:
hugepagesz=1G hugepages=1:4,3:8,5:2
would say to allocate 4 pages from node 1, 8 pages from node 3 and 2 pages from node 5.
Yes, the expanding of hugepages is more elegant. I will change it in the next version.
Quoted 30 lines · Matthew Wilcox <[email protected]> 于2021年8月23日周一 上午6:28写道:
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Fri, 20 Aug 2021 11:05:36 +0800 yaozhenguo <[email protected]> wrote:
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add
hugepages_nodekernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:Quoted 7 lines
Quoted 3 lines
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
If were going to do this, shouldn't we permit more than one node?
hugepages_nodes=1,2,5I'd think we'd be better off expanding the definition of hugepages. eg:
hugepagesz=1G hugepages=1:4,3:8,5:2
would say to allocate 4 pages from node 1, 8 pages from node 3 and 2 pages from node 5.
Quoted 22 lines · Matthew Wilcox
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Fri, 20 Aug 2021 11:05:36 +0800 yaozhenguo <[email protected]> wrote:
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add
hugepages_nodekernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:Quoted 7 lines
Quoted 3 lines
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
If were going to do this, shouldn't we permit more than one node?
hugepages_nodes=1,2,5
Quoted 7 lines
I'd think we'd be better off expanding the definition of hugepages. eg:
hugepagesz=1G hugepages=1:4,3:8,5:2
would say to allocate 4 pages from node 1, 8 pages from node 3 and 2 pages from node 5.
Thanks Matthew and Andrew!
I was trying to wrap my head around the big issue before making any suggestions. It is true that the desired functionality of allocating huge pages from a specific node is lacking today.
I like the idea of expanding the definition of hugepages so that nodes can be specified.
One word of caution. It is easy to make mistakes when taking data directly from the user on the command line. For example, in the follow on patch I do not believe node is not checked against MAX_NUMNODES so it may write beyond the end of array. Also, we need to think about what the behavior should be if part of the 'node1:count1,node2:count2,node3:count3' string is invalid? Suppose node2 is invalid. Do we still allocate from node1 and node3, or do we just discard the entire string? During a recent rewrite of hugetlb command line processing, I had a matrix of different command line options, order, values and expected results. We need to be as thorough when adding this new option.
I'll take a closer look at the proposed patch in the next few days.
Signature · 1 line
Mike Kravetz
OK, It's better to use a concise way to add this function. I will use a better way in the next version.
Quoted 21 lines · Andrew Morton <[email protected]> 于2021年8月23日周一 上午6:19写道:
Quoted 11 lines · On Fri, 20 Aug 2021 11:05:36 +0800 yaozhenguo <[email protected]> wrote:
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 hugepags in one node. For example: DPDK needs hugepages which is in the same node as NIC. if DPDK needs four hugepags of 1G size in node1 and system has 16 numa nodes. We must reserve 64 hugepags in kernel cmdline. But, only four hugepages is used. The others should be free after boot.If the system memory is low(for example: 64G), it will be an impossible task. So, add
hugepages_nodekernel parameter to specify node number of hugepages to allocate at boot.
For example add following parameter:Quoted 3 lines
hugepagesz=1G hugepages_node=1 hugepages=4
It will allocate 4 hugepags in node1 at boot.
If were going to do this, shouldn't we permit more than one node?
hugepages_nodes=1,2,5