Skip to contentSkip to conversation

zsmalloc: Add Kconfig for enabling PTE method

PATCH Superseded Minchan Kim 5 participants 8 messages Feb 6, 2013 – Feb 18, 2013

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 zsmalloc: Add Kconfig for enabling PTE method

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

But it was bad choice that adding hard coding to select architecture which want to use pte based method. This patch removed it and adds new Kconfig to select the approach.

This patch is based on next-20130205.

[1] https://lkml.org/lkml/2012/7/11/58

* Changelog from v1
* Fix CONFIG_PGTABLE_MAPPING in zsmalloc-main.c - Greg

Cc Andrew Morton <[email protected]>
Cc Seth Jennings <[email protected]>
Cc Nitin Gupta <[email protected]>
Cc Dan Magenheimer <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 drivers/staging/zsmalloc/Kconfig         | 12 ++++++++++++
 drivers/staging/zsmalloc/zsmalloc-main.c | 20 +++++---------------
 2 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/zsmalloc/Kconfig +12 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
 	  non-standard allocator interface where a handle, not a pointer, is
 	  returned by an alloc().  This handle must be mapped in order to
 	  access the allocated space.
+
+config PGTABLE_MAPPING
+        bool "Use page table mapping to access allocations that span two pages"
+        depends on ZSMALLOC
+        default n
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc
drivers/staging/zsmalloc/zsmalloc-main.c +5 -15
index 06f73a9..2c1805c 100644
@@ -207,6 +207,7 @@ struct zs_pool {
 	struct size_class size_class[ZS_SIZE_CLASSES];
 
 	gfp_t flags;	/* allocation flags used when growing pool */
+
 };
 
 /*
@@ -218,19 +219,8 @@ struct zs_pool {
 #define CLASS_IDX_MASK	((1 << CLASS_IDX_BITS) - 1)
 #define FULLNESS_MASK	((1 << FULLNESS_BITS) - 1)
 
-/*
- * By default, zsmalloc uses a copy-based object mapping method to access
- * allocations that span two pages. However, if a particular architecture
- * performs VM mapping faster than copying, then it should be added here
- * so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use
- * page table mapping rather than copying for object mapping.
-*/
-#if defined(CONFIG_ARM)
-#define USE_PGTABLE_MAPPING
-#endif
-
 struct mapping_area {
-#ifdef USE_PGTABLE_MAPPING
+#ifdef CONFIG_PGTABLE_MAPPING
 	struct vm_struct *vm; /* vm area for mapping object that span pages */
 #else
 	char *vm_buf; /* copy buffer for objects that span pages */
@@ -622,7 +612,7 @@ static struct page *find_get_zspage(struct size_class *class)
 	return page;
 }
 
-#ifdef USE_PGTABLE_MAPPING
+#ifdef CONFIG_PGTABLE_MAPPING
 static inline int __zs_cpu_up(struct mapping_area *area)
 {
 	/*
@@ -663,7 +653,7 @@ static inline void __zs_unmap_object(struct mapping_area *area,
 	flush_tlb_kernel_range(addr, end);
 }
 
-#else /* USE_PGTABLE_MAPPING */
+#else /* CONFIG_PGTABLE_MAPPING*/
 
 static inline int __zs_cpu_up(struct mapping_area *area)
 {
@@ -741,7 +731,7 @@ out:
 	pagefault_enable();
 }
 
-#endif /* USE_PGTABLE_MAPPING */
+#endif /* CONFIG_PGTABLE_MAPPING */
 
 static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
 				void *pcpu)
Signature · 7 lines
1.8.1.1

--
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>
#1 lore raw

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 13

Quoted 11 lines · Minchan Kim
drivers/staging/zsmalloc/Kconfig +3 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
 	  non-standard allocator interface where a handle, not a pointer, is
 	  returned by an alloc().  This handle must be mapped in order to
 	  access the allocated space.
+
+config PGTABLE_MAPPING
+        bool "Use page table mapping to access allocations that span two pages"

No tabs?

Please also put "ZSmalloc somewhere in the text here, otherwise it really doesn't make much sense when seeing it in a menu.

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 15

Quoted 2 lines
drivers/staging/zsmalloc/Kconfig +2 -0
+        depends on ZSMALLOC
+        default n

That's the default, so it can be dropped.

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 22

Quoted 7 lines
drivers/staging/zsmalloc/Kconfig +7 -0
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc

Care to specify exactly _what_ architectures this should be set for or not? That will help the distros out a lot in determining if this should be enabled or not.

drivers/staging/zsmalloc/zsmalloc-main.c struct zs_pool { · line 213

Quoted 12 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1 -0
index 06f73a9..2c1805c 100644
@@ -207,6 +207,7 @@ struct zs_pool {
 	struct size_class size_class[ZS_SIZE_CLASSES];
 
 	gfp_t flags;	/* allocation flags used when growing pool */
+
 };
 
 /*

Why add this extra line?

thanks,

greg k-h

--
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>

#2 lore raw
Quoted 46 lines · Greg Kroah-Hartman

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 13

Quoted 11 lines · Minchan Kim
drivers/staging/zsmalloc/Kconfig +3 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
 	  non-standard allocator interface where a handle, not a pointer, is
 	  returned by an alloc().  This handle must be mapped in order to
 	  access the allocated space.
+
+config PGTABLE_MAPPING
+        bool "Use page table mapping to access allocations that span two pages"

No tabs?

Please also put "ZSmalloc somewhere in the text here, otherwise it really doesn't make much sense when seeing it in a menu.

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 15

Quoted 2 lines
drivers/staging/zsmalloc/Kconfig +2 -0
+        depends on ZSMALLOC
+        default n

That's the default, so it can be dropped.

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 22

Quoted 7 lines
drivers/staging/zsmalloc/Kconfig +7 -0
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc

Care to specify exactly _what_ architectures this should be set for or not? That will help the distros out a lot in determining if this should be enabled or not.

Quoted 11 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1 -0
index 06f73a9..2c1805c 100644
@@ -207,6 +207,7 @@ struct zs_pool {
 	struct size_class size_class[ZS_SIZE_CLASSES];
 
 	gfp_t flags;	/* allocation flags used when growing pool */
+
 };
 
Quoted 7 lines

drivers/staging/zsmalloc/zsmalloc-main.c struct zs_pool { · line 213

Quoted 1 line
drivers/staging/zsmalloc/zsmalloc-main.c +0 -0
 /*

Why add this extra line?

thanks,

greg k-h

Sorry for bothering you.
I fixed all you pointed out.
Thanks for the review, Greg!

Here it goes.

------------------- 8< -------------------

#3 lore raw
In reply to Minchan Kim
Quoted 39 lines · Minchan Kim

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

But it was bad choice that adding hard coding to select architecture which want to use pte based method. This patch removed it and adds new Kconfig to select the approach.

This patch is based on next-20130205.

[1] https://lkml.org/lkml/2012/7/11/58

* Changelog from v1
* Fix CONFIG_PGTABLE_MAPPING in zsmalloc-main.c - Greg

Cc Andrew Morton <[email protected]>
Cc Seth Jennings <[email protected]>
Cc Nitin Gupta <[email protected]>
Cc Dan Magenheimer <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 drivers/staging/zsmalloc/Kconfig         | 12 ++++++++++++
 drivers/staging/zsmalloc/zsmalloc-main.c | 20 +++++---------------
 2 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/zsmalloc/Kconfig +2 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
 	  non-standard allocator interface where a handle, not a pointer, is
 	  returned by an alloc().  This handle must be mapped in order to
 	  access the allocated space.
+
+config PGTABLE_MAPPING

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 22

Quoted 10 lines
drivers/staging/zsmalloc/Kconfig +10 -0
+        bool "Use page table mapping to access allocations that span two pages"
+        depends on ZSMALLOC
+        default n
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc

Hmm, I'm not sure we want to include this link in the Kconfig. While I don't have any plans to take that repo down, I could see it getting stale at some point for yet-to-be-determined reasons.

Of course, without this tool (or something like it) it is hard to know which option is better for your particular platform.

Would having this in a Documentation/ file, once one exists, be better?

Seth

--
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>

#4 lore raw
Quoted 55 lines · Seth Jennings
Quoted 39 lines · Minchan Kim

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

But it was bad choice that adding hard coding to select architecture which want to use pte based method. This patch removed it and adds new Kconfig to select the approach.

This patch is based on next-20130205.

[1] https://lkml.org/lkml/2012/7/11/58

* Changelog from v1
* Fix CONFIG_PGTABLE_MAPPING in zsmalloc-main.c - Greg

Cc Andrew Morton <[email protected]>
Cc Seth Jennings <[email protected]>
Cc Nitin Gupta <[email protected]>
Cc Dan Magenheimer <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
 drivers/staging/zsmalloc/Kconfig         | 12 ++++++++++++
 drivers/staging/zsmalloc/zsmalloc-main.c | 20 +++++---------------
 2 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/zsmalloc/Kconfig +2 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
 	  non-standard allocator interface where a handle, not a pointer, is
 	  returned by an alloc().  This handle must be mapped in order to
 	  access the allocated space.
+
+config PGTABLE_MAPPING

drivers/staging/zsmalloc/Kconfig config ZSMALLOC · line 22

Quoted 10 lines
drivers/staging/zsmalloc/Kconfig +10 -0
+        bool "Use page table mapping to access allocations that span two pages"
+        depends on ZSMALLOC
+        default n
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc

Hmm, I'm not sure we want to include this link in the Kconfig. While I don't have any plans to take that repo down, I could see it getting stale at some point for yet-to-be-determined reasons.

Quoted 4 lines

Of course, without this tool (or something like it) it is hard to know which option is better for your particular platform.

Would having this in a Documentation/ file, once one exists, be better?

It could be better. Then, Let's point out that documentataion in Kconfig. Okay, Let's sort it out.

Quoted 8 lines

Seth

--
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>
#5 lore raw
In reply to Minchan Kim
Quoted 6 lines · Minchan Kim

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

Why in some arches copy-based method is better and in the other arches pte-based is better? What's the root reason?

Quoted 95 lines

But it was bad choice that adding hard coding to select architecture which want to use pte based method. This patch removed it and adds new Kconfig to select the approach.

This patch is based on next-20130205.

[1] https://lkml.org/lkml/2012/7/11/58

* Changelog from v1
* Fix CONFIG_PGTABLE_MAPPING in zsmalloc-main.c - Greg

Cc Andrew Morton <[email protected]>
Cc Seth Jennings <[email protected]>
Cc Nitin Gupta <[email protected]>
Cc Dan Magenheimer <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
---
  drivers/staging/zsmalloc/Kconfig         | 12 ++++++++++++
  drivers/staging/zsmalloc/zsmalloc-main.c | 20 +++++---------------
  2 files changed, 17 insertions(+), 15 deletions(-)
drivers/staging/zsmalloc/Kconfig +12 -0
index 9084565..232b3b6 100644
@@ -8,3 +8,15 @@ config ZSMALLOC
  	  non-standard allocator interface where a handle, not a pointer, is
  	  returned by an alloc().  This handle must be mapped in order to
  	  access the allocated space.
+
+config PGTABLE_MAPPING
+        bool "Use page table mapping to access allocations that span two pages"
+        depends on ZSMALLOC
+        default n
+        help
+	  By default, zsmalloc uses a copy-based object mapping method to access
+	  allocations that span two pages. However, if a particular architecture
+	  performs VM mapping faster than copying, then you should select this.
+	  This causes zsmalloc to use page table mapping rather than copying
+	  for object mapping. You can check speed with zsmalloc benchmark[1].
+	  [1] https://github.com/spartacus06/zsmalloc
drivers/staging/zsmalloc/zsmalloc-main.c +4 -14
index 06f73a9..2c1805c 100644
@@ -207,6 +207,7 @@ struct zs_pool {
  	struct size_class size_class[ZS_SIZE_CLASSES];
 
  	gfp_t flags;	/* allocation flags used when growing pool */
+
  };
 
  /*
@@ -218,19 +219,8 @@ struct zs_pool {
  #define CLASS_IDX_MASK	((1 << CLASS_IDX_BITS) - 1)
  #define FULLNESS_MASK	((1 << FULLNESS_BITS) - 1)
 
-/*
- * By default, zsmalloc uses a copy-based object mapping method to access
- * allocations that span two pages. However, if a particular architecture
- * performs VM mapping faster than copying, then it should be added here
- * so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use
- * page table mapping rather than copying for object mapping.
-*/
-#if defined(CONFIG_ARM)
-#define USE_PGTABLE_MAPPING
-#endif
-
  struct mapping_area {
-#ifdef USE_PGTABLE_MAPPING
+#ifdef CONFIG_PGTABLE_MAPPING
  	struct vm_struct *vm; /* vm area for mapping object that span pages */
  #else
  	char *vm_buf; /* copy buffer for objects that span pages */
@@ -622,7 +612,7 @@ static struct page *find_get_zspage(struct size_class *class)
  	return page;
  }
 
-#ifdef USE_PGTABLE_MAPPING
+#ifdef CONFIG_PGTABLE_MAPPING
  static inline int __zs_cpu_up(struct mapping_area *area)
  {
  	/*
@@ -663,7 +653,7 @@ static inline void __zs_unmap_object(struct mapping_area *area,
  	flush_tlb_kernel_range(addr, end);
  }
 
-#else /* USE_PGTABLE_MAPPING */
+#else /* CONFIG_PGTABLE_MAPPING*/
 
  static inline int __zs_cpu_up(struct mapping_area *area)
  {

drivers/staging/zsmalloc/zsmalloc-main.c out: · line 737

Quoted 8 lines
drivers/staging/zsmalloc/zsmalloc-main.c +1 -1
@@ -741,7 +731,7 @@ out:
  	pagefault_enable();
  }
 
-#endif /* USE_PGTABLE_MAPPING */
+#endif /* CONFIG_PGTABLE_MAPPING */
 
  static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
  				void *pcpu)

--
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>

#6 lore raw
Quoted 12 lines

From: Ric Mason [mailto:[email protected]]
Sent: Saturday, February 16, 2013 11:19 PM
To: Minchan Kim
Cc: Greg Kroah-Hartman; [email protected]; [email protected]; Andrew Morton; Seth Jennings; Nitin Gupta; Dan Magenheimer; Konrad Rzeszutek Wilk
Subject: Re: [PATCH v2] zsmalloc: Add Kconfig for enabling PTE method

Quoted 4 lines · Minchan Kim

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

Quoted 5 lines
Quoted 2 lines

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

Why in some arches copy-based method is better and in the other arches pte-based is better? What's the root reason?

Minchan, if you post another version, I think these precise numbers (of "times faster") should be removed. The speed is very data dependent, because the copy-based method is copying a zpage which may vary widely in size from ~100 bytes to nearly PAGE_SIZE bytes, a factor of 40x or more.

Please at least say "up to 3 times" or "approximately 3x faster for an average compressed page".

Ric, the copy-based method does an extra copy of N bytes (where N is the compressed size of a page). The pte-based method requires extra TLB actions. The relative speed of TLB operations vs copying is very architecture-dependent. It is also probably dependent on the specific implementation of the architecture (i.e x86 sandybridge is likely very different than x86 nehalem) and, as noted above, dependent on N which is unpredictable.

So it makes sense to have both choices, but it's not at all clear how to select which one to use!

--
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>

#7 lore raw
In reply to Ric Mason
Quoted 10 lines · Ric Mason
Quoted 6 lines · Minchan Kim

Zsmalloc has two methods 1) copy-based and 2) pte-based to access allocations that span two pages. You can see history why we supported two approach from [1].

In summary, copy-based method is 3 times fater in x86 while pte-based is 6 times faster in ARM.

Why in some arches copy-based method is better and in the other arches pte-based is better? What's the root reason?

Minchan might know more about this (or Russell King) but I'll give it a try.

MMU designs can vary pretty significantly from arch to arch. An operation that is cheap on one MMU design can be expensive on another, especially once SMP gets involved, possibly resulting in inter-processor interrupts.

RAM speed is also a factor since the copy-method will use more memory bandwidth. Embedded systems typically won't have really fast memory.

Seth