[Devel] [PATCH 2/5] net/vhost: Replace kmalloc with kvmalloc for order>=3

Alexander Mikhalitsyn alexander.mikhalitsyn at virtuozzo.com
Fri May 21 18:56:10 MSK 2021


From: Oleg Babin <obabin at virtuozzo.com>

Currently we allocate 8 pages of memory in vhost_net_set_ubuf_info() function
and we do not need them to be physically contiguous, so it is feasible to
replace a call to kmalloc() with a call to kvmalloc().

UIO_MAXIOV = 1024
struct ubuf_info {
        void (*callback)(struct ubuf_info *, bool zerocopy_success);
        void *ctx;
        unsigned long desc;
};

sizeof(struct ubuf_info) = 24
1024 * 24 / 4096 = 6, rounded up to 2^3 = 8 pages.

https://jira.sw.ru/browse/PSBM-81803

Signed-off-by: Oleg Babin <obabin at virtuozzo.com>
Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
(cherry picked from commit 0cd748d35c100b1bc6f9e7fffa44a7d0f70a1728)

VZ 8 rebase part https://jira.sw.ru/browse/PSBM-127797

Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 drivers/vhost/net.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 267877d8273b..07a2d3482d9d 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -272,7 +272,7 @@ static void vhost_net_clear_ubuf_info(struct vhost_net *n)
 	int i;
 
 	for (i = 0; i < VHOST_NET_VQ_MAX; ++i) {
-		kfree(n->vqs[i].ubuf_info);
+		kvfree(n->vqs[i].ubuf_info);
 		n->vqs[i].ubuf_info = NULL;
 	}
 }
@@ -287,7 +287,7 @@ static int vhost_net_set_ubuf_info(struct vhost_net *n)
 		if (!zcopy)
 			continue;
 		n->vqs[i].ubuf_info =
-			kmalloc_array(UIO_MAXIOV,
+			kvmalloc_array(UIO_MAXIOV,
 				      sizeof(*n->vqs[i].ubuf_info),
 				      GFP_KERNEL);
 		if  (!n->vqs[i].ubuf_info)
-- 
2.28.0



More information about the Devel mailing list