mm: discard __GFP_ATOMIC
authorNeilBrown <neilb@suse.de>
Fri, 13 Jan 2023 11:12:17 +0000 (11:12 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 3 Feb 2023 06:33:13 +0000 (22:33 -0800)
__GFP_ATOMIC serves little purpose.  Its main effect is to set
ALLOC_HARDER which adds a few little boosts to increase the chance of an
allocation succeeding, one of which is to lower the water-mark at which it
will succeed.

It is *always* paired with __GFP_HIGH which sets ALLOC_HIGH which also
adjusts this watermark.  It is probable that other users of __GFP_HIGH
should benefit from the other little bonuses that __GFP_ATOMIC gets.

__GFP_ATOMIC also gives a warning if used with __GFP_DIRECT_RECLAIM.
There is little point to this.  We already get a might_sleep() warning if
__GFP_DIRECT_RECLAIM is set.

__GFP_ATOMIC allows the "watermark_boost" to be side-stepped.  It is
probable that testing ALLOC_HARDER is a better fit here.

__GFP_ATOMIC is used by tegra-smmu.c to check if the allocation might
sleep.  This should test __GFP_DIRECT_RECLAIM instead.

This patch:
 - removes __GFP_ATOMIC
 - allows __GFP_HIGH allocations to ignore watermark boosting as well
   as GFP_ATOMIC requests.
 - makes other adjustments as suggested by the above.

The net result is not change to GFP_ATOMIC allocations.  Other
allocations that use __GFP_HIGH will benefit from a few different extra
privileges.  This affects:
  xen, dm, md, ntfs3
  the vermillion frame buffer
  hibernation
  ksm
  swap
all of which likely produce more benefit than cost if these selected
allocation are more likely to succeed quickly.

[mgorman: Minor adjustments to rework on top of a series]
Link: https://lkml.kernel.org/r/163712397076.13692.4727608274002939094@noble.neil.brown.name
Link: https://lkml.kernel.org/r/20230113111217.14134-7-mgorman@techsingularity.net
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Mel Gorman <mgorman@techsingularity.net>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/mm/balance.rst
drivers/iommu/tegra-smmu.c
include/linux/gfp_types.h
include/trace/events/mmflags.h
lib/test_printf.c
mm/internal.h
mm/page_alloc.c
tools/perf/builtin-kmem.c

index 6a1fadf3e1735eb5b01837290730525c2d2a172d..e38e9d83c1c72be024ac2f05925a8db0fd2c262f 100644 (file)
@@ -6,7 +6,7 @@ Memory Balancing
 
 Started Jan 2000 by Kanoj Sarcar <kanoj@sgi.com>
 
-Memory balancing is needed for !__GFP_ATOMIC and !__GFP_KSWAPD_RECLAIM as
+Memory balancing is needed for !__GFP_HIGH and !__GFP_KSWAPD_RECLAIM as
 well as for non __GFP_IO allocations.
 
 The first reason why a caller may avoid reclaim is that the caller can not
index 5b1af40221ec1490767ca990a69d44398a67c52f..af8d0e6852602a7822184c6dc916b66d3f549a90 100644 (file)
@@ -671,12 +671,12 @@ static struct page *as_get_pde_page(struct tegra_smmu_as *as,
         * allocate page in a sleeping context if GFP flags permit. Hence
         * spinlock needs to be unlocked and re-locked after allocation.
         */
-       if (!(gfp & __GFP_ATOMIC))
+       if (gfpflags_allow_blocking(gfp))
                spin_unlock_irqrestore(&as->lock, *flags);
 
        page = alloc_page(gfp | __GFP_DMA | __GFP_ZERO);
 
-       if (!(gfp & __GFP_ATOMIC))
+       if (gfpflags_allow_blocking(gfp))
                spin_lock_irqsave(&as->lock, *flags);
 
        /*
index d88c46ca82e17c343455a5fe064b63e861025dae..5088637fe5c2d233c3c9480107902c666be101f0 100644 (file)
@@ -31,7 +31,7 @@ typedef unsigned int __bitwise gfp_t;
 #define ___GFP_IO              0x40u
 #define ___GFP_FS              0x80u
 #define ___GFP_ZERO            0x100u
-#define ___GFP_ATOMIC          0x200u
+/* 0x200u unused */
 #define ___GFP_DIRECT_RECLAIM  0x400u
 #define ___GFP_KSWAPD_RECLAIM  0x800u
 #define ___GFP_WRITE           0x1000u
@@ -116,11 +116,8 @@ typedef unsigned int __bitwise gfp_t;
  *
  * %__GFP_HIGH indicates that the caller is high-priority and that granting
  * the request is necessary before the system can make forward progress.
- * For example, creating an IO context to clean pages.
- *
- * %__GFP_ATOMIC indicates that the caller cannot reclaim or sleep and is
- * high priority. Users are typically interrupt handlers. This may be
- * used in conjunction with %__GFP_HIGH
+ * For example creating an IO context to clean pages and requests
+ * from atomic context.
  *
  * %__GFP_MEMALLOC allows access to all memory. This should only be used when
  * the caller guarantees the allocation will allow more memory to be freed
@@ -135,7 +132,6 @@ typedef unsigned int __bitwise gfp_t;
  * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves.
  * This takes precedence over the %__GFP_MEMALLOC flag if both are set.
  */
-#define __GFP_ATOMIC   ((__force gfp_t)___GFP_ATOMIC)
 #define __GFP_HIGH     ((__force gfp_t)___GFP_HIGH)
 #define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC)
 #define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC)
@@ -329,7 +325,7 @@ typedef unsigned int __bitwise gfp_t;
  * version does not attempt reclaim/compaction at all and is by default used
  * in page fault path, while the non-light is used by khugepaged.
  */
-#define GFP_ATOMIC     (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM)
+#define GFP_ATOMIC     (__GFP_HIGH|__GFP_KSWAPD_RECLAIM)
 #define GFP_KERNEL     (__GFP_RECLAIM | __GFP_IO | __GFP_FS)
 #define GFP_KERNEL_ACCOUNT (GFP_KERNEL | __GFP_ACCOUNT)
 #define GFP_NOWAIT     (__GFP_KSWAPD_RECLAIM)
index 412b5a46374c036f52bc8f69a4b4b0faa2693f20..9db52bc4ce192dd746281d3579ad46f10760a846 100644 (file)
@@ -31,7 +31,6 @@
        gfpflag_string(__GFP_HIGHMEM),          \
        gfpflag_string(GFP_DMA32),              \
        gfpflag_string(__GFP_HIGH),             \
-       gfpflag_string(__GFP_ATOMIC),           \
        gfpflag_string(__GFP_IO),               \
        gfpflag_string(__GFP_FS),               \
        gfpflag_string(__GFP_NOWARN),           \
index d34dc636b81c794b22ee5341bed0257e6bf34d66..46b4e6c414a3573f9714ea36173cf7a28bc50a02 100644 (file)
@@ -674,17 +674,17 @@ flags(void)
        gfp = GFP_ATOMIC|__GFP_DMA;
        test("GFP_ATOMIC|GFP_DMA", "%pGg", &gfp);
 
-       gfp = __GFP_ATOMIC;
-       test("__GFP_ATOMIC", "%pGg", &gfp);
+       gfp = __GFP_HIGH;
+       test("__GFP_HIGH", "%pGg", &gfp);
 
        /* Any flags not translated by the table should remain numeric */
        gfp = ~__GFP_BITS_MASK;
        snprintf(cmp_buffer, BUF_SIZE, "%#lx", (unsigned long) gfp);
        test(cmp_buffer, "%pGg", &gfp);
 
-       snprintf(cmp_buffer, BUF_SIZE, "__GFP_ATOMIC|%#lx",
+       snprintf(cmp_buffer, BUF_SIZE, "__GFP_HIGH|%#lx",
                                                        (unsigned long) gfp);
-       gfp |= __GFP_ATOMIC;
+       gfp |= __GFP_HIGH;
        test(cmp_buffer, "%pGg", &gfp);
 
        kfree(cmp_buffer);
index b0b88a95347fac510feee56850741867ab09d05a..2d09a7a0600a10de8f3fbbcb21c6ecd18b4eb585 100644 (file)
@@ -24,7 +24,7 @@ struct folio_batch;
 #define GFP_RECLAIM_MASK (__GFP_RECLAIM|__GFP_HIGH|__GFP_IO|__GFP_FS|\
                        __GFP_NOWARN|__GFP_RETRY_MAYFAIL|__GFP_NOFAIL|\
                        __GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC|\
-                       __GFP_ATOMIC|__GFP_NOLOCKDEP)
+                       __GFP_NOLOCKDEP)
 
 /* The GFP flags allowed during early boot */
 #define GFP_BOOT_MASK (__GFP_BITS_MASK & ~(__GFP_RECLAIM|__GFP_IO|__GFP_FS))
index 18ca33a1945d663ac4020719ac983887d96a1f10..0cfad30fb44ce51bcc38b6ef13830b44afaf3929 100644 (file)
@@ -4105,13 +4105,14 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order,
        if (__zone_watermark_ok(z, order, mark, highest_zoneidx, alloc_flags,
                                        free_pages))
                return true;
+
        /*
-        * Ignore watermark boosting for GFP_ATOMIC order-0 allocations
+        * Ignore watermark boosting for __GFP_HIGH order-0 allocations
         * when checking the min watermark. The min watermark is the
         * point where boosting is ignored so that kswapd is woken up
         * when below the low watermark.
         */
-       if (unlikely(!order && (gfp_mask & __GFP_ATOMIC) && z->watermark_boost
+       if (unlikely(!order && (alloc_flags & ALLOC_MIN_RESERVE) && z->watermark_boost
                && ((alloc_flags & ALLOC_WMARK_MASK) == WMARK_MIN))) {
                mark = z->_watermark[WMARK_MIN];
                return __zone_watermark_ok(z, order, mark, highest_zoneidx,
@@ -5076,14 +5077,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
        unsigned int zonelist_iter_cookie;
        int reserve_flags;
 
-       /*
-        * We also sanity check to catch abuse of atomic reserves being used by
-        * callers that are not in atomic context.
-        */
-       if (WARN_ON_ONCE((gfp_mask & (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)) ==
-                               (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)))
-               gfp_mask &= ~__GFP_ATOMIC;
-
 restart:
        compaction_retries = 0;
        no_progress_loops = 0;
index 8ae0a1535293620505d5e41984cbd8a70ff79675..f3029742b800f34d2178027ab0f97b6130023afa 100644 (file)
@@ -653,7 +653,6 @@ static const struct {
        { "__GFP_HIGHMEM",              "HM" },
        { "GFP_DMA32",                  "D32" },
        { "__GFP_HIGH",                 "H" },
-       { "__GFP_ATOMIC",               "_A" },
        { "__GFP_IO",                   "I" },
        { "__GFP_FS",                   "F" },
        { "__GFP_NOWARN",               "NWR" },