[Devel] [PATCH RHEL7 COMMIT] vznetstat: Convert some kmalloc()/kfree() to __vmalloc()/vfree()

Konstantin Khorenko khorenko at virtuozzo.com
Wed Dec 20 12:47:14 MSK 2017


The commit is pushed to "branch-rh7-3.10.0-693.11.1.vz7.39.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.11.1.vz7.39.8
------>
commit 63591337c8ca3a3c1f46b67a831c092c3074b26f
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Wed Dec 20 12:47:14 2017 +0300

    vznetstat: Convert some kmalloc()/kfree() to __vmalloc()/vfree()
    
    Let's use virtually continuos pages instead of physically continuos
    as it's easier to allocate them.
    
    Also, add __GFP_NOWARN to not disturb a user in case of ENOMEM.
    
    https://jira.sw.ru/browse/PSBM-79502
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    Acked-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    khorenko@: the reason for that: we faced so huge table that
    it required 5-order page allocation.
---
 kernel/ve/vznetstat/vznetstat.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/kernel/ve/vznetstat/vznetstat.c b/kernel/ve/vznetstat/vznetstat.c
index 92541dbc2a3f..140da0fc3b0a 100644
--- a/kernel/ve/vznetstat/vznetstat.c
+++ b/kernel/ve/vznetstat/vznetstat.c
@@ -65,7 +65,10 @@ static int venet_acct_set_classes(const void __user *user_info, int length, int
 	else
 		size = sizeof(struct vz_tc_class_info);
 
-	info = kmalloc(sizeof(struct class_info_set) + size * length, GFP_KERNEL);
+	info = __vmalloc((sizeof(struct class_info_set) + size * length),
+			 GFP_KERNEL | __GFP_HIGHMEM | __GFP_NOWARN,
+			 PAGE_KERNEL);
+
 	if (info == NULL)
 		return -ENOMEM;
 
@@ -97,11 +100,11 @@ static int venet_acct_set_classes(const void __user *user_info, int length, int
 	synchronize_net();
 	/* IMPORTANT. I think reset of statistics collected should not be
 	 * done here. */
-	kfree(old);
+	vfree(old);
 	return 0;
 
 out_free:
-	kfree(info);
+	vfree(info);
 	return err;
 }
 
@@ -119,7 +122,9 @@ static int venet_acct_get_classes(void __user *ret, int length, int v6)
 		size = sizeof(struct vz_tc_class_info);
 
 	/* due to spinlock locking, see below */
-	info = kmalloc(size * length, GFP_KERNEL);
+	info = __vmalloc(size * length,
+			 GFP_KERNEL | __GFP_HIGHMEM | __GFP_NOWARN,
+			 PAGE_KERNEL);
 	if (!info)
 		return -ENOMEM;
 
@@ -136,7 +141,7 @@ static int venet_acct_get_classes(void __user *ret, int length, int v6)
 	err = -EFAULT;
 	if (!copy_to_user(ret, info, size * len))
 		err = len;
-	kfree(info);
+	vfree(info);
 	return err;
 }
 
@@ -502,7 +507,9 @@ static int venet_acct_get_stat_list(envid_t *__list, int length)
 	if (length <= 0)
 		return -EINVAL;
 
-	list = kmalloc(sizeof(envid_t) * length, GFP_KERNEL);
+	list = __vmalloc(sizeof(envid_t) * length,
+			 GFP_KERNEL | __GFP_HIGHMEM | __GFP_NOWARN,
+			 PAGE_KERNEL);
 	if (list == NULL)
 		return -ENOMEM;
 
@@ -520,7 +527,7 @@ static int venet_acct_get_stat_list(envid_t *__list, int length)
 	err = -EFAULT;
 	if (!copy_to_user(__list, list, sizeof(envid_t) * i))
 		err = i;
-	kfree(list);
+	vfree(list);
 	return err;
 }
 
@@ -1145,8 +1152,8 @@ void __exit venetstat_exit(void)
 	remove_proc_entry("venetstat_v6", proc_vz_dir);
 	remove_proc_entry("venetstat", proc_vz_dir);
 #endif
-	kfree(info_v4);
-	kfree(info_v6);
+	vfree(info_v4);
+	vfree(info_v6);
 }
 
 module_init(venetstat_init);


More information about the Devel mailing list