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

Kirill Tkhai ktkhai at virtuozzo.com
Tue Dec 19 15:25:02 MSK 2017


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>
---
 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 a65e05378ff4..a40715acc754 100644
--- a/kernel/ve/vznetstat/vznetstat.c
+++ b/kernel/ve/vznetstat/vznetstat.c
@@ -66,7 +66,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;
 
@@ -104,11 +107,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;
 }
 
@@ -126,7 +129,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;
 
@@ -143,7 +148,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;
 }
 
@@ -509,7 +514,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;
 
@@ -527,7 +534,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;
 }
 
@@ -1152,8 +1159,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