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

Submitted by Kirill Tkhai on Dec. 19, 2017, 12:25 p.m.

Details

Message ID 151368628246.27901.10473403541553005926.stgit@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai Dec. 19, 2017, 12:25 p.m.
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@virtuozzo.com>
---
 kernel/ve/vznetstat/vznetstat.c |   25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

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);

Comments

Andrey Ryabinin Dec. 20, 2017, 8:53 a.m.
On 12/19/2017 03:25 PM, Kirill Tkhai wrote:
> 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@virtuozzo.com>
> ---

Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>