]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: discard __GFP_ATOMIC
authorNeilBrown <neilb@suse.de>
Mon, 22 Aug 2022 22:57:49 +0000 (15:57 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 22 Aug 2022 22:57:49 +0000 (15:57 -0700)
__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
 - causes __GFP_HIGH to set ALLOC_HARDER unless __GFP_NOMEMALLOC is set
   (as well as ALLOC_HIGH).
 - 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.

Link: https://lkml.kernel.org/r/163712397076.13692.4727608274002939094@noble.neil.brown.name
Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Mel Gorman <mgorman@techsingularity.net>
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/include/linux/gfp.h
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 2a8de975fe63bbc9212221cf6bb8994fb282053c..555ae07ce0277ba66ee08262d143e4fbf291d45c 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 (gfp & __GFP_DIRECT_RECLAIM)
                spin_unlock_irqrestore(&as->lock, *flags);
 
        page = alloc_page(gfp | __GFP_DMA | __GFP_ZERO);
 
-       if (!(gfp & __GFP_ATOMIC))
+       if (gfp & __GFP_DIRECT_RECLAIM)
                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 e87cb2b80ed3c1aa380c8f8723b61ca93e0b449a..11524cda4a9556e781748c4bf24154f257f14b1f 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 4bd15a593fbd938c142f6ef9cac80a5f4c3033e0..fe13de1bed5fe3077ea5d4ba030e8a818a74699a 100644 (file)
@@ -686,17 +686,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 785409805ed797be3792ea99b360d2b23f7832a4..7d1f654f0a0503d91726945858e8e88d58ca30f7 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 e5486d47406e81c3c1f96551c1eded4551e1a38b..75a5ed078c6f24dd0fa63c6f4f0744dd25edd9aa 100644 (file)
@@ -4065,12 +4065,12 @@ static inline bool zone_watermark_fast(struct zone *z, unsigned int order,
                                        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_HARDER) && z->watermark_boost
                && ((alloc_flags & ALLOC_WMARK_MASK) == WMARK_MIN))) {
                mark = z->_watermark[WMARK_MIN];
                return __zone_watermark_ok(z, order, mark, highest_zoneidx,
@@ -4805,12 +4805,12 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
         * The caller may dip into page reserves a bit more if the caller
         * cannot run direct reclaim, or if the caller has realtime scheduling
         * 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 (unless __GFP_NOMEMALLOC) and ALLOC_HIGH.
         */
        alloc_flags |= (__force int)
                (gfp_mask & (__GFP_HIGH | __GFP_KSWAPD_RECLAIM));
 
-       if (gfp_mask & __GFP_ATOMIC) {
+       if (gfp_mask & __GFP_HIGH) {
                /*
                 * Not worth trying to allocate harder for __GFP_NOMEMALLOC even
                 * if it can't schedule.
@@ -5003,14 +5003,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
        unsigned int cpuset_mems_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;
-
 retry_cpuset:
        compaction_retries = 0;
        no_progress_loops = 0;
index b238dbc9eb858675f701456da7cf6e1f52365197..56eec4445bc9e5e0bfe4274256033c871ec959a5 100644 (file)
@@ -12,7 +12,6 @@
 #define __GFP_FS               0x80u
 #define __GFP_NOWARN           0x200u
 #define __GFP_ZERO             0x8000u
-#define __GFP_ATOMIC           0x80000u
 #define __GFP_ACCOUNT          0x100000u
 #define __GFP_DIRECT_RECLAIM   0x400000u
 #define __GFP_KSWAPD_RECLAIM   0x2000000u
@@ -20,7 +19,7 @@
 #define __GFP_RECLAIM  (__GFP_DIRECT_RECLAIM | __GFP_KSWAPD_RECLAIM)
 
 #define GFP_ZONEMASK   0x0fu
-#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_NOWAIT     (__GFP_KSWAPD_RECLAIM)
 
index ebfab2ca17024d69779cd5ad4ef7de0e33f29303..4a06d83f2ac5a3c800ca782b65271042623b0d5c 100644 (file)
@@ -640,7 +640,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" },