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

Konstantin Khorenko khorenko at virtuozzo.com
Thu Sep 30 16:04:00 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit e8a46f4391440c3ba07eb54fce4e278680214532
Author: Oleg Babin <obabin at virtuozzo.com>
Date:   Thu Sep 30 16:04:00 2021 +0300

    net/vhost: Replace kmalloc with kvmalloc for order>=3
    
    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 vz7 commit 0cd748d35c10 ("net/vhost: Replace kmalloc with
    kvmalloc for order>=3")
    
    VZ 8 rebase part https://jira.sw.ru/browse/PSBM-127797
    
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
    
    (cherry picked from vz8 commit e1f1e1e8a44af104a6cb4cc2ab24a577f7c061f3)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko 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 6414bd5741b8..913dac8e0da5 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -271,7 +271,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;
 	}
 }
@@ -286,7 +286,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)


More information about the Devel mailing list