Skip to contentSkip to conversation

dma-contiguous: support numa CMA for specified node

PATCH Superseded Yajun Deng 1 participant 1 message Jul 11, 2023

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Yajun Deng

author
#0 lore raw

PATCH v2 1/1 dma-contiguous: support numa CMA for specified node

The kernel parameter 'cma_pernuma=' only supports reserving the same size of CMA area for each node. We need to reserve different sizes of CMA area for specified nodes if these devices belong to different nodes.

Adding another kernel parameter 'numa_cma=' to reserve CMA area for the specified node. If we want to use one of the parameters, we need to enable DMA_NUMA_CMA.

At the same time, print the node id in cma_declare_contiguous_nid() if CONFIG_NUMA is enabled.

---
V1 -> V2: Add 'numa_cma=' and keep 'cma_pernuma=' kernel parameter.

---
 .../admin-guide/kernel-parameters.txt         |  11 ++
 kernel/dma/Kconfig                            |   9 +-
 kernel/dma/contiguous.c                       | 101 ++++++++++++++----
 mm/cma.c                                      |  12 ++-
 4 files changed, 104 insertions(+), 29 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +11 -0
index bdf0ab6716c8..87ad8154b730 100644
@@ -706,6 +706,17 @@
 			which is located in node nid, if the allocation fails,
 			they will fallback to the global default memory area.
 
+	numa_cma=<node>:nn[MG][,<node>:nn[MG]]
+			[KNL,CMA]
+			Sets the size of kernel numa memory area for
+			contiguous memory allocations. It will reserve CMA
+			area for the specified node.
+
+			With numa CMA enabled, DMA users on node nid will
+			first try to allocate buffer from the numa area
+			which is located in node nid, if the allocation fails,
+			they will fallback to the global default memory area.
+
 	cmo_free_hint=	[PPC] Format: { yes | no }
 			Specify whether pages are marked as being inactive
 			when they are freed.  This is used in CMO environments
kernel/dma/Kconfig +5 -4
index 7afde9bc529f..562463fe30ea 100644
@@ -145,15 +145,16 @@ config DMA_CMA
 
 if  DMA_CMA
 
-config DMA_PERNUMA_CMA
-	bool "Enable separate DMA Contiguous Memory Area for each NUMA Node"
+config DMA_NUMA_CMA
+	bool "Enable separate DMA Contiguous Memory Area for NUMA Node"
 	default NUMA
 	help
-	  Enable this option to get pernuma CMA areas so that NUMA devices
+	  Enable this option to get numa CMA areas so that NUMA devices
 	  can get local memory by DMA coherent APIs.
 
 	  You can set the size of pernuma CMA by specifying "cma_pernuma=size"
-	  on the kernel's command line.
+	  or set the node id and its size of CMA by specifying "numa_cma=
+	  <node>:size[,<node>:size]" on the kernel's command line.
 
 comment "Default contiguous memory area size:"
 
kernel/dma/contiguous.c +79 -22

167 lines not on this page · raw message

mm/cma.c +9 -3
index 4880f72102fa..af5945932e9e 100644
@@ -244,6 +244,7 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,
 {
 	phys_addr_t memblock_end = memblock_end_of_DRAM();
 	phys_addr_t highmem_start;
+	char nid_buf[32] = "";
 	int ret = 0;
 
 	/*
@@ -267,6 +268,10 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,
 	if (alignment && !is_power_of_2(alignment))
 		return -EINVAL;
 
+#ifdef CONFIG_NUMA
+	if (nid != NUMA_NO_NODE)
+		snprintf(nid_buf, sizeof(nid_buf), " on node %d", nid);
+#endif
 	/* Sanitise input arguments. */
 	alignment = max_t(phys_addr_t, alignment, CMA_MIN_ALIGNMENT_BYTES);
 	if (fixed && base & (alignment - 1)) {
@@ -372,14 +377,15 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,
 	if (ret)
 		goto free_mem;
 
-	pr_info("Reserved %ld MiB at %pa\n", (unsigned long)size / SZ_1M,
-		&base);
+	pr_info("Reserved %ld MiB at %pa%s\n", (unsigned long)size / SZ_1M,
+		&base, nid_buf);
 	return 0;
 
 free_mem:
 	memblock_phys_free(base, size);
 err:
-	pr_err("Failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M);
+	pr_err("Failed to reserve %ld MiB%s\n", (unsigned long)size / SZ_1M,
+	       nid_buf);
 	return ret;
 }
 
Signature · 1 line
2.25.1