From: Deepak R Varma <drv@mailo.com>
To: Russell King <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Cc: Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
drv@mailo.com
Subject: [PATCH] ARM/dma-mapping: use kvzalloc for fallback memory allocation need
Date: Tue, 20 Dec 2022 10:55:11 +0530 [thread overview]
Message-ID: <Y6FHN9RyUKsQLo0i@qemulion> (raw)
When the memory sizes are not known upfront, it is preferred to use the
kvzalloc helper function instead of direct conditional evaluation of
size and kzalloc/vzalloc fallback design. The kvzalloc helper function
in this case is more efficient as it avoids indefinite kzalloc retries
when a small memory size is needed but is unavailable.
This LWN article has further details on the advantages of using
kvzalloc in case of fallback memory allocation needs:
https://lwn.net/Articles/711653/
This patch proposal is based on following Coccinelle warning using the
kvmalloc.cocci semantic patch.
arch/arm/mm/dma-mapping.c:858:28-29: WARNING opportunity for kvmalloc
Signed-off-by: Deepak R Varma <drv@mailo.com>
---
Note: The patch proposal is compile tested only.
arch/arm/mm/dma-mapping.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c135f6e37a00..2b79af377a81 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -855,10 +855,7 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
int i = 0;
int order_idx = 0;
- if (array_size <= PAGE_SIZE)
- pages = kzalloc(array_size, GFP_KERNEL);
- else
- pages = vzalloc(array_size);
+ pages = kvzalloc(array_size, GFP_KERNEL);
if (!pages)
return NULL;
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next reply other threads:[~2022-12-20 5:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 5:25 Deepak R Varma [this message]
2023-01-20 11:30 ` [PATCH] ARM/dma-mapping: use kvzalloc for fallback memory allocation need Deepak R Varma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y6FHN9RyUKsQLo0i@qemulion \
--to=drv@mailo.com \
--cc=kumarpraveen@linux.microsoft.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=ssengar@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox