From: He Zhai <[email protected]>
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.
Signed-off-by: He Zhai <[email protected]>
---
kernel/dma/contiguous.c | 11 +++++++++--
mm/cma.c | 2 +-
2 files changed, 10 insertions(+), 3 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..f225b3f65bd2 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -495,7 +495,7 @@ 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",
+ pr_debug("%s: %s: alloc failed, req-size: %lu pages, ret: %d, try to use default cma\n",
__func__, cma->name, count, ret);
cma_debug_show_areas(cma);
}
--
2.34.1
On Wed, Jun 12, 2024 at 10:38:31AM +0800, zhai.he wrote:
> From: He Zhai <[email protected]>
>
> 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.
>
> Signed-off-by: He Zhai <[email protected]>
> ---
> kernel/dma/contiguous.c | 11 +++++++++--
> mm/cma.c | 2 +-
> 2 files changed, 10 insertions(+), 3 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..f225b3f65bd2 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -495,7 +495,7 @@ 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",
> + pr_debug("%s: %s: alloc failed, req-size: %lu pages, ret: %d, try to use default cma\n",
> __func__, cma->name, count, ret);
Why did you change the error level here?
And when you use pr_debug(), you NEVER need to use __func__, as it is
already included automatically in the message output. So now you have
it twice :)
thanks,
greg k-h
Thanks Greg for your review.
The reason I changed the error level is because these logs will be printed
when memory allocation from the specified device CMA fails, but if the
allocation fails, it will be allocated from the default cma area. It can
easily mislead developers' judgment, so I changed it to debug level.
I will not use "__func__" in the next version of this patch.
-----Original Message-----
From: Greg KH <[email protected]>
Sent: Wednesday, June 12, 2024 3:20 PM
To: Zhai He <[email protected]>
Cc: [email protected]; [email protected]; [email protected];
[email protected]; [email protected]; Zhipeng Wang
<[email protected]>; Jindong Yue <[email protected]>
Subject: [EXT] Re: [PATCH] Supports to use the default CMA when the
device-specified CMA memory is not enough.
Caution: This is an external email. Please take care when clicking links or
opening attachments. When in doubt, report the message using the 'Report
this email' button
On Wed, Jun 12, 2024 at 10:38:31AM +0800, zhai.he wrote:
> From: He Zhai <[email protected]>
>
> 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.
>
> Signed-off-by: He Zhai <[email protected]>
> ---
> kernel/dma/contiguous.c | 11 +++++++++--
> mm/cma.c | 2 +-
> 2 files changed, 10 insertions(+), 3 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..f225b3f65bd2 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -495,7 +495,7 @@ 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",
> + pr_debug("%s: %s: alloc failed, req-size: %lu pages,
> + ret: %d, try to use default cma\n",
> __func__, cma->name, count, ret);
Why did you change the error level here?
And when you use pr_debug(), you NEVER need to use __func__, as it is
already included automatically in the message output. So now you have it
twice :)
thanks,
greg k-h
A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
A: No.
Q: Should I include quotations after my reply?
http://daringfireball.net/2007/07/on_top
On Wed, Jun 12, 2024 at 07:34:56AM +0000, Zhai He wrote:
> Thanks Greg for your review.
> The reason I changed the error level is because these logs will be printed
> when memory allocation from the specified device CMA fails, but if the
> allocation fails, it will be allocated from the default cma area. It can
> easily mislead developers' judgment, so I changed it to debug level.
Then you need to explain this in the changelog text :(
thanks,
greg k-h