* Applies per-task gfp context to the given allocation flags.
  * PF_MEMALLOC_NOIO implies GFP_NOIO
  * PF_MEMALLOC_NOFS implies GFP_NOFS
- * PF_MEMALLOC_NOCMA implies no allocation from CMA region.
  */
 static inline gfp_t current_gfp_context(gfp_t flags)
 {
-       if (unlikely(current->flags &
-                    (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS | PF_MEMALLOC_NOCMA))) {
+       if (unlikely(current->flags & (PF_MEMALLOC_NOIO | PF_MEMALLOC_NOFS))) {
                /*
                 * NOIO implies both NOIO and NOFS and it is a weaker context
                 * so always make sure it makes precedence
                        flags &= ~(__GFP_IO | __GFP_FS);
                else if (current->flags & PF_MEMALLOC_NOFS)
                        flags &= ~__GFP_FS;
-#ifdef CONFIG_CMA
-               if (current->flags & PF_MEMALLOC_NOCMA)
-                       flags &= ~__GFP_MOVABLE;
-#endif
        }
        return flags;
 }
 
         * allocating from CMA when over half of the zone's free memory
         * is in the CMA area.
         */
-       if (migratetype == MIGRATE_MOVABLE &&
+       if (alloc_flags & ALLOC_CMA &&
            zone_page_state(zone, NR_FREE_CMA_PAGES) >
            zone_page_state(zone, NR_FREE_PAGES) / 2) {
                page = __rmqueue_cma_fallback(zone, order);
 retry:
        page = __rmqueue_smallest(zone, order, migratetype);
        if (unlikely(!page)) {
-               if (migratetype == MIGRATE_MOVABLE)
+               if (alloc_flags & ALLOC_CMA)
                        page = __rmqueue_cma_fallback(zone, order);
 
                if (!page && __rmqueue_fallback(zone, order, migratetype,
        return alloc_flags;
 }
 
+static inline unsigned int current_alloc_flags(gfp_t gfp_mask,
+                                       unsigned int alloc_flags)
+{
+#ifdef CONFIG_CMA
+       unsigned int pflags = current->flags;
+
+       if (!(pflags & PF_MEMALLOC_NOCMA) &&
+                       gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE)
+               alloc_flags |= ALLOC_CMA;
+
+#endif
+       return alloc_flags;
+}
+
 /*
  * get_page_from_freelist goes through the zonelist trying to allocate
  * a page.
        } else if (unlikely(rt_task(current)) && !in_interrupt())
                alloc_flags |= ALLOC_HARDER;
 
-#ifdef CONFIG_CMA
-       if (gfp_migratetype(gfp_mask) == MIGRATE_MOVABLE)
-               alloc_flags |= ALLOC_CMA;
-#endif
+       alloc_flags = current_alloc_flags(gfp_mask, alloc_flags);
+
        return alloc_flags;
 }
 
 
        reserve_flags = __gfp_pfmemalloc_flags(gfp_mask);
        if (reserve_flags)
-               alloc_flags = reserve_flags;
+               alloc_flags = current_alloc_flags(gfp_mask, reserve_flags);
 
        /*
         * Reset the nodemask and zonelist iterators if memory policies can be
 
        /* Avoid allocations with no watermarks from looping endlessly */
        if (tsk_is_oom_victim(current) &&
-           (alloc_flags == ALLOC_OOM ||
+           (alloc_flags & ALLOC_OOM ||
             (gfp_mask & __GFP_NOMEMALLOC)))
                goto nopage;
 
        if (should_fail_alloc_page(gfp_mask, order))
                return false;
 
-       if (IS_ENABLED(CONFIG_CMA) && ac->migratetype == MIGRATE_MOVABLE)
-               *alloc_flags |= ALLOC_CMA;
+       *alloc_flags = current_alloc_flags(gfp_mask, *alloc_flags);
 
        return true;
 }