* [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
@ 2008-11-16 4:33 Lai Jiangshan
2008-11-16 4:51 ` Alexey Dobriyan
0 siblings, 1 reply; 6+ messages in thread
From: Lai Jiangshan @ 2008-11-16 4:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: kamezawa.hiroyu, Balbir Singh, Linux Kernel Mailing List
use simple_malloc()/simple_free() instead of current codes.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 866dcc7..66e1c6d 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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);
}
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
2008-11-16 4:33 [PATCH 3/7] memcontrol: use simple_malloc()/simple_free() Lai Jiangshan
@ 2008-11-16 4:51 ` Alexey Dobriyan
2008-11-16 4:54 ` Alexey Dobriyan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Alexey Dobriyan @ 2008-11-16 4:51 UTC (permalink / raw)
To: Lai Jiangshan
Cc: Andrew Morton, kamezawa.hiroyu, Balbir Singh,
Linux Kernel Mailing List
On Sun, Nov 16, 2008 at 12:33:46PM +0800, Lai Jiangshan wrote:
> use simple_malloc()/simple_free() instead of current codes.
struct mem_cgroup can't reach the size when kmalloc starts failing.
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -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);
> }
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
2008-11-16 4:51 ` Alexey Dobriyan
@ 2008-11-16 4:54 ` Alexey Dobriyan
2008-11-17 0:09 ` KAMEZAWA Hiroyuki
2008-11-16 5:01 ` Lai Jiangshan
2008-11-16 8:16 ` David Miller
2 siblings, 1 reply; 6+ messages in thread
From: Alexey Dobriyan @ 2008-11-16 4:54 UTC (permalink / raw)
To: Lai Jiangshan
Cc: Andrew Morton, kamezawa.hiroyu, Balbir Singh,
Linux Kernel Mailing List
On Sun, Nov 16, 2008 at 07:51:28AM +0300, Alexey Dobriyan wrote:
> On Sun, Nov 16, 2008 at 12:33:46PM +0800, Lai Jiangshan wrote:
> > 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];
};
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -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);
> > }
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
2008-11-16 4:51 ` Alexey Dobriyan
2008-11-16 4:54 ` Alexey Dobriyan
@ 2008-11-16 5:01 ` Lai Jiangshan
2008-11-16 8:16 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: Lai Jiangshan @ 2008-11-16 5:01 UTC (permalink / raw)
To: Alexey Dobriyan
Cc: Andrew Morton, kamezawa.hiroyu, Balbir Singh,
Linux Kernel Mailing List
Alexey Dobriyan wrote:
> On Sun, Nov 16, 2008 at 12:33:46PM +0800, Lai Jiangshan wrote:
>> 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.
>
>> --- a/mm/memcontrol.c
>> +++ b/mm/memcontrol.c
>> @@ -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);
>> }
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
2008-11-16 4:51 ` Alexey Dobriyan
2008-11-16 4:54 ` Alexey Dobriyan
2008-11-16 5:01 ` Lai Jiangshan
@ 2008-11-16 8:16 ` David Miller
2 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2008-11-16 8:16 UTC (permalink / raw)
To: adobriyan; +Cc: laijs, akpm, kamezawa.hiroyu, balbir, linux-kernel
From: Alexey Dobriyan <adobriyan@gmail.com>
Date: Sun, 16 Nov 2008 07:51:28 +0300
> On Sun, Nov 16, 2008 at 12:33:46PM +0800, Lai Jiangshan wrote:
> > 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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/7] memcontrol: use simple_malloc()/simple_free()
2008-11-16 4:54 ` Alexey Dobriyan
@ 2008-11-17 0:09 ` KAMEZAWA Hiroyuki
0 siblings, 0 replies; 6+ messages in thread
From: KAMEZAWA Hiroyuki @ 2008-11-17 0:09 UTC (permalink / raw)
To: Alexey Dobriyan
Cc: Lai Jiangshan, Andrew Morton, Balbir Singh,
Linux Kernel Mailing List
On Sun, 16 Nov 2008 07:54:04 +0300
Alexey Dobriyan <adobriyan@gmail.com> wrote:
> On Sun, Nov 16, 2008 at 07:51:28AM +0300, Alexey Dobriyan wrote:
> > On Sun, Nov 16, 2008 at 12:33:46PM +0800, Lai Jiangshan wrote:
> > > 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
>
> > > --- a/mm/memcontrol.c
> > > +++ b/mm/memcontrol.c
> > > @@ -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);
> > > }
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-11-17 0:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-16 4:33 [PATCH 3/7] memcontrol: use simple_malloc()/simple_free() Lai Jiangshan
2008-11-16 4:51 ` Alexey Dobriyan
2008-11-16 4:54 ` Alexey Dobriyan
2008-11-17 0:09 ` KAMEZAWA Hiroyuki
2008-11-16 5:01 ` Lai Jiangshan
2008-11-16 8:16 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox