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

Konstantin Khorenko khorenko at virtuozzo.com
Tue Feb 27 13:57:22 MSK 2018


The commit is pushed to "branch-rh7-3.10.0-693.17.1.vz7.45.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.17.1.vz7.45.4
------>
commit 0cd748d35c100b1bc6f9e7fffa44a7d0f70a1728
Author: Oleg Babin <obabin at virtuozzo.com>
Date:   Tue Feb 27 13:57:22 2018 +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>
---
 drivers/vhost/net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 1076a4613669..900463b9cc92 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -165,7 +165,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;
 	}
 }
@@ -179,8 +179,8 @@ int vhost_net_set_ubuf_info(struct vhost_net *n)
 		zcopy = vhost_net_zcopy_mask & (0x1 << i);
 		if (!zcopy)
 			continue;
-		n->vqs[i].ubuf_info = kmalloc(sizeof(*n->vqs[i].ubuf_info) *
-					      UIO_MAXIOV, GFP_KERNEL);
+		n->vqs[i].ubuf_info = kvmalloc(sizeof(*n->vqs[i].ubuf_info) *
+					       UIO_MAXIOV, GFP_KERNEL);
 		if  (!n->vqs[i].ubuf_info)
 			goto err;
 	}


More information about the Devel mailing list