[Devel] [PATCH RHEL7 COMMIT] ms/mm/memcg: do not use vmalloc for mem_cgroup allocations

Konstantin Khorenko khorenko at odin.com
Thu Apr 30 08:28:18 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.4.9
------>
commit b527d3cd43eea6fa1b0d75d72c99dd1af522f0b7
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Thu Apr 30 19:28:18 2015 +0400

    ms/mm/memcg: do not use vmalloc for mem_cgroup allocations
    
    The vmalloc was introduced by 33327948782b ("memcgroup: use vmalloc for
    mem_cgroup allocation"), because at that time MAX_NUMNODES was used for
    defining the per-node array in the mem_cgroup structure so that the
    structure could be huge even if the system had the only NUMA node.
    
    The situation was significantly improved by commit 45cf7ebd5a03 ("memcg:
    reduce the size of struct memcg 244-fold"), which made the size of the
    mem_cgroup structure calculated dynamically depending on the real number
    of NUMA nodes installed on the system (nr_node_ids), so now there is no
    point in using vmalloc here: the structure is allocated rarely and on
    most systems its size is about 1K.
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    
    Acked-by: Michal Hocko <mhocko at suse.cz>
    Cc: Glauber Costa <glommer at openvz.org>
    Cc: Johannes Weiner <hannes at cmpxchg.org>
    Cc: Balbir Singh <bsingharora at gmail.com>
    Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
    Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
    (cherry picked from commit 8ff69e2c85f84b6b371e3c1d01207e73c0500125)
---
 mm/memcontrol.c | 28 ++++++----------------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index ac75d76..e772a06 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -48,7 +48,6 @@
 #include <linux/sort.h>
 #include <linux/fs.h>
 #include <linux/seq_file.h>
-#include <linux/vmalloc.h>
 #include <linux/vmpressure.h>
 #include <linux/mm_inline.h>
 #include <linux/page_cgroup.h>
@@ -357,12 +356,6 @@ struct mem_cgroup {
 	struct mem_cgroup_lru_info info;
 };
 
-static size_t memcg_size(void)
-{
-	return sizeof(struct mem_cgroup) +
-		nr_node_ids * sizeof(struct mem_cgroup_per_node *);
-}
-
 /* internal only representation about the status of kmem accounting. */
 enum {
 	KMEM_ACCOUNTED_ACTIVE, /* accounted by this cgroup itself */
@@ -6010,14 +6003,12 @@ static void free_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node)
 static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *memcg;
-	size_t size = memcg_size();
+	size_t size;
 
-	/* Can be very big if nr_node_ids is very big */
-	if (size < PAGE_SIZE)
-		memcg = kzalloc(size, GFP_KERNEL);
-	else
-		memcg = vzalloc(size);
+	size = sizeof(struct mem_cgroup);
+	size += nr_node_ids * sizeof(struct mem_cgroup_per_node *);
 
+	memcg = kzalloc(size, GFP_KERNEL);
 	if (!memcg)
 		return NULL;
 
@@ -6028,10 +6019,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 	return memcg;
 
 out_free:
-	if (size < PAGE_SIZE)
-		kfree(memcg);
-	else
-		vfree(memcg);
+	kfree(memcg);
 	return NULL;
 }
 
@@ -6049,7 +6037,6 @@ out_free:
 static void __mem_cgroup_free(struct mem_cgroup *memcg)
 {
 	int node;
-	size_t size = memcg_size();
 
 	mem_cgroup_remove_from_trees(memcg);
 	free_css_id(&mem_cgroup_subsys, &memcg->css);
@@ -6071,10 +6058,7 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg)
 	 * the cgroup_lock.
 	 */
 	disarm_static_keys(memcg);
-	if (size < PAGE_SIZE)
-		kfree(memcg);
-	else
-		vfree(memcg);
+	kfree(memcg);
 }
 
 /*



More information about the Devel mailing list