Commit 736838e9 authored by Mateusz Nosek's avatar Mateusz Nosek Committed by Linus Torvalds

mm, pagealloc: micro-optimisation: save two branches on hot page allocation path

This patch makes ALLOC_KSWAPD equal to __GFP_KSWAPD_RECLAIM (cast to int).

Thanks to that code like:

    if (gfp_mask & __GFP_KSWAPD_RECLAIM)
	    alloc_flags |= ALLOC_KSWAPD;

can be changed to:

    alloc_flags |= (__force int) (gfp_mask &__GFP_KSWAPD_RECLAIM);

Thanks to this one branch less is generated in the assembly.

In case of ALLOC_KSWAPD flag two branches are saved, first one in code
that always executes in the beginning of page allocation and the second
one in loop in page allocator slowpath.
Signed-off-by: default avatarMateusz Nosek <mateusznosek0@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Acked-by: default avatarMel Gorman <mgorman@techsingularity.net>
Link: http://lkml.kernel.org/r/20200304162118.14784-1-mateusznosek0@gmail.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee8eb9a5
...@@ -555,7 +555,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, ...@@ -555,7 +555,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone,
#else #else
#define ALLOC_NOFRAGMENT 0x0 #define ALLOC_NOFRAGMENT 0x0
#endif #endif
#define ALLOC_KSWAPD 0x200 /* allow waking of kswapd */ #define ALLOC_KSWAPD 0x800 /* allow waking of kswapd, __GFP_KSWAPD_RECLAIM set */
enum ttu_flags; enum ttu_flags;
struct tlbflush_unmap_batch; struct tlbflush_unmap_batch;
......
...@@ -3536,10 +3536,13 @@ static bool zone_allows_reclaim(struct zone *local_zone, struct zone *zone) ...@@ -3536,10 +3536,13 @@ static bool zone_allows_reclaim(struct zone *local_zone, struct zone *zone)
static inline unsigned int static inline unsigned int
alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask) alloc_flags_nofragment(struct zone *zone, gfp_t gfp_mask)
{ {
unsigned int alloc_flags = 0; unsigned int alloc_flags;
if (gfp_mask & __GFP_KSWAPD_RECLAIM) /*
alloc_flags |= ALLOC_KSWAPD; * __GFP_KSWAPD_RECLAIM is assumed to be the same as ALLOC_KSWAPD
* to save a branch.
*/
alloc_flags = (__force int) (gfp_mask & __GFP_KSWAPD_RECLAIM);
#ifdef CONFIG_ZONE_DMA32 #ifdef CONFIG_ZONE_DMA32
if (!zone) if (!zone)
...@@ -4175,8 +4178,13 @@ gfp_to_alloc_flags(gfp_t gfp_mask) ...@@ -4175,8 +4178,13 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
{ {
unsigned int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET; unsigned int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
/* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */ /*
* __GFP_HIGH is assumed to be the same as ALLOC_HIGH
* and __GFP_KSWAPD_RECLAIM is assumed to be the same as ALLOC_KSWAPD
* to save two branches.
*/
BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH); BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH);
BUILD_BUG_ON(__GFP_KSWAPD_RECLAIM != (__force gfp_t) ALLOC_KSWAPD);
/* /*
* The caller may dip into page reserves a bit more if the caller * The caller may dip into page reserves a bit more if the caller
...@@ -4184,7 +4192,8 @@ gfp_to_alloc_flags(gfp_t gfp_mask) ...@@ -4184,7 +4192,8 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
* policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will * policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will
* set both ALLOC_HARDER (__GFP_ATOMIC) and ALLOC_HIGH (__GFP_HIGH). * set both ALLOC_HARDER (__GFP_ATOMIC) and ALLOC_HIGH (__GFP_HIGH).
*/ */
alloc_flags |= (__force int) (gfp_mask & __GFP_HIGH); alloc_flags |= (__force int)
(gfp_mask & (__GFP_HIGH | __GFP_KSWAPD_RECLAIM));
if (gfp_mask & __GFP_ATOMIC) { if (gfp_mask & __GFP_ATOMIC) {
/* /*
...@@ -4201,9 +4210,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask) ...@@ -4201,9 +4210,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
} else if (unlikely(rt_task(current)) && !in_interrupt()) } else if (unlikely(rt_task(current)) && !in_interrupt())
alloc_flags |= ALLOC_HARDER; alloc_flags |= ALLOC_HARDER;
if (gfp_mask & __GFP_KSWAPD_RECLAIM)
alloc_flags |= ALLOC_KSWAPD;
#ifdef CONFIG_CMA #ifdef CONFIG_CMA
if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE) if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE)
alloc_flags |= ALLOC_CMA; alloc_flags |= ALLOC_CMA;
......
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