summaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorMel Gorman <mgorman@techsingularity.net>2015-11-06 19:28:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-06 20:50:42 -0500
commitd0164adc89f6bb374d304ffcc375c6d2652fe67d (patch)
treede1cbe09c86dcd24a4a476f7e0b41af239bbdc29 /mm
parent016c13daa5c9e4827eca703e2f0621c131f2cca3 (diff)
mm, page_alloc: distinguish between being unable to sleep, unwilling to sleep and avoiding waking kswapd
__GFP_WAIT has been used to identify atomic context in callers that hold spinlocks or are in interrupts. They are expected to be high priority and have access one of two watermarks lower than "min" which can be referred to as the "atomic reserve". __GFP_HIGH users get access to the first lower watermark and can be called the "high priority reserve". Over time, callers had a requirement to not block when fallback options were available. Some have abused __GFP_WAIT leading to a situation where an optimisitic allocation with a fallback option can access atomic reserves. This patch uses __GFP_ATOMIC to identify callers that are truely atomic, cannot sleep and have no alternative. High priority users continue to use __GFP_HIGH. __GFP_DIRECT_RECLAIM identifies callers that can sleep and are willing to enter direct reclaim. __GFP_KSWAPD_RECLAIM to identify callers that want to wake kswapd for background reclaim. __GFP_WAIT is redefined as a caller that is willing to enter direct reclaim and wake kswapd for background reclaim. This patch then converts a number of sites o __GFP_ATOMIC is used by callers that are high priority and have memory pools for those requests. GFP_ATOMIC uses this flag. o Callers that have a limited mempool to guarantee forward progress clear __GFP_DIRECT_RECLAIM but keep __GFP_KSWAPD_RECLAIM. bio allocations fall into this category where kswapd will still be woken but atomic reserves are not used as there is a one-entry mempool to guarantee progress. o Callers that are checking if they are non-blocking should use the helper gfpflags_allow_blocking() where possible. This is because checking for __GFP_WAIT as was done historically now can trigger false positives. Some exceptions like dm-crypt.c exist where the code intent is clearer if __GFP_DIRECT_RECLAIM is used instead of the helper due to flag manipulations. o Callers that built their own GFP flags instead of starting with GFP_KERNEL and friends now also need to specify __GFP_KSWAPD_RECLAIM. The first key hazard to watch out for is callers that removed __GFP_WAIT and was depending on access to atomic reserves for inconspicuous reasons. In some cases it may be appropriate for them to use __GFP_HIGH. The second key hazard is callers that assembled their own combination of GFP flags instead of starting with something like GFP_KERNEL. They may now wish to specify __GFP_KSWAPD_RECLAIM. It's almost certainly harmless if it's missed in most cases as other activity will wake kswapd. Signed-off-by: Mel Gorman <mgorman@techsingularity.net> Acked-by: Vlastimil Babka <vbabka@suse.cz> Acked-by: Michal Hocko <mhocko@suse.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Cc: Vitaly Wool <vitalywool@gmail.com> Cc: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/backing-dev.c2
-rw-r--r--mm/dmapool.c2
-rw-r--r--mm/memcontrol.c6
-rw-r--r--mm/mempool.c10
-rw-r--r--mm/migrate.c2
-rw-r--r--mm/page_alloc.c43
-rw-r--r--mm/slab.c18
-rw-r--r--mm/slub.c10
-rw-r--r--mm/vmalloc.c2
-rw-r--r--mm/vmscan.c4
-rw-r--r--mm/zswap.c5
11 files changed, 58 insertions, 46 deletions
diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 619984fc07ec..8ed2ffd963c5 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -637,7 +637,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
637{ 637{
638 struct bdi_writeback *wb; 638 struct bdi_writeback *wb;
639 639
640 might_sleep_if(gfp & __GFP_WAIT); 640 might_sleep_if(gfpflags_allow_blocking(gfp));
641 641
642 if (!memcg_css->parent) 642 if (!memcg_css->parent)
643 return &bdi->wb; 643 return &bdi->wb;
diff --git a/mm/dmapool.c b/mm/dmapool.c
index 312a716fa14c..57312b5d6e12 100644
--- a/mm/dmapool.c
+++ b/mm/dmapool.c
@@ -326,7 +326,7 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
326 size_t offset; 326 size_t offset;
327 void *retval; 327 void *retval;
328 328
329 might_sleep_if(mem_flags & __GFP_WAIT); 329 might_sleep_if(gfpflags_allow_blocking(mem_flags));
330 330
331 spin_lock_irqsave(&pool->lock, flags); 331 spin_lock_irqsave(&pool->lock, flags);
332 list_for_each_entry(page, &pool->page_list, page_list) { 332 list_for_each_entry(page, &pool->page_list, page_list) {
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index bc502e590366..05374f09339c 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2046,7 +2046,7 @@ retry:
2046 if (unlikely(task_in_memcg_oom(current))) 2046 if (unlikely(task_in_memcg_oom(current)))
2047 goto nomem; 2047 goto nomem;
2048 2048
2049 if (!(gfp_mask & __GFP_WAIT)) 2049 if (!gfpflags_allow_blocking(gfp_mask))
2050 goto nomem; 2050 goto nomem;
2051 2051
2052 mem_cgroup_events(mem_over_limit, MEMCG_MAX, 1); 2052 mem_cgroup_events(mem_over_limit, MEMCG_MAX, 1);
@@ -4364,8 +4364,8 @@ static int mem_cgroup_do_precharge(unsigned long count)
4364{ 4364{
4365 int ret; 4365 int ret;
4366 4366
4367 /* Try a single bulk charge without reclaim first */ 4367 /* Try a single bulk charge without reclaim first, kswapd may wake */
4368 ret = try_charge(mc.to, GFP_KERNEL & ~__GFP_WAIT, count); 4368 ret = try_charge(mc.to, GFP_KERNEL & ~__GFP_DIRECT_RECLAIM, count);
4369 if (!ret) { 4369 if (!ret) {
4370 mc.precharge += count; 4370 mc.precharge += count;
4371 return ret; 4371 return ret;
diff --git a/mm/mempool.c b/mm/mempool.c
index 4c533bc51d73..004d42b1dfaf 100644
--- a/mm/mempool.c
+++ b/mm/mempool.c
@@ -320,13 +320,13 @@ void * mempool_alloc(mempool_t *pool, gfp_t gfp_mask)
320 gfp_t gfp_temp; 320 gfp_t gfp_temp;
321 321
322 VM_WARN_ON_ONCE(gfp_mask & __GFP_ZERO); 322 VM_WARN_ON_ONCE(gfp_mask & __GFP_ZERO);
323 might_sleep_if(gfp_mask & __GFP_WAIT); 323 might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM);
324 324
325 gfp_mask |= __GFP_NOMEMALLOC; /* don't allocate emergency reserves */ 325 gfp_mask |= __GFP_NOMEMALLOC; /* don't allocate emergency reserves */
326 gfp_mask |= __GFP_NORETRY; /* don't loop in __alloc_pages */ 326 gfp_mask |= __GFP_NORETRY; /* don't loop in __alloc_pages */
327 gfp_mask |= __GFP_NOWARN; /* failures are OK */ 327 gfp_mask |= __GFP_NOWARN; /* failures are OK */
328 328
329 gfp_temp = gfp_mask & ~(__GFP_WAIT|__GFP_IO); 329 gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO);
330 330
331repeat_alloc: 331repeat_alloc:
332 332
@@ -349,7 +349,7 @@ repeat_alloc:
349 } 349 }
350 350
351 /* 351 /*
352 * We use gfp mask w/o __GFP_WAIT or IO for the first round. If 352 * We use gfp mask w/o direct reclaim or IO for the first round. If
353 * alloc failed with that and @pool was empty, retry immediately. 353 * alloc failed with that and @pool was empty, retry immediately.
354 */ 354 */
355 if (gfp_temp != gfp_mask) { 355 if (gfp_temp != gfp_mask) {
@@ -358,8 +358,8 @@ repeat_alloc:
358 goto repeat_alloc; 358 goto repeat_alloc;
359 } 359 }
360 360
361 /* We must not sleep if !__GFP_WAIT */ 361 /* We must not sleep if !__GFP_DIRECT_RECLAIM */
362 if (!(gfp_mask & __GFP_WAIT)) { 362 if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) {
363 spin_unlock_irqrestore(&pool->lock, flags); 363 spin_unlock_irqrestore(&pool->lock, flags);
364 return NULL; 364 return NULL;
365 } 365 }
diff --git a/mm/migrate.c b/mm/migrate.c
index 2834faba719a..e60379eb23f8 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1578,7 +1578,7 @@ static struct page *alloc_misplaced_dst_page(struct page *page,
1578 (GFP_HIGHUSER_MOVABLE | 1578 (GFP_HIGHUSER_MOVABLE |
1579 __GFP_THISNODE | __GFP_NOMEMALLOC | 1579 __GFP_THISNODE | __GFP_NOMEMALLOC |
1580 __GFP_NORETRY | __GFP_NOWARN) & 1580 __GFP_NORETRY | __GFP_NOWARN) &
1581 ~GFP_IOFS, 0); 1581 ~(__GFP_IO | __GFP_FS), 0);
1582 1582
1583 return newpage; 1583 return newpage;
1584} 1584}
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 67390988881a..70461f3e3378 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -169,12 +169,12 @@ void pm_restrict_gfp_mask(void)
169 WARN_ON(!mutex_is_locked(&pm_mutex)); 169 WARN_ON(!mutex_is_locked(&pm_mutex));
170 WARN_ON(saved_gfp_mask); 170 WARN_ON(saved_gfp_mask);
171 saved_gfp_mask = gfp_allowed_mask; 171 saved_gfp_mask = gfp_allowed_mask;
172 gfp_allowed_mask &= ~GFP_IOFS; 172 gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
173} 173}
174 174
175bool pm_suspended_storage(void) 175bool pm_suspended_storage(void)
176{ 176{
177 if ((gfp_allowed_mask & GFP_IOFS) == GFP_IOFS) 177 if ((gfp_allowed_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS))
178 return false; 178 return false;
179 return true; 179 return true;
180} 180}
@@ -2183,7 +2183,7 @@ static bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
2183 return false; 2183 return false;
2184 if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM)) 2184 if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM))
2185 return false; 2185 return false;
2186 if (fail_page_alloc.ignore_gfp_wait && (gfp_mask & __GFP_WAIT)) 2186 if (fail_page_alloc.ignore_gfp_wait && (gfp_mask & __GFP_DIRECT_RECLAIM))
2187 return false; 2187 return false;
2188 2188
2189 return should_fail(&fail_page_alloc.attr, 1 << order); 2189 return should_fail(&fail_page_alloc.attr, 1 << order);
@@ -2685,7 +2685,7 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
2685 if (test_thread_flag(TIF_MEMDIE) || 2685 if (test_thread_flag(TIF_MEMDIE) ||
2686 (current->flags & (PF_MEMALLOC | PF_EXITING))) 2686 (current->flags & (PF_MEMALLOC | PF_EXITING)))
2687 filter &= ~SHOW_MEM_FILTER_NODES; 2687 filter &= ~SHOW_MEM_FILTER_NODES;
2688 if (in_interrupt() || !(gfp_mask & __GFP_WAIT)) 2688 if (in_interrupt() || !(gfp_mask & __GFP_DIRECT_RECLAIM))
2689 filter &= ~SHOW_MEM_FILTER_NODES; 2689 filter &= ~SHOW_MEM_FILTER_NODES;
2690 2690
2691 if (fmt) { 2691 if (fmt) {
@@ -2945,7 +2945,6 @@ static inline int
2945gfp_to_alloc_flags(gfp_t gfp_mask) 2945gfp_to_alloc_flags(gfp_t gfp_mask)
2946{ 2946{
2947 int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET; 2947 int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
2948 const bool atomic = !(gfp_mask & (__GFP_WAIT | __GFP_NO_KSWAPD));
2949 2948
2950 /* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */ 2949 /* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */
2951 BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH); 2950 BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH);
@@ -2954,11 +2953,11 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
2954 * The caller may dip into page reserves a bit more if the caller 2953 * The caller may dip into page reserves a bit more if the caller
2955 * cannot run direct reclaim, or if the caller has realtime scheduling 2954 * cannot run direct reclaim, or if the caller has realtime scheduling
2956 * policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will 2955 * policy or is asking for __GFP_HIGH memory. GFP_ATOMIC requests will
2957 * set both ALLOC_HARDER (atomic == true) and ALLOC_HIGH (__GFP_HIGH). 2956 * set both ALLOC_HARDER (__GFP_ATOMIC) and ALLOC_HIGH (__GFP_HIGH).
2958 */ 2957 */
2959 alloc_flags |= (__force int) (gfp_mask & __GFP_HIGH); 2958 alloc_flags |= (__force int) (gfp_mask & __GFP_HIGH);
2960 2959
2961 if (atomic) { 2960 if (gfp_mask & __GFP_ATOMIC) {
2962 /* 2961 /*
2963 * Not worth trying to allocate harder for __GFP_NOMEMALLOC even 2962 * Not worth trying to allocate harder for __GFP_NOMEMALLOC even
2964 * if it can't schedule. 2963 * if it can't schedule.
@@ -2995,11 +2994,16 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
2995 return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS); 2994 return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS);
2996} 2995}
2997 2996
2997static inline bool is_thp_gfp_mask(gfp_t gfp_mask)
2998{
2999 return (gfp_mask & (GFP_TRANSHUGE | __GFP_KSWAPD_RECLAIM)) == GFP_TRANSHUGE;
3000}
3001
2998static inline struct page * 3002static inline struct page *
2999__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, 3003__alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
3000 struct alloc_context *ac) 3004 struct alloc_context *ac)
3001{ 3005{
3002 const gfp_t wait = gfp_mask & __GFP_WAIT; 3006 bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM;
3003 struct page *page = NULL; 3007 struct page *page = NULL;
3004 int alloc_flags; 3008 int alloc_flags;
3005 unsigned long pages_reclaimed = 0; 3009 unsigned long pages_reclaimed = 0;
@@ -3020,15 +3024,23 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
3020 } 3024 }
3021 3025
3022 /* 3026 /*
3027 * We also sanity check to catch abuse of atomic reserves being used by
3028 * callers that are not in atomic context.
3029 */
3030 if (WARN_ON_ONCE((gfp_mask & (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)) ==
3031 (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)))
3032 gfp_mask &= ~__GFP_ATOMIC;
3033
3034 /*
3023 * If this allocation cannot block and it is for a specific node, then 3035 * If this allocation cannot block and it is for a specific node, then
3024 * fail early. There's no need to wakeup kswapd or retry for a 3036 * fail early. There's no need to wakeup kswapd or retry for a
3025 * speculative node-specific allocation. 3037 * speculative node-specific allocation.
3026 */ 3038 */
3027 if (IS_ENABLED(CONFIG_NUMA) && (gfp_mask & __GFP_THISNODE) && !wait) 3039 if (IS_ENABLED(CONFIG_NUMA) && (gfp_mask & __GFP_THISNODE) && !can_direct_reclaim)
3028 goto nopage; 3040 goto nopage;
3029 3041
3030retry: 3042retry:
3031 if (!(gfp_mask & __GFP_NO_KSWAPD)) 3043 if (gfp_mask & __GFP_KSWAPD_RECLAIM)
3032 wake_all_kswapds(order, ac); 3044 wake_all_kswapds(order, ac);
3033 3045
3034 /* 3046 /*
@@ -3071,8 +3083,8 @@ retry:
3071 } 3083 }
3072 } 3084 }
3073 3085
3074 /* Atomic allocations - we can't balance anything */ 3086 /* Caller is not willing to reclaim, we can't balance anything */
3075 if (!wait) { 3087 if (!can_direct_reclaim) {
3076 /* 3088 /*
3077 * All existing users of the deprecated __GFP_NOFAIL are 3089 * All existing users of the deprecated __GFP_NOFAIL are
3078 * blockable, so warn of any new users that actually allow this 3090 * blockable, so warn of any new users that actually allow this
@@ -3102,7 +3114,7 @@ retry:
3102 goto got_pg; 3114 goto got_pg;
3103 3115
3104 /* Checks for THP-specific high-order allocations */ 3116 /* Checks for THP-specific high-order allocations */
3105 if ((gfp_mask & GFP_TRANSHUGE) == GFP_TRANSHUGE) { 3117 if (is_thp_gfp_mask(gfp_mask)) {
3106 /* 3118 /*
3107 * If compaction is deferred for high-order allocations, it is 3119 * If compaction is deferred for high-order allocations, it is
3108 * because sync compaction recently failed. If this is the case 3120 * because sync compaction recently failed. If this is the case
@@ -3137,8 +3149,7 @@ retry:
3137 * fault, so use asynchronous memory compaction for THP unless it is 3149 * fault, so use asynchronous memory compaction for THP unless it is
3138 * khugepaged trying to collapse. 3150 * khugepaged trying to collapse.
3139 */ 3151 */
3140 if ((gfp_mask & GFP_TRANSHUGE) != GFP_TRANSHUGE || 3152 if (!is_thp_gfp_mask(gfp_mask) || (current->flags & PF_KTHREAD))
3141 (current->flags & PF_KTHREAD))
3142 migration_mode = MIGRATE_SYNC_LIGHT; 3153 migration_mode = MIGRATE_SYNC_LIGHT;
3143 3154
3144 /* Try direct reclaim and then allocating */ 3155 /* Try direct reclaim and then allocating */
@@ -3209,7 +3220,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
3209 3220
3210 lockdep_trace_alloc(gfp_mask); 3221 lockdep_trace_alloc(gfp_mask);
3211 3222
3212 might_sleep_if(gfp_mask & __GFP_WAIT); 3223 might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM);
3213 3224
3214 if (should_fail_alloc_page(gfp_mask, order)) 3225 if (should_fail_alloc_page(gfp_mask, order))
3215 return NULL; 3226 return NULL;
diff --git a/mm/slab.c b/mm/slab.c
index 272e809404d5..a9ef77d19a9a 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1031,12 +1031,12 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
1031} 1031}
1032 1032
1033/* 1033/*
1034 * Construct gfp mask to allocate from a specific node but do not invoke reclaim 1034 * Construct gfp mask to allocate from a specific node but do not direct reclaim
1035 * or warn about failures. 1035 * or warn about failures. kswapd may still wake to reclaim in the background.
1036 */ 1036 */
1037static inline gfp_t gfp_exact_node(gfp_t flags) 1037static inline gfp_t gfp_exact_node(gfp_t flags)
1038{ 1038{
1039 return (flags | __GFP_THISNODE | __GFP_NOWARN) & ~__GFP_WAIT; 1039 return (flags | __GFP_THISNODE | __GFP_NOWARN) & ~__GFP_DIRECT_RECLAIM;
1040} 1040}
1041#endif 1041#endif
1042 1042
@@ -2633,7 +2633,7 @@ static int cache_grow(struct kmem_cache *cachep,
2633 2633
2634 offset *= cachep->colour_off; 2634 offset *= cachep->colour_off;
2635 2635
2636 if (local_flags & __GFP_WAIT) 2636 if (gfpflags_allow_blocking(local_flags))
2637 local_irq_enable(); 2637 local_irq_enable();
2638 2638
2639 /* 2639 /*
@@ -2663,7 +2663,7 @@ static int cache_grow(struct kmem_cache *cachep,
2663 2663
2664 cache_init_objs(cachep, page); 2664 cache_init_objs(cachep, page);
2665 2665
2666 if (local_flags & __GFP_WAIT) 2666 if (gfpflags_allow_blocking(local_flags))
2667 local_irq_disable(); 2667 local_irq_disable();
2668 check_irq_off(); 2668 check_irq_off();
2669 spin_lock(&n->list_lock); 2669 spin_lock(&n->list_lock);
@@ -2677,7 +2677,7 @@ static int cache_grow(struct kmem_cache *cachep,
2677opps1: 2677opps1:
2678 kmem_freepages(cachep, page); 2678 kmem_freepages(cachep, page);
2679failed: 2679failed:
2680 if (local_flags & __GFP_WAIT) 2680 if (gfpflags_allow_blocking(local_flags))
2681 local_irq_disable(); 2681 local_irq_disable();
2682 return 0; 2682 return 0;
2683} 2683}
@@ -2869,7 +2869,7 @@ force_grow:
2869static inline void cache_alloc_debugcheck_before(struct kmem_cache *cachep, 2869static inline void cache_alloc_debugcheck_before(struct kmem_cache *cachep,
2870 gfp_t flags) 2870 gfp_t flags)
2871{ 2871{
2872 might_sleep_if(flags & __GFP_WAIT); 2872 might_sleep_if(gfpflags_allow_blocking(flags));
2873#if DEBUG 2873#if DEBUG
2874 kmem_flagcheck(cachep, flags); 2874 kmem_flagcheck(cachep, flags);
2875#endif 2875#endif
@@ -3057,11 +3057,11 @@ retry:
3057 */ 3057 */
3058 struct page *page; 3058 struct page *page;
3059 3059
3060 if (local_flags & __GFP_WAIT) 3060 if (gfpflags_allow_blocking(local_flags))
3061 local_irq_enable(); 3061 local_irq_enable();
3062 kmem_flagcheck(cache, flags); 3062 kmem_flagcheck(cache, flags);
3063 page = kmem_getpages(cache, local_flags, numa_mem_id()); 3063 page = kmem_getpages(cache, local_flags, numa_mem_id());
3064 if (local_flags & __GFP_WAIT) 3064 if (gfpflags_allow_blocking(local_flags))
3065 local_irq_disable(); 3065 local_irq_disable();
3066 if (page) { 3066 if (page) {
3067 /* 3067 /*
diff --git a/mm/slub.c b/mm/slub.c
index 75a5fa92ac2a..97695622a858 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1265,7 +1265,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s,
1265{ 1265{
1266 flags &= gfp_allowed_mask; 1266 flags &= gfp_allowed_mask;
1267 lockdep_trace_alloc(flags); 1267 lockdep_trace_alloc(flags);
1268 might_sleep_if(flags & __GFP_WAIT); 1268 might_sleep_if(gfpflags_allow_blocking(flags));
1269 1269
1270 if (should_failslab(s->object_size, flags, s->flags)) 1270 if (should_failslab(s->object_size, flags, s->flags))
1271 return NULL; 1271 return NULL;
@@ -1353,7 +1353,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
1353 1353
1354 flags &= gfp_allowed_mask; 1354 flags &= gfp_allowed_mask;
1355 1355
1356 if (flags & __GFP_WAIT) 1356 if (gfpflags_allow_blocking(flags))
1357 local_irq_enable(); 1357 local_irq_enable();
1358 1358
1359 flags |= s->allocflags; 1359 flags |= s->allocflags;
@@ -1363,8 +1363,8 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
1363 * so we fall-back to the minimum order allocation. 1363 * so we fall-back to the minimum order allocation.
1364 */ 1364 */
1365 alloc_gfp = (flags | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_NOFAIL; 1365 alloc_gfp = (flags | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_NOFAIL;
1366 if ((alloc_gfp & __GFP_WAIT) && oo_order(oo) > oo_order(s->min)) 1366 if ((alloc_gfp & __GFP_DIRECT_RECLAIM) && oo_order(oo) > oo_order(s->min))
1367 alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_WAIT; 1367 alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_DIRECT_RECLAIM;
1368 1368
1369 page = alloc_slab_page(s, alloc_gfp, node, oo); 1369 page = alloc_slab_page(s, alloc_gfp, node, oo);
1370 if (unlikely(!page)) { 1370 if (unlikely(!page)) {
@@ -1424,7 +1424,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
1424 page->frozen = 1; 1424 page->frozen = 1;
1425 1425
1426out: 1426out:
1427 if (flags & __GFP_WAIT) 1427 if (gfpflags_allow_blocking(flags))
1428 local_irq_disable(); 1428 local_irq_disable();
1429 if (!page) 1429 if (!page)
1430 return NULL; 1430 return NULL;
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 9db9ef5e8481..7ee94dc10000 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1617,7 +1617,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
1617 goto fail; 1617 goto fail;
1618 } 1618 }
1619 area->pages[i] = page; 1619 area->pages[i] = page;
1620 if (gfp_mask & __GFP_WAIT) 1620 if (gfpflags_allow_blocking(gfp_mask))
1621 cond_resched(); 1621 cond_resched();
1622 } 1622 }
1623 1623
diff --git a/mm/vmscan.c b/mm/vmscan.c
index e0cd7eed4e38..2aec4241b42a 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1476,7 +1476,7 @@ static int too_many_isolated(struct zone *zone, int file,
1476 * won't get blocked by normal direct-reclaimers, forming a circular 1476 * won't get blocked by normal direct-reclaimers, forming a circular
1477 * deadlock. 1477 * deadlock.
1478 */ 1478 */
1479 if ((sc->gfp_mask & GFP_IOFS) == GFP_IOFS) 1479 if ((sc->gfp_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS))
1480 inactive >>= 3; 1480 inactive >>= 3;
1481 1481
1482 return isolated > inactive; 1482 return isolated > inactive;
@@ -3791,7 +3791,7 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
3791 /* 3791 /*
3792 * Do not scan if the allocation should not be delayed. 3792 * Do not scan if the allocation should not be delayed.
3793 */ 3793 */
3794 if (!(gfp_mask & __GFP_WAIT) || (current->flags & PF_MEMALLOC)) 3794 if (!gfpflags_allow_blocking(gfp_mask) || (current->flags & PF_MEMALLOC))
3795 return ZONE_RECLAIM_NOSCAN; 3795 return ZONE_RECLAIM_NOSCAN;
3796 3796
3797 /* 3797 /*
diff --git a/mm/zswap.c b/mm/zswap.c
index 4043df7c672f..e54166d3732e 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -571,7 +571,7 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
571static struct zswap_pool *zswap_pool_create(char *type, char *compressor) 571static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
572{ 572{
573 struct zswap_pool *pool; 573 struct zswap_pool *pool;
574 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN; 574 gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
575 575
576 pool = kzalloc(sizeof(*pool), GFP_KERNEL); 576 pool = kzalloc(sizeof(*pool), GFP_KERNEL);
577 if (!pool) { 577 if (!pool) {
@@ -1011,7 +1011,8 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
1011 /* store */ 1011 /* store */
1012 len = dlen + sizeof(struct zswap_header); 1012 len = dlen + sizeof(struct zswap_header);
1013 ret = zpool_malloc(entry->pool->zpool, len, 1013 ret = zpool_malloc(entry->pool->zpool, len,
1014 __GFP_NORETRY | __GFP_NOWARN, &handle); 1014 __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM,
1015 &handle);
1015 if (ret == -ENOSPC) { 1016 if (ret == -ENOSPC) {
1016 zswap_reject_compress_poor++; 1017 zswap_reject_compress_poor++;
1017 goto put_dstmem; 1018 goto put_dstmem;