Commit 3dd28266 authored by Mel Gorman's avatar Mel Gorman Committed by Linus Torvalds

page allocator: calculate the migratetype for allocation only once

GFP mask is converted into a migratetype when deciding which pagelist to
take a page from.  However, it is happening multiple times per allocation,
at least once per zone traversed.  Calculate it once.
Signed-off-by: default avatarMel Gorman <mel@csn.ul.ie>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5117f45d
...@@ -1061,13 +1061,13 @@ void split_page(struct page *page, unsigned int order) ...@@ -1061,13 +1061,13 @@ void split_page(struct page *page, unsigned int order)
* or two. * or two.
*/ */
static struct page *buffered_rmqueue(struct zone *preferred_zone, static struct page *buffered_rmqueue(struct zone *preferred_zone,
struct zone *zone, int order, gfp_t gfp_flags) struct zone *zone, int order, gfp_t gfp_flags,
int migratetype)
{ {
unsigned long flags; unsigned long flags;
struct page *page; struct page *page;
int cold = !!(gfp_flags & __GFP_COLD); int cold = !!(gfp_flags & __GFP_COLD);
int cpu; int cpu;
int migratetype = allocflags_to_migratetype(gfp_flags);
again: again:
cpu = get_cpu(); cpu = get_cpu();
...@@ -1389,7 +1389,7 @@ static void zlc_mark_zone_full(struct zonelist *zonelist, struct zoneref *z) ...@@ -1389,7 +1389,7 @@ static void zlc_mark_zone_full(struct zonelist *zonelist, struct zoneref *z)
static struct page * static struct page *
get_page_from_freelist(gfp_t gfp_mask, nodemask_t *nodemask, unsigned int order, get_page_from_freelist(gfp_t gfp_mask, nodemask_t *nodemask, unsigned int order,
struct zonelist *zonelist, int high_zoneidx, int alloc_flags, struct zonelist *zonelist, int high_zoneidx, int alloc_flags,
struct zone *preferred_zone) struct zone *preferred_zone, int migratetype)
{ {
struct zoneref *z; struct zoneref *z;
struct page *page = NULL; struct page *page = NULL;
...@@ -1433,7 +1433,8 @@ zonelist_scan: ...@@ -1433,7 +1433,8 @@ zonelist_scan:
} }
} }
page = buffered_rmqueue(preferred_zone, zone, order, gfp_mask); page = buffered_rmqueue(preferred_zone, zone, order,
gfp_mask, migratetype);
if (page) if (page)
break; break;
this_zone_full: this_zone_full:
...@@ -1495,7 +1496,8 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order, ...@@ -1495,7 +1496,8 @@ should_alloc_retry(gfp_t gfp_mask, unsigned int order,
static inline struct page * static inline struct page *
__alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
struct zonelist *zonelist, enum zone_type high_zoneidx, struct zonelist *zonelist, enum zone_type high_zoneidx,
nodemask_t *nodemask, struct zone *preferred_zone) nodemask_t *nodemask, struct zone *preferred_zone,
int migratetype)
{ {
struct page *page; struct page *page;
...@@ -1513,7 +1515,7 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order, ...@@ -1513,7 +1515,7 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask,
order, zonelist, high_zoneidx, order, zonelist, high_zoneidx,
ALLOC_WMARK_HIGH|ALLOC_CPUSET, ALLOC_WMARK_HIGH|ALLOC_CPUSET,
preferred_zone); preferred_zone, migratetype);
if (page) if (page)
goto out; goto out;
...@@ -1534,7 +1536,7 @@ static inline struct page * ...@@ -1534,7 +1536,7 @@ static inline struct page *
__alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
struct zonelist *zonelist, enum zone_type high_zoneidx, struct zonelist *zonelist, enum zone_type high_zoneidx,
nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone, nodemask_t *nodemask, int alloc_flags, struct zone *preferred_zone,
unsigned long *did_some_progress) int migratetype, unsigned long *did_some_progress)
{ {
struct page *page = NULL; struct page *page = NULL;
struct reclaim_state reclaim_state; struct reclaim_state reclaim_state;
...@@ -1567,7 +1569,8 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, ...@@ -1567,7 +1569,8 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
if (likely(*did_some_progress)) if (likely(*did_some_progress))
page = get_page_from_freelist(gfp_mask, nodemask, order, page = get_page_from_freelist(gfp_mask, nodemask, order,
zonelist, high_zoneidx, zonelist, high_zoneidx,
alloc_flags, preferred_zone); alloc_flags, preferred_zone,
migratetype);
return page; return page;
} }
...@@ -1587,14 +1590,15 @@ is_allocation_high_priority(struct task_struct *p, gfp_t gfp_mask) ...@@ -1587,14 +1590,15 @@ is_allocation_high_priority(struct task_struct *p, gfp_t gfp_mask)
static inline struct page * static inline struct page *
__alloc_pages_high_priority(gfp_t gfp_mask, unsigned int order, __alloc_pages_high_priority(gfp_t gfp_mask, unsigned int order,
struct zonelist *zonelist, enum zone_type high_zoneidx, struct zonelist *zonelist, enum zone_type high_zoneidx,
nodemask_t *nodemask, struct zone *preferred_zone) nodemask_t *nodemask, struct zone *preferred_zone,
int migratetype)
{ {
struct page *page; struct page *page;
do { do {
page = get_page_from_freelist(gfp_mask, nodemask, order, page = get_page_from_freelist(gfp_mask, nodemask, order,
zonelist, high_zoneidx, ALLOC_NO_WATERMARKS, zonelist, high_zoneidx, ALLOC_NO_WATERMARKS,
preferred_zone); preferred_zone, migratetype);
if (!page && gfp_mask & __GFP_NOFAIL) if (!page && gfp_mask & __GFP_NOFAIL)
congestion_wait(WRITE, HZ/50); congestion_wait(WRITE, HZ/50);
...@@ -1617,7 +1621,8 @@ void wake_all_kswapd(unsigned int order, struct zonelist *zonelist, ...@@ -1617,7 +1621,8 @@ void wake_all_kswapd(unsigned int order, struct zonelist *zonelist,
static inline struct page * static inline struct page *
__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
struct zonelist *zonelist, enum zone_type high_zoneidx, struct zonelist *zonelist, enum zone_type high_zoneidx,
nodemask_t *nodemask, struct zone *preferred_zone) nodemask_t *nodemask, struct zone *preferred_zone,
int migratetype)
{ {
const gfp_t wait = gfp_mask & __GFP_WAIT; const gfp_t wait = gfp_mask & __GFP_WAIT;
struct page *page = NULL; struct page *page = NULL;
...@@ -1668,7 +1673,8 @@ restart: ...@@ -1668,7 +1673,8 @@ restart:
*/ */
page = get_page_from_freelist(gfp_mask, nodemask, order, zonelist, page = get_page_from_freelist(gfp_mask, nodemask, order, zonelist,
high_zoneidx, alloc_flags, high_zoneidx, alloc_flags,
preferred_zone); preferred_zone,
migratetype);
if (page) if (page)
goto got_pg; goto got_pg;
...@@ -1678,7 +1684,8 @@ rebalance: ...@@ -1678,7 +1684,8 @@ rebalance:
/* Do not dip into emergency reserves if specified */ /* Do not dip into emergency reserves if specified */
if (!(gfp_mask & __GFP_NOMEMALLOC)) { if (!(gfp_mask & __GFP_NOMEMALLOC)) {
page = __alloc_pages_high_priority(gfp_mask, order, page = __alloc_pages_high_priority(gfp_mask, order,
zonelist, high_zoneidx, nodemask, preferred_zone); zonelist, high_zoneidx, nodemask, preferred_zone,
migratetype);
if (page) if (page)
goto got_pg; goto got_pg;
} }
...@@ -1696,7 +1703,7 @@ rebalance: ...@@ -1696,7 +1703,7 @@ rebalance:
zonelist, high_zoneidx, zonelist, high_zoneidx,
nodemask, nodemask,
alloc_flags, preferred_zone, alloc_flags, preferred_zone,
&did_some_progress); migratetype, &did_some_progress);
if (page) if (page)
goto got_pg; goto got_pg;
...@@ -1708,7 +1715,8 @@ rebalance: ...@@ -1708,7 +1715,8 @@ rebalance:
if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) { if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
page = __alloc_pages_may_oom(gfp_mask, order, page = __alloc_pages_may_oom(gfp_mask, order,
zonelist, high_zoneidx, zonelist, high_zoneidx,
nodemask, preferred_zone); nodemask, preferred_zone,
migratetype);
if (page) if (page)
goto got_pg; goto got_pg;
...@@ -1755,6 +1763,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, ...@@ -1755,6 +1763,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
enum zone_type high_zoneidx = gfp_zone(gfp_mask); enum zone_type high_zoneidx = gfp_zone(gfp_mask);
struct zone *preferred_zone; struct zone *preferred_zone;
struct page *page; struct page *page;
int migratetype = allocflags_to_migratetype(gfp_mask);
lockdep_trace_alloc(gfp_mask); lockdep_trace_alloc(gfp_mask);
...@@ -1779,11 +1788,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, ...@@ -1779,11 +1788,11 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
/* First allocation attempt */ /* First allocation attempt */
page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order, page = get_page_from_freelist(gfp_mask|__GFP_HARDWALL, nodemask, order,
zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET, zonelist, high_zoneidx, ALLOC_WMARK_LOW|ALLOC_CPUSET,
preferred_zone); preferred_zone, migratetype);
if (unlikely(!page)) if (unlikely(!page))
page = __alloc_pages_slowpath(gfp_mask, order, page = __alloc_pages_slowpath(gfp_mask, order,
zonelist, high_zoneidx, nodemask, zonelist, high_zoneidx, nodemask,
preferred_zone); preferred_zone, migratetype);
return page; return page;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment