mm, vmalloc: use __GFP_HIGHMEM implicitly
authorMichal Hocko <mhocko@suse.com>
Mon, 8 May 2017 22:57:44 +0000 (15:57 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 May 2017 00:15:13 +0000 (17:15 -0700)
__vmalloc* allows users to provide gfp flags for the underlying
allocation.  This API is quite popular

  $ git grep "=[[:space:]]__vmalloc\|return[[:space:]]*__vmalloc" | wc -l
  77

The only problem is that many people are not aware that they really want
to give __GFP_HIGHMEM along with other flags because there is really no
reason to consume precious lowmemory on CONFIG_HIGHMEM systems for pages
which are mapped to the kernel vmalloc space.  About half of users don't
use this flag, though.  This signals that we make the API unnecessarily
too complex.

This patch simply uses __GFP_HIGHMEM implicitly when allocating pages to
be mapped to the vmalloc space.  Current users which add __GFP_HIGHMEM
are simplified and drop the flag.

Link: http://lkml.kernel.org/r/20170307141020.29107-1-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: David Rientjes <rientjes@google.com>
Cc: Cristopher Lameter <cl@linux.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
20 files changed:
arch/parisc/kernel/module.c
arch/x86/kernel/module.c
drivers/block/drbd/drbd_bitmap.c
drivers/gpu/drm/etnaviv/etnaviv_dump.c
drivers/md/dm-bufio.c
fs/btrfs/free-space-tree.c
fs/file.c
fs/xfs/kmem.c
include/drm/drm_mem_util.h
kernel/bpf/core.c
kernel/bpf/syscall.c
kernel/fork.c
kernel/groups.c
kernel/module.c
mm/kasan/kasan.c
mm/nommu.c
mm/util.c
mm/vmalloc.c
net/ceph/ceph_common.c
net/netfilter/x_tables.c

index c66c943d93224f342cb71c97bd6a690bf8fb225b..f1a76935a3149495c8a65faeee8028295c24e559 100644 (file)
@@ -218,7 +218,7 @@ void *module_alloc(unsigned long size)
         * easier than trying to map the text, data, init_text and
         * init_data correctly */
        return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
-                                   GFP_KERNEL | __GFP_HIGHMEM,
+                                   GFP_KERNEL,
                                    PAGE_KERNEL_RWX, 0, NUMA_NO_NODE,
                                    __builtin_return_address(0));
 }
index 477ae806c2fa71f425ff56a8b75b1306dfcf7535..f67bd3205df7aafd61d22d55b0a4f4573bf90b9e 100644 (file)
@@ -85,7 +85,7 @@ void *module_alloc(unsigned long size)
 
        p = __vmalloc_node_range(size, MODULE_ALIGN,
                                    MODULES_VADDR + get_module_load_offset(),
-                                   MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
+                                   MODULES_END, GFP_KERNEL,
                                    PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
                                    __builtin_return_address(0));
        if (p && (kasan_module_alloc(p, size) < 0)) {
index dece26f119d4a637f742dca833b7ec9eecd25ebe..a804a4107fbc132795ae67a000f2b517b1047d32 100644 (file)
@@ -409,7 +409,7 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
        new_pages = kzalloc(bytes, GFP_NOIO | __GFP_NOWARN);
        if (!new_pages) {
                new_pages = __vmalloc(bytes,
-                               GFP_NOIO | __GFP_HIGHMEM | __GFP_ZERO,
+                               GFP_NOIO | __GFP_ZERO,
                                PAGE_KERNEL);
                if (!new_pages)
                        return NULL;
index d019b5e311cc5502e2d273525ea4144f5d0a796d..2d955d7d7b6d83ecdfae58e5bf26084f28a98999 100644 (file)
@@ -161,8 +161,8 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
        file_size += sizeof(*iter.hdr) * n_obj;
 
        /* Allocate the file in vmalloc memory, it's likely to be big */
-       iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_HIGHMEM |
-                              __GFP_NOWARN | __GFP_NORETRY, PAGE_KERNEL);
+       iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
+                              PAGE_KERNEL);
        if (!iter.start) {
                dev_warn(gpu->dev, "failed to allocate devcoredump file\n");
                return;
index c92c31b23e543b8b68fec94918348f79740a9a61..5db11a40512940df04d0dc871498830ec45f03ee 100644 (file)
@@ -406,7 +406,7 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
        if (gfp_mask & __GFP_NORETRY)
                noio_flag = memalloc_noio_save();
 
-       ptr = __vmalloc(c->block_size, gfp_mask | __GFP_HIGHMEM, PAGE_KERNEL);
+       ptr = __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
 
        if (gfp_mask & __GFP_NORETRY)
                memalloc_noio_restore(noio_flag);
index dd7fb22a955a6bff32be4632053bcd9086efe6e2..fc0bd84067582523b958db030a3439d1088f5832 100644 (file)
@@ -167,8 +167,7 @@ static u8 *alloc_bitmap(u32 bitmap_size)
        if (mem)
                return mem;
 
-       return __vmalloc(bitmap_size, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,
-                        PAGE_KERNEL);
+       return __vmalloc(bitmap_size, GFP_NOFS | __GFP_ZERO, PAGE_KERNEL);
 }
 
 int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
index ad6f094f2eff2f90314d237fa3f3cb16c5b79b66..1c2972e3a405455e292520032342276cc621d369 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -42,7 +42,7 @@ static void *alloc_fdmem(size_t size)
                if (data != NULL)
                        return data;
        }
-       return __vmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
+       return __vmalloc(size, GFP_KERNEL_ACCOUNT, PAGE_KERNEL);
 }
 
 static void __free_fdtable(struct fdtable *fdt)
index 780fc8986dabd163058747e6b71e3aae90b7e67c..393b6849aeb31991ed43808ff213fb3cadba00d0 100644 (file)
@@ -67,7 +67,7 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
                nofs_flag = memalloc_nofs_save();
 
        lflags = kmem_flags_convert(flags);
-       ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
+       ptr = __vmalloc(size, lflags | __GFP_ZERO, PAGE_KERNEL);
 
        if (flags & KM_NOFS)
                memalloc_nofs_restore(nofs_flag);
index 70d4e221a3adb485ff7927c33737db23a127b577..d0f6cf2e5324411ac20d3f53515df0899a9601ed 100644 (file)
@@ -37,8 +37,7 @@ static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
        if (size * nmemb <= PAGE_SIZE)
            return kcalloc(nmemb, size, GFP_KERNEL);
 
-       return __vmalloc(size * nmemb,
-                        GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
+       return vzalloc(size * nmemb);
 }
 
 /* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */
@@ -50,8 +49,7 @@ static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size)
        if (size * nmemb <= PAGE_SIZE)
            return kmalloc(nmemb * size, GFP_KERNEL);
 
-       return __vmalloc(size * nmemb,
-                        GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
+       return vmalloc(size * nmemb);
 }
 
 static __inline__ void *drm_malloc_gfp(size_t nmemb, size_t size, gfp_t gfp)
@@ -69,8 +67,7 @@ static __inline__ void *drm_malloc_gfp(size_t nmemb, size_t size, gfp_t gfp)
                        return ptr;
        }
 
-       return __vmalloc(size * nmemb,
-                        gfp | __GFP_HIGHMEM, PAGE_KERNEL);
+       return __vmalloc(size * nmemb, gfp, PAGE_KERNEL);
 }
 
 static __inline void drm_free_large(void *ptr)
index 6f81e0f5a0faa2f7df85ae1771f9dfde48e59651..dedf367f59bba529ded5603d61782bccb80782cb 100644 (file)
@@ -76,8 +76,7 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
 
 struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
 {
-       gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
-                         gfp_extra_flags;
+       gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
        struct bpf_prog_aux *aux;
        struct bpf_prog *fp;
 
@@ -107,8 +106,7 @@ EXPORT_SYMBOL_GPL(bpf_prog_alloc);
 struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
                                  gfp_t gfp_extra_flags)
 {
-       gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
-                         gfp_extra_flags;
+       gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
        struct bpf_prog *fp;
        u32 pages, delta;
        int ret;
@@ -655,8 +653,7 @@ out:
 static struct bpf_prog *bpf_prog_clone_create(struct bpf_prog *fp_other,
                                              gfp_t gfp_extra_flags)
 {
-       gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
-                         gfp_extra_flags;
+       gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
        struct bpf_prog *fp;
 
        fp = __vmalloc(fp_other->pages * PAGE_SIZE, gfp_flags, PAGE_KERNEL);
index 13642c73dca0b4c4461099f3a2774d8ec733160e..fd2411fd69148cff375120316fba0a0e033541f6 100644 (file)
@@ -67,8 +67,7 @@ void *bpf_map_area_alloc(size_t size)
                        return area;
        }
 
-       return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | flags,
-                        PAGE_KERNEL);
+       return __vmalloc(size, GFP_KERNEL | flags, PAGE_KERNEL);
 }
 
 void bpf_map_area_free(void *area)
index 55e325f4b45747ddd95bb5c362434364fca40977..08ba696aa56119e669c3edb158bf2f153073dae2 100644 (file)
@@ -221,7 +221,7 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
 
        stack = __vmalloc_node_range(THREAD_SIZE, THREAD_SIZE,
                                     VMALLOC_START, VMALLOC_END,
-                                    THREADINFO_GFP | __GFP_HIGHMEM,
+                                    THREADINFO_GFP,
                                     PAGE_KERNEL,
                                     0, node, __builtin_return_address(0));
 
index 8dd7a61b7115e8808408cd2cb911d224a9528297..d09727692a2af1801fb82982d4a08daee5c86d62 100644 (file)
@@ -18,7 +18,7 @@ struct group_info *groups_alloc(int gidsetsize)
        len = sizeof(struct group_info) + sizeof(kgid_t) * gidsetsize;
        gi = kmalloc(len, GFP_KERNEL_ACCOUNT|__GFP_NOWARN|__GFP_NORETRY);
        if (!gi)
-               gi = __vmalloc(len, GFP_KERNEL_ACCOUNT|__GFP_HIGHMEM, PAGE_KERNEL);
+               gi = __vmalloc(len, GFP_KERNEL_ACCOUNT, PAGE_KERNEL);
        if (!gi)
                return NULL;
 
index f37308b733d845526918588d2948673925e7ac5b..2b316b95482817c30a972276d204ada3787f79f3 100644 (file)
@@ -2864,7 +2864,7 @@ static int copy_module_from_user(const void __user *umod, unsigned long len,
 
        /* Suck in entire file: we'll want most of it. */
        info->hdr = __vmalloc(info->len,
-                       GFP_KERNEL | __GFP_HIGHMEM | __GFP_NOWARN, PAGE_KERNEL);
+                       GFP_KERNEL | __GFP_NOWARN, PAGE_KERNEL);
        if (!info->hdr)
                return -ENOMEM;
 
index 9348d27088c1145872495859c8eee26f6dc7f23f..b10da59cf7654c71a17d3971035e29dcd36872a6 100644 (file)
@@ -691,7 +691,7 @@ int kasan_module_alloc(void *addr, size_t size)
 
        ret = __vmalloc_node_range(shadow_size, 1, shadow_start,
                        shadow_start + shadow_size,
-                       GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                       GFP_KERNEL | __GFP_ZERO,
                        PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE,
                        __builtin_return_address(0));
 
