Re: [PATCH] mm: use vmalloc fallback path for certain memcg allocations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon 05-12-16 15:09:33, Heiko Carstens wrote:
> On Mon, Dec 05, 2016 at 06:23:26AM +0100, Michal Hocko wrote:
> > > > 
> > > > 	ret = kzalloc(size, gfp_mask);
> > > > 	if (ret)
> > > > 		return ret;
> > > > 	return vzalloc(size);
> > > > 
> > > 
> > > > I also do not like memcg_alloc helper name. It suggests we are
> > > > allocating a memcg while it is used for cache arrays and slab LRUS.
> > > > Anyway this pattern is quite widespread in the kernel so I would simply
> > > > suggest adding kvmalloc function instead.
> > > 
> > > Agreed, it would be nice to have a generic call.
> > > I would suggest an impl. like this:
> > > 
> > > void *kvmalloc(size_t size)
> > 
> > gfp_t gfp_mask should be a parameter as this should be a generic helper.
> > 
> > > {
> > > 	gfp_t gfp_mask = GFP_KERNEL;
> > 
> > 
> > > 	void *ret;
> > > 
> > >  	if (size > PAGE_SIZE)
> > >  		gfp_mask |= __GFP_NORETRY | __GFP_NOWARN;
> > > 
> > > 
> > > 	if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) {
> > > 		ret = kzalloc(size, gfp_mask);
> > > 		if (ret)
> > > 			return ret;
> > > 	}
> > 
> > No, please just do as suggested above. Tweak the gfp_mask for higher
> > order requests and do kmalloc first with vmalloc as a  fallback.
> 
> You may simply use the slightly different and open-coded variant within
> fs/seq_file.c:seq_buf_alloc(). That one got a lot of testing in the
> meantime...

Yeah. I would just add WARN_ON((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
to catch users who might want to rely on GFP_NOFS, GFP_NOWAIT or other
restricted requests because vmalloc cannot cope with those properly.

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]