Commit e1ca7788 authored by Dave Young's avatar Dave Young Committed by Linus Torvalds
Browse files

mm: add vzalloc() and vzalloc_node() helpers



Add vzalloc() and vzalloc_node() to encapsulate the
vmalloc-then-memset-zero operation.

Use __GFP_ZERO to zero fill the allocated memory.
Signed-off-by: default avatarDave Young <hidave.darkstar@gmail.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Acked-by: default avatarGreg Ungerer <gerg@snapgear.com>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7bbc0905
...@@ -53,8 +53,10 @@ static inline void vmalloc_init(void) ...@@ -53,8 +53,10 @@ static inline void vmalloc_init(void)
#endif #endif
extern void *vmalloc(unsigned long size); extern void *vmalloc(unsigned long size);
extern void *vzalloc(unsigned long size);
extern void *vmalloc_user(unsigned long size); extern void *vmalloc_user(unsigned long size);
extern void *vmalloc_node(unsigned long size, int node); extern void *vmalloc_node(unsigned long size, int node);
extern void *vzalloc_node(unsigned long size, int node);
extern void *vmalloc_exec(unsigned long size); extern void *vmalloc_exec(unsigned long size);
extern void *vmalloc_32(unsigned long size); extern void *vmalloc_32(unsigned long size);
extern void *vmalloc_32_user(unsigned long size); extern void *vmalloc_32_user(unsigned long size);
......
...@@ -293,11 +293,58 @@ void *vmalloc(unsigned long size) ...@@ -293,11 +293,58 @@ void *vmalloc(unsigned long size)
} }
EXPORT_SYMBOL(vmalloc); EXPORT_SYMBOL(vmalloc);
/*
* vzalloc - allocate virtually continguos memory with zero fill
*
* @size: allocation size
*
* Allocate enough pages to cover @size from the page level
* allocator and map them into continguos kernel virtual space.
* The memory allocated is set to zero.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/
void *vzalloc(unsigned long size)
{
return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
PAGE_KERNEL);
}
EXPORT_SYMBOL(vzalloc);
/**
* vmalloc_node - allocate memory on a specific node
* @size: allocation size
* @node: numa node
*
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/
void *vmalloc_node(unsigned long size, int node) void *vmalloc_node(unsigned long size, int node)
{ {
return vmalloc(size); return vmalloc(size);
} }
EXPORT_SYMBOL(vmalloc_node);
/**
* vzalloc_node - allocate memory on a specific node with zero fill
* @size: allocation size
* @node: numa node
*
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
* The memory allocated is set to zero.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/
void *vzalloc_node(unsigned long size, int node)
{
return vzalloc(size);
}
EXPORT_SYMBOL(vzalloc_node);
#ifndef PAGE_KERNEL_EXEC #ifndef PAGE_KERNEL_EXEC
# define PAGE_KERNEL_EXEC PAGE_KERNEL # define PAGE_KERNEL_EXEC PAGE_KERNEL
......
...@@ -1596,6 +1596,13 @@ void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) ...@@ -1596,6 +1596,13 @@ void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
} }
EXPORT_SYMBOL(__vmalloc); EXPORT_SYMBOL(__vmalloc);
static inline void *__vmalloc_node_flags(unsigned long size,
int node, gfp_t flags)
{
return __vmalloc_node(size, 1, flags, PAGE_KERNEL,
node, __builtin_return_address(0));
}
/** /**
* vmalloc - allocate virtually contiguous memory * vmalloc - allocate virtually contiguous memory
* @size: allocation size * @size: allocation size
...@@ -1607,11 +1614,27 @@ EXPORT_SYMBOL(__vmalloc); ...@@ -1607,11 +1614,27 @@ EXPORT_SYMBOL(__vmalloc);
*/ */
void *vmalloc(unsigned long size) void *vmalloc(unsigned long size)
{ {
return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL, return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
-1, __builtin_return_address(0));
} }
EXPORT_SYMBOL(vmalloc); EXPORT_SYMBOL(vmalloc);
/**
* vzalloc - allocate virtually contiguous memory with zero fill
* @size: allocation size
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
* The memory allocated is set to zero.
*
* For tight control over page level allocator and protection flags
* use __vmalloc() instead.
*/
void *vzalloc(unsigned long size)
{
return __vmalloc_node_flags(size, -1,
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
}
EXPORT_SYMBOL(vzalloc);
/** /**
* vmalloc_user - allocate zeroed virtually contiguous memory for userspace * vmalloc_user - allocate zeroed virtually contiguous memory for userspace
* @size: allocation size * @size: allocation size
...@@ -1653,6 +1676,25 @@ void *vmalloc_node(unsigned long size, int node) ...@@ -1653,6 +1676,25 @@ void *vmalloc_node(unsigned long size, int node)
} }
EXPORT_SYMBOL(vmalloc_node); EXPORT_SYMBOL(vmalloc_node);
/**
* vzalloc_node - allocate memory on a specific node with zero fill
* @size: allocation size
* @node: numa node
*
* Allocate enough pages to cover @size from the page level
* allocator and map them into contiguous kernel virtual space.
* The memory allocated is set to zero.
*
* For tight control over page level allocator and protection flags
* use __vmalloc_node() instead.
*/
void *vzalloc_node(unsigned long size, int node)
{
return __vmalloc_node_flags(size, node,
GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
}
EXPORT_SYMBOL(vzalloc_node);
#ifndef PAGE_KERNEL_EXEC #ifndef PAGE_KERNEL_EXEC
# define PAGE_KERNEL_EXEC PAGE_KERNEL # define PAGE_KERNEL_EXEC PAGE_KERNEL
#endif #endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment