Re: [PATCH] mm: gfp_to_alloc_flags()

Peter Zijlstra
2009-02-24T09:00:27Z

On Mon, 2009-02-23 at 14:59 -0800, Andrew Morton wrote:
> On Mon, 23 Feb 2009 12:55:03 +0100
> Peter Zijlstra <peterz@infradead.org> wrote:
>
> > +static int gfp_to_alloc_flags(gfp_t gfp_mask)
> > +{
> > + struct task_struct *p = current;
> > + int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
> > + const gfp_t wait = gfp_mask & __GFP_WAIT;
> > +
> > + /*
> > + * The caller may dip into page reserves a bit more if the caller
> > + * cannot run direct reclaim, or if the caller has realtime scheduling
> > + * policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will
> > + * set both ALLOC_HARDER (!wait) and ALLOC_HIGH (__GFP_HIGH).
> > + */
> > + if (gfp_mask & __GFP_HIGH)
> > + alloc_flags |= ALLOC_HIGH;
>
> This could be sped up by making ALLOC_HIGH==__GFP_HIGH (hack)

:-)

> But really, the whole function can be elided on the fastpath. Try the
> allocation with the current flags (and __GFP_NOWARN) and only if it
> failed will we try altering the flags to try harder?

It is slowpath only.

After Mel's patches the fast path looks like so:

page = __get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
preferred_zone, migratetype);
if (unlikely(!page))
page = __alloc_pages_slowpath(gfp_mask, order,
zonelist, high_zoneidx, nodemask,
preferred_zone, migratetype);

and gfp_to_alloc_flags() is only used in __alloc_pages_slowpath().