Skip to contentSkip to conversation

Add vzalloc shortcut

PATCH In review Dave Young 4 participants 9 messages Oct 16, 2010 – Oct 19, 2010

Subsystems (4)
lore
Share & tools
lore

Dave Young

author
#0 lore raw

PATCH 1/2 Add vzalloc shortcut

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++
 2 files changed, 14 insertions(+)
include/linux/vmalloc.h +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
 #endif
 
 extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
 extern void *vmalloc_user(unsigned long size);
 extern void *vmalloc_node(unsigned long size, int node);
 extern void *vmalloc_exec(unsigned long size);
mm/vmalloc.c +13 -0
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
 EXPORT_SYMBOL(vmalloc);
 
 /**
+ *	vzalloc  -  allocate virtually contiguous memory with zero filled
+ *	@size:		allocation size
+ *	Allocate enough pages to cover @size from the page level
+ *	allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+	return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+				PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);
+
+/**
  * vmalloc_user - allocate zeroed virtually contiguous memory for userspace
  * @size: allocation size
  *
Reviewed-by on v1 1/2
#1 lore raw
Quoted 3 lines · Dave Young

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

Looks good to me.

There are many place we need this.
Although it affects meta pages for vmalloc as well as data pages, it's not a big.
In this case, Maintaining code simple is better than little bit performance overhead.

Quoted 2 lines

Isn't it useful in nommu, either?

Quoted 45 lines

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++

 2 files changed, 14 insertions(+)
include/linux/vmalloc.h   2010-10-16 10:50:54.739996121 +0800 renamed from include/linux/vmalloc.h      2010-08-22 15:31:38.000000000 +0800 +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
  #endif
 
  extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
  extern void *vmalloc_user(unsigned long size);
  extern void *vmalloc_node(unsigned long size, int node);
  extern void *vmalloc_exec(unsigned long size);
mm/vmalloc.c      2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c 2010-08-22 15:31:39.000000000 +0800 +13 -1
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
  EXPORT_SYMBOL(vmalloc);
 
  /**
+ *     vzalloc  -  allocate virtually contiguous memory with zero filled
+ *     @size:          allocation size
+ *     Allocate enough pages to cover @size from the page level
+ *     allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+       return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                               PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);
+
+/**
  * vmalloc_user - allocate zeroed virtually contiguous memory for userspace
  * @size: allocation size
  *
 
--

To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 8 lines
Kind regards,
Minchan Kim

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/2
#2 lore raw
In reply to Dave Young
Quoted 1 line · Dave Young

Add vzalloc for convinience of vmalloc-then-memset-zero case

Wish we would also have vzalloc_node() but I guess that can wait.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#3 lore raw
In reply to Dave Young
Quoted 23 lines · On Sat, 16 Oct 2010 12:33:31 +0800 Dave Young <[email protected]> wrote:

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++
 2 files changed, 14 insertions(+)
include/linux/vmalloc.h +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
 #endif
 
 extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
 extern void *vmalloc_user(unsigned long size);
 extern void *vmalloc_node(unsigned long size, int node);
 extern void *vmalloc_exec(unsigned long size);

mm/vmalloc.c void *vmalloc(unsigned long size) · line 1607

Quoted 4 lines
mm/vmalloc.c +1 -0
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
 EXPORT_SYMBOL(vmalloc);
 
 /**
+ *	vzalloc  -  allocate virtually contiguous memory with zero filled

s/filled/fill/

mm/vmalloc.c void *vmalloc(unsigned long size) · line 1617

Quoted 10 lines
mm/vmalloc.c +10 -0
+ *	@size:		allocation size
+ *	Allocate enough pages to cover @size from the page level
+ *	allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+	return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+				PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);

We'd need to add the same interface to nommu, please.

Also, a slightly better implementation would be

static inline void *__vmalloc_node_flags(unsigned long size, gfp_t flags)

{
	return __vmalloc_node(size, 1, flags, PAGE_KERNEL, -1,
				__builtin_return_address(0));
}

void *vzalloc(unsigned long size)

{
	return __vmalloc_node_flags(size,
				GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
}

void *vmalloc(unsigned long size)

{
	return __vmalloc_node_flags(size, GFP_KERNEL | __GFP_HIGHMEM);
}

just to avoid code duplication (and possible later errors derived from it).

Perhaps it should be always_inline, so the __builtin_return_address() can't get broken.

Or just leave it the way you had it :)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#4 lore raw
Quoted 28 lines · Andrew Morton
Quoted 25 lines · On Sat, 16 Oct 2010 12:33:31 +0800 Dave Young <[email protected]> wrote:

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++

 2 files changed, 14 insertions(+)
include/linux/vmalloc.h 2010-10-16 10:50:54.739996121 +0800 renamed from include/linux/vmalloc.h    2010-08-22 15:31:38.000000000 +0800 +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
  #endif
 
  extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
  extern void *vmalloc_user(unsigned long size);
  extern void *vmalloc_node(unsigned long size, int node);
  extern void *vmalloc_exec(unsigned long size);
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +0 -0
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
  EXPORT_SYMBOL(vmalloc);
 
Quoted 4 lines

mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 void *vmalloc(unsigned long size) · line 1607

Quoted 2 lines
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +1 -0
  /**
+ *   vzalloc  -  allocate virtually contiguous memory with zero filled

s/filled/fill/

Thanks, Will fix

Quoted 13 lines

mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 void *vmalloc(unsigned long size) · line 1617

Quoted 11 lines
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +10 -0
+ *   @size:          allocation size
+ *   Allocate enough pages to cover @size from the page level
+ *   allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+     return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                             PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);

We'd need to add the same interface to nommu, please.

Ok, will do

Minchan kim, thanks as well. I missed your comments about nommu before.

Quoted 20 lines

Also, a slightly better implementation would be

static inline void *__vmalloc_node_flags(unsigned long size, gfp_t flags) {
       return __vmalloc_node(size, 1, flags, PAGE_KERNEL, -1, __builtin_return_address(0)); }

void *vzalloc(unsigned long size)
{
       return __vmalloc_node_flags(size,
                               GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO); }

void *vmalloc(unsigned long size)
{
       return __vmalloc_node_flags(size, GFP_KERNEL | __GFP_HIGHMEM); }

Quoted 6 lines

just to avoid code duplication (and possible later errors derived from it).

Perhaps it should be always_inline, so the __builtin_return_address() can't get broken.

Or just leave it the way you had it :)

Andrew, your suggestion is cleaner and better. I will do as yours.

Signature · 8 lines
Regards
dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#5 lore raw
Quoted 51 lines · Dave Young
Quoted 28 lines · Andrew Morton
Quoted 25 lines · On Sat, 16 Oct 2010 12:33:31 +0800 Dave Young <[email protected]> wrote:

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++

 2 files changed, 14 insertions(+)
include/linux/vmalloc.h 2010-10-16 10:50:54.739996121 +0800 renamed from include/linux/vmalloc.h    2010-08-22 15:31:38.000000000 +0800 +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
  #endif
 
  extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
  extern void *vmalloc_user(unsigned long size);
  extern void *vmalloc_node(unsigned long size, int node);
  extern void *vmalloc_exec(unsigned long size);
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +0 -0
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
  EXPORT_SYMBOL(vmalloc);
 
Quoted 4 lines

mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 void *vmalloc(unsigned long size) · line 1607

Quoted 2 lines
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +1 -0
  /**
+ *   vzalloc  -  allocate virtually contiguous memory with zero filled

s/filled/fill/

Thanks, Will fix

Quoted 13 lines

mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 void *vmalloc(unsigned long size) · line 1617

Quoted 11 lines
mm/vmalloc.c    2010-10-16 10:51:57.126665918 +0800 renamed from mm/vmalloc.c       2010-08-22 15:31:39.000000000 +0800 +10 -0
+ *   @size:          allocation size
+ *   Allocate enough pages to cover @size from the page level
+ *   allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+     return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+                             PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);

We'd need to add the same interface to nommu, please.

Quoted 12 lines

Ok, will do

Minchan kim, thanks as well. I missed your comments about nommu before.

Quoted 8 lines

Also, a slightly better implementation would be

static inline void *__vmalloc_node_flags(unsigned long size, gfp_t flags) {
       return __vmalloc_node(size, 1, flags, PAGE_KERNEL, -1, __builtin_return_address(0)); }

Is this better? might __vmalloc_node_flags would be used by other than vmalloc?

static inline void *__vmalloc_node_flags(unsigned long size, int node, gfp_t flags)

Quoted 25 lines
Quoted 12 lines

void *vzalloc(unsigned long size)
{
       return __vmalloc_node_flags(size,
                               GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO); }

void *vmalloc(unsigned long size)
{
       return __vmalloc_node_flags(size, GFP_KERNEL | __GFP_HIGHMEM); }

Quoted 6 lines

just to avoid code duplication (and possible later errors derived from it).

Perhaps it should be always_inline, so the __builtin_return_address() can't get broken.

Or just leave it the way you had it :)

Andrew, your suggestion is cleaner and better. I will do as yours.

--
Regards
dave

Signature · 8 lines
Regards
dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
maintainer
#6 lore raw
Quoted 11 lines · On Tue, 19 Oct 2010 09:55:17 +0800 Dave Young <[email protected]> wrote:
Quoted 9 lines · Dave Young

On Tue, Oct 19, 2010 at 7:46 AM, Andrew Morton

Quoted 8 lines

Also, a slightly better implementation would be

static inline void * vmalloc_node_flags(unsigned long size, gfp_t flags) {
return vmalloc_node(size, 1, flags, PAGE_KERNEL, -1,
builtin_return_address(0));
}

Quoted 4 lines

Is this better? might vmalloc_node_flags would be used by other than vmalloc?

static inline void * vmalloc_node_flags(unsigned long size, int node, gfp_t flags)

I have no strong opinions, really. If we add more and more arguments to vmalloc_node_flags() it ends up looking like vmalloc_node(), so we may as well just call vmalloc_node(). Do whatever feels good ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#7 lore raw
Quoted 13 lines · Andrew Morton
Quoted 11 lines · On Tue, 19 Oct 2010 09:55:17 +0800 Dave Young <[email protected]> wrote:
Quoted 9 lines · Dave Young

On Tue, Oct 19, 2010 at 7:46 AM, Andrew Morton

Quoted 8 lines

Also, a slightly better implementation would be

static inline void * vmalloc_node_flags(unsigned long size, gfp_t flags) {
       return  vmalloc_node(size, 1, flags, PAGE_KERNEL, -1, builtin_return_address(0)); }

Quoted 8 lines
Quoted 4 lines

Is this better? might  vmalloc_node_flags would be used by other than vmalloc?

static inline void * vmalloc_node_flags(unsigned long size, int node, gfp_t flags)

I have no strong opinions, really.  If we add more and more arguments to vmalloc_node_flags() it ends up looking like vmalloc_node(), so we may as well just call vmalloc_node().  Do whatever feels good ;)

Ok, thanks.

Then I would prefer add 'node' argument due to the function name of vmalloc_node_flags

Signature · 8 lines
Regards
dave

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#8 lore raw
In reply to Andrew Morton
Quoted 65 lines · Andrew Morton
Quoted 23 lines · On Sat, 16 Oct 2010 12:33:31 +0800 Dave Young <[email protected]> wrote:

Add vzalloc for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

---
 include/linux/vmalloc.h |    1 +
 mm/vmalloc.c            |   13 +++++++++++++
 2 files changed, 14 insertions(+)
include/linux/vmalloc.h +1 -0
@@ -53,6 +53,7 @@ static inline void vmalloc_init(void)
 #endif
 
 extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
 extern void *vmalloc_user(unsigned long size);
 extern void *vmalloc_node(unsigned long size, int node);
 extern void *vmalloc_exec(unsigned long size);

mm/vmalloc.c void *vmalloc(unsigned long size) · line 1607

Quoted 4 lines
mm/vmalloc.c +1 -0
@@ -1604,6 +1604,19 @@ void *vmalloc(unsigned long size)
 EXPORT_SYMBOL(vmalloc);
 
 /**
+ *	vzalloc  -  allocate virtually contiguous memory with zero filled

s/filled/fill/

mm/vmalloc.c void *vmalloc(unsigned long size) · line 1617

Quoted 10 lines
mm/vmalloc.c +10 -0
+ *	@size:		allocation size
+ *	Allocate enough pages to cover @size from the page level
+ *	allocator and map them into contiguous kernel virtual space.
+ */
+void *vzalloc(unsigned long size)
+{
+	return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
+				PAGE_KERNEL, -1, __builtin_return_address(0));
+}
+EXPORT_SYMBOL(vzalloc);

We'd need to add the same interface to nommu, please.

Also, a slightly better implementation would be

static inline void *__vmalloc_node_flags(unsigned long size, gfp_t flags)

{
	return __vmalloc_node(size, 1, flags, PAGE_KERNEL, -1,
				__builtin_return_address(0));
}

void *vzalloc(unsigned long size)

{
	return __vmalloc_node_flags(size,
				GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
}

void *vmalloc(unsigned long size)

{
	return __vmalloc_node_flags(size, GFP_KERNEL | __GFP_HIGHMEM);
}
Quoted 8 lines

just to avoid code duplication (and possible later errors derived from it).

Perhaps it should be always_inline, so the __builtin_return_address() can't get broken.

Or just leave it the way you had it :)

Hi, here is the updated version:
---

Add vzalloc and vzalloc_node for convinience of vmalloc-then-memset-zero case

Use __GFP_ZERO in vzalloc to zero fill the allocated memory.

changes from first submit:
nommu part (Minchan kim and Andrew Morton)
comment fixes / __vmalloc_node_flags helper for clean code (Andrew Morton) add vzalloc_node for completeness

---
 include/linux/vmalloc.h |    2 +
 mm/nommu.c              |   49 +++++++++++++++++++++++++++++++++++++++++++++++-
 mm/vmalloc.c            |   46 +++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 94 insertions(+), 3 deletions(-)
include/linux/vmalloc.h +2 -0
@@ -53,8 +53,10 @@ static inline void vmalloc_init(void)
 #endif
 
 extern void *vmalloc(unsigned long size);
+extern void *vzalloc(unsigned long size);
 extern void *vmalloc_user(unsigned long size);
 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_32(unsigned long size);
 extern void *vmalloc_32_user(unsigned long size);
mm/vmalloc.c +44 -2

68 lines not on this page · raw message

mm/nommu.c +48 -1

59 lines not on this page · raw message

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>