]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
mm, page_alloc: distinguish between being unable to sleep, unwilling to sleep and...
authorMel Gorman <mgorman@techsingularity.net>
Wed, 21 Oct 2015 22:03:07 +0000 (09:03 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 21 Oct 2015 22:03:07 +0000 (09:03 +1100)
__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>
66 files changed:
Documentation/vm/balance
arch/arm/mm/dma-mapping.c
arch/arm/xen/mm.c
arch/arm64/mm/dma-mapping.c
arch/x86/kernel/pci-dma.c
block/bio.c
block/blk-core.c
block/blk-ioc.c
block/blk-mq-tag.c
block/blk-mq.c
drivers/block/drbd/drbd_receiver.c
drivers/block/osdblk.c
drivers/connector/connector.c
drivers/firewire/core-cdev.c
drivers/gpu/drm/i915/i915_gem.c
drivers/infiniband/core/sa_query.c
drivers/iommu/amd_iommu.c
drivers/iommu/intel-iommu.c
drivers/md/dm-crypt.c
drivers/md/dm-kcopyd.c
drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
drivers/media/pci/solo6x10/solo6x10-v4l2.c
drivers/media/pci/tw68/tw68-video.c
drivers/mtd/mtdcore.c
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
drivers/staging/android/ion/ion_system_heap.c
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
drivers/usb/host/u132-hcd.c
drivers/video/fbdev/vermilion/vermilion.c
fs/btrfs/disk-io.c
fs/btrfs/extent_io.c
fs/btrfs/volumes.c
fs/ext4/super.c
fs/fscache/cookie.c
fs/fscache/page.c
fs/jbd2/transaction.c
fs/nfs/file.c
fs/xfs/xfs_qm.c
include/linux/gfp.h
include/linux/skbuff.h
include/net/sock.h
include/trace/events/gfpflags.h
kernel/audit.c
kernel/cgroup.c
kernel/locking/lockdep.c
kernel/power/snapshot.c
kernel/smp.c
lib/idr.c
lib/radix-tree.c
mm/backing-dev.c
mm/dmapool.c
mm/memcontrol.c
mm/mempool.c
mm/migrate.c
mm/page_alloc.c
mm/slab.c
mm/slub.c
mm/vmalloc.c
mm/vmscan.c
mm/zswap.c
net/core/skbuff.c
net/core/sock.c
net/netlink/af_netlink.c
net/rds/ib_recv.c
net/rxrpc/ar-connection.c
net/sctp/associola.c

index c46e68cf93449aadb652bdce92953c53bb00ca22..964595481af683a7a9c344182ca707fd1c2a33fa 100644 (file)
@@ -1,12 +1,14 @@
 Started Jan 2000 by Kanoj Sarcar <kanoj@sgi.com>
 
-Memory balancing is needed for non __GFP_WAIT as well as for non
-__GFP_IO allocations.
+Memory balancing is needed for !__GFP_ATOMIC and !__GFP_KSWAPD_RECLAIM as
+well as for non __GFP_IO allocations.
 
-There are two reasons to be requesting non __GFP_WAIT allocations:
-the caller can not sleep (typically intr context), or does not want
-to incur cost overheads of page stealing and possible swap io for
-whatever reasons.
+The first reason why a caller may avoid reclaim is that the caller can not
+sleep due to holding a spinlock or is in interrupt context. The second may
+be that the caller is willing to fail the allocation without incurring the
+overhead of page reclaim. This may happen for opportunistic high-order
+allocation requests that have order-0 fallback options. In such cases,
+the caller may also wish to avoid waking kswapd.
 
 __GFP_IO allocation requests are made to prevent file system deadlocks.
 
index 1a7815e5421b6b1d3ad774b28915b84b52726136..38307d8312ac6b7a51bb155980f52bc7fca8ea7e 100644 (file)
@@ -651,12 +651,12 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 
        if (nommu())
                addr = __alloc_simple_buffer(dev, size, gfp, &page);
-       else if (dev_get_cma_area(dev) && (gfp & __GFP_WAIT))
+       else if (dev_get_cma_area(dev) && (gfp & __GFP_DIRECT_RECLAIM))
                addr = __alloc_from_contiguous(dev, size, prot, &page,
                                               caller, want_vaddr);
        else if (is_coherent)
                addr = __alloc_simple_buffer(dev, size, gfp, &page);
-       else if (!(gfp & __GFP_WAIT))
+       else if (!gfpflags_allow_blocking(gfp))
                addr = __alloc_from_pool(size, &page);
        else
                addr = __alloc_remap_buffer(dev, size, gfp, prot, &page,
@@ -1363,7 +1363,7 @@ static void *arm_iommu_alloc_attrs(struct device *dev, size_t size,
        *handle = DMA_ERROR_CODE;
        size = PAGE_ALIGN(size);
 
-       if (!(gfp & __GFP_WAIT))
+       if (!gfpflags_allow_blocking(gfp))
                return __iommu_alloc_atomic(dev, size, handle);
 
        /*
index 6dd911d1f0ac6c0f2c328abbee593d85d5bd5bcd..99eec9063f68afd075dfe87e5a2f0d0ef30502cf 100644 (file)
@@ -25,7 +25,7 @@
 unsigned long xen_get_swiotlb_free_pages(unsigned int order)
 {
        struct memblock_region *reg;
-       gfp_t flags = __GFP_NOWARN;
+       gfp_t flags = __GFP_NOWARN|__GFP_KSWAPD_RECLAIM;
 
        for_each_memblock(memory, reg) {
                if (reg->base < (phys_addr_t)0xffffffff) {
index 99224dcebdc51d40cb2dff423280727ec44bacd3..478234383c2cd8c90087eca0031b425a3d01b606 100644 (file)
@@ -100,7 +100,7 @@ static void *__dma_alloc_coherent(struct device *dev, size_t size,
        if (IS_ENABLED(CONFIG_ZONE_DMA) &&
            dev->coherent_dma_mask <= DMA_BIT_MASK(32))
                flags |= GFP_DMA;
-       if (dev_get_cma_area(dev) && (flags & __GFP_WAIT)) {
+       if (dev_get_cma_area(dev) && gfpflags_allow_blocking(flags)) {
                struct page *page;
                void *addr;
 
@@ -148,7 +148,7 @@ static void *__dma_alloc(struct device *dev, size_t size,
 
        size = PAGE_ALIGN(size);
 
-       if (!coherent && !(flags & __GFP_WAIT)) {
+       if (!coherent && !gfpflags_allow_blocking(flags)) {
                struct page *page = NULL;
                void *addr = __alloc_from_pool(size, &page, flags);
 
index 1b55de1267cfc4f3032b37c72c14239533fbdbcf..a8e618b16a66a25f07260dac1379998a79b8ac9a 100644 (file)
@@ -90,7 +90,7 @@ void *dma_generic_alloc_coherent(struct device *dev, size_t size,
 again:
        page = NULL;
        /* CMA can be used only in the context which permits sleeping */
-       if (flag & __GFP_WAIT) {
+       if (gfpflags_allow_blocking(flag)) {
                page = dma_alloc_from_contiguous(dev, count, get_order(size));
                if (page && page_to_phys(page) + size > dma_mask) {
                        dma_release_from_contiguous(dev, page, count);
index ad3f276d74bcb5a21474c49c786dee82f2f1b9f6..4f184d938942dcbbbbedbac3b330f6e4bb39a4a9 100644 (file)
@@ -211,7 +211,7 @@ fallback:
                bvl = mempool_alloc(pool, gfp_mask);
        } else {
                struct biovec_slab *bvs = bvec_slabs + *idx;
-               gfp_t __gfp_mask = gfp_mask & ~(__GFP_WAIT | __GFP_IO);
+               gfp_t __gfp_mask = gfp_mask & ~(__GFP_DIRECT_RECLAIM | __GFP_IO);
 
                /*
                 * Make this allocation restricted and don't dump info on
@@ -221,11 +221,11 @@ fallback:
                __gfp_mask |= __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
 
                /*
-                * Try a slab allocation. If this fails and __GFP_WAIT
+                * Try a slab allocation. If this fails and __GFP_DIRECT_RECLAIM
                 * is set, retry with the 1-entry mempool
                 */
                bvl = kmem_cache_alloc(bvs->slab, __gfp_mask);
-               if (unlikely(!bvl && (gfp_mask & __GFP_WAIT))) {
+               if (unlikely(!bvl && (gfp_mask & __GFP_DIRECT_RECLAIM))) {
                        *idx = BIOVEC_MAX_IDX;
                        goto fallback;
                }
@@ -395,12 +395,12 @@ static void punt_bios_to_rescuer(struct bio_set *bs)
  *   If @bs is NULL, uses kmalloc() to allocate the bio; else the allocation is
  *   backed by the @bs's mempool.
  *
- *   When @bs is not NULL, if %__GFP_WAIT is set then bio_alloc will always be
- *   able to allocate a bio. This is due to the mempool guarantees. To make this
- *   work, callers must never allocate more than 1 bio at a time from this pool.
- *   Callers that need to allocate more than 1 bio must always submit the
- *   previously allocated bio for IO before attempting to allocate a new one.
- *   Failure to do so can cause deadlocks under memory pressure.
+ *   When @bs is not NULL, if %__GFP_DIRECT_RECLAIM is set then bio_alloc will
+ *   always be able to allocate a bio. This is due to the mempool guarantees.
+ *   To make this work, callers must never allocate more than 1 bio at a time
+ *   from this pool. Callers that need to allocate more than 1 bio must always
+ *   submit the previously allocated bio for IO before attempting to allocate
+ *   a new one. Failure to do so can cause deadlocks under memory pressure.
  *
  *   Note that when running under generic_make_request() (i.e. any block
  *   driver), bios are not submitted until after you return - see the code in
@@ -459,13 +459,13 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
                 * We solve this, and guarantee forward progress, with a rescuer
                 * workqueue per bio_set. If we go to allocate and there are
                 * bios on current->bio_list, we first try the allocation
-                * without __GFP_WAIT; if that fails, we punt those bios we
-                * would be blocking to the rescuer workqueue before we retry
-                * with the original gfp_flags.
+                * without __GFP_DIRECT_RECLAIM; if that fails, we punt those
+                * bios we would be blocking to the rescuer workqueue before
+                * we retry with the original gfp_flags.
                 */
 
                if (current->bio_list && !bio_list_empty(current->bio_list))
-                       gfp_mask &= ~__GFP_WAIT;
+                       gfp_mask &= ~__GFP_DIRECT_RECLAIM;
 
                p = mempool_alloc(bs->bio_pool, gfp_mask);
                if (!p && gfp_mask != saved_gfp) {
index 2eb722d48773cb8a8de49d58b934eed830755da7..0391206868e9a81dca0add4a72fc065c3b66d5c0 100644 (file)
@@ -1160,8 +1160,8 @@ rq_starved:
  * @bio: bio to allocate request for (can be %NULL)
  * @gfp_mask: allocation mask
  *
- * Get a free request from @q.  If %__GFP_WAIT is set in @gfp_mask, this
- * function keeps retrying under memory pressure and fails iff @q is dead.
+ * Get a free request from @q.  If %__GFP_DIRECT_RECLAIM is set in @gfp_mask,
+ * this function keeps retrying under memory pressure and fails iff @q is dead.
  *
  * Must be called with @q->queue_lock held and,
  * Returns ERR_PTR on failure, with @q->queue_lock held.
@@ -1181,7 +1181,7 @@ retry:
        if (!IS_ERR(rq))
                return rq;
 
-       if (!(gfp_mask & __GFP_WAIT) || unlikely(blk_queue_dying(q))) {
+       if (!gfpflags_allow_blocking(gfp_mask) || unlikely(blk_queue_dying(q))) {
                blk_put_rl(rl);
                return rq;
        }
@@ -1259,11 +1259,11 @@ EXPORT_SYMBOL(blk_get_request);
  * BUG.
  *
  * WARNING: When allocating/cloning a bio-chain, careful consideration should be
- * given to how you allocate bios. In particular, you cannot use __GFP_WAIT for
- * anything but the first bio in the chain. Otherwise you risk waiting for IO
- * completion of a bio that hasn't been submitted yet, thus resulting in a
- * deadlock. Alternatively bios should be allocated using bio_kmalloc() instead
- * of bio_alloc(), as that avoids the mempool deadlock.
+ * given to how you allocate bios. In particular, you cannot use
+ * __GFP_DIRECT_RECLAIM for anything but the first bio in the chain. Otherwise
+ * you risk waiting for IO completion of a bio that hasn't been submitted yet,
+ * thus resulting in a deadlock. Alternatively bios should be allocated using
+ * bio_kmalloc() instead of bio_alloc(), as that avoids the mempool deadlock.
  * If possible a big IO should be split into smaller parts when allocation
  * fails. Partial allocation should not be an error, or you risk a live-lock.
  */
index 1a27f45ec776a4e0a951a89de3185dc2ead26a42..381cb50a673c33ed86f6f5d597331137f2881ce3 100644 (file)
@@ -289,7 +289,7 @@ struct io_context *get_task_io_context(struct task_struct *task,
 {
        struct io_context *ioc;
 
-       might_sleep_if(gfp_flags & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(gfp_flags));
 
        do {
                task_lock(task);
index ed96474d75cb62fb261526736727c67ea2238d46..adbc577d83c481d4763848e9ed4b415afd4193c1 100644 (file)
@@ -264,7 +264,7 @@ static int bt_get(struct blk_mq_alloc_data *data,
        if (tag != -1)
                return tag;
 
-       if (!(data->gfp & __GFP_WAIT))
+       if (!gfpflags_allow_blocking(data->gfp))
                return -1;
 
        bs = bt_wait_ptr(bt, hctx);
index 7785ae96267a197926c700f74bcd6524892a8c01..93fa70631a6ed6dc583ecb84d37c1b28da17fcd5 100644 (file)
@@ -85,7 +85,7 @@ static int blk_mq_queue_enter(struct request_queue *q, gfp_t gfp)
                if (percpu_ref_tryget_live(&q->mq_usage_counter))
                        return 0;
 
-               if (!(gfp & __GFP_WAIT))
+               if (!gfpflags_allow_blocking(gfp))
                        return -EBUSY;
 
                ret = wait_event_interruptible(q->mq_freeze_wq,
@@ -261,11 +261,11 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, gfp_t gfp,
 
        ctx = blk_mq_get_ctx(q);
        hctx = q->mq_ops->map_queue(q, ctx->cpu);
-       blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_WAIT,
+       blk_mq_set_alloc_data(&alloc_data, q, gfp & ~__GFP_DIRECT_RECLAIM,
                        reserved, ctx, hctx);
 
        rq = __blk_mq_alloc_request(&alloc_data, rw);
-       if (!rq && (gfp & __GFP_WAIT)) {
+       if (!rq && (gfp & __GFP_DIRECT_RECLAIM)) {
                __blk_mq_run_hw_queue(hctx);
                blk_mq_put_ctx(ctx);
 
@@ -1199,7 +1199,7 @@ static struct request *blk_mq_map_request(struct request_queue *q,
                ctx = blk_mq_get_ctx(q);
                hctx = q->mq_ops->map_queue(q, ctx->cpu);
                blk_mq_set_alloc_data(&alloc_data, q,
-                               __GFP_WAIT|GFP_ATOMIC, false, ctx, hctx);
+                               __GFP_WAIT|__GFP_HIGH, false, ctx, hctx);
                rq = __blk_mq_alloc_request(&alloc_data, rw);
                ctx = alloc_data.ctx;
                hctx = alloc_data.hctx;
index c097909c589c240e4b9d2ca44e1a9b7084ea9b15..b4b5680ac6adb1dcdbda2428b08398d38e2c8d4b 100644 (file)
@@ -357,7 +357,8 @@ drbd_alloc_peer_req(struct drbd_peer_device *peer_device, u64 id, sector_t secto
        }
 
        if (has_payload && data_size) {
-               page = drbd_alloc_pages(peer_device, nr_pages, (gfp_mask & __GFP_WAIT));
+               page = drbd_alloc_pages(peer_device, nr_pages,
+                                       gfpflags_allow_blocking(gfp_mask));
                if (!page)
                        goto fail;
        }
index e229425962074cf358ee234b853af452435495ea..1b709a4e3b5ec62eaf9709b366ea11c0d097ffd3 100644 (file)
@@ -271,7 +271,7 @@ static struct bio *bio_chain_clone(struct bio *old_chain, gfp_t gfpmask)
                        goto err_out;
 
                tmp->bi_bdev = NULL;
-               gfpmask &= ~__GFP_WAIT;
+               gfpmask &= ~__GFP_DIRECT_RECLAIM;
                tmp->bi_next = NULL;
 
                if (!new_chain)
index 30f522848c7353166af0d9605215205101c0b013..d7373ca69c9947a83dd8a1d67b77c7fc9e77209e 100644 (file)
@@ -124,7 +124,8 @@ int cn_netlink_send_mult(struct cn_msg *msg, u16 len, u32 portid, u32 __group,
        if (group)
                return netlink_broadcast(dev->nls, skb, portid, group,
                                         gfp_mask);
-       return netlink_unicast(dev->nls, skb, portid, !(gfp_mask&__GFP_WAIT));
+       return netlink_unicast(dev->nls, skb, portid,
+                       !gfpflags_allow_blocking(gfp_mask));
 }
 EXPORT_SYMBOL_GPL(cn_netlink_send_mult);
 
index 2a3973a7c44179457f635196696bc78e756a76e1..36a7c2d89a010e7a567224c89a01a2ebe0c8fd20 100644 (file)
@@ -486,7 +486,7 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
 static int add_client_resource(struct client *client,
                               struct client_resource *resource, gfp_t gfp_mask)
 {
-       bool preload = !!(gfp_mask & __GFP_WAIT);
+       bool preload = gfpflags_allow_blocking(gfp_mask);
        unsigned long flags;
        int ret;
 
index 4d631a94648194957512d096e89da0e5242bd822..d58cb9e034fe896acf71d6a399cf00e599ff357b 100644 (file)
@@ -2215,7 +2215,7 @@ i915_gem_object_get_pages_gtt(struct drm_i915_gem_object *obj)
         */
        mapping = file_inode(obj->base.filp)->i_mapping;
        gfp = mapping_gfp_mask(mapping);
-       gfp |= __GFP_NORETRY | __GFP_NOWARN | __GFP_NO_KSWAPD;
+       gfp |= __GFP_NORETRY | __GFP_NOWARN;
        gfp &= ~(__GFP_IO | __GFP_WAIT);
        sg = st->sgl;
        st->nents = 0;
index 8c014b33d8e0a5bc97e6e2408b3ded37ddfd06c2..59ab264c99c4f4a87c92cf654f14cc0806539cd6 100644 (file)
@@ -1083,7 +1083,7 @@ static void init_mad(struct ib_sa_mad *mad, struct ib_mad_agent *agent)
 
 static int send_mad(struct ib_sa_query *query, int timeout_ms, gfp_t gfp_mask)
 {
-       bool preload = !!(gfp_mask & __GFP_WAIT);
+       bool preload = gfpflags_allow_blocking(gfp_mask);
        unsigned long flags;
        int ret, id;
 
index 08d2775887f7add00e44858cc6bf4a5eece6e260..3aa0116c843c050490b675498ac09e825ba78807 100644 (file)
@@ -2764,7 +2764,7 @@ static void *alloc_coherent(struct device *dev, size_t size,
 
        page = alloc_pages(flag | __GFP_NOWARN,  get_order(size));
        if (!page) {
-               if (!(flag & __GFP_WAIT))
+               if (!gfpflags_allow_blocking(flag))
                        return NULL;
 
                page = dma_alloc_from_contiguous(dev, size >> PAGE_SHIFT,
index 35365f046923db7df50f43f318310711e7fd5e31..0c139f63b8bedd5201370289ebba66ad742ed87c 100644 (file)
@@ -3536,7 +3536,7 @@ static void *intel_alloc_coherent(struct device *dev, size_t size,
                        flags |= GFP_DMA32;
        }
 
-       if (flags & __GFP_WAIT) {
+       if (gfpflags_allow_blocking(flags)) {
                unsigned int count = size >> PAGE_SHIFT;
 
                page = dma_alloc_from_contiguous(dev, count, order);
index 4b3b6f8aff0cb4112a7bafa2c128027f804468b6..ca718c98bb9d666a7dd8e5306b049d7fe2fcd3f1 100644 (file)
@@ -994,7 +994,7 @@ static struct bio *crypt_alloc_buffer(struct dm_crypt_io *io, unsigned size)
        struct bio_vec *bvec;
 
 retry:
-       if (unlikely(gfp_mask & __GFP_WAIT))
+       if (unlikely(gfp_mask & __GFP_DIRECT_RECLAIM))
                mutex_lock(&cc->bio_alloc_lock);
 
        clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
@@ -1010,7 +1010,7 @@ retry:
                if (!page) {
                        crypt_free_buffer_pages(cc, clone);
                        bio_put(clone);
-                       gfp_mask |= __GFP_WAIT;
+                       gfp_mask |= __GFP_DIRECT_RECLAIM;
                        goto retry;
                }
 
@@ -1027,7 +1027,7 @@ retry:
        }
 
 return_clone:
-       if (unlikely(gfp_mask & __GFP_WAIT))
+       if (unlikely(gfp_mask & __GFP_DIRECT_RECLAIM))
                mutex_unlock(&cc->bio_alloc_lock);
 
        return clone;
index 3a7cade5e27d828ffa2df3b9254f9064ec078c84..1452ed9aacb4222e4ee86c28480ddf373ac5e3c7 100644 (file)
@@ -244,7 +244,7 @@ static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
        *pages = NULL;
 
        do {
-               pl = alloc_pl(__GFP_NOWARN | __GFP_NORETRY);
+               pl = alloc_pl(__GFP_NOWARN | __GFP_NORETRY | __GFP_KSWAPD_RECLAIM);
                if (unlikely(!pl)) {
                        /* Use reserved pages */
                        pl = kc->pages;
index 53fff5425c13817e1242f08dbf2f6365c2c8de48..fb2cb4bdc0c181258f9a44d7fc95f1f8a9fad263 100644 (file)
@@ -1291,7 +1291,7 @@ static struct solo_enc_dev *solo_enc_alloc(struct solo_dev *solo_dev,
        solo_enc->vidq.ops = &solo_enc_video_qops;
        solo_enc->vidq.mem_ops = &vb2_dma_sg_memops;
        solo_enc->vidq.drv_priv = solo_enc;
-       solo_enc->vidq.gfp_flags = __GFP_DMA32;
+       solo_enc->vidq.gfp_flags = __GFP_DMA32 | __GFP_KSWAPD_RECLAIM;
        solo_enc->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
        solo_enc->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
        solo_enc->vidq.lock = &solo_enc->lock;
index 63ae8a61f6030d20fe2d67aad87f2cd0583d0942..bde77b22340c4ee93591960f905af8b0d76ecce5 100644 (file)
@@ -675,7 +675,7 @@ int solo_v4l2_init(struct solo_dev *solo_dev, unsigned nr)
        solo_dev->vidq.mem_ops = &vb2_dma_contig_memops;
        solo_dev->vidq.drv_priv = solo_dev;
        solo_dev->vidq.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-       solo_dev->vidq.gfp_flags = __GFP_DMA32;
+       solo_dev->vidq.gfp_flags = __GFP_DMA32 | __GFP_KSWAPD_RECLAIM;
        solo_dev->vidq.buf_struct_size = sizeof(struct solo_vb2_buf);
        solo_dev->vidq.lock = &solo_dev->lock;
        ret = vb2_queue_init(&solo_dev->vidq);
index 8355e55b4e8ed75fa94d0f087f5908b95e78e12c..e556f989aaabd26bf6d2cebaa0b67fe97ac9aa84 100644 (file)
@@ -975,7 +975,7 @@ int tw68_video_init2(struct tw68_dev *dev, int video_nr)
        dev->vidq.ops = &tw68_video_qops;
        dev->vidq.mem_ops = &vb2_dma_sg_memops;
        dev->vidq.drv_priv = dev;
-       dev->vidq.gfp_flags = __GFP_DMA32;
+       dev->vidq.gfp_flags = __GFP_DMA32 | __GFP_KSWAPD_RECLAIM;
        dev->vidq.buf_struct_size = sizeof(struct tw68_buf);
        dev->vidq.lock = &dev->lock;
        dev->vidq.min_buffers_needed = 2;
index 8bbbb751bf45e2340e727439b6368c78d148089f..2dfb291a47c6da6e64caa1788f1329305658b9c5 100644 (file)
@@ -1188,8 +1188,7 @@ EXPORT_SYMBOL_GPL(mtd_writev);
  */
 void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
 {
-       gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
-                      __GFP_NORETRY | __GFP_NO_KSWAPD;
+       gfp_t flags = __GFP_NOWARN | __GFP_DIRECT_RECLAIM | __GFP_NORETRY;
        size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
        void *kbuf;
 
index 44173be5cbf0d914111304ba2420954f44d5a7e7..f8d7a2f06950139b936dc7d793bb884bb579980d 100644 (file)
@@ -691,7 +691,7 @@ static void *bnx2x_frag_alloc(const struct bnx2x_fastpath *fp, gfp_t gfp_mask)
 {
        if (fp->rx_frag_size) {
                /* GFP_KERNEL allocations are used only during initialization */
-               if (unlikely(gfp_mask & __GFP_WAIT))
+               if (unlikely(gfpflags_allow_blocking(gfp_mask)))
                        return (void *)__get_free_page(gfp_mask);
 
                return netdev_alloc_frag(fp->rx_frag_size);
index 7a7a9a047230889a8d0883e68364609968c875a0..d4cdbf28dbb6701fae141493dbad5516eb5d4d8e 100644 (file)
@@ -27,7 +27,7 @@
 #include "ion_priv.h"
 
 static gfp_t high_order_gfp_flags = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN |
-                                    __GFP_NORETRY) & ~__GFP_WAIT;
+                                    __GFP_NORETRY) & ~__GFP_DIRECT_RECLAIM;
 static gfp_t low_order_gfp_flags  = (GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN);
 static const unsigned int orders[] = {8, 4, 0};
 static const int num_orders = ARRAY_SIZE(orders);
index 9544860e32920a851dd35f20757a199ea5346fef..78bde2c11b50ba44928d0a27a2d50d2a2d9e6d05 100644 (file)
@@ -95,7 +95,7 @@ do {                                                              \
 do {                                                                       \
        LASSERT(!in_interrupt() ||                                          \
                ((size) <= LIBCFS_VMALLOC_SIZE &&                           \
-                ((mask) & __GFP_WAIT) == 0));                              \
+                !gfpflags_allow_blocking(mask)));                          \
 } while (0)
 
 #define LIBCFS_ALLOC_POST(ptr, size)                                       \
index a67bd509033097cfc156f84605f43f3617b951d8..67b3b9d9dfd13c471ac31908737a0d30e9284a78 100644 (file)
@@ -2244,7 +2244,7 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 {
        struct u132 *u132 = hcd_to_u132(hcd);
        if (irqs_disabled()) {
-               if (__GFP_WAIT & mem_flags) {
+               if (gfpflags_allow_blocking(mem_flags)) {
                        printk(KERN_ERR "invalid context for function that migh"
                                "t sleep\n");
                        return -EINVAL;
index 6b70d7f62b2fa43aa9f286d51b6aa8983fd08353..1c1e95a0b8faa04006c857158c79ac11bc904d96 100644 (file)
@@ -99,7 +99,7 @@ static int vmlfb_alloc_vram_area(struct vram_area *va, unsigned max_order,
                 * below the first 16MB.
                 */
 
-               flags = __GFP_DMA | __GFP_HIGH;
+               flags = __GFP_DMA | __GFP_HIGH | __GFP_KSWAPD_RECLAIM;
                va->logical =
                         __get_free_pages(flags, --max_order);
        } while (va->logical == 0 && max_order > min_order);
index 1e60d00d4ea7c42104614ede9e203a1f56e6408a..c339d561e59654935378fb8c23593f418aee2c8f 100644 (file)
@@ -2572,7 +2572,7 @@ int open_ctree(struct super_block *sb,
        fs_info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
        fs_info->avg_delayed_ref_runtime = NSEC_PER_SEC >> 6; /* div by 64 */
        /* readahead state */
-       INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_WAIT);
+       INIT_RADIX_TREE(&fs_info->reada_tree, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
        spin_lock_init(&fs_info->reada_lock);
 
        fs_info->thread_pool_size = min_t(unsigned long,
index 3915c9473e9445d4aeada81c8fb96af7fb521f2c..032abfbebe76e6e4ba41e25d7c9326079ed71f68 100644 (file)
@@ -594,7 +594,7 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
        if (bits & (EXTENT_IOBITS | EXTENT_BOUNDARY))
                clear = 1;
 again:
-       if (!prealloc && (mask & __GFP_WAIT)) {
+       if (!prealloc && gfpflags_allow_blocking(mask)) {
                /*
                 * Don't care for allocation failure here because we might end
                 * up not needing the pre-allocated extent state at all, which
@@ -718,7 +718,7 @@ search_again:
        if (start > end)
                goto out;
        spin_unlock(&tree->lock);
-       if (mask & __GFP_WAIT)
+       if (gfpflags_allow_blocking(mask))
                cond_resched();
        goto again;
 }
@@ -850,7 +850,7 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
 
        bits |= EXTENT_FIRST_DELALLOC;
 again:
-       if (!prealloc && (mask & __GFP_WAIT)) {
+       if (!prealloc && gfpflags_allow_blocking(mask)) {
                prealloc = alloc_extent_state(mask);
                BUG_ON(!prealloc);
        }
@@ -1028,7 +1028,7 @@ search_again:
        if (start > end)
                goto out;
        spin_unlock(&tree->lock);
-       if (mask & __GFP_WAIT)
+       if (gfpflags_allow_blocking(mask))
                cond_resched();
        goto again;
 }
@@ -1076,7 +1076,7 @@ int convert_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
        btrfs_debug_check_extent_io_range(tree, start, end);
 
 again:
-       if (!prealloc && (mask & __GFP_WAIT)) {
+       if (!prealloc && gfpflags_allow_blocking(mask)) {
                /*
                 * Best effort, don't worry if extent state allocation fails
                 * here for the first iteration. We might have a cached state
@@ -1253,7 +1253,7 @@ search_again:
        if (start > end)
                goto out;
        spin_unlock(&tree->lock);
-       if (mask & __GFP_WAIT)
+       if (gfpflags_allow_blocking(mask))
                cond_resched();
        first_iteration = false;
        goto again;
@@ -4319,7 +4319,7 @@ int try_release_extent_mapping(struct extent_map_tree *map,
        u64 start = page_offset(page);
        u64 end = start + PAGE_CACHE_SIZE - 1;
 
-       if ((mask & __GFP_WAIT) &&
+       if (gfpflags_allow_blocking(mask) &&
            page->mapping->host->i_size > 16 * 1024 * 1024) {
                u64 len;
                while (start <= end) {
index 6fc735869c186c35fb79fa66decc7d3519ed2e93..e023919b447064cbc6fad6984065731cbbde68c3 100644 (file)
@@ -156,8 +156,8 @@ static struct btrfs_device *__alloc_device(void)
        spin_lock_init(&dev->reada_lock);
        atomic_set(&dev->reada_in_flight, 0);
        atomic_set(&dev->dev_stats_ccnt, 0);
-       INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_WAIT);
-       INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_WAIT);
+       INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
+       INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
 
        return dev;
 }
index a63c7b0a10cfca3b3075f4dc14435add1bcec91b..49f6c78ee3afe26aa45941d443c5ea242ef95676 100644 (file)
@@ -1058,7 +1058,7 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
                return 0;
        if (journal)
                return jbd2_journal_try_to_free_buffers(journal, page,
-                                                       wait & ~__GFP_WAIT);
+                                               wait & ~__GFP_DIRECT_RECLAIM);
        return try_to_free_buffers(page);
 }
 
index d403c69bee0829fba9187114bc318dd810e8d179..4304072161aa08c14d24291bf24eb2481c567874 100644 (file)
@@ -111,7 +111,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
 
        /* radix tree insertion won't use the preallocation pool unless it's
         * told it may not wait */
-       INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_WAIT);
+       INIT_RADIX_TREE(&cookie->stores, GFP_NOFS & ~__GFP_DIRECT_RECLAIM);
 
        switch (cookie->def->type) {
        case FSCACHE_COOKIE_TYPE_INDEX:
index 483bbc613bf04528cbc66d5d54a5b54b6a8dc85b..79483b3d8c6f273f9a8e8a5c0c997efa949d48ff 100644 (file)
@@ -58,7 +58,7 @@ bool release_page_wait_timeout(struct fscache_cookie *cookie, struct page *page)
 
 /*
  * decide whether a page can be released, possibly by cancelling a store to it
- * - we're allowed to sleep if __GFP_WAIT is flagged
+ * - we're allowed to sleep if __GFP_DIRECT_RECLAIM is flagged
  */
 bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
                                  struct page *page,
@@ -122,7 +122,7 @@ page_busy:
         * allocator as the work threads writing to the cache may all end up
         * sleeping on memory allocation, so we may need to impose a timeout
         * too. */
-       if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
+       if (!(gfp & __GFP_DIRECT_RECLAIM) || !(gfp & __GFP_FS)) {
                fscache_stat(&fscache_n_store_vmscan_busy);
                return false;
        }
@@ -132,7 +132,7 @@ page_busy:
                _debug("fscache writeout timeout page: %p{%lx}",
                        page, page->index);
 
-       gfp &= ~__GFP_WAIT;
+       gfp &= ~__GFP_DIRECT_RECLAIM;
        goto try_again;
 }
 EXPORT_SYMBOL(__fscache_maybe_release_page);
index 6b8338ec246454444d0dce734b9dee36b15c9f30..89463eee67914643a02ce711463e62fac0b83c8d 100644 (file)
@@ -1937,8 +1937,8 @@ out:
  * @journal: journal for operation
  * @page: to try and free
  * @gfp_mask: we use the mask to detect how hard should we try to release
- * buffers. If __GFP_WAIT and __GFP_FS is set, we wait for commit code to
- * release the buffers.
+ * buffers. If __GFP_DIRECT_RECLAIM and __GFP_FS is set, we wait for commit
+ * code to release the buffers.
  *
  *
  * For all the buffers on this page,
index c0f9b1ed12b9eb281909926f2befacd13db1a026..17d3417c8a74375a2974af6e1c4f13219b188476 100644 (file)
@@ -473,8 +473,8 @@ static int nfs_release_page(struct page *page, gfp_t gfp)
        dfprintk(PAGECACHE, "NFS: release_page(%p)\n", page);
 
        /* Always try to initiate a 'commit' if relevant, but only
-        * wait for it if __GFP_WAIT is set.  Even then, only wait 1
-        * second and only if the 'bdi' is not congested.
+        * wait for it if the caller allows blocking.  Even then,
+        * only wait 1 second and only if the 'bdi' is not congested.
         * Waiting indefinitely can cause deadlocks when the NFS
         * server is on this machine, when a new TCP connection is
         * needed and in other rare cases.  There is no particular
@@ -484,7 +484,7 @@ static int nfs_release_page(struct page *page, gfp_t gfp)
        if (mapping) {
                struct nfs_server *nfss = NFS_SERVER(mapping->host);
                nfs_commit_inode(mapping->host, 0);
-               if ((gfp & __GFP_WAIT) &&
+               if (gfpflags_allow_blocking(gfp) &&
                    !bdi_write_congested(&nfss->backing_dev_info)) {
                        wait_on_page_bit_killable_timeout(page, PG_private,
                                                          HZ);
index eac9549efd52c824d7e298b494a470f43923936e..587174fd4f2c216637eda70b9986848a0980fd09 100644 (file)
@@ -525,7 +525,7 @@ xfs_qm_shrink_scan(
        unsigned long           freed;
        int                     error;
 
-       if ((sc->gfp_mask & (__GFP_FS|__GFP_WAIT)) != (__GFP_FS|__GFP_WAIT))
+       if ((sc->gfp_mask & (__GFP_FS|__GFP_DIRECT_RECLAIM)) != (__GFP_FS|__GFP_DIRECT_RECLAIM))
                return 0;
 
        INIT_LIST_HEAD(&isol.buffers);
index 440fca3e7e5d2acbf77c85ee1fe9ea8b28003996..b56e811b6f7c77f91a3535da405c919574c2f4f7 100644 (file)
@@ -29,12 +29,13 @@ struct vm_area_struct;
 #define ___GFP_NOMEMALLOC      0x10000u
 #define ___GFP_HARDWALL                0x20000u
 #define ___GFP_THISNODE                0x40000u
-#define ___GFP_WAIT            0x80000u
+#define ___GFP_ATOMIC          0x80000u
 #define ___GFP_NOACCOUNT       0x100000u
 #define ___GFP_NOTRACK         0x200000u
-#define ___GFP_NO_KSWAPD       0x400000u
+#define ___GFP_DIRECT_RECLAIM  0x400000u
 #define ___GFP_OTHER_NODE      0x800000u
 #define ___GFP_WRITE           0x1000000u
+#define ___GFP_KSWAPD_RECLAIM  0x2000000u
 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
 
 /*
@@ -71,7 +72,7 @@ struct vm_area_struct;
  * __GFP_MOVABLE: Flag that this page will be movable by the page migration
  * mechanism or reclaimed
  */
-#define __GFP_WAIT     ((__force gfp_t)___GFP_WAIT)    /* Can wait and reschedule? */
+#define __GFP_ATOMIC   ((__force gfp_t)___GFP_ATOMIC)  /* Caller cannot wait or reschedule */
 #define __GFP_HIGH     ((__force gfp_t)___GFP_HIGH)    /* Should access emergency pools? */
 #define __GFP_IO       ((__force gfp_t)___GFP_IO)      /* Can start physical IO? */
 #define __GFP_FS       ((__force gfp_t)___GFP_FS)      /* Can call down to low-level FS? */
@@ -94,23 +95,37 @@ struct vm_area_struct;
 #define __GFP_NOACCOUNT        ((__force gfp_t)___GFP_NOACCOUNT) /* Don't account to kmemcg */
 #define __GFP_NOTRACK  ((__force gfp_t)___GFP_NOTRACK)  /* Don't track with kmemcheck */
 
-#define __GFP_NO_KSWAPD        ((__force gfp_t)___GFP_NO_KSWAPD)
 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
 #define __GFP_WRITE    ((__force gfp_t)___GFP_WRITE)   /* Allocator intends to dirty page */
 
+/*
+ * A caller that is willing to wait may enter direct reclaim and will
+ * wake kswapd to reclaim pages in the background until the high
+ * watermark is met. A caller may wish to clear __GFP_DIRECT_RECLAIM to
+ * avoid unnecessary delays when a fallback option is available but
+ * still allow kswapd to reclaim in the background. The kswapd flag
+ * can be cleared when the reclaiming of pages would cause unnecessary
+ * disruption.
+ */
+#define __GFP_WAIT ((__force gfp_t)(___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM))
+#define __GFP_DIRECT_RECLAIM   ((__force gfp_t)___GFP_DIRECT_RECLAIM) /* Caller can reclaim */
+#define __GFP_KSWAPD_RECLAIM   ((__force gfp_t)___GFP_KSWAPD_RECLAIM) /* kswapd can wake */
+
 /*
  * This may seem redundant, but it's a way of annotating false positives vs.
  * allocations that simply cannot be supported (e.g. page tables).
  */
 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
 
-#define __GFP_BITS_SHIFT 25    /* Room for N __GFP_FOO bits */
+#define __GFP_BITS_SHIFT 26    /* Room for N __GFP_FOO bits */
 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
 
-/* This equals 0, but use constants in case they ever change */
-#define GFP_NOWAIT     (GFP_ATOMIC & ~__GFP_HIGH)
-/* GFP_ATOMIC means both !wait (__GFP_WAIT not set) and use emergency pool */
-#define GFP_ATOMIC     (__GFP_HIGH)
+/*
+ * GFP_ATOMIC callers can not sleep, need the allocation to succeed.
+ * A lower watermark is applied to allow access to "atomic reserves"
+ */
+#define GFP_ATOMIC     (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM)
+#define GFP_NOWAIT     (__GFP_KSWAPD_RECLAIM)
 #define GFP_NOIO       (__GFP_WAIT)
 #define GFP_NOFS       (__GFP_WAIT | __GFP_IO)
 #define GFP_KERNEL     (__GFP_WAIT | __GFP_IO | __GFP_FS)
@@ -119,10 +134,10 @@ struct vm_area_struct;
 #define GFP_USER       (__GFP_WAIT | __GFP_IO | __GFP_FS | __GFP_HARDWALL)
 #define GFP_HIGHUSER   (GFP_USER | __GFP_HIGHMEM)
 #define GFP_HIGHUSER_MOVABLE   (GFP_HIGHUSER | __GFP_MOVABLE)
-#define GFP_IOFS       (__GFP_IO | __GFP_FS)
-#define GFP_TRANSHUGE  (GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
-                        __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN | \
-                        __GFP_NO_KSWAPD)
+#define GFP_IOFS       (__GFP_IO | __GFP_FS | __GFP_KSWAPD_RECLAIM)
+#define GFP_TRANSHUGE  ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \
+                        __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN) & \
+                        ~__GFP_KSWAPD_RECLAIM)
 
 /* This mask makes up all the page movable related flags */
 #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE)
@@ -164,6 +179,11 @@ static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
        return (gfp_flags & GFP_MOVABLE_MASK) >> GFP_MOVABLE_SHIFT;
 }
 
+static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
+{
+       return gfp_flags & __GFP_DIRECT_RECLAIM;
+}
+
 #ifdef CONFIG_HIGHMEM
 #define OPT_ZONE_HIGHMEM ZONE_HIGHMEM
 #else
index 4398411236f16c3f87691162909dc6197fb62b08..4d82b886af839af39f92325da3952567eb4464c6 100644 (file)
@@ -1215,7 +1215,7 @@ static inline int skb_cloned(const struct sk_buff *skb)
 
 static inline int skb_unclone(struct sk_buff *skb, gfp_t pri)
 {
-       might_sleep_if(pri & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(pri));
 
        if (skb_cloned(skb))
                return pskb_expand_head(skb, 0, 0, pri);
@@ -1299,7 +1299,7 @@ static inline int skb_shared(const struct sk_buff *skb)
  */
 static inline struct sk_buff *skb_share_check(struct sk_buff *skb, gfp_t pri)
 {
-       might_sleep_if(pri & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(pri));
        if (skb_shared(skb)) {
                struct sk_buff *nskb = skb_clone(skb, pri);
 
@@ -1335,7 +1335,7 @@ static inline struct sk_buff *skb_share_check(struct sk_buff *skb, gfp_t pri)
 static inline struct sk_buff *skb_unshare(struct sk_buff *skb,
                                          gfp_t pri)
 {
-       might_sleep_if(pri & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(pri));
        if (skb_cloned(skb)) {
                struct sk_buff *nskb = skb_copy(skb, pri);
 
index e23717013a4e6cb1ef84e6b8ba6654b011ee8670..509694740bede696abd69910aee0d1e87a68caf5 100644 (file)
@@ -2028,7 +2028,7 @@ struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp,
  */
 static inline struct page_frag *sk_page_frag(struct sock *sk)
 {
-       if (sk->sk_allocation & __GFP_WAIT)
+       if (gfpflags_allow_blocking(sk->sk_allocation))
                return &current->task_frag;
 
        return &sk->sk_frag;
index d6fd8e5b14b76c41bfd532c3fa86255e4e92b0f3..dde6bf092c8ac356d1502b7d444e73ce8b8c143a 100644 (file)
@@ -20,7 +20,7 @@
        {(unsigned long)GFP_ATOMIC,             "GFP_ATOMIC"},          \
        {(unsigned long)GFP_NOIO,               "GFP_NOIO"},            \
        {(unsigned long)__GFP_HIGH,             "GFP_HIGH"},            \
-       {(unsigned long)__GFP_WAIT,             "GFP_WAIT"},            \
+       {(unsigned long)__GFP_ATOMIC,           "GFP_ATOMIC"},          \
        {(unsigned long)__GFP_IO,               "GFP_IO"},              \
        {(unsigned long)__GFP_COLD,             "GFP_COLD"},            \
        {(unsigned long)__GFP_NOWARN,           "GFP_NOWARN"},          \
@@ -36,7 +36,8 @@
        {(unsigned long)__GFP_RECLAIMABLE,      "GFP_RECLAIMABLE"},     \
        {(unsigned long)__GFP_MOVABLE,          "GFP_MOVABLE"},         \
        {(unsigned long)__GFP_NOTRACK,          "GFP_NOTRACK"},         \
-       {(unsigned long)__GFP_NO_KSWAPD,        "GFP_NO_KSWAPD"},       \
+       {(unsigned long)__GFP_DIRECT_RECLAIM,   "GFP_DIRECT_RECLAIM"},  \
+       {(unsigned long)__GFP_KSWAPD_RECLAIM,   "GFP_KSWAPD_RECLAIM"},  \
        {(unsigned long)__GFP_OTHER_NODE,       "GFP_OTHER_NODE"}       \
        ) : "GFP_NOWAIT"
 
index 662c007635fb778bef2bca5cc213f8cb23ed364e..6ae6e2b62e3e5aa567526b0b24dc622e5de33e98 100644 (file)
@@ -1357,16 +1357,16 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
        if (unlikely(audit_filter_type(type)))
                return NULL;
 
-       if (gfp_mask & __GFP_WAIT) {
+       if (gfp_mask & __GFP_DIRECT_RECLAIM) {
                if (audit_pid && audit_pid == current->pid)
-                       gfp_mask &= ~__GFP_WAIT;
+                       gfp_mask &= ~__GFP_DIRECT_RECLAIM;
                else
                        reserve = 0;
        }
 
        while (audit_backlog_limit
               && skb_queue_len(&audit_skb_queue) > audit_backlog_limit + reserve) {
-               if (gfp_mask & __GFP_WAIT && audit_backlog_wait_time) {
+               if (gfp_mask & __GFP_DIRECT_RECLAIM && audit_backlog_wait_time) {
                        long sleep_time;
 
                        sleep_time = timeout_start + audit_backlog_wait_time - jiffies;
index 2c9eae6ad9704d3278557f6c692d2ef0027b587b..311b00c30a889e02eec2fbbffd0b0565a347943e 100644 (file)
@@ -208,7 +208,7 @@ static int cgroup_idr_alloc(struct idr *idr, void *ptr, int start, int end,
 
        idr_preload(gfp_mask);
        spin_lock_bh(&cgroup_idr_lock);
-       ret = idr_alloc(idr, ptr, start, end, gfp_mask & ~__GFP_WAIT);
+       ret = idr_alloc(idr, ptr, start, end, gfp_mask & ~__GFP_DIRECT_RECLAIM);
        spin_unlock_bh(&cgroup_idr_lock);
        idr_preload_end();
        return ret;
index 4e49cc4c9952ca82eff8a2b5e5e61765d48ea96f..deae3907ac1eec585bbe71a44f6dc57ad024784a 100644 (file)
@@ -2738,7 +2738,7 @@ static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags)
                return;
 
        /* no reclaim without waiting on it */
-       if (!(gfp_mask & __GFP_WAIT))
+       if (!(gfp_mask & __GFP_DIRECT_RECLAIM))
                return;
 
        /* this guy won't enter reclaim */
index 5235dd4e1e2f68a97fa6836d98854d2e8e46724e..3a970604308ff5365f431e8190d1b82f7ac306d1 100644 (file)
@@ -1779,7 +1779,7 @@ alloc_highmem_pages(struct memory_bitmap *bm, unsigned int nr_highmem)
        while (to_alloc-- > 0) {
                struct page *page;
 
-               page = alloc_image_page(__GFP_HIGHMEM);
+               page = alloc_image_page(__GFP_HIGHMEM|__GFP_KSWAPD_RECLAIM);
                memory_bm_set_bit(bm, page_to_pfn(page));
        }
        return nr_highmem;
index 07854477c16447ff87df874b4f117bcafadd4f33..d903c02223afbaa2776b2610f00ae3def7de442e 100644 (file)
@@ -669,7 +669,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info),
        cpumask_var_t cpus;
        int cpu, ret;
 
-       might_sleep_if(gfp_flags & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(gfp_flags));
 
        if (likely(zalloc_cpumask_var(&cpus, (gfp_flags|__GFP_NOWARN)))) {
                preempt_disable();
index 5335c43adf46af55bb90717aa63afe33a6a30e9c..6098336df2672e09f0d022aa5c1a1c8252aa73c7 100644 (file)
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -399,7 +399,7 @@ void idr_preload(gfp_t gfp_mask)
         * allocation guarantee.  Disallow usage from those contexts.
         */
        WARN_ON_ONCE(in_interrupt());
-       might_sleep_if(gfp_mask & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(gfp_mask));
 
        preempt_disable();
 
@@ -453,7 +453,7 @@ int idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask)
        struct idr_layer *pa[MAX_IDR_LEVEL + 1];
        int id;
 
-       might_sleep_if(gfp_mask & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(gfp_mask));
 
        /* sanity checks */
        if (WARN_ON_ONCE(start < 0))
index f9ebe1c82060ec330ac7ae7a9d1678f18058cf65..fcf5d98574ce46871dca087d2c803dbfb67c0b81 100644 (file)
@@ -188,7 +188,7 @@ radix_tree_node_alloc(struct radix_tree_root *root)
         * preloading in the interrupt anyway as all the allocations have to
         * be atomic. So just do normal allocation when in interrupt.
         */
-       if (!(gfp_mask & __GFP_WAIT) && !in_interrupt()) {
+       if (!gfpflags_allow_blocking(gfp_mask) && !in_interrupt()) {
                struct radix_tree_preload *rtp;
 
                /*
@@ -249,7 +249,7 @@ radix_tree_node_free(struct radix_tree_node *node)
  * with preemption not disabled.
  *
  * To make use of this facility, the radix tree must be initialised without
- * __GFP_WAIT being passed to INIT_RADIX_TREE().
+ * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE().
  */
 static int __radix_tree_preload(gfp_t gfp_mask)
 {
@@ -286,12 +286,12 @@ out:
  * with preemption not disabled.
  *
  * To make use of this facility, the radix tree must be initialised without
- * __GFP_WAIT being passed to INIT_RADIX_TREE().
+ * __GFP_DIRECT_RECLAIM being passed to INIT_RADIX_TREE().
  */
 int radix_tree_preload(gfp_t gfp_mask)
 {
        /* Warn on non-sensical use... */
-       WARN_ON_ONCE(!(gfp_mask & __GFP_WAIT));
+       WARN_ON_ONCE(!gfpflags_allow_blocking(gfp_mask));
        return __radix_tree_preload(gfp_mask);
 }
 EXPORT_SYMBOL(radix_tree_preload);
@@ -303,7 +303,7 @@ EXPORT_SYMBOL(radix_tree_preload);
  */
 int radix_tree_maybe_preload(gfp_t gfp_mask)
 {
-       if (gfp_mask & __GFP_WAIT)
+       if (gfpflags_allow_blocking(gfp_mask))
                return __radix_tree_preload(gfp_mask);
        /* Preloading doesn't help anything with this gfp mask, skip it */
        preempt_disable();
index 2df8ddcb0ca0a7f7a055456de4b46a8c55bbfdf1..e7781eb35fd122507149fe8b8306948a95b32455 100644 (file)
@@ -632,7 +632,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
 {
        struct bdi_writeback *wb;
 
-       might_sleep_if(gfp & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(gfp));
 
        if (!memcg_css->parent)
                return &bdi->wb;
index 312a716fa14c2ef0d2780832bc378c05a3d08d16..57312b5d6e12aaf2da3f6acd38a19bbe28959077 100644 (file)
@@ -326,7 +326,7 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
        size_t offset;
        void *retval;
 
-       might_sleep_if(mem_flags & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(mem_flags));
 
        spin_lock_irqsave(&pool->lock, flags);
        list_for_each_entry(page, &pool->page_list, page_list) {
index e208fab362c48c28ab25768a5b381895a123abbd..96d4c94c681b614e844115662327a54dc47ab261 100644 (file)
@@ -2046,7 +2046,7 @@ retry:
        if (unlikely(task_in_memcg_oom(current)))
                goto nomem;
 
-       if (!(gfp_mask & __GFP_WAIT))
+       if (!gfpflags_allow_blocking(gfp_mask))
                goto nomem;
 
        mem_cgroup_events(mem_over_limit, MEMCG_MAX, 1);
@@ -4422,8 +4422,8 @@ static int mem_cgroup_do_precharge(unsigned long count)
 {
        int ret;
 
-       /* Try a single bulk charge without reclaim first */
-       ret = try_charge(mc.to, GFP_KERNEL & ~__GFP_WAIT, count);
+       /* Try a single bulk charge without reclaim first, kswapd may wake */
+       ret = try_charge(mc.to, GFP_KERNEL & ~__GFP_DIRECT_RECLAIM, count);
        if (!ret) {
                mc.precharge += count;
                return ret;
index 4c533bc51d733989f12c9f5e25cad713f647baea..004d42b1dfaf928ab174e057696afa580447f3d9 100644 (file)
@@ -320,13 +320,13 @@ void * mempool_alloc(mempool_t *pool, gfp_t gfp_mask)
        gfp_t gfp_temp;
 
        VM_WARN_ON_ONCE(gfp_mask & __GFP_ZERO);
-       might_sleep_if(gfp_mask & __GFP_WAIT);
+       might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM);
 
        gfp_mask |= __GFP_NOMEMALLOC;   /* don't allocate emergency reserves */
        gfp_mask |= __GFP_NORETRY;      /* don't loop in __alloc_pages */
        gfp_mask |= __GFP_NOWARN;       /* failures are OK */
 
-       gfp_temp = gfp_mask & ~(__GFP_WAIT|__GFP_IO);
+       gfp_temp = gfp_mask & ~(__GFP_DIRECT_RECLAIM|__GFP_IO);
 
 repeat_alloc:
 
@@ -349,7 +349,7 @@ repeat_alloc:
        }
 
        /*
-        * We use gfp mask w/o __GFP_WAIT or IO for the first round.  If
+        * We use gfp mask w/o direct reclaim or IO for the first round.  If
         * alloc failed with that and @pool was empty, retry immediately.
         */
        if (gfp_temp != gfp_mask) {
@@ -358,8 +358,8 @@ repeat_alloc:
                goto repeat_alloc;
        }
 
-       /* We must not sleep if !__GFP_WAIT */
-       if (!(gfp_mask & __GFP_WAIT)) {
+       /* We must not sleep if !__GFP_DIRECT_RECLAIM */
+       if (!(gfp_mask & __GFP_DIRECT_RECLAIM)) {
                spin_unlock_irqrestore(&pool->lock, flags);
                return NULL;
        }
index 94961f4654b7fd6d7fbd32fa179286cc93e0474f..efdf9a31dd6cd47a9fd335c7d4278048aa71c716 100644 (file)
@@ -1576,7 +1576,7 @@ static struct page *alloc_misplaced_dst_page(struct page *page,
                                         (GFP_HIGHUSER_MOVABLE |
                                          __GFP_THISNODE | __GFP_NOMEMALLOC |
                                          __GFP_NORETRY | __GFP_NOWARN) &
-                                        ~GFP_IOFS, 0);
+                                        ~(__GFP_IO | __GFP_FS), 0);
 
        return newpage;
 }
index 7bd10d34b762a30c62f96140b7f56ca081b85239..7c7f7a3098442f36c58ebeb4b309b0e3f518ebce 100644 (file)
@@ -169,12 +169,12 @@ void pm_restrict_gfp_mask(void)
        WARN_ON(!mutex_is_locked(&pm_mutex));
        WARN_ON(saved_gfp_mask);
        saved_gfp_mask = gfp_allowed_mask;
-       gfp_allowed_mask &= ~GFP_IOFS;
+       gfp_allowed_mask &= ~(__GFP_IO | __GFP_FS);
 }
 
 bool pm_suspended_storage(void)
 {
-       if ((gfp_allowed_mask & GFP_IOFS) == GFP_IOFS)
+       if ((gfp_allowed_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS))
                return false;
        return true;
 }
@@ -2183,7 +2183,7 @@ static bool should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
                return false;
        if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM))
                return false;
-       if (fail_page_alloc.ignore_gfp_wait && (gfp_mask & __GFP_WAIT))
+       if (fail_page_alloc.ignore_gfp_wait && (gfp_mask & __GFP_DIRECT_RECLAIM))
                return false;
 
        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, ...)
                if (test_thread_flag(TIF_MEMDIE) ||
                    (current->flags & (PF_MEMALLOC | PF_EXITING)))
                        filter &= ~SHOW_MEM_FILTER_NODES;
-       if (in_interrupt() || !(gfp_mask & __GFP_WAIT))
+       if (in_interrupt() || !(gfp_mask & __GFP_DIRECT_RECLAIM))
                filter &= ~SHOW_MEM_FILTER_NODES;
 
        if (fmt) {
@@ -2945,7 +2945,6 @@ static inline int
 gfp_to_alloc_flags(gfp_t gfp_mask)
 {
        int alloc_flags = ALLOC_WMARK_MIN | ALLOC_CPUSET;
-       const bool atomic = !(gfp_mask & (__GFP_WAIT | __GFP_NO_KSWAPD));
 
        /* __GFP_HIGH is assumed to be the same as ALLOC_HIGH to save a branch. */
        BUILD_BUG_ON(__GFP_HIGH != (__force gfp_t) ALLOC_HIGH);
@@ -2954,11 +2953,11 @@ 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 (atomic == true) and ALLOC_HIGH (__GFP_HIGH).
+        * set both ALLOC_HARDER (__GFP_ATOMIC) and ALLOC_HIGH (__GFP_HIGH).
         */
        alloc_flags |= (__force int) (gfp_mask & __GFP_HIGH);
 
-       if (atomic) {
+       if (gfp_mask & __GFP_ATOMIC) {
                /*
                 * Not worth trying to allocate harder for __GFP_NOMEMALLOC even
                 * if it can't schedule.
@@ -2995,11 +2994,16 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
        return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS);
 }
 
+static inline bool is_thp_gfp_mask(gfp_t gfp_mask)
+{
+       return (gfp_mask & (GFP_TRANSHUGE | __GFP_KSWAPD_RECLAIM)) == GFP_TRANSHUGE;
+}
+
 static inline struct page *
 __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
                                                struct alloc_context *ac)
 {
-       const gfp_t wait = gfp_mask & __GFP_WAIT;
+       bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM;
        struct page *page = NULL;
        int alloc_flags;
        unsigned long pages_reclaimed = 0;
@@ -3019,16 +3023,24 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
                return NULL;
        }
 
+       /*
+        * 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;
+
        /*
         * If this allocation cannot block and it is for a specific node, then
         * fail early.  There's no need to wakeup kswapd or retry for a
         * speculative node-specific allocation.
         */
-       if (IS_ENABLED(CONFIG_NUMA) && (gfp_mask & __GFP_THISNODE) && !wait)
+       if (IS_ENABLED(CONFIG_NUMA) && (gfp_mask & __GFP_THISNODE) && !can_direct_reclaim)
                goto nopage;
 
 retry:
-       if (!(gfp_mask & __GFP_NO_KSWAPD))
+       if (gfp_mask & __GFP_KSWAPD_RECLAIM)
                wake_all_kswapds(order, ac);
 
        /*
@@ -3071,8 +3083,8 @@ retry:
                }
        }
 
-       /* Atomic allocations - we can't balance anything */
-       if (!wait) {
+       /* Caller is not willing to reclaim, we can't balance anything */
+       if (!can_direct_reclaim) {
                /*
                 * All existing users of the deprecated __GFP_NOFAIL are
                 * blockable, so warn of any new users that actually allow this
@@ -3102,7 +3114,7 @@ retry:
                goto got_pg;
 
        /* Checks for THP-specific high-order allocations */
-       if ((gfp_mask & GFP_TRANSHUGE) == GFP_TRANSHUGE) {
+       if (is_thp_gfp_mask(gfp_mask)) {
                /*
                 * If compaction is deferred for high-order allocations, it is
                 * because sync compaction recently failed. If this is the case
@@ -3137,8 +3149,7 @@ retry:
         * fault, so use asynchronous memory compaction for THP unless it is
         * khugepaged trying to collapse.
         */
-       if ((gfp_mask & GFP_TRANSHUGE) != GFP_TRANSHUGE ||
-                                               (current->flags & PF_KTHREAD))
+       if (!is_thp_gfp_mask(gfp_mask) || (current->flags & PF_KTHREAD))
                migration_mode = MIGRATE_SYNC_LIGHT;
 
        /* Try direct reclaim and then allocating */
@@ -3209,7 +3220,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 
        lockdep_trace_alloc(gfp_mask);
 
-       might_sleep_if(gfp_mask & __GFP_WAIT);
+       might_sleep_if(gfp_mask & __GFP_DIRECT_RECLAIM);
 
        if (should_fail_alloc_page(gfp_mask, order))
                return NULL;
index 6b1f04ae04246777ea1ddf3d9fa6f3f468f577ec..02f17758aed52f7422ee131c0dbff39d4169a335 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1030,12 +1030,12 @@ static inline int cache_free_alien(struct kmem_cache *cachep, void *objp)
 }
 
 /*
- * Construct gfp mask to allocate from a specific node but do not invoke reclaim
- * or warn about failures.
+ * Construct gfp mask to allocate from a specific node but do not direct reclaim
+ * or warn about failures. kswapd may still wake to reclaim in the background.
  */
 static inline gfp_t gfp_exact_node(gfp_t flags)
 {
-       return (flags | __GFP_THISNODE | __GFP_NOWARN) & ~__GFP_WAIT;
+       return (flags | __GFP_THISNODE | __GFP_NOWARN) & ~__GFP_DIRECT_RECLAIM;
 }
 #endif
 
@@ -2632,7 +2632,7 @@ static int cache_grow(struct kmem_cache *cachep,
 
        offset *= cachep->colour_off;
 
-       if (local_flags & __GFP_WAIT)
+       if (gfpflags_allow_blocking(local_flags))
                local_irq_enable();
 
        /*
@@ -2662,7 +2662,7 @@ static int cache_grow(struct kmem_cache *cachep,
 
        cache_init_objs(cachep, page);
 
-       if (local_flags & __GFP_WAIT)
+       if (gfpflags_allow_blocking(local_flags))
                local_irq_disable();
        check_irq_off();
        spin_lock(&n->list_lock);
@@ -2676,7 +2676,7 @@ static int cache_grow(struct kmem_cache *cachep,
 opps1:
        kmem_freepages(cachep, page);
 failed:
-       if (local_flags & __GFP_WAIT)
+       if (gfpflags_allow_blocking(local_flags))
                local_irq_disable();
        return 0;
 }
@@ -2868,7 +2868,7 @@ force_grow:
 static inline void cache_alloc_debugcheck_before(struct kmem_cache *cachep,
                                                gfp_t flags)
 {
-       might_sleep_if(flags & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(flags));
 #if DEBUG
        kmem_flagcheck(cachep, flags);
 #endif
@@ -3056,11 +3056,11 @@ retry:
                 */
                struct page *page;
 
-               if (local_flags & __GFP_WAIT)
+               if (gfpflags_allow_blocking(local_flags))
                        local_irq_enable();
                kmem_flagcheck(cache, flags);
                page = kmem_getpages(cache, local_flags, numa_mem_id());
-               if (local_flags & __GFP_WAIT)
+               if (gfpflags_allow_blocking(local_flags))
                        local_irq_disable();
                if (page) {
                        /*
index 455853222ff30a2f68c65a17b645968ad3fb9d7c..5192c3401cb1da954562788f8b9091a58a3eb546 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1282,7 +1282,7 @@ static inline struct kmem_cache *slab_pre_alloc_hook(struct kmem_cache *s,
 {
        flags &= gfp_allowed_mask;
        lockdep_trace_alloc(flags);
-       might_sleep_if(flags & __GFP_WAIT);
+       might_sleep_if(gfpflags_allow_blocking(flags));
 
        if (should_failslab(s->object_size, flags, s->flags))
                return NULL;
@@ -1394,7 +1394,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 
        flags &= gfp_allowed_mask;
 
-       if (flags & __GFP_WAIT)
+       if (gfpflags_allow_blocking(flags))
                local_irq_enable();
 
        flags |= s->allocflags;
@@ -1404,8 +1404,8 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
         * so we fall-back to the minimum order allocation.
         */
        alloc_gfp = (flags | __GFP_NOWARN | __GFP_NORETRY) & ~__GFP_NOFAIL;
-       if ((alloc_gfp & __GFP_WAIT) && oo_order(oo) > oo_order(s->min))
-               alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_WAIT;
+       if ((alloc_gfp & __GFP_DIRECT_RECLAIM) && oo_order(oo) > oo_order(s->min))
+               alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_DIRECT_RECLAIM;
 
        page = alloc_slab_page(s, alloc_gfp, node, oo);
        if (unlikely(!page)) {
@@ -1465,7 +1465,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
        page->frozen = 1;
 
 out:
-       if (flags & __GFP_WAIT)
+       if (gfpflags_allow_blocking(flags))
                local_irq_disable();
        if (!page)
                return NULL;
index b51b73330f875d953c2a3a86a7b4cadb52026990..91e86bc8a945fe3b88927a85655ee9ccad9ccdfb 100644 (file)
@@ -1617,7 +1617,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
                        goto fail;
                }
                area->pages[i] = page;
-               if (gfp_mask & __GFP_WAIT)
+               if (gfpflags_allow_blocking(gfp_mask))
                        cond_resched();
        }
 
index c6d6964c0c104a6c46aa43217f6c87e44d3508aa..b32f544a2704859a0f50667dd4ae995299dd883b 100644 (file)
@@ -1476,7 +1476,7 @@ static int too_many_isolated(struct zone *zone, int file,
         * won't get blocked by normal direct-reclaimers, forming a circular
         * deadlock.
         */
-       if ((sc->gfp_mask & GFP_IOFS) == GFP_IOFS)
+       if ((sc->gfp_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS))
                inactive >>= 3;
 
        return isolated > inactive;
@@ -3791,7 +3791,7 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
        /*
         * Do not scan if the allocation should not be delayed.
         */
-       if (!(gfp_mask & __GFP_WAIT) || (current->flags & PF_MEMALLOC))
+       if (!gfpflags_allow_blocking(gfp_mask) || (current->flags & PF_MEMALLOC))
                return ZONE_RECLAIM_NOSCAN;
 
        /*
index 4043df7c672fb6f5b1be298b8d510fd17a3bbf42..e54166d3732e8e4bae250a0b06607a42863f42c2 100644 (file)
@@ -571,7 +571,7 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
 static struct zswap_pool *zswap_pool_create(char *type, char *compressor)
 {
        struct zswap_pool *pool;
-       gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN;
+       gfp_t gfp = __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM;
 
        pool = kzalloc(sizeof(*pool), GFP_KERNEL);
        if (!pool) {
@@ -1011,7 +1011,8 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
        /* store */
        len = dlen + sizeof(struct zswap_header);
        ret = zpool_malloc(entry->pool->zpool, len,
-                          __GFP_NORETRY | __GFP_NOWARN, &handle);
+                          __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM,
+                          &handle);
        if (ret == -ENOSPC) {
                zswap_reject_compress_poor++;
                goto put_dstmem;
index fab4599ba8b261dc43977af8349a336edc4d2799..aa41e6dd642913f2181832145e22ec1dad6fa7b8 100644 (file)
@@ -414,7 +414,7 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len,
        len += NET_SKB_PAD;
 
        if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) ||
-           (gfp_mask & (__GFP_WAIT | GFP_DMA))) {
+           (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
                skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);
                if (!skb)
                        goto skb_fail;
@@ -481,7 +481,7 @@ struct sk_buff *__napi_alloc_skb(struct napi_struct *napi, unsigned int len,
        len += NET_SKB_PAD + NET_IP_ALIGN;
 
        if ((len > SKB_WITH_OVERHEAD(PAGE_SIZE)) ||
-           (gfp_mask & (__GFP_WAIT | GFP_DMA))) {
+           (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
                skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX, NUMA_NO_NODE);
                if (!skb)
                        goto skb_fail;
@@ -4452,7 +4452,7 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
                return NULL;
 
        gfp_head = gfp_mask;
-       if (gfp_head & __GFP_WAIT)
+       if (gfp_head & __GFP_DIRECT_RECLAIM)
                gfp_head |= __GFP_REPEAT;
 
        *errcode = -ENOBUFS;
@@ -4467,7 +4467,7 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len,
 
                while (order) {
                        if (npages >= 1 << order) {
-                               page = alloc_pages((gfp_mask & ~__GFP_WAIT) |
+                               page = alloc_pages((gfp_mask & ~__GFP_DIRECT_RECLAIM) |
                                                   __GFP_COMP |
                                                   __GFP_NOWARN |
                                                   __GFP_NORETRY,
index 3307c02244d39cfa3fbae969ea478fa0f195e595..8cab9d90b0185cfe216d75ecf932b75b31b0a222 100644 (file)
@@ -1879,8 +1879,10 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t gfp)
 
        pfrag->offset = 0;
        if (SKB_FRAG_PAGE_ORDER) {
-               pfrag->page = alloc_pages((gfp & ~__GFP_WAIT) | __GFP_COMP |
-                                         __GFP_NOWARN | __GFP_NORETRY,
+               /* Avoid direct reclaim but allow kswapd to wake */
+               pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) |
+                                         __GFP_COMP | __GFP_NOWARN |
+                                         __GFP_NORETRY,
                                          SKB_FRAG_PAGE_ORDER);
                if (likely(pfrag->page)) {
                        pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER;
index 0a49a8c7c56432989de924e01563f692cf10e545..ab061cca59d2265d018fc109c2becd2ca626306c 100644 (file)
@@ -2116,7 +2116,7 @@ int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, u32 portid
        consume_skb(info.skb2);
 
        if (info.delivered) {
-               if (info.congested && (allocation & __GFP_WAIT))
+               if (info.congested && gfpflags_allow_blocking(allocation))
                        yield();
                return 0;
        }
index f43831e4186a3543af1b8cd8beba803c66a233d3..dcfb59775acc2bccdce963a06998a1b2d1fa70a0 100644 (file)
@@ -305,7 +305,7 @@ static int rds_ib_recv_refill_one(struct rds_connection *conn,
        gfp_t slab_mask = GFP_NOWAIT;
        gfp_t page_mask = GFP_NOWAIT;
 
-       if (gfp & __GFP_WAIT) {
+       if (gfp & __GFP_DIRECT_RECLAIM) {
                slab_mask = GFP_KERNEL;
                page_mask = GFP_HIGHUSER;
        }
@@ -379,7 +379,7 @@ void rds_ib_recv_refill(struct rds_connection *conn, int prefill, gfp_t gfp)
        struct ib_recv_wr *failed_wr;
        unsigned int posted = 0;
        int ret = 0;
-       bool can_wait = !!(gfp & __GFP_WAIT);
+       bool can_wait = !!(gfp & __GFP_DIRECT_RECLAIM);
        u32 pos;
 
        /* the goal here is to just make sure that someone, somewhere
index 6631f4f1e39be713029c8b9b504db4ea741fb3e6..3b5de4b86058334b4d762ef965e86f2877503932 100644 (file)
@@ -500,7 +500,7 @@ int rxrpc_connect_call(struct rxrpc_sock *rx,
                if (bundle->num_conns >= 20) {
                        _debug("too many conns");
 
-                       if (!(gfp & __GFP_WAIT)) {
+                       if (!gfpflags_allow_blocking(gfp)) {
                                _leave(" = -EAGAIN");
                                return -EAGAIN;
                        }
index b00f1f9611d64a7f46fdd37460d9c5ec9711f37f..559afd0ee7de099ba013c8921045fedb4e7e5488 100644 (file)
@@ -1590,7 +1590,7 @@ int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
 /* Set an association id for a given association */
 int sctp_assoc_set_id(struct sctp_association *asoc, gfp_t gfp)
 {
-       bool preload = !!(gfp & __GFP_WAIT);
+       bool preload = gfpflags_allow_blocking(gfp);
        int ret;
 
        /* If the id is already assigned, keep it. */