[PATCH 3/3] Quick vmalloc vs kmalloc fix to the case where array size is too large

KAMEZAWA Hiroyuki kamezawa.hiroyu at jp.fujitsu.com
Sun Jul 12 23:03:03 PDT 2009


On Mon, 13 Jul 2009 11:03:03 +0800
Li Zefan <lizf at cn.fujitsu.com> wrote:

> Ben Blum wrote:
> > Quick vmalloc vs kmalloc fix to the case where array size is too large
> > 
> > Separates all pidlist allocation requests to a separate function that judges
> > based on the requested size whether or not the array needs to be vmalloced or
> > can be gotten via kmalloc, and similar for kfree/vfree. Should be replaced
> > entirely with a kernel-wide solution to this general problem.
> > 
> > Depends on cgroup-pidlist-namespace.patch, cgroup-procs.patch
> > 
> 
> Since this is a patchset, you don't need to tell the dependencies of
> this patch, at least not in changelog, but can put it ...
> 
> > Signed-off-by: Ben Blum <bblum at google.com>
> > 
> > ---
> > 
> 
> ... here
> 
> ---  <- followed by this mark
> 
> >  kernel/cgroup.c |   34 ++++++++++++++++++++++++++++------
> >  1 files changed, 28 insertions(+), 6 deletions(-)
> > 
> > diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> > index 33d89be..0ed85fa 100644
> > --- a/kernel/cgroup.c
> > +++ b/kernel/cgroup.c
> > @@ -48,6 +48,7 @@
> >  #include <linux/namei.h>
> >  #include <linux/smp_lock.h>
> >  #include <linux/pid_namespace.h>
> > +#include <linux/vmalloc.h> /* TODO: replace with more sophisticated array */
> >  
> 
> Is this TODO different with the below one?
> 
> >  #include <asm/atomic.h>
> >  
> > @@ -2121,6 +2122,27 @@ int cgroup_scan_tasks(struct cgroup_scanner *scan)
> >   */
> >  
> >  /*
> > + * The following two functions "fix" the issue where there are more pids
> > + * than kmalloc will give memory for; in such cases, we use vmalloc/vfree.
> > + * TODO: replace with a kernel-wide solution to this problem
> > + */
> > +#define PIDLIST_TOO_LARGE(c) ((c) * sizeof(pid_t) > (PAGE_SIZE * 2))
> 
> I think order-0 is most robust and should be used as much as possible.
> 
> > +static inline void *pidlist_allocate(int count)
> 
> It's better to let gcc decide to inline it or not.
> 
> > +{
> > +	if (PIDLIST_TOO_LARGE(count))
> > +		return vmalloc(count * sizeof(pid_t));
> > +	else
> > +		return kmalloc(count * sizeof(pid_t), GFP_KERNEL);
> > +}
> > +static inline void pidlist_free(void *p)
> 
> ditto
> 
???? why not using vmalloc() always ? 

Thanks,
-Kame



> > +{
> > +	if (is_vmalloc_addr(p))
> > +		vfree(p);
> > +	else
> > +		kfree(p);
> > +}
> > +
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 



More information about the Containers mailing list