[Devel] Re: [PATCH] cgroup: prefer [kv]zalloc over [kv]malloc+memset in memory controller code.

Minchan Kim minchan.kim at gmail.com
Mon Nov 1 16:21:43 PDT 2010


On Tue, Nov 2, 2010 at 4:59 AM, Jesper Juhl <jj at chaosbits.net> wrote:
> On Mon, 1 Nov 2010, Johannes Weiner wrote:
>
>> On Mon, Nov 01, 2010 at 08:40:56PM +0100, Jesper Juhl wrote:
>> > Hi (please CC me on replies),
>> >
>> >
>> > Apologies to those who receive this multiple times. I screwed up the To:
>> > field in my original mail :-(
>> >
>> >
>> > In mem_cgroup_alloc() we currently do either kmalloc() or vmalloc() then
>> > followed by memset() to zero the memory. This can be more efficiently
>> > achieved by using kzalloc() and vzalloc().
>> >
>> >
>> > Signed-off-by: Jesper Juhl <jj at chaosbits.net>
>>
>> Looks good to me, but there is also the memset after kmalloc in
>> alloc_mem_cgroup_per_zone_info().
>
> Dang, I missed that one. Thanks for pointing it out.
>
> Hmm, I'm wondering if we should perhaps add kzalloc_node()/vzalloc_node()
> just like kzalloc() and vzalloc()..

I am not against that.
As looking code, there are many places to use kzalloc_node but few vzalloc_node.
Although it is, Only adding kzalloc_node would make code rather ugly like this.

if (some size > limit)
  ptr =  kzalloc_node(...);
else  {
  prt = vmalloc_node(...)
  vmalloced = 1;
}

if (ptr && vmalloced)
   memset(prt, xxxx);

So if we will add kzalloc_node, we have to add vzalloc_node, too.

>
>> Can you switch that over as well in
>> this patch?  You can pass __GFP_ZERO to kmalloc_node() for zeroing.
>>
>
> Sure thing.
>
>
> Signed-off-by: Jesper Juhl <jj at chaosbits.net>
Reviewed-by: Minchan Kim <minchan.kim at gmail.com>

-- 
Kind regards,
Minchan Kim
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list