Skip to content

Commit 19809c2

Browse files
Michal Hockotorvalds
authored andcommitted
mm, vmalloc: use __GFP_HIGHMEM implicitly
__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>
1 parent 54f180d commit 19809c2

File tree

20 files changed

+31
-41
lines changed

20 files changed

+31
-41
lines changed

arch/parisc/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void *module_alloc(unsigned long size)
218218
* easier than trying to map the text, data, init_text and
219219
* init_data correctly */
220220
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
221-
GFP_KERNEL | __GFP_HIGHMEM,
221+
GFP_KERNEL,
222222
PAGE_KERNEL_RWX, 0, NUMA_NO_NODE,
223223
__builtin_return_address(0));
224224
}

arch/x86/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void *module_alloc(unsigned long size)
8585

8686
p = __vmalloc_node_range(size, MODULE_ALIGN,
8787
MODULES_VADDR + get_module_load_offset(),
88-
MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
88+
MODULES_END, GFP_KERNEL,
8989
PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
9090
__builtin_return_address(0));
9191
if (p && (kasan_module_alloc(p, size) < 0)) {

drivers/block/drbd/drbd_bitmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static struct page **bm_realloc_pages(struct drbd_bitmap *b, unsigned long want)
409409
new_pages = kzalloc(bytes, GFP_NOIO | __GFP_NOWARN);
410410
if (!new_pages) {
411411
new_pages = __vmalloc(bytes,
412-
GFP_NOIO | __GFP_HIGHMEM | __GFP_ZERO,
412+
GFP_NOIO | __GFP_ZERO,
413413
PAGE_KERNEL);
414414
if (!new_pages)
415415
return NULL;

drivers/gpu/drm/etnaviv/etnaviv_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)
161161
file_size += sizeof(*iter.hdr) * n_obj;
162162

163163
/* Allocate the file in vmalloc memory, it's likely to be big */
164-
iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_HIGHMEM |
165-
__GFP_NOWARN | __GFP_NORETRY, PAGE_KERNEL);
164+
iter.start = __vmalloc(file_size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
165+
PAGE_KERNEL);
166166
if (!iter.start) {
167167
dev_warn(gpu->dev, "failed to allocate devcoredump file\n");
168168
return;

drivers/md/dm-bufio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
406406
if (gfp_mask & __GFP_NORETRY)
407407
noio_flag = memalloc_noio_save();
408408

409-
ptr = __vmalloc(c->block_size, gfp_mask | __GFP_HIGHMEM, PAGE_KERNEL);
409+
ptr = __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
410410

411411
if (gfp_mask & __GFP_NORETRY)
412412
memalloc_noio_restore(noio_flag);

fs/btrfs/free-space-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ static u8 *alloc_bitmap(u32 bitmap_size)
167167
if (mem)
168168
return mem;
169169

170-
return __vmalloc(bitmap_size, GFP_NOFS | __GFP_HIGHMEM | __GFP_ZERO,
171-
PAGE_KERNEL);
170+
return __vmalloc(bitmap_size, GFP_NOFS | __GFP_ZERO, PAGE_KERNEL);
172171
}
173172

174173
int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,

fs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static void *alloc_fdmem(size_t size)
4242
if (data != NULL)
4343
return data;
4444
}
45-
return __vmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_HIGHMEM, PAGE_KERNEL);
45+
return __vmalloc(size, GFP_KERNEL_ACCOUNT, PAGE_KERNEL);
4646
}
4747

4848
static void __free_fdtable(struct fdtable *fdt)

fs/xfs/kmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
6767
nofs_flag = memalloc_nofs_save();
6868

6969
lflags = kmem_flags_convert(flags);
70-
ptr = __vmalloc(size, lflags | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
70+
ptr = __vmalloc(size, lflags | __GFP_ZERO, PAGE_KERNEL);
7171

7272
if (flags & KM_NOFS)
7373
memalloc_nofs_restore(nofs_flag);

include/drm/drm_mem_util.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ static __inline__ void *drm_calloc_large(size_t nmemb, size_t size)
3737
if (size * nmemb <= PAGE_SIZE)
3838
return kcalloc(nmemb, size, GFP_KERNEL);
3939

40-
return __vmalloc(size * nmemb,
41-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
40+
return vzalloc(size * nmemb);
4241
}
4342

4443
/* 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)
5049
if (size * nmemb <= PAGE_SIZE)
5150
return kmalloc(nmemb * size, GFP_KERNEL);
5251

53-
return __vmalloc(size * nmemb,
54-
GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL);
52+
return vmalloc(size * nmemb);
5553
}
5654

5755
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)
6967
return ptr;
7068
}
7169

72-
return __vmalloc(size * nmemb,
73-
gfp | __GFP_HIGHMEM, PAGE_KERNEL);
70+
return __vmalloc(size * nmemb, gfp, PAGE_KERNEL);
7471
}
7572

7673
static __inline void drm_free_large(void *ptr)

kernel/bpf/core.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
7676

7777
struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
7878
{
79-
gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
80-
gfp_extra_flags;
79+
gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
8180
struct bpf_prog_aux *aux;
8281
struct bpf_prog *fp;
8382

@@ -107,8 +106,7 @@ EXPORT_SYMBOL_GPL(bpf_prog_alloc);
107106
struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
108107
gfp_t gfp_extra_flags)
109108
{
110-
gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
111-
gfp_extra_flags;
109+
gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
112110
struct bpf_prog *fp;
113111
u32 pages, delta;
114112
int ret;
@@ -655,8 +653,7 @@ static int bpf_jit_blind_insn(const struct bpf_insn *from,
655653
static struct bpf_prog *bpf_prog_clone_create(struct bpf_prog *fp_other,
656654
gfp_t gfp_extra_flags)
657655
{
658-
gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
659-
gfp_extra_flags;
656+
gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO | gfp_extra_flags;
660657
struct bpf_prog *fp;
661658

662659
fp = __vmalloc(fp_other->pages * PAGE_SIZE, gfp_flags, PAGE_KERNEL);

kernel/bpf/syscall.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ void *bpf_map_area_alloc(size_t size)
6767
return area;
6868
}
6969

70-
return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | flags,
71-
PAGE_KERNEL);
70+
return __vmalloc(size, GFP_KERNEL | flags, PAGE_KERNEL);
7271
}
7372

7473
void bpf_map_area_free(void *area)

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node)
221221

222222
stack = __vmalloc_node_range(THREAD_SIZE, THREAD_SIZE,
223223
VMALLOC_START, VMALLOC_END,
224-
THREADINFO_GFP | __GFP_HIGHMEM,
224+
THREADINFO_GFP,
225225
PAGE_KERNEL,
226226
0, node, __builtin_return_address(0));
227227

kernel/groups.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct group_info *groups_alloc(int gidsetsize)
1818
len = sizeof(struct group_info) + sizeof(kgid_t) * gidsetsize;
1919
gi = kmalloc(len, GFP_KERNEL_ACCOUNT|__GFP_NOWARN|__GFP_NORETRY);
2020
if (!gi)
21-
gi = __vmalloc(len, GFP_KERNEL_ACCOUNT|__GFP_HIGHMEM, PAGE_KERNEL);
21+
gi = __vmalloc(len, GFP_KERNEL_ACCOUNT, PAGE_KERNEL);
2222
if (!gi)
2323
return NULL;
2424

kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2864,7 +2864,7 @@ static int copy_module_from_user(const void __user *umod, unsigned long len,
28642864

28652865
/* Suck in entire file: we'll want most of it. */
28662866
info->hdr = __vmalloc(info->len,
2867-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_NOWARN, PAGE_KERNEL);
2867+
GFP_KERNEL | __GFP_NOWARN, PAGE_KERNEL);
28682868
if (!info->hdr)
28692869
return -ENOMEM;
28702870

mm/kasan/kasan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ int kasan_module_alloc(void *addr, size_t size)
691691

692692
ret = __vmalloc_node_range(shadow_size, 1, shadow_start,
693693
shadow_start + shadow_size,
694-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
694+
GFP_KERNEL | __GFP_ZERO,
695695
PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE,
696696
__builtin_return_address(0));
697697

mm/nommu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ void *vmalloc_user(unsigned long size)
246246
{
247247
void *ret;
248248

249-
ret = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
250-
PAGE_KERNEL);
249+
ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
251250
if (ret) {
252251
struct vm_area_struct *vma;
253252

mm/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void *kvmalloc_node(size_t size, gfp_t flags, int node)
382382
if (ret || size <= PAGE_SIZE)
383383
return ret;
384384

385-
return __vmalloc_node_flags(size, node, flags | __GFP_HIGHMEM);
385+
return __vmalloc_node_flags(size, node, flags);
386386
}
387387
EXPORT_SYMBOL(kvmalloc_node);
388388

mm/vmalloc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
16551655
struct page **pages;
16561656
unsigned int nr_pages, array_size, i;
16571657
const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
1658-
const gfp_t alloc_mask = gfp_mask | __GFP_NOWARN;
1658+
const gfp_t alloc_mask = gfp_mask | __GFP_HIGHMEM | __GFP_NOWARN;
16591659

16601660
nr_pages = get_vm_area_size(area) >> PAGE_SHIFT;
16611661
array_size = (nr_pages * sizeof(struct page *));
@@ -1818,7 +1818,7 @@ EXPORT_SYMBOL(__vmalloc);
18181818
void *vmalloc(unsigned long size)
18191819
{
18201820
return __vmalloc_node_flags(size, NUMA_NO_NODE,
1821-
GFP_KERNEL | __GFP_HIGHMEM);
1821+
GFP_KERNEL);
18221822
}
18231823
EXPORT_SYMBOL(vmalloc);
18241824

@@ -1835,7 +1835,7 @@ EXPORT_SYMBOL(vmalloc);
18351835
void *vzalloc(unsigned long size)
18361836
{
18371837
return __vmalloc_node_flags(size, NUMA_NO_NODE,
1838-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
1838+
GFP_KERNEL | __GFP_ZERO);
18391839
}
18401840
EXPORT_SYMBOL(vzalloc);
18411841

@@ -1852,7 +1852,7 @@ void *vmalloc_user(unsigned long size)
18521852
void *ret;
18531853

18541854
ret = __vmalloc_node(size, SHMLBA,
1855-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
1855+
GFP_KERNEL | __GFP_ZERO,
18561856
PAGE_KERNEL, NUMA_NO_NODE,
18571857
__builtin_return_address(0));
18581858
if (ret) {
@@ -1876,7 +1876,7 @@ EXPORT_SYMBOL(vmalloc_user);
18761876
*/
18771877
void *vmalloc_node(unsigned long size, int node)
18781878
{
1879-
return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
1879+
return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL,
18801880
node, __builtin_return_address(0));
18811881
}
18821882
EXPORT_SYMBOL(vmalloc_node);
@@ -1896,7 +1896,7 @@ EXPORT_SYMBOL(vmalloc_node);
18961896
void *vzalloc_node(unsigned long size, int node)
18971897
{
18981898
return __vmalloc_node_flags(size, node,
1899-
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
1899+
GFP_KERNEL | __GFP_ZERO);
19001900
}
19011901
EXPORT_SYMBOL(vzalloc_node);
19021902

@@ -1918,7 +1918,7 @@ EXPORT_SYMBOL(vzalloc_node);
19181918

19191919
void *vmalloc_exec(unsigned long size)
19201920
{
1921-
return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
1921+
return __vmalloc_node(size, 1, GFP_KERNEL, PAGE_KERNEL_EXEC,
19221922
NUMA_NO_NODE, __builtin_return_address(0));
19231923
}
19241924

net/ceph/ceph_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void *ceph_kvmalloc(size_t size, gfp_t flags)
187187
return ptr;
188188
}
189189

190-
return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL);
190+
return __vmalloc(size, flags, PAGE_KERNEL);
191191
}
192192

193193

net/netfilter/x_tables.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,7 @@ struct xt_table_info *xt_alloc_table_info(unsigned int size)
998998
if (sz <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
999999
info = kmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
10001000
if (!info) {
1001-
info = __vmalloc(sz, GFP_KERNEL | __GFP_NOWARN |
1002-
__GFP_NORETRY | __GFP_HIGHMEM,
1001+
info = __vmalloc(sz, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY,
10031002
PAGE_KERNEL);
10041003
if (!info)
10051004
return NULL;

0 commit comments

Comments
 (0)