Skip to content

Commit 559089e

Browse files
liu-song-6torvalds
authored andcommitted
vmalloc: replace VM_NO_HUGE_VMAP with VM_ALLOW_HUGE_VMAP
Huge page backed vmalloc memory could benefit performance in many cases. However, some users of vmalloc may not be ready to handle huge pages for various reasons: hardware constraints, potential pages split, etc. VM_NO_HUGE_VMAP was introduced to allow vmalloc users to opt-out huge pages. However, it is not easy to track down all the users that require the opt-out, as the allocation are passed different stacks and may cause issues in different layers. To address this issue, replace VM_NO_HUGE_VMAP with an opt-in flag, VM_ALLOW_HUGE_VMAP, so that users that benefit from huge pages could ask specificially. Also, remove vmalloc_no_huge() and add opt-in helper vmalloc_huge(). Fixes: fac54e2 ("x86/Kconfig: Select HAVE_ARCH_HUGE_VMALLOC with HAVE_ARCH_HUGE_VMAP") Link: https://lore.kernel.org/netdev/14444103-d51b-0fb3-ee63-c3f182f0b546@molgen.mpg.de/" Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Song Liu <song@kernel.org> Reviewed-by: Rik van Riel <riel@surriel.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b7f7340 commit 559089e

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

arch/Kconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,8 @@ config HAVE_ARCH_HUGE_VMAP
854854

855855
#
856856
# Archs that select this would be capable of PMD-sized vmaps (i.e.,
857-
# arch_vmap_pmd_supported() returns true), and they must make no assumptions
858-
# that vmalloc memory is mapped with PAGE_SIZE ptes. The VM_NO_HUGE_VMAP flag
859-
# can be used to prohibit arch-specific allocations from using hugepages to
860-
# help with this (e.g., modules may require it).
857+
# arch_vmap_pmd_supported() returns true). The VM_ALLOW_HUGE_VMAP flag
858+
# must be used to enable allocations to use hugepages.
861859
#
862860
config HAVE_ARCH_HUGE_VMALLOC
863861
depends on HAVE_ARCH_HUGE_VMAP

arch/powerpc/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ __module_alloc(unsigned long size, unsigned long start, unsigned long end, bool
101101
* too.
102102
*/
103103
return __vmalloc_node_range(size, 1, start, end, gfp, prot,
104-
VM_FLUSH_RESET_PERMS | VM_NO_HUGE_VMAP,
104+
VM_FLUSH_RESET_PERMS,
105105
NUMA_NO_NODE, __builtin_return_address(0));
106106
}
107107

arch/s390/kvm/pv.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,7 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)
137137
/* Allocate variable storage */
138138
vlen = ALIGN(virt * ((npages * PAGE_SIZE) / HPAGE_SIZE), PAGE_SIZE);
139139
vlen += uv_info.guest_virt_base_stor_len;
140-
/*
141-
* The Create Secure Configuration Ultravisor Call does not support
142-
* using large pages for the virtual memory area.
143-
* This is a hardware limitation.
144-
*/
145-
kvm->arch.pv.stor_var = vmalloc_no_huge(vlen);
140+
kvm->arch.pv.stor_var = vzalloc(vlen);
146141
if (!kvm->arch.pv.stor_var)
147142
goto out_err;
148143
return 0;

include/linux/vmalloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct notifier_block; /* in notifier.h */
2626
#define VM_KASAN 0x00000080 /* has allocated kasan shadow memory */
2727
#define VM_FLUSH_RESET_PERMS 0x00000100 /* reset direct map and flush TLB on unmap, can't be freed in atomic context */
2828
#define VM_MAP_PUT_PAGES 0x00000200 /* put pages and free array in vfree */
29-
#define VM_NO_HUGE_VMAP 0x00000400 /* force PAGE_SIZE pte mapping */
29+
#define VM_ALLOW_HUGE_VMAP 0x00000400 /* Allow for huge pages on archs with HAVE_ARCH_HUGE_VMALLOC */
3030

3131
#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
3232
!defined(CONFIG_KASAN_VMALLOC)
@@ -153,7 +153,7 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
153153
const void *caller) __alloc_size(1);
154154
void *__vmalloc_node(unsigned long size, unsigned long align, gfp_t gfp_mask,
155155
int node, const void *caller) __alloc_size(1);
156-
void *vmalloc_no_huge(unsigned long size) __alloc_size(1);
156+
void *vmalloc_huge(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
157157

158158
extern void *__vmalloc_array(size_t n, size_t size, gfp_t flags) __alloc_size(1, 2);
159159
extern void *vmalloc_array(size_t n, size_t size) __alloc_size(1, 2);

mm/vmalloc.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,7 +3095,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
30953095
return NULL;
30963096
}
30973097

3098-
if (vmap_allow_huge && !(vm_flags & VM_NO_HUGE_VMAP)) {
3098+
if (vmap_allow_huge && (vm_flags & VM_ALLOW_HUGE_VMAP)) {
30993099
unsigned long size_per_node;
31003100

31013101
/*
@@ -3262,21 +3262,24 @@ void *vmalloc(unsigned long size)
32623262
EXPORT_SYMBOL(vmalloc);
32633263

32643264
/**
3265-
* vmalloc_no_huge - allocate virtually contiguous memory using small pages
3266-
* @size: allocation size
3265+
* vmalloc_huge - allocate virtually contiguous memory, allow huge pages
3266+
* @size: allocation size
3267+
* @gfp_mask: flags for the page level allocator
32673268
*
3268-
* Allocate enough non-huge pages to cover @size from the page level
3269+
* Allocate enough pages to cover @size from the page level
32693270
* allocator and map them into contiguous kernel virtual space.
3271+
* If @size is greater than or equal to PMD_SIZE, allow using
3272+
* huge pages for the memory
32703273
*
32713274
* Return: pointer to the allocated memory or %NULL on error
32723275
*/
3273-
void *vmalloc_no_huge(unsigned long size)
3276+
void *vmalloc_huge(unsigned long size, gfp_t gfp_mask)
32743277
{
32753278
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
3276-
GFP_KERNEL, PAGE_KERNEL, VM_NO_HUGE_VMAP,
3279+
gfp_mask, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
32773280
NUMA_NO_NODE, __builtin_return_address(0));
32783281
}
3279-
EXPORT_SYMBOL(vmalloc_no_huge);
3282+
EXPORT_SYMBOL_GPL(vmalloc_huge);
32803283

32813284
/**
32823285
* vzalloc - allocate virtually contiguous memory with zero fill

0 commit comments

Comments
 (0)