Skip to contentSkip to conversation

memcontrol: use simple_malloc()/simple_free()

PATCH In review Lai Jiangshan 4 participants 6 messages Nov 16, 2008 – Nov 17, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/7 memcontrol: use simple_malloc()/simple_free()

use simple_malloc()/simple_free() instead of current codes.

---

mm/memcontrol.c +2 -9
index 866dcc7..66e1c6d 100644
@@ -1062,11 +1062,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *mem;
 
-	if (sizeof(*mem) < PAGE_SIZE)
-		mem = kmalloc(sizeof(*mem), GFP_KERNEL);
-	else
-		mem = vmalloc(sizeof(*mem));
-
+	mem = simple_malloc(sizeof(*mem));
 	if (mem)
 		memset(mem, 0, sizeof(*mem));
 	return mem;
@@ -1074,10 +1070,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 static void mem_cgroup_free(struct mem_cgroup *mem)
 {
-	if (sizeof(*mem) < PAGE_SIZE)
-		kfree(mem);
-	else
-		vfree(mem);
+	simple_free(mem);
 }
 
 
#1 lore raw
Quoted 1 line · Lai Jiangshan

use simple_malloc()/simple_free() instead of current codes.

struct mem_cgroup can't reach the size when kmalloc starts failing.

Quoted 25 lines
mm/memcontrol.c +2 -9
@@ -1062,11 +1062,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *mem;
 
-	if (sizeof(*mem) < PAGE_SIZE)
-		mem = kmalloc(sizeof(*mem), GFP_KERNEL);
-	else
-		mem = vmalloc(sizeof(*mem));
-
+	mem = simple_malloc(sizeof(*mem));
 	if (mem)
 		memset(mem, 0, sizeof(*mem));
 	return mem;
@@ -1074,10 +1070,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 static void mem_cgroup_free(struct mem_cgroup *mem)
 {
-	if (sizeof(*mem) < PAGE_SIZE)
-		kfree(mem);
-	else
-		vfree(mem);
+	simple_free(mem);
 }
#2 lore raw
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Lai Jiangshan

use simple_malloc()/simple_free() instead of current codes.

struct mem_cgroup can't reach the size when kmalloc starts failing.

Or it probably can with big NR_CPUS.

	struct mem_cgroup_stat {
  	      struct mem_cgroup_stat_cpu cpustat[NR_CPUS];
	};
Quoted 25 lines
Quoted 25 lines
mm/memcontrol.c +2 -9
@@ -1062,11 +1062,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *mem;
 
-	if (sizeof(*mem) < PAGE_SIZE)
-		mem = kmalloc(sizeof(*mem), GFP_KERNEL);
-	else
-		mem = vmalloc(sizeof(*mem));
-
+	mem = simple_malloc(sizeof(*mem));
 	if (mem)
 		memset(mem, 0, sizeof(*mem));
 	return mem;
@@ -1074,10 +1070,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 static void mem_cgroup_free(struct mem_cgroup *mem)
 {
-	if (sizeof(*mem) < PAGE_SIZE)
-		kfree(mem);
-	else
-		vfree(mem);
+	simple_free(mem);
 }
#3 lore raw
Quoted 11 lines · On Sun, 16 Nov 2008 07:54:04 +0300 Alexey Dobriyan <[email protected]> wrote:
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Lai Jiangshan

use simple_malloc()/simple_free() instead of current codes.

struct mem_cgroup can't reach the size when kmalloc starts failing.

Or it probably can with big NR_CPUS.

	struct mem_cgroup_stat {
  	      struct mem_cgroup_stat_cpu cpustat[NR_CPUS];
	};

It's now changed. see mmotm.

Thanks,
-Kame

Quoted 27 lines
Quoted 26 lines
Quoted 26 lines
mm/memcontrol.c +2 -9
@@ -1062,11 +1062,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *mem;
 
-	if (sizeof(*mem) < PAGE_SIZE)
-		mem = kmalloc(sizeof(*mem), GFP_KERNEL);
-	else
-		mem = vmalloc(sizeof(*mem));
-
+	mem = simple_malloc(sizeof(*mem));
 	if (mem)
 		memset(mem, 0, sizeof(*mem));
 	return mem;
@@ -1074,10 +1070,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 static void mem_cgroup_free(struct mem_cgroup *mem)
 {
-	if (sizeof(*mem) < PAGE_SIZE)
-		kfree(mem);
-	else
-		vfree(mem);
+	simple_free(mem);
 }
#4 lore raw
In reply to Alexey Dobriyan
Quoted 4 lines · Alexey Dobriyan
Quoted 1 line · Lai Jiangshan

use simple_malloc()/simple_free() instead of current codes.

struct mem_cgroup can't reach the size when kmalloc starts failing.

Good catch! Thanx!

compiler will optimize it and select the correct way. using "simple_malloc()/simple_free()" here is no sense.

Quoted 29 lines
Quoted 26 lines
mm/memcontrol.c +2 -9
@@ -1062,11 +1062,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 {
 	struct mem_cgroup *mem;
 
-	if (sizeof(*mem) < PAGE_SIZE)
-		mem = kmalloc(sizeof(*mem), GFP_KERNEL);
-	else
-		mem = vmalloc(sizeof(*mem));
-
+	mem = simple_malloc(sizeof(*mem));
 	if (mem)
 		memset(mem, 0, sizeof(*mem));
 	return mem;
@@ -1074,10 +1070,7 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
 
 static void mem_cgroup_free(struct mem_cgroup *mem)
 {
-	if (sizeof(*mem) < PAGE_SIZE)
-		kfree(mem);
-	else
-		vfree(mem);
+	simple_free(mem);
 }
#5 lore raw
In reply to Alexey Dobriyan

From: Alexey Dobriyan <[email protected]>
Date: Sun, 16 Nov 2008 07:51:28 +0300

Quoted 4 lines · Lai Jiangshan
Quoted 1 line

use simple_malloc()/simple_free() instead of current codes.

struct mem_cgroup can't reach the size when kmalloc starts failing.

That's not the point.

When you got past a page, kmalloc/gfp allocations are less reliable, and people also want NUMA spreading when possible.

That's why we use PAGE_SIZE as the table vmalloc() breakpoint. We do this in many places already, with the exact same heuristics, and for the exact same reasons.