index a80411d258fc7d42870538fb5679a63260904e32..fc184f597d59d9af942f8dc60229b999173fe22f 100644 (file)
@@ -246,8 +246,7 @@ void *vmalloc_user(unsigned long size)
 {
        void *ret;
 
-       ret = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
-                       PAGE_KERNEL);
+       ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
        if (ret) {
                struct vm_area_struct *vma;
 
index f4e590b2c0dad1d5c27ebf4aa72ba6521543ddb3..718154debc870bc0f8b5af923c3464d50a9cad66 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -382,7 +382,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
        if (ret || size <= PAGE_SIZE)
                return ret;
 
-       return __vmalloc_node_flags(size, node, flags | __GFP_HIGHMEM);
+       return __vmalloc_node_flags(size, node, flags);
 }
 EXPORT_SYMBOL(kvmalloc_node);
 
index 717b1e8b942c52260dc9d44eaff7ac4d728869cc..1dda6d8a200a899bb95874ab88d0800340c669be 100644 (file)
@@ -1655,7 +1655,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
        struct page **pages;
        unsigned int nr_pages, array_size, i;
        const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
-       const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN;
+       const gfp_t alloc_mask = gfp_mask | __GFP_HIGHMEM | __GFP_NOWARN;
 
        nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
        array_size = (nr_pages * sizeof(struct page *));
@@ -1818,7 +1818,7 @@ EXPORT_SYMBOL(__vmalloc);
 void *vmalloc(unsigned long size)
 {
        return __vmalloc_node_flags(size, NUMA_NO_NODE,
-                                   GFP_KERNEL | __GFP_HIGHMEM);
+                                   GFP_KERNEL);
 }
 EXPORT_SYMBOL(vmalloc);
 
@@ -1835,7 +1835,7 @@ EXPORT_SYMBOL(vmalloc);
 void *vzalloc(unsigned long size)
 {
        return __vmalloc_node_flags(size, NUMA_NO_NODE,
-                               GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
+                               GFP_KERNEL | __GFP_ZERO);
 }
 EXPORT_SYMBOL(vzalloc);
 
@@ -1852,7 +1852,7 @@ void *vmalloc_user(unsigned long size)
        void *ret;
 
        ret = __vmalloc_node(size, SHMLBA,
-                            GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                            GFP_KERNEL | __GFP_ZERO,
                             PAGE_KERNEL, NUMA_NO_NODE,
                             __builtin_return_address(0));
        if (ret) {
@@ -1876,7 +1876,7 @@ EXPORT_SYMBOL(vmalloc_user);
  */
 void *vmalloc_node(unsigned long size, int node)
 {
-       return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
+       return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL,
                                        node, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(vmalloc_node);
@@ -1896,7 +1896,7 @@ EXPORT_SYMBOL(vmalloc_node);
 void *vzalloc_node(unsigned long size, int node)
 {
        return __vmalloc_node_flags(size, node,
-                        GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
+                        GFP_KERNEL | __GFP_ZERO);
 }
 EXPORT_SYMBOL(vzalloc_node);
 
@@ -1918,7 +1918,7 @@ EXPORT_SYMBOL(vzalloc_node);
 
 void *vmalloc_exec(unsigned long size)
 {
-       return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
+       return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL_EXEC,
                              NUMA_NO_NODE, __builtin_return_address(0));
 }
 
index 108533859a53292cde61a3cedd052a2579684e87..4eb773ccce110aad98051636ed28c1b61121df04 100644 (file)
@@ -187,7 +187,7 @@ void *ceph_kvmalloc(size_t size, gfp_t flags)
                        return ptr;
        }
 
-       return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL);
+       return __vmalloc(size, flags, PAGE_KERNEL);
 }
 
 
index 3d0584665b5ddd55f5572ce89708274a93840a6c..8876b7da6884c210393d1988032cbb5bd7018507 100644 (file)
@@ -998,8 +998,7 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
        if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
                info = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
        if (!info) {
-               info = __vmalloc(sz, GFP_KERNEL | __GFP_NOWARN |
-                                    __GFP_NORETRY | __GFP_HIGHMEM,
+               info = __vmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
                                 PAGE_KERNEL);
                if (!info)
                        return NULL;