linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Supports to use the default CMA when the device-specified CMA memory is not enough.
@ 2024-06-12  8:12 zhai.he
  2024-06-12 18:47 ` Andrew Morton
  0 siblings, 1 reply; 13+ messages in thread
From: zhai.he @ 2024-06-12  8:12 UTC (permalink / raw)
  To: akpm; +Cc: sboyd, linux-mm, linux-kernel, stable, zhipeng.wang_1, jindong.yue

From: He Zhai <zhai.he@nxp.com>

In the current code logic, if the device-specified CMA memory
allocation fails, memory will not be allocated from the default CMA area.
This patch will use the default cma region when the device's
specified CMA is not enough.

In addition, the log level of allocation failure is changed to debug.
Because these logs will be printed when memory allocation from the
device specified CMA fails, but if the allocation fails, it will be
allocated from the default cma area. It can easily mislead developers'
judgment.

Signed-off-by: He Zhai <zhai.he@nxp.com>
---
 kernel/dma/contiguous.c | 11 +++++++++--
 mm/cma.c                |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
index 055da410ac71..e45cfb24500f 100644
--- a/kernel/dma/contiguous.c
+++ b/kernel/dma/contiguous.c
@@ -357,8 +357,13 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp)
 	/* CMA can be used only in the context which permits sleeping */
 	if (!gfpflags_allow_blocking(gfp))
 		return NULL;
-	if (dev->cma_area)
-		return cma_alloc_aligned(dev->cma_area, size, gfp);
+	if (dev->cma_area) {
+		struct page *page = NULL;
+
+		page = cma_alloc_aligned(dev->cma_area, size, gfp);
+		if (page)
+			return page;
+	}
 	if (size <= PAGE_SIZE)
 		return NULL;
 
@@ -406,6 +411,8 @@ void dma_free_contiguous(struct device *dev, struct page *page, size_t size)
 	if (dev->cma_area) {
 		if (cma_release(dev->cma_area, page, count))
 			return;
+		if (cma_release(dma_contiguous_default_area, page, count))
+			return;
 	} else {
 		/*
 		 * otherwise, page is from either per-numa cma or default cma
diff --git a/mm/cma.c b/mm/cma.c
index 3e9724716bad..6e12faf1bea7 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -495,8 +495,8 @@ struct page *cma_alloc(struct cma *cma, unsigned long count,
 	}
 
 	if (ret && !no_warn) {
-		pr_err_ratelimited("%s: %s: alloc failed, req-size: %lu pages, ret: %d\n",
-				   __func__, cma->name, count, ret);
+		pr_debug("%s: alloc failed, req-size: %lu pages, ret: %d, try to use default cma\n",
+			    cma->name, count, ret);
 		cma_debug_show_areas(cma);
 	}
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-06-13 10:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12  8:12 [PATCH v2] Supports to use the default CMA when the device-specified CMA memory is not enough zhai.he
2024-06-12 18:47 ` Andrew Morton
2024-06-12 21:37   ` Barry Song
2024-06-13  2:34     ` [EXT] " Zhai He
2024-06-13  3:28       ` Barry Song
2024-06-13  5:32         ` Zhai He
2024-06-13  6:15           ` Barry Song
2024-06-13  7:11             ` Zhai He
2024-06-13  7:37               ` Barry Song
2024-06-13  8:49                 ` Zhai He
2024-06-13  9:43                   ` Barry Song
2024-06-13 10:32                     ` Zhai He
2024-06-13  2:12   ` Zhai He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox