mm: add vmalloc_no_huge and use it
Subsystems (5)
Claudio Imbrenda
maintainerv4 cover mm: add vmalloc_no_huge and use it
Add vmalloc_no_huge and export it, so modules can allocate memory with small pages.
Use the newly added vmalloc_no_huge in KVM on s390 to get around a hardware limitation.
v3->v4:
* reword commit messages to be more clear
* add comment in the second patch
v2->v3:
* do not export __vmalloc_node_range
* add vmalloc_no_huge as a wrapper around __vmalloc_node_range
* use vmalloc_no_huge instead of __vmalloc_node_range in kvm on s390x
Claudio Imbrenda (2):
mm/vmalloc: add vmalloc_no_huge
KVM: s390: prepare for hugepage vmalloc
arch/s390/kvm/pv.c | 7 ++++++- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
Claudio Imbrenda
maintainerPATCH v4 1/2 mm/vmalloc: add vmalloc_no_huge
Commit 121e6f3258fe3 ("mm/vmalloc: hugepage vmalloc mappings") added support for hugepage vmalloc mappings, it also added the flag VM_NO_HUGE_VMAP for __vmalloc_node_range to request the allocation to be performed with 0-order non-huge pages. This flag is not accessible when calling vmalloc, the only option is to call directly __vmalloc_node_range, which is not exported.
This means that a module can't vmalloc memory with small pages.
Case in point: KVM on s390x needs to vmalloc a large area, and it needs to be mapped with non-huge pages, because of a hardware limitation.
This patch adds the function vmalloc_no_huge, which works like vmalloc, but it is guaranteed to always back the mapping using small pages. This new function is exported, therefore it is usable by modules.
--- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
include/linux/vmalloc.h +1 -0
@@ -135,6 +135,7 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align, const void *caller);void *__vmalloc_node (unsigned long size,unsigned long align,gfp_t gfp_mask,int node,const void *caller); +void *vmalloc_no_huge (unsigned long size);extern void vfree (const void *addr);extern void vfree_atomic (const void *addr);
mm/vmalloc.c +16 -0
@@ -2998,6 +2998,22 @@ void *vmalloc(unsigned long size) }EXPORT_SYMBOL (vmalloc); +/** +* vmalloc_no_huge - allocate virtually contiguous memory using small pages +* @size: allocation size +* +* Allocate enough non-huge pages to cover @size from the page level +* allocator and map them into contiguous kernel virtual space. +* +* Return: pointer to the allocated memory or %NULL on error +*/ +void *vmalloc_no_huge (unsigned long size) +{ +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL , +VM_NO_HUGE_VMAP ,NUMA_NO_NODE ,__builtin_return_address (0 )); +} +EXPORT_SYMBOL (vmalloc_no_huge); +/** * vzalloc - allocate virtually contiguous memory with zero fill * @size: allocation size
Signature · 1 line
2.31.1
Re: [PATCH v4 1/2] mm/vmalloc: add vmalloc_no_huge
Quoted 62 lines · Claudio Imbrenda
Commit
121e6f3258fe3("mm/vmalloc: hugepage vmalloc mappings") added support for hugepage vmalloc mappings, it also added the flagVM_NO_HUGE_VMAPfor__vmalloc_node_rangeto request the allocation to be performed with 0-order non-huge pages. This flag is not accessible when calling vmalloc, the only option is to call directly__vmalloc_node_range, which is not exported.This means that a module can't vmalloc memory with small pages.
Case in point: KVM on s390x needs to vmalloc a large area, and it needs to be mapped with non-huge pages, because of a hardware limitation.
This patch adds the function
vmalloc_no_huge, which works like vmalloc, but it is guaranteed to always back the mapping using small pages. This new function is exported, therefore it is usable by modules.Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by Uladzislau Rezki (Sony) <[email protected]>Acked-by Nicholas Piggin <[email protected]>Cc Andrew Morton <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Uladzislau Rezki (Sony) <[email protected]>Cc Catalin Marinas <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Hellwig <[email protected]>--- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)include/linux/vmalloc.h +1
-0@@ -135,6 +135,7 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align, const void *caller);void *__vmalloc_node (unsigned long size,unsigned long align,gfp_t gfp_mask,int node,const void *caller); +void *vmalloc_no_huge (unsigned long size);extern void vfree (const void *addr);extern void vfree_atomic (const void *addr);mm/vmalloc.c +9
-0@@ -2998,6 +2998,22 @@ void *vmalloc(unsigned long size) }EXPORT_SYMBOL (vmalloc); +/** +* vmalloc_no_huge - allocate virtually contiguous memory using small pages +* @size: allocation size +* +* Allocate enough non-huge pages to cover @size from the page level +* allocator and map them into contiguous kernel virtual space. +* +* Return: pointer to the allocated memory or %NULL on error +*/
mm/vmalloc.c void *vmalloc(unsigned long size) · line 3019
Quoted 10 lines
mm/vmalloc.c +7
-0+void *vmalloc_no_huge (unsigned long size) +{ +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL , +VM_NO_HUGE_VMAP ,NUMA_NO_NODE ,__builtin_return_address (0 )); +} +EXPORT_SYMBOL (vmalloc_no_huge); +/** * vzalloc - allocate virtually contiguous memory with zero fill * @size: allocation size
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH v4 1/2] mm/vmalloc: add vmalloc_no_huge
Quoted 65 lines · Claudio Imbrenda
Quoted 64 lines
Commit
121e6f3258fe3("mm/vmalloc: hugepage vmalloc mappings") added support for hugepage vmalloc mappings, it also added the flagVM_NO_HUGE_VMAPfor__vmalloc_node_rangeto request the allocation to be performed with 0-order non-huge pages. This flag is not accessible when calling vmalloc, the only option is to call directly__vmalloc_node_range, which is not exported.This means that a module can't vmalloc memory with small pages.
Case in point: KVM on s390x needs to vmalloc a large area, and it needs to be mapped with non-huge pages, because of a hardware limitation.
This patch adds the function
vmalloc_no_huge, which works like vmalloc, but it is guaranteed to always back the mapping using small pages. This new function is exported, therefore it is usable by modules.Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by Uladzislau Rezki (Sony) <[email protected]>Acked-by Nicholas Piggin <[email protected]>Cc Andrew Morton <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Uladzislau Rezki (Sony) <[email protected]>Cc Catalin Marinas <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Hellwig <[email protected]>--- include/linux/vmalloc.h | 1 + mm/vmalloc.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)include/linux/vmalloc.h +1
-0@@ -135,6 +135,7 @@ extern void *__vmalloc_node_range(unsigned long size, unsigned long align, const void *caller);void *__vmalloc_node (unsigned long size,unsigned long align,gfp_t gfp_mask,int node,const void *caller); +void *vmalloc_no_huge (unsigned long size);extern void vfree (const void *addr);extern void vfree_atomic (const void *addr);mm/vmalloc.c +14
-0@@ -2998,6 +2998,22 @@ void *vmalloc(unsigned long size) }EXPORT_SYMBOL (vmalloc); +/** +* vmalloc_no_huge - allocate virtually contiguous memory using small pages +* @size: allocation size +* +* Allocate enough non-huge pages to cover @size from the page level +* allocator and map them into contiguous kernel virtual space. +* +* Return: pointer to the allocated memory or %NULL on error +*/ +void *vmalloc_no_huge (unsigned long size) +{ +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL , +VM_NO_HUGE_VMAP ,NUMA_NO_NODE ,__builtin_return_address (0 )); +}
Quoted 10 lines
mm/vmalloc.c void *vmalloc(unsigned long size)
Quoted 6 lines
mm/vmalloc.c +2
-0+EXPORT_SYMBOL (vmalloc_no_huge); +/** * vzalloc - allocate virtually contiguous memory with zero fill * @size: allocation size Reviewed-by David Hildenbrand <[email protected]>
--
Vlad Rezki
Re: [PATCH v4 1/2] mm/vmalloc: add vmalloc_no_huge
In reply to Claudio Imbrendamm/vmalloc.c void *vmalloc(unsigned long size) · line 3013
Quoted 4 lines · Claudio Imbrenda
mm/vmalloc.c +4
-0+void *vmalloc_no_huge (unsigned long size) +{ +return __vmalloc_node_range (size,1 ,VMALLOC_START ,VMALLOC_END ,GFP_KERNEL ,PAGE_KERNEL , +VM_NO_HUGE_VMAP ,NUMA_NO_NODE ,__builtin_return_address (0 ));
Please avoid the overly long lines in favor of something actually human-readable like:
return __vmalloc_node_range(size, 1, VMALLOC_START, VMALLOC_END,
GFP_KERNEL, PAGE_KERNEL, VM_NO_HUGE_VMAP, NUMA_NO_NODE, __builtin_return_address(0));
Re: [PATCH v4 1/2] mm/vmalloc: add vmalloc_no_huge
In reply to Claudio ImbrendaQuoted 16 lines · Claudio Imbrenda
Commit
121e6f3258fe3("mm/vmalloc: hugepage vmalloc mappings") added support for hugepage vmalloc mappings, it also added the flagVM_NO_HUGE_VMAPfor__vmalloc_node_rangeto request the allocation to be performed with 0-order non-huge pages. This flag is not accessible when calling vmalloc, the only option is to call directly__vmalloc_node_range, which is not exported.This means that a module can't vmalloc memory with small pages.
Case in point: KVM on s390x needs to vmalloc a large area, and it needs to be mapped with non-huge pages, because of a hardware limitation.
This patch adds the function
vmalloc_no_huge, which works like vmalloc, but it is guaranteed to always back the mapping using small pages. This new function is exported, therefore it is usable by modules.
Quoted 11 lines
Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by Uladzislau Rezki (Sony) <[email protected]>Acked-by Nicholas Piggin <[email protected]>Cc Andrew Morton <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Uladzislau Rezki (Sony) <[email protected]>Cc Catalin Marinas <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Hellwig <[email protected]>
Claudio Imbrenda
maintainerPATCH v4 2/2 KVM: s390: prepare for hugepage vmalloc
In reply to Claudio ImbrendaThe Create Secure Configuration Ultravisor Call does not support using large pages for the virtual memory area. This is a hardware limitation.
This patch replaces the vzalloc call with an almost equivalent call to the newly introduced vmalloc_no_huge function, which guarantees that only small pages will be used for the backing.
The new call will not clear the allocated memory, but that has never been an actual requirement.
--- arch/s390/kvm/pv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/s390/kvm/pv.c +6 -1
@@ -140,7 +140,12 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)/* Allocate variable storage */ vlen =ALIGN (virt * ((npages *PAGE_SIZE ) /HPAGE_SIZE ),PAGE_SIZE ); vlen += uv_info.guest_virt_base_stor_len; - kvm->arch.pv.stor_var =vzalloc (vlen); +/* +* The Create Secure Configuration Ultravisor Call does not support +* using large pages for the virtual memory area. +* This is a hardware limitation. +*/ + kvm->arch.pv.stor_var =vmalloc_no_huge (vlen);if (!kvm->arch.pv.stor_var) goto out_err;return 0 ;
Signature · 1 line
2.31.1
Re: [PATCH v4 2/2] KVM: s390: prepare for hugepage vmalloc
Quoted 35 lines · Claudio Imbrenda
The Create Secure Configuration Ultravisor Call does not support using large pages for the virtual memory area. This is a hardware limitation.
This patch replaces the vzalloc call with an almost equivalent call to the newly introduced
vmalloc_no_hugefunction, which guarantees that only small pages will be used for the backing.The new call will not clear the allocated memory, but that has never been an actual requirement.
Signed-off-by Claudio Imbrenda <[email protected]>Reviewed-by Janosch Frank <[email protected]>Acked-by Nicholas Piggin <[email protected]>Cc Andrew Morton <[email protected]>Cc Nicholas Piggin <[email protected]>Cc Uladzislau Rezki (Sony) <[email protected]>Cc Catalin Marinas <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Hellwig <[email protected]>--- arch/s390/kvm/pv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)arch/s390/kvm/pv.c +0
-0@@ -140,7 +140,12 @@ static int kvm_s390_pv_alloc_vm(struct kvm *kvm)/* Allocate variable storage */ vlen =ALIGN (virt * ((npages *PAGE_SIZE ) /HPAGE_SIZE ),PAGE_SIZE ); vlen += uv_info.guest_virt_base_stor_len;
arch/s390/kvm/pv.c static int kvm_s390_pv_alloc_vm(struct kvm *kvm) · line 151
Quoted 10 lines
arch/s390/kvm/pv.c +6
-1- kvm->arch.pv.stor_var =vzalloc (vlen); +/* +* The Create Secure Configuration Ultravisor Call does not support +* using large pages for the virtual memory area. +* This is a hardware limitation. +*/ + kvm->arch.pv.stor_var =vmalloc_no_huge (vlen);if (!kvm->arch.pv.stor_var) goto out_err;return 0 ;
Signature · 3 lines
Thanks, David / dhildenb
Andrew Morton
maintainerQuoted 5 lines · On Mon, 14 Jun 2021 15:23:55 +0200 Claudio Imbrenda <[email protected]>…
Add
vmalloc_no_hugeand export it, so modules can allocate memory with small pages.Use the newly added
vmalloc_no_hugein KVM on s390 to get around a hardware limitation.
Thanks. I added
and also addressed the whitespace thing which Christoph noted.
No cc:stable since 121e6f3258fe3 wasn't in 5.12.