Skip to contentSkip to conversation

zsmalloc: support zsmalloc to ARM, MIPS, SUPERH

PATCH In review Minchan Kim 10 participants 34 messages May 16, 2012 – Jun 15, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 zsmalloc: support zsmalloc to ARM, MIPS, SUPERH

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

---

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future. Seth might support it in PowerPC. :)

 drivers/staging/zsmalloc/Kconfig         |    6 ++---
 drivers/staging/zsmalloc/zsmalloc-main.c |   36 +++++++++++++++++++++---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |    1 -
 3 files changed, 29 insertions(+), 14 deletions(-)
drivers/staging/zsmalloc/Kconfig +3 -3
index a5ab720..def2483 100644
@@ -1,9 +1,9 @@
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	# X86 dependency is because of the use of __flush_tlb_one and set_pte
+	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
-	# TODO: convert these to portable functions
-	depends on X86
+	# TODO: implement local_unmap_kernel_range in all architecture.
+	depends on (ARM || MIPS || SUPERH)
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
drivers/staging/zsmalloc/zsmalloc-main.c +26 -10
index 4496737..8a8b08f 100644
@@ -442,7 +442,7 @@ static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
 		area = &per_cpu(zs_map_area, cpu);
 		if (area->vm)
 			break;
-		area->vm = alloc_vm_area(2 * PAGE_SIZE, area->vm_ptes);
+		area->vm = alloc_vm_area(2 * PAGE_SIZE, NULL);
 		if (!area->vm)
 			return notifier_from_errno(-ENOMEM);
 		break;
@@ -696,13 +696,22 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 	} else {
 		/* this object spans two pages */
 		struct page *nextp;
+		struct page *pages[2];
+		struct page **page_array = &pages[0];
+		int err;
 
 		nextp = get_next_page(page);
 		BUG_ON(!nextp);
 
+		page_array[0] = page;
+		page_array[1] = nextp;
 
-		set_pte(area->vm_ptes[0], mk_pte(page, PAGE_KERNEL));
-		set_pte(area->vm_ptes[1], mk_pte(nextp, PAGE_KERNEL));
+		/*
+		 * map_vm_area never fail because we already allocated
+		 * pages for page table in alloc_vm_area.
+		 */
+		err = map_vm_area(area->vm, PAGE_KERNEL, &page_array);
+		BUG_ON(err);
 
 		/* We pre-allocated VM area so mapping can never fail */
 		area->vm_addr = area->vm->addr;
@@ -712,6 +721,15 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 }
 EXPORT_SYMBOL_GPL(zs_map_object);
 
+static void local_unmap_kernel_range(unsigned long addr, unsigned long size)
+{
+	unsigned long end = addr + size;
+
+	flush_cache_vunmap(addr, end);
+	unmap_kernel_range_noflush(addr, size);
+	local_flush_tlb_kernel_range(addr, end);
+}
+
 void zs_unmap_object(struct zs_pool *pool, void *handle)
 {
 	struct page *page;
@@ -730,14 +748,12 @@ void zs_unmap_object(struct zs_pool *pool, void *handle)
 	off = obj_idx_to_offset(page, obj_idx, class->size);
 
 	area = &__get_cpu_var(zs_map_area);
-	if (off + class->size <= PAGE_SIZE) {
+	if (off + class->size <= PAGE_SIZE)
 		kunmap_atomic(area->vm_addr);
-	} else {
-		set_pte(area->vm_ptes[0], __pte(0));
-		set_pte(area->vm_ptes[1], __pte(0));
-		__flush_tlb_one((unsigned long)area->vm_addr);
-		__flush_tlb_one((unsigned long)area->vm_addr + PAGE_SIZE);
-	}
+	else
+		local_unmap_kernel_range((unsigned long)area->vm->addr,
+					PAGE_SIZE * 2);
+
 	put_cpu_var(zs_map_area);
 }
 EXPORT_SYMBOL_GPL(zs_unmap_object);
drivers/staging/zsmalloc/zsmalloc_int.h +0 -1
index 6fd32a9..eaec845 100644
@@ -111,7 +111,6 @@ static const int fullness_threshold_frac = 4;
 
 struct mapping_area {
 	struct vm_struct *vm;
-	pte_t *vm_ptes[2];
 	char *vm_addr;
 };
 
Signature · 8 lines
1.7.9.5

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH v2 2/3 remove dependency with x86

Exactly saying, [zram|zcache] should has a dependency with zsmalloc, not x86. So replace x86 dependeny with ZSMALLOC.

---
 drivers/staging/zcache/Kconfig |    3 +--
 drivers/staging/zram/Kconfig   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/staging/zcache/Kconfig +1 -2
index 7048e01..ceb7f28 100644
@@ -2,8 +2,7 @@ config ZCACHE
 	bool "Dynamic compression of swap pages and clean pagecache pages"
 	# X86 dependency is because zsmalloc uses non-portable pte/tlb
 	# functions
-	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && X86
-	select ZSMALLOC
+	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && ZSMALLOC
 	select CRYPTO_LZO
 	default n
 	help
drivers/staging/zram/Kconfig +1 -2
index 9d11a4c..e3ac62d 100644
@@ -2,8 +2,7 @@ config ZRAM
 	tristate "Compressed RAM block device support"
 	# X86 dependency is because zsmalloc uses non-portable pte/tlb
 	# functions
-	depends on BLOCK && SYSFS && X86
-	select ZSMALLOC
+	depends on BLOCK && SYSFS && ZSMALLOC
 	select LZO_COMPRESS
 	select LZO_DECOMPRESS
 	default n
Signature · 8 lines
1.7.9.5

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw

PATCH v2 3/3 x86: Support local_flush_tlb_kernel_range

In reply to Minchan Kim

The zsmalloc [un]maps non-physical contiguos pages to contiguous virual address frequently so it needs frequent tlb-flush. Now x86 doesn't support common utility function for flushing just a few tlb entries so zsmalloc have been used set_pte and __flush_tlb_one which are x86 specific functions. It means zsmalloc have a dependency with x86.

This patch adds new function, local_flush_tlb_kernel_range which are good candidate for being common utility function because other architecture(ex, MIPS, sh, unicore32, arm, score) already have supportd it.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Tejun Heo <[email protected]>
Cc David Howells <[email protected]>
---
 arch/x86/include/asm/tlbflush.h  |   12 ++++++++++++
 drivers/staging/zsmalloc/Kconfig |    2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/include/asm/tlbflush.h +12 -0
index 4ece077..6e1253a 100644
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
 	flush_tlb_all();
 }
 
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+		unsigned long end)
+{
+	if (cpu_has_invlpg) {
+		while (start < end) {
+			__flush_tlb_single(start);
+			start += PAGE_SIZE;
+		}
+	} else
+		local_flush_tlb();
+}
+
 #endif /* _ASM_X86_TLBFLUSH_H */
drivers/staging/zsmalloc/Kconfig +1 -1
index def2483..29819b8 100644
@@ -3,7 +3,7 @@ config ZSMALLOC
 	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
 	# TODO: implement local_unmap_kernel_range in all architecture.
-	depends on (ARM || MIPS || SUPERH)
+	depends on (ARM || MIPS || SUPERH || X86)
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
Signature · 8 lines
1.7.9.5

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#23 lore raw
In reply to Minchan Kim
Quoted 42 lines · Minchan Kim

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

---

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future. Seth might support it in PowerPC. :)

 drivers/staging/zsmalloc/Kconfig         |    6 ++---
 drivers/staging/zsmalloc/zsmalloc-main.c |   36 +++++++++++++++++++++---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |    1 -
 3 files changed, 29 insertions(+), 14 deletions(-)
drivers/staging/zsmalloc/Kconfig +0 -0
index a5ab720..def2483 100644

drivers/staging/zsmalloc/Kconfig line 6

Quoted 9 lines
drivers/staging/zsmalloc/Kconfig +3 -3
@@ -1,9 +1,9 @@
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	# X86 dependency is because of the use of __flush_tlb_one and set_pte
+	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
-	# TODO: convert these to portable functions
-	depends on X86
+	# TODO: implement local_unmap_kernel_range in all architecture.
+	depends on (ARM || MIPS || SUPERH)

I suggest removing above line, so if I want to use zsmalloc, I could enable this configuration easily.

Quoted 28 lines
drivers/staging/zsmalloc/Kconfig +0 -0
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
drivers/staging/zsmalloc/zsmalloc-main.c +5 -1
index 4496737..8a8b08f 100644
@@ -442,7 +442,7 @@ static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
 		area = &per_cpu(zs_map_area, cpu);
 		if (area->vm)
 			break;
-		area->vm = alloc_vm_area(2 * PAGE_SIZE, area->vm_ptes);
+		area->vm = alloc_vm_area(2 * PAGE_SIZE, NULL);
 		if (!area->vm)
 			return notifier_from_errno(-ENOMEM);
 		break;
@@ -696,13 +696,22 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 	} else {
 		/* this object spans two pages */
 		struct page *nextp;
+		struct page *pages[2];
+		struct page **page_array = &pages[0];
+		int err;
 
 		nextp = get_next_page(page);
 		BUG_ON(!nextp);
 
+		page_array[0] = page;

drivers/staging/zsmalloc/zsmalloc-main.c void *zs_map_object(struct zs_pool *pool, void *handle) · line 714

Quoted 10 lines
drivers/staging/zsmalloc/zsmalloc-main.c +7 -2
+		page_array[1] = nextp;
 
-		set_pte(area->vm_ptes[0], mk_pte(page, PAGE_KERNEL));
-		set_pte(area->vm_ptes[1], mk_pte(nextp, PAGE_KERNEL));
+		/*
+		 * map_vm_area never fail because we already allocated
+		 * pages for page table in alloc_vm_area.
+		 */
+		err = map_vm_area(area->vm, PAGE_KERNEL, &page_array);
+		BUG_ON(err);

I think WARN_ON() is better than BUG_ON() here.

Quoted 44 lines
drivers/staging/zsmalloc/zsmalloc-main.c +14 -7
 		/* We pre-allocated VM area so mapping can never fail */
 		area->vm_addr = area->vm->addr;
@@ -712,6 +721,15 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 }
 EXPORT_SYMBOL_GPL(zs_map_object);
 
+static void local_unmap_kernel_range(unsigned long addr, unsigned long size)
+{
+	unsigned long end = addr + size;
+
+	flush_cache_vunmap(addr, end);
+	unmap_kernel_range_noflush(addr, size);
+	local_flush_tlb_kernel_range(addr, end);
+}
+
 void zs_unmap_object(struct zs_pool *pool, void *handle)
 {
 	struct page *page;
@@ -730,14 +748,12 @@ void zs_unmap_object(struct zs_pool *pool, void *handle)
 	off = obj_idx_to_offset(page, obj_idx, class->size);
 
 	area = &__get_cpu_var(zs_map_area);
-	if (off + class->size <= PAGE_SIZE) {
+	if (off + class->size <= PAGE_SIZE)
 		kunmap_atomic(area->vm_addr);
-	} else {
-		set_pte(area->vm_ptes[0], __pte(0));
-		set_pte(area->vm_ptes[1], __pte(0));
-		__flush_tlb_one((unsigned long)area->vm_addr);
-		__flush_tlb_one((unsigned long)area->vm_addr + PAGE_SIZE);
-	}
+	else
+		local_unmap_kernel_range((unsigned long)area->vm->addr,
+					PAGE_SIZE * 2);
+
 	put_cpu_var(zs_map_area);
 }
 EXPORT_SYMBOL_GPL(zs_unmap_object);
drivers/staging/zsmalloc/zsmalloc_int.h +0 -0
index 6fd32a9..eaec845 100644

drivers/staging/zsmalloc/zsmalloc_int.h static const int fullness_threshold_frac = 4; · line 116

Quoted 7 lines
drivers/staging/zsmalloc/zsmalloc_int.h +0 -1
@@ -111,7 +111,6 @@ static const int fullness_threshold_frac = 4;
 
 struct mapping_area {
 	struct vm_struct *vm;
-	pte_t *vm_ptes[2];
 	char *vm_addr;
 };
 

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Re: [PATCH v2 2/3] remove dependency with x86

In reply to Minchan Kim
Quoted 15 lines · Minchan Kim

Exactly saying, [zram|zcache] should has a dependency with zsmalloc, not x86. So replace x86 dependeny with ZSMALLOC.

---
 drivers/staging/zcache/Kconfig |    3 +--
 drivers/staging/zram/Kconfig   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/staging/zcache/Kconfig +0 -0
index 7048e01..ceb7f28 100644

drivers/staging/zcache/Kconfig config ZCACHE · line 5

Quoted 6 lines
drivers/staging/zcache/Kconfig +1 -2
@@ -2,8 +2,7 @@ config ZCACHE
 	bool "Dynamic compression of swap pages and clean pagecache pages"
 	# X86 dependency is because zsmalloc uses non-portable pte/tlb
 	# functions
-	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && X86
-	select ZSMALLOC
+	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && ZSMALLOC

Sorry Minchan, I should have said this the first time around. I ran into this issue before with CRYTPO vs CRYPTO=y. ZCACHE is a bool where ZSMALLOC is a tristate. It is not sufficient for ZSMALLOC to be set; it _must_ be builtin, otherwise you get linker errors.

The dependency should be ZSMALLOC=y.

Thanks,
Seth

#24 lore raw
In reply to Guan Xuetao
Quoted 38 lines · Guan Xuetao
Quoted 37 lines · Minchan Kim

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

---

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future. Seth might support it in PowerPC. :)

 drivers/staging/zsmalloc/Kconfig         |    6 ++---
 drivers/staging/zsmalloc/zsmalloc-main.c |   36 +++++++++++++++++++++---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |    1 -
 3 files changed, 29 insertions(+), 14 deletions(-)
Quoted 16 lines
Quoted 5 lines
drivers/staging/zsmalloc/Kconfig +0 -0
index a5ab720..def2483 100644

drivers/staging/zsmalloc/Kconfig line 6

Quoted 9 lines
drivers/staging/zsmalloc/Kconfig +3 -3
@@ -1,9 +1,9 @@
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	# X86 dependency is because of the use of __flush_tlb_one and set_pte
+	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
-	# TODO: convert these to portable functions
-	depends on X86
+	# TODO: implement local_unmap_kernel_range in all architecture.
+	depends on (ARM || MIPS || SUPERH)

I suggest removing above line, so if I want to use zsmalloc, I could enable this configuration easily.

I don't get it. What do you mean?
If I remove above line, compile error will happen if arch doesn't support local_unmap_kernel_range.

Quoted 31 lines
Quoted 31 lines
drivers/staging/zsmalloc/Kconfig +0 -0
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
drivers/staging/zsmalloc/zsmalloc-main.c +6 -1
index 4496737..8a8b08f 100644
@@ -442,7 +442,7 @@ static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
 		area = &per_cpu(zs_map_area, cpu);
 		if (area->vm)
 			break;
-		area->vm = alloc_vm_area(2 * PAGE_SIZE, area->vm_ptes);
+		area->vm = alloc_vm_area(2 * PAGE_SIZE, NULL);
 		if (!area->vm)
 			return notifier_from_errno(-ENOMEM);
 		break;
@@ -696,13 +696,22 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 	} else {
 		/* this object spans two pages */
 		struct page *nextp;
+		struct page *pages[2];
+		struct page **page_array = &pages[0];
+		int err;
 
 		nextp = get_next_page(page);
 		BUG_ON(!nextp);
 
+		page_array[0] = page;
+		page_array[1] = nextp;
 
Quoted 9 lines

drivers/staging/zsmalloc/zsmalloc-main.c void *zs_map_object(struct zs_pool *pool, void *handle) · line 714

Quoted 8 lines
drivers/staging/zsmalloc/zsmalloc-main.c +6 -2
-		set_pte(area->vm_ptes[0], mk_pte(page, PAGE_KERNEL));
-		set_pte(area->vm_ptes[1], mk_pte(nextp, PAGE_KERNEL));
+		/*
+		 * map_vm_area never fail because we already allocated
+		 * pages for page table in alloc_vm_area.
+		 */
+		err = map_vm_area(area->vm, PAGE_KERNEL, &page_array);
+		BUG_ON(err);

I think WARN_ON() is better than BUG_ON() here.

If we don't do BUG_ON, zsmalloc's user can use dangling pointer so that it can make system very unstable, even fatal.

Quoted 61 lines
Quoted 45 lines
drivers/staging/zsmalloc/zsmalloc-main.c +14 -7
 		/* We pre-allocated VM area so mapping can never fail */
 		area->vm_addr = area->vm->addr;
@@ -712,6 +721,15 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 }
 EXPORT_SYMBOL_GPL(zs_map_object);
 
+static void local_unmap_kernel_range(unsigned long addr, unsigned long size)
+{
+	unsigned long end = addr + size;
+
+	flush_cache_vunmap(addr, end);
+	unmap_kernel_range_noflush(addr, size);
+	local_flush_tlb_kernel_range(addr, end);
+}
+
 void zs_unmap_object(struct zs_pool *pool, void *handle)
 {
 	struct page *page;
@@ -730,14 +748,12 @@ void zs_unmap_object(struct zs_pool *pool, void *handle)
 	off = obj_idx_to_offset(page, obj_idx, class->size);
 
 	area = &__get_cpu_var(zs_map_area);
-	if (off + class->size <= PAGE_SIZE) {
+	if (off + class->size <= PAGE_SIZE)
 		kunmap_atomic(area->vm_addr);
-	} else {
-		set_pte(area->vm_ptes[0], __pte(0));
-		set_pte(area->vm_ptes[1], __pte(0));
-		__flush_tlb_one((unsigned long)area->vm_addr);
-		__flush_tlb_one((unsigned long)area->vm_addr + PAGE_SIZE);
-	}
+	else
+		local_unmap_kernel_range((unsigned long)area->vm->addr,
+					PAGE_SIZE * 2);
+
 	put_cpu_var(zs_map_area);
 }
 EXPORT_SYMBOL_GPL(zs_unmap_object);
drivers/staging/zsmalloc/zsmalloc_int.h +0 -0
index 6fd32a9..eaec845 100644

drivers/staging/zsmalloc/zsmalloc_int.h static const int fullness_threshold_frac = 4; · line 116

Quoted 7 lines
drivers/staging/zsmalloc/zsmalloc_int.h +0 -1
@@ -111,7 +111,6 @@ static const int fullness_threshold_frac = 4;
 
 struct mapping_area {
 	struct vm_struct *vm;
-	pte_t *vm_ptes[2];
 	char *vm_addr;
 };
 

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#25 lore raw
Quoted 58 lines · Minchan Kim
Quoted 38 lines · Guan Xuetao
Quoted 37 lines · Minchan Kim

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

---

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future. Seth might support it in PowerPC. :)

 drivers/staging/zsmalloc/Kconfig         |    6 ++---
 drivers/staging/zsmalloc/zsmalloc-main.c |   36 +++++++++++++++++++++---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |    1 -
 3 files changed, 29 insertions(+), 14 deletions(-)
Quoted 16 lines
Quoted 5 lines
drivers/staging/zsmalloc/Kconfig +0 -0
index a5ab720..def2483 100644

drivers/staging/zsmalloc/Kconfig line 6

Quoted 9 lines
drivers/staging/zsmalloc/Kconfig +3 -3
@@ -1,9 +1,9 @@
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	# X86 dependency is because of the use of __flush_tlb_one and set_pte
+	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
-	# TODO: convert these to portable functions
-	depends on X86
+	# TODO: implement local_unmap_kernel_range in all architecture.
+	depends on (ARM || MIPS || SUPERH)

I suggest removing above line, so if I want to use zsmalloc, I could enable this configuration easily.

Quoted 2 lines

I don't get it. What do you mean?
If I remove above line, compile error will happen if arch doesn't support local_unmap_kernel_range.

If I want to use zsmalloc, I will verify local_unmap_kernel_range function. In fact, only local_flush_tlb_kernel_range need to be considered. So, just keeping the default option 'n' is enough.

Quoted 43 lines
Quoted 32 lines
Quoted 32 lines
drivers/staging/zsmalloc/Kconfig +0 -0
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
drivers/staging/zsmalloc/zsmalloc-main.c +6 -1
index 4496737..8a8b08f 100644
@@ -442,7 +442,7 @@ static int zs_cpu_notifier(struct notifier_block *nb, unsigned long action,
 		area = &per_cpu(zs_map_area, cpu);
 		if (area->vm)
 			break;
-		area->vm = alloc_vm_area(2 * PAGE_SIZE, area->vm_ptes);
+		area->vm = alloc_vm_area(2 * PAGE_SIZE, NULL);
 		if (!area->vm)
 			return notifier_from_errno(-ENOMEM);
 		break;
@@ -696,13 +696,22 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 	} else {
 		/* this object spans two pages */
 		struct page *nextp;
+		struct page *pages[2];
+		struct page **page_array = &pages[0];
+		int err;
 
 		nextp = get_next_page(page);
 		BUG_ON(!nextp);
 
+		page_array[0] = page;
+		page_array[1] = nextp;
 
Quoted 9 lines

drivers/staging/zsmalloc/zsmalloc-main.c void *zs_map_object(struct zs_pool *pool, void *handle) · line 714

Quoted 8 lines
drivers/staging/zsmalloc/zsmalloc-main.c +6 -2
-		set_pte(area->vm_ptes[0], mk_pte(page, PAGE_KERNEL));
-		set_pte(area->vm_ptes[1], mk_pte(nextp, PAGE_KERNEL));
+		/*
+		 * map_vm_area never fail because we already allocated
+		 * pages for page table in alloc_vm_area.
+		 */
+		err = map_vm_area(area->vm, PAGE_KERNEL, &page_array);
+		BUG_ON(err);

I think WARN_ON() is better than BUG_ON() here.

Quoted 2 lines

If we don't do BUG_ON, zsmalloc's user can use dangling pointer so that it can make system very unstable, even fatal.

The majority of archs treat BUG_ON as panic, so if zsmalloc has some error, the kernel will be halted immediately. Is it the result you want? If yes, just ignore my suggestion.

Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
drivers/staging/zsmalloc/zsmalloc-main.c +14 -7
 		/* We pre-allocated VM area so mapping can never fail */
 		area->vm_addr = area->vm->addr;
@@ -712,6 +721,15 @@ void *zs_map_object(struct zs_pool *pool, void *handle)
 }
 EXPORT_SYMBOL_GPL(zs_map_object);
 
+static void local_unmap_kernel_range(unsigned long addr, unsigned long size)
+{
+	unsigned long end = addr + size;
+
+	flush_cache_vunmap(addr, end);
+	unmap_kernel_range_noflush(addr, size);
+	local_flush_tlb_kernel_range(addr, end);
+}
+
 void zs_unmap_object(struct zs_pool *pool, void *handle)
 {
 	struct page *page;
@@ -730,14 +748,12 @@ void zs_unmap_object(struct zs_pool *pool, void *handle)
 	off = obj_idx_to_offset(page, obj_idx, class->size);
 
 	area = &__get_cpu_var(zs_map_area);
-	if (off + class->size <= PAGE_SIZE) {
+	if (off + class->size <= PAGE_SIZE)
 		kunmap_atomic(area->vm_addr);
-	} else {
-		set_pte(area->vm_ptes[0], __pte(0));
-		set_pte(area->vm_ptes[1], __pte(0));
-		__flush_tlb_one((unsigned long)area->vm_addr);
-		__flush_tlb_one((unsigned long)area->vm_addr + PAGE_SIZE);
-	}
+	else
+		local_unmap_kernel_range((unsigned long)area->vm->addr,
+					PAGE_SIZE * 2);
+
 	put_cpu_var(zs_map_area);
 }
 EXPORT_SYMBOL_GPL(zs_unmap_object);
drivers/staging/zsmalloc/zsmalloc_int.h +0 -0
index 6fd32a9..eaec845 100644
@@ -111,7 +111,6 @@ static const int fullness_threshold_frac = 4;
 
Quoted 18 lines
Quoted 8 lines

drivers/staging/zsmalloc/zsmalloc_int.h static const int fullness_threshold_frac = 4; · line 116

Quoted 6 lines
drivers/staging/zsmalloc/zsmalloc_int.h +0 -1
 struct mapping_area {
 	struct vm_struct *vm;
-	pte_t *vm_ptes[2];
 	char *vm_addr;
 };
 
Quoted 7 lines

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#26 lore raw
Quoted 59 lines · Guan Xuetao
Quoted 58 lines · Minchan Kim
Quoted 54 lines · Guan Xuetao
Quoted 42 lines · Minchan Kim

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

---

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future. Seth might support it in PowerPC. :)

 drivers/staging/zsmalloc/Kconfig         |    6 ++---
 drivers/staging/zsmalloc/zsmalloc-main.c |   36 +++++++++++++++++++++---------
 drivers/staging/zsmalloc/zsmalloc_int.h  |    1 -
 3 files changed, 29 insertions(+), 14 deletions(-)
drivers/staging/zsmalloc/Kconfig +0 -0
index a5ab720..def2483 100644

drivers/staging/zsmalloc/Kconfig line 6

Quoted 9 lines
drivers/staging/zsmalloc/Kconfig +3 -3
@@ -1,9 +1,9 @@
 config ZSMALLOC
 	tristate "Memory allocator for compressed pages"
-	# X86 dependency is because of the use of __flush_tlb_one and set_pte
+	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
-	# TODO: convert these to portable functions
-	depends on X86
+	# TODO: implement local_unmap_kernel_range in all architecture.
+	depends on (ARM || MIPS || SUPERH)

I suggest removing above line, so if I want to use zsmalloc, I could enable this configuration easily.

Quoted 5 lines
Quoted 2 lines

I don't get it. What do you mean?
If I remove above line, compile error will happen if arch doesn't support local_unmap_kernel_range.

If I want to use zsmalloc, I will verify local_unmap_kernel_range function. In fact, only local_flush_tlb_kernel_range need to be considered. So, just keeping the default option 'n' is enough.

I don't think so.
It's terrible experience if all users have to look up local_flush_tlb_kernel_range of arch for using zsmalloc.

BTW, does unicore32 support that function?
If so, I would like to add unicore32 in Kconfig.

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Re: [PATCH v2 2/3] remove dependency with x86

In reply to Seth Jennings
Quoted 32 lines · Seth Jennings
Quoted 15 lines · Minchan Kim

Exactly saying, [zram|zcache] should has a dependency with zsmalloc, not x86. So replace x86 dependeny with ZSMALLOC.

---
 drivers/staging/zcache/Kconfig |    3 +--
 drivers/staging/zram/Kconfig   |    3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/staging/zcache/Kconfig +0 -0
index 7048e01..ceb7f28 100644

drivers/staging/zcache/Kconfig config ZCACHE · line 5

Quoted 6 lines
drivers/staging/zcache/Kconfig +1 -2
@@ -2,8 +2,7 @@ config ZCACHE
 	bool "Dynamic compression of swap pages and clean pagecache pages"
 	# X86 dependency is because zsmalloc uses non-portable pte/tlb
 	# functions
-	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && X86
-	select ZSMALLOC
+	depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && ZSMALLOC

Sorry Minchan, I should have said this the first time around. I ran into this issue before with CRYTPO vs CRYPTO=y. ZCACHE is a bool where ZSMALLOC is a tristate. It is not sufficient for ZSMALLOC to be set; it _must_ be builtin, otherwise you get linker errors.

Quoted 1 line

The dependency should be ZSMALLOC=y.

Sigh. I should have been more careful.
Thanks. I will fix it in next spin.

Quoted 4 lines

Thanks,
Seth

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Minchan Kim

Isn't there anyone for taking a time to review this patch? :)

Quoted 57 lines · Minchan Kim

The zsmalloc [un]maps non-physical contiguos pages to contiguous virual address frequently so it needs frequent tlb-flush. Now x86 doesn't support common utility function for flushing just a few tlb entries so zsmalloc have been used set_pte and __flush_tlb_one which are x86 specific functions. It means zsmalloc have a dependency with x86.

This patch adds new function, local_flush_tlb_kernel_range which are good candidate for being common utility function because other architecture(ex, MIPS, sh, unicore32, arm, score) already have supportd it.

Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Tejun Heo <[email protected]>
Cc David Howells <[email protected]>
---
 arch/x86/include/asm/tlbflush.h  |   12 ++++++++++++
 drivers/staging/zsmalloc/Kconfig |    2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/include/asm/tlbflush.h +12 -0
index 4ece077..6e1253a 100644
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
 	flush_tlb_all();
 }
 
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+		unsigned long end)
+{
+	if (cpu_has_invlpg) {
+		while (start < end) {
+			__flush_tlb_single(start);
+			start += PAGE_SIZE;
+		}
+	} else
+		local_flush_tlb();
+}
+
 #endif /* _ASM_X86_TLBFLUSH_H */
drivers/staging/zsmalloc/Kconfig +1 -1
index def2483..29819b8 100644
@@ -3,7 +3,7 @@ config ZSMALLOC
 	# arch dependency is because of the use of local_unmap_kernel_range
 	# in zsmalloc-main.c.
 	# TODO: implement local_unmap_kernel_range in all architecture.
-	depends on (ARM || MIPS || SUPERH)
+	depends on (ARM || MIPS || SUPERH || X86)
 	default n
 	help
 	  zsmalloc is a slab-based memory allocator designed to store
Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#29 lore raw
In reply to Minchan Kim
Quoted 6 lines · Minchan Kim

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

..

Quoted 8 lines

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future.

One thing you might consider is providing a stubbed definition that wraps to flush_tlb_kernel_range() in the !SMP case, as this will extend your testing coverage for staging considerably.

Once you exclude all of the non-SMP platforms, you're left with the following:

- blackfin: doesn't count, no TLB to worry about.
- hexagon: seems to imply that the SMP case uses thread-based CPUs that share an MMU, so no additional cost.
- ia64: Does a global flush, which already has a FIXME comment.
- m32r, mn10300: local_flush_tlb_all() could be wrapped.
- parisc: global flush?
- s390: Tests the cpumask to do a local flush, otherwise has a __tlb_flush_local() that can be wrapped.
- sparc32: global flush
- sparc64: __flush_tlb_kernel_range() looks like a local flush.
- tile: does strange hypervisory things, presumably global.
- x86: has a local_flush_tlb() that could be wrapped.

Which doesn't look quite that bad. You could probably get away with a Kconfig option for optimized local TLB flushing or something, since single function Kconfig options seem to be all the rage these days.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#30 lore raw
Quoted 18 lines · Paul Mundt
Quoted 6 lines · Minchan Kim

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

..

Quoted 8 lines

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future.

Quoted 3 lines

One thing you might consider is providing a stubbed definition that wraps to flush_tlb_kernel_range() in the !SMP case, as this will extend your testing coverage for staging considerably.

AFAIUC, you mean following as,

ifndef CONFIG_SMP
void flush_tlb_kernel_range(unsinged long start, unsigned log end)

{
	local_flush_tlb_kernel_range(start, end);
}

#endif

I can do it on some arch which I know a little bit but concern is I'm not sure what's effective between all entries flush and each entry flush if range is very big.

It's not a goal of this patch so I would like to pass it to arch maintainers. But I absolutely agree on testing coverage on your comment.

Quoted 20 lines

Once you exclude all of the non-SMP platforms, you're left with the following:

- blackfin: doesn't count, no TLB to worry about.
- hexagon: seems to imply that the SMP case uses thread-based CPUs that share an MMU, so no additional cost.
- ia64: Does a global flush, which already has a FIXME comment.
- m32r, mn10300: local_flush_tlb_all() could be wrapped.
- parisc: global flush?
- s390: Tests the cpumask to do a local flush, otherwise has a __tlb_flush_local() that can be wrapped.
- sparc32: global flush
- sparc64: __flush_tlb_kernel_range() looks like a local flush.
- tile: does strange hypervisory things, presumably global.
- x86: has a local_flush_tlb() that could be wrapped.

Quoted 3 lines

Which doesn't look quite that bad. You could probably get away with a Kconfig option for optimized local TLB flushing or something, since single function Kconfig options seem to be all the rage these days.

Actually, I didn't want to implement dumb flush functions on all architecture which those functions flush all entries although we need flush a few entries. It might zsmalloc unuseful so I expected each maintainers can implement it much efficient than stupid me and then, they add their arch in Kconfig. :(

If this approach is really bad, I need time to implement dumb stub functions in all architecture and have to receive all acks from them. Sigh.

Quoted 8 lines

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#32 lore raw
In reply to Paul Mundt
Quoted 38 lines · Paul Mundt
Quoted 6 lines · Minchan Kim

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

..

Quoted 8 lines

Need double check about supporting local_flush_tlb_kernel_range in ARM, MIPS, SUPERH maintainers. And I will Ccing unicore32 and score maintainers because arch directory in those arch have local_flush_tlb_kernel_range, too but I'm very unfamiliar with those architecture so pass it to maintainers.
I didn't coded up dumb local_flush_tlb_kernel_range which flush all cpus. I expect someone need ZSMALLOC will implement it easily in future.

One thing you might consider is providing a stubbed definition that wraps to flush_tlb_kernel_range() in the !SMP case, as this will extend your testing coverage for staging considerably.

Once you exclude all of the non-SMP platforms, you're left with the following:

- blackfin: doesn't count, no TLB to worry about.
- hexagon: seems to imply that the SMP case uses thread-based CPUs that share an MMU, so no additional cost.
- ia64: Does a global flush, which already has a FIXME comment.
- m32r, mn10300: local_flush_tlb_all() could be wrapped.
- parisc: global flush?
- s390: Tests the cpumask to do a local flush, otherwise has a __tlb_flush_local() that can be wrapped.
- sparc32: global flush
- sparc64: __flush_tlb_kernel_range() looks like a local flush.
- tile: does strange hypervisory things, presumably global.
- x86: has a local_flush_tlb() that could be wrapped.

Quoted 3 lines

Which doesn't look quite that bad. You could probably get away with a Kconfig option for optimized local TLB flushing or something, since single function Kconfig options seem to be all the rage these days.

I missed this sentence.

Thanks for very helpful comment, Paul!

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#31 lore raw
In reply to Minchan Kim
Quoted 6 lines · Minchan Kim
Quoted 3 lines · Paul Mundt

One thing you might consider is providing a stubbed definition that wraps to flush_tlb_kernel_range() in the !SMP case, as this will extend your testing coverage for staging considerably.

Quoted 9 lines

AFAIUC, you mean following as,

ifndef CONFIG_SMP
void flush_tlb_kernel_range(unsinged long start, unsigned log end)

{
	local_flush_tlb_kernel_range(start, end);
}

#endif

Actually I meant the opposite:

#ifndef CONFIG_SMP
#define local_flush_tlb_kernel_range flush_tlb_kernel_range #endif

as the UP case is going to be local already. It's a bit hacky, though.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Minchan Kim
Quoted 3 lines · Minchan Kim

Isn't there anyone for taking a time to review this patch? :)

On 05/16/2012 11:05 AM, Minchan Kim wrote:

<snip>

You want review within 24 hours for a staging tree patch for a feature that no one uses?

That's very bold of you. Please be realistic.

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#8 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Minchan Kim
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

Also, does it even work if the range happens to be backed by huge pages? IIRC we try and do the identity map with large pages wherever possible.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 3 lines · Peter Zijlstra

Also, does it even work if the range happens to be backed by huge pages? IIRC we try and do the identity map with large pages wherever possible.

OK, the Intel SDM seems to suggest it will indeed invalidate ANY mapping to that linear address, which would include 2M and 1G pages.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw
In reply to Minchan Kim
Quoted 7 lines · Minchan Kim

...
I don't think so.
It's terrible experience if all users have to look up local_flush_tlb_kernel_range of arch for using zsmalloc.

BTW, does unicore32 support that function?
If so, I would like to add unicore32 in Kconfig.

Yes. Thanks.

Could you give me some materials on performance and testsuite?

Guan Xuetao

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Greg Kroah-Hartman

Hi Greg,

Quoted 11 lines · Greg Kroah-Hartman
Quoted 3 lines · Minchan Kim

Isn't there anyone for taking a time to review this patch? :)

On 05/16/2012 11:05 AM, Minchan Kim wrote:

<snip>

You want review within 24 hours for a staging tree patch for a feature that no one uses?

That's very bold of you. Please be realistic.

I admit I was hurry because I thought portability issue of zsmalloc may be a urgent issue for [zram|zsmalloc] to go out of staging and I want to move [zsmalloc|zram] into mainline as soon as possible.

I should have grown my patience.

As an excuse, exactly speaking, it's not 24 hours because I sent first patch 5/14 and I didn't change that patch from then. :)

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Peter Zijlstra

Hi Peter,

Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 15 lines
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

Thanks for the information. I will watch that patchset. Thanks.

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#28 lore raw
In reply to Guan Xuetao

Hi Guan,

Quoted 6 lines · Guan Xuetao
Quoted 4 lines · Minchan Kim

...
I don't think so.
It's terrible experience if all users have to look up local_flush_tlb_kernel_range of arch for using zsmalloc.

Quoted 6 lines
Quoted 3 lines

BTW, does unicore32 support that function?
If so, I would like to add unicore32 in Kconfig.

Yes. Thanks.

Could you give me some materials on performance and testsuite?

Unfortunately, I don't have them. Nitin, Could you help Guan?

Signature · 9 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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Peter Zijlstra
Quoted 7 lines · Peter Zijlstra
Quoted 3 lines · Peter Zijlstra

Also, does it even work if the range happens to be backed by huge pages? IIRC we try and do the identity map with large pages wherever possible.

OK, the Intel SDM seems to suggest it will indeed invalidate ANY mapping to that linear address, which would include 2M and 1G pages.

As for as I know, the 1GB TLB fold into 2MB now, and 2MB page still maybe fold into 4K page in TLB flush. We are tracking this.

Quoted 7 lines

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a hrefmailto:"[email protected]"> [email protected] </a>

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Acked-by on v2 1/3
#33 lore raw
In reply to Minchan Kim
Quoted 14 lines · Minchan Kim

zsmalloc uses set_pte and __flush_tlb_one for performance but many architecture don't support it. so this patch removes set_pte and __flush_tlb_one which are x86 dependency. Instead of it, use local_flush_tlb_kernel_range which are available by more architectures. It would be better than supporting only x86 and last patch in series will enable again with supporting local_flush_tlb_kernel_range in x86.

About local_flush_tlb_kernel_range,
If architecture is very smart, it could flush only tlb entries related to vaddr. If architecture is smart, it could flush only tlb entries related to a CPU. If architecture is _NOT_ smart, it could flush all entries of all CPUs. So, it would be best to support both portability and performance.

Quoted 6 lines
Cc Russell King <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Mundt <[email protected]>
Cc Guan Xuetao <[email protected]>
Cc Chen Liqin <[email protected]>

For the zsmalloc changes:

Thanks,
Seth

#12 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Peter Zijlstra
Quoted 23 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

Quoted 1 line

From what I can tell Alex's patches have stalled. The last post was v6

on 5/17 and there wasn't a single reply to them afaict.

According to Alex's investigation of this "tipping point", it seems that a good generic value is 8. In other words, on most x86 hardware, it is cheaper to flush up to 8 tlb entries one by one rather than doing a complete flush.

So we can do something like:

     if (cpu_has_invlpg && (end - start)/PAGE_SIZE <= 8) {
             while (start < end) {

Would this be acceptable?

Thanks,
Seth

#13 lore raw

RE: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 39 lines

From: Seth Jennings [mailto:[email protected]]
Sent: Friday, June 15, 2012 9:13 AM
To: Peter Zijlstra
Cc: Minchan Kim; Greg Kroah-Hartman; Nitin Gupta; Dan Magenheimer; [email protected]; [email protected]; Thomas Gleixner; Ingo Molnar; Tejun Heo; David Howells; [email protected]; Nick Piggin
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 14 lines
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

From what I can tell Alex's patches have stalled. The last post was v6 on 5/17 and there wasn't a single reply to them afaict.

According to Alex's investigation of this "tipping point", it seems that a good generic value is 8. In other words, on most x86 hardware, it is cheaper to flush up to 8 tlb entries one by one rather than doing a complete flush.

Quoted 6 lines

So we can do something like:

     if (cpu_has_invlpg && (end - start)/PAGE_SIZE <= 8) {
             while (start < end) {

Would this be acceptable?

Hey Seth, Nitin --

After more work digging around zsmalloc and zbud, I really think this TLB flushing, as well as the "page pair mapping" code can be completely eliminated IFF zsmalloc is limited to items PAGE_SIZE or less. Since this is already true of zram (and in-tree zcache), and zsmalloc currently has no other users, I think you should seriously consider limiting zsmalloc in that way, or possibly splitting out one version of zsmalloc which handles items PAGE_SIZE or less, and a second version that can handle larger items but has (AFAIK) no users.

If you consider it an option to have (a version of) zsmalloc limited to items PAGE_SIZE or less, let me know and we can get into the details.

Thanks,
Dan

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

#14 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 58 lines · Dan Magenheimer
Quoted 39 lines

From: Seth Jennings [mailto:[email protected]]
Sent: Friday, June 15, 2012 9:13 AM
To: Peter Zijlstra
Cc: Minchan Kim; Greg Kroah-Hartman; Nitin Gupta; Dan Magenheimer; [email protected]; [email protected]; Thomas Gleixner; Ingo Molnar; Tejun Heo; David Howells; [email protected]; Nick Piggin
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 14 lines
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

From what I can tell Alex's patches have stalled. The last post was v6 on 5/17 and there wasn't a single reply to them afaict.

According to Alex's investigation of this "tipping point", it seems that a good generic value is 8. In other words, on most x86 hardware, it is cheaper to flush up to 8 tlb entries one by one rather than doing a complete flush.

Quoted 6 lines

So we can do something like:

     if (cpu_has_invlpg && (end - start)/PAGE_SIZE <= 8) {
             while (start < end) {

Would this be acceptable?

Hey Seth, Nitin --

After more work digging around zsmalloc and zbud, I really think this TLB flushing, as well as the "page pair mapping" code can be completely eliminated IFF zsmalloc is limited to items PAGE_SIZE or less. Since this is already true of zram (and in-tree zcache), and zsmalloc currently has no other users, I think you should seriously consider limiting zsmalloc in that way, or possibly splitting out one version of zsmalloc which handles items PAGE_SIZE or less, and a second version that can handle larger items but has (AFAIK) no users.

Quoted 4 lines

If you consider it an option to have (a version of) zsmalloc limited to items PAGE_SIZE or less, let me know and we can get into the details.

zsmalloc is already limited to objects of size PAGE_SIZE or less. This two-page splitting is for efficiently storing objects in range (PAGE_SIZE/2, PAGE_SIZE) which is very common in both zram and zcache.

SLUB achieves this efficiency by allocating higher order pages but that is not an option for zsmalloc.

Thanks,
Nitin

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

#22 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Dan Magenheimer
Quoted 44 lines · Dan Magenheimer
Quoted 44 lines

From: Seth Jennings [mailto:[email protected]]
Sent: Friday, June 15, 2012 9:13 AM
To: Peter Zijlstra
Cc: Minchan Kim; Greg Kroah-Hartman; Nitin Gupta; Dan Magenheimer; [email protected]; [email protected]; Thomas Gleixner; Ingo Molnar; Tejun Heo; David Howells; [email protected]; Nick Piggin
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 14 lines
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

From what I can tell Alex's patches have stalled. The last post was v6 on 5/17 and there wasn't a single reply to them afaict.

According to Alex's investigation of this "tipping point", it seems that a good generic value is 8. In other words, on most x86 hardware, it is cheaper to flush up to 8 tlb entries one by one rather than doing a complete flush.

So we can do something like:

     if (cpu_has_invlpg && (end - start)/PAGE_SIZE <= 8) {
             while (start < end) {
Quoted 8 lines
Quoted 1 line

Would this be acceptable?

Hey Seth, Nitin --

After more work digging around zsmalloc and zbud, I really think this TLB flushing, as well as the "page pair mapping" code can be completely eliminated IFF zsmalloc is limited to items PAGE_SIZE or less.

To add to what Nitin just sent, without the page mapping, zsmalloc and the late xvmalloc have the same issue. Say you have a whole class of objects that are 3/4 of a page. Without the mapping, you can't cross non-contiguous page boundaries and you'll have 25% fragmentation in the memory pool. This is the whole point of zsmalloc.

--
Seth

#15 lore raw

RE: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

In reply to Nitin Gupta
Quoted 66 lines

From: Nitin Gupta [mailto:[email protected]]
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 58 lines · Dan Magenheimer
Quoted 39 lines

From: Seth Jennings [mailto:[email protected]]
Sent: Friday, June 15, 2012 9:13 AM
To: Peter Zijlstra
Cc: Minchan Kim; Greg Kroah-Hartman; Nitin Gupta; Dan Magenheimer; [email protected]; [email protected]; Thomas Gleixner; Ingo Molnar; Tejun Heo; David Howells; [email protected]; Nick Piggin
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 6 lines · Peter Zijlstra
Quoted 5 lines · Minchan Kim
Quoted 5 lines

+++ b/arch/x86/include/asm/tlbflush.h

arch/x86/include/asm/tlbflush.h +0 -0
@@ -172,4 +172,16 @@ static inline void flush_tlb_kernel_range(unsigned long start,
      flush_tlb_all();
 }
 
Quoted 14 lines
Quoted 11 lines

arch/x86/include/asm/tlbflush.h static inline void flush_tlb_kernel_range(unsigned long start, · line 185

Quoted 11 lines
arch/x86/include/asm/tlbflush.h +11 -0
+static inline void local_flush_tlb_kernel_range(unsigned long start,
+             unsigned long end)
+{
+     if (cpu_has_invlpg) {
+             while (start < end) {
+                     __flush_tlb_single(start);
+                     start += PAGE_SIZE;
+             }
+     } else
+             local_flush_tlb();
+}

It would be much better if you wait for Alex Shi's patch to mature. doing the invlpg thing for ranges is not an unconditional win.

From what I can tell Alex's patches have stalled. The last post was v6 on 5/17 and there wasn't a single reply to them afaict.

According to Alex's investigation of this "tipping point", it seems that a good generic value is 8. In other words, on most x86 hardware, it is cheaper to flush up to 8 tlb entries one by one rather than doing a complete flush.

Quoted 6 lines

So we can do something like:

     if (cpu_has_invlpg && (end - start)/PAGE_SIZE <= 8) {
             while (start < end) {

Would this be acceptable?

Hey Seth, Nitin --

After more work digging around zsmalloc and zbud, I really think this TLB flushing, as well as the "page pair mapping" code can be completely eliminated IFF zsmalloc is limited to items PAGE_SIZE or less. Since this is already true of zram (and in-tree zcache), and zsmalloc currently has no other users, I think you should seriously consider limiting zsmalloc in that way, or possibly splitting out one version of zsmalloc which handles items PAGE_SIZE or less, and a second version that can handle larger items but has (AFAIK) no users.

Quoted 3 lines

If you consider it an option to have (a version of) zsmalloc limited to items PAGE_SIZE or less, let me know and we can get into the details.

Quoted 6 lines

zsmalloc is already limited to objects of size PAGE_SIZE or less. This two-page splitting is for efficiently storing objects in range (PAGE_SIZE/2, PAGE_SIZE) which is very common in both zram and zcache.

SLUB achieves this efficiency by allocating higher order pages but that is not an option for zsmalloc.

That's what I thought, but a separate thread about ensuring zsmalloc was as generic as possible led me to believe that zsmalloc was moving in the direction of larger sizes.

Quoted 7 lines

From: Seth Jennings [mailto:[email protected]]

To add to what Nitin just sent, without the page mapping, zsmalloc and the late xvmalloc have the same issue. Say you have a whole class of objects that are 3/4 of a page. Without the mapping, you can't cross non-contiguous page boundaries and you'll have 25% fragmentation in the memory pool. This is the whole point of zsmalloc.

Yes, understood. This suggestion doesn't change any of that. It only assumes that no more than one page boundary is crossed.

So, briefly, IIRC the "pair mapping" is what creates the necessity to do special TLB stuff. That pair mapping is necessary to create the illusion to the compression/decompression code (and one other memcpy) that no pageframe boundary is crossed. Correct?

The compression code already compresses to a per-cpu page-pair already and then that "zpage" is copied into the space allocated for it by zsmalloc. For that final copy, if the copy code knows the target may cross a page boundary, has both target pages kmap'ed, and is smart about doing the copy, the "pair mapping" can be avoided for compression.

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

What about the horrible cost of that extra copy? Well, much of the cost of a large copy is due to cache effects. Since you are copying into a page that will immediately be overwritten by the decompress, I'll bet that cost is much smaller. And compared to the cost of setting up and tearing down TLB entries (especially on machines with no local_tlb_kernel_range), I suspect that special copy may be a LOT cheaper. And with no special TLB code required, zsmalloc should be a lot more portable.

Thoughts?
Dan

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

#16 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 8 lines
Quoted 7 lines

From: Seth Jennings [mailto:[email protected]]

To add to what Nitin just sent, without the page mapping, zsmalloc and the late xvmalloc have the same issue. Say you have a whole class of objects that are 3/4 of a page. Without the mapping, you can't cross non-contiguous page boundaries and you'll have 25% fragmentation in the memory pool. This is the whole point of zsmalloc.

Quoted 8 lines

Yes, understood. This suggestion doesn't change any of that. It only assumes that no more than one page boundary is crossed.

So, briefly, IIRC the "pair mapping" is what creates the necessity to do special TLB stuff. That pair mapping is necessary to create the illusion to the compression/decompression code (and one other memcpy) that no pageframe boundary is crossed. Correct?

Yes.

Quoted 6 lines

The compression code already compresses to a per-cpu page-pair already and then that "zpage" is copied into the space allocated for it by zsmalloc. For that final copy, if the copy code knows the target may cross a page boundary, has both target pages kmap'ed, and is smart about doing the copy, the "pair mapping" can be avoided for compression.

The problem is that by "smart" you mean "has access to zsmalloc internals". zcache, or any user, would need the know the kmapped address of the first page, the offset to start at within that page, and the kmapped address of the second page in order to do the smart copy you're talking about. Then the complexity to do the smart copy that would have to be implemented in each user.

Quoted 9 lines

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

This is an interesting thought.

But this does result in a copy in the decompression (i.e. page fault) path, where right now, it is copy free. The compressed data is decompressed directly from its zsmalloc allocation to the page allocated in the fault path.

Doing this smart copy stuff would move most of the complexity out of zsmalloc into the user which defeats the purpose of abstracting the functionality out in the first place: so the each user that wants to do something like this doesn't have to reinvent the wheel.

--
Seth

#17 lore raw

RE: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 8 lines

From: Seth Jennings [mailto:[email protected]]

Quoted 6 lines

The compression code already compresses to a per-cpu page-pair already and then that "zpage" is copied into the space allocated for it by zsmalloc. For that final copy, if the copy code knows the target may cross a page boundary, has both target pages kmap'ed, and is smart about doing the copy, the "pair mapping" can be avoided for compression.

Quoted 6 lines

The problem is that by "smart" you mean "has access to zsmalloc internals". zcache, or any user, would need the know the kmapped address of the first page, the offset to start at within that page, and the kmapped address of the second page in order to do the smart copy you're talking about. Then the complexity to do the smart copy that would have to be implemented in each user.

Or simply add a zsmalloc_copy in zsmalloc and require that it be used by the caller (instead of a memcpy).

Quoted 10 lines
Quoted 9 lines

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

Quoted 6 lines

This is an interesting thought.

But this does result in a copy in the decompression (i.e. page fault) path, where right now, it is copy free. The compressed data is decompressed directly from its zsmalloc allocation to the page allocated in the fault path.

The page fault occurs as soon as the lzo1x compression code starts anyway, as do all the cache faults... both just occur earlier, so the only additional cost is the actual cpu instructions to move the sequence of (compressed) bytes from the zsmalloc-allocated area to the end of the target page.

TLB operations can be very expensive, not to mention (as the subject of this thread attests) non-portable.

Quoted 4 lines

Doing this smart copy stuff would move most of the complexity out of zsmalloc into the user which defeats the purpose of abstracting the functionality out in the first place: so the each user that wants to do something like this doesn't have to reinvent the wheel.

See above. It can be buried in zsmalloc.

Again, this is all just a suggestion, admittedly from someone who doesn't like pure abstractions in kernel code ;-)

Dan

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

#18 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 30 lines · Dan Magenheimer
Quoted 8 lines

From: Seth Jennings [mailto:[email protected]]

Quoted 6 lines

The compression code already compresses to a per-cpu page-pair already and then that "zpage" is copied into the space allocated for it by zsmalloc. For that final copy, if the copy code knows the target may cross a page boundary, has both target pages kmap'ed, and is smart about doing the copy, the "pair mapping" can be avoided for compression.

Quoted 6 lines

The problem is that by "smart" you mean "has access to zsmalloc internals". zcache, or any user, would need the know the kmapped address of the first page, the offset to start at within that page, and the kmapped address of the second page in order to do the smart copy you're talking about. Then the complexity to do the smart copy that would have to be implemented in each user.

Or simply add a zsmalloc_copy in zsmalloc and require that it be used by the caller (instead of a memcpy).

Quoted 12 lines
Quoted 9 lines

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

This is an interesting thought.

Quoted 7 lines
Quoted 4 lines

But this does result in a copy in the decompression (i.e. page fault) path, where right now, it is copy free. The compressed data is decompressed directly from its zsmalloc allocation to the page allocated in the fault path.

The page fault occurs as soon as the lzo1x compression code starts anyway, a

s do all the cache faults... both just occur earlier, so the only

Quoted 7 lines

additional cost is the actual cpu instructions to move the sequence of (compressed) bytes from the zsmalloc-allocated area to the end of the target page.

TLB operations can be very expensive, not to mention (as the subject of this thread attests) non-portable.

Even if you go for copying chunks followed by decompression, it still requires two kmaps and kunmaps. Each of these require one local TLB invlpg. So, a total of 2 local maps + unmaps even with this approach.

The only additional requirement of zsmalloc is that it requires two mappings which are virtually contiguous. The cost is the same in both approaches but the current zsmalloc approach presents a much cleaner interface.

Thanks,
Nitin

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

#19 lore raw

RE: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 28 lines

From: Nitin Gupta [mailto:[email protected]]
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 24 lines · Dan Magenheimer
Quoted 11 lines

From: Seth Jennings [mailto:[email protected]]

Quoted 9 lines

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

Quoted 6 lines

This is an interesting thought.

But this does result in a copy in the decompression (i.e. page fault) path, where right now, it is copy free. The compressed data is decompressed directly from its zsmalloc allocation to the page allocated in the fault path.

The page fault occurs as soon as the lzo1x compression code starts anyway, as do all the cache faults... both just occur earlier, so the only additional cost is the actual cpu instructions to move the sequence of (compressed) bytes from the zsmalloc-allocated area to the end of the target page.

Quoted 6 lines
Quoted 2 lines

TLB operations can be very expensive, not to mention (as the subject of this thread attests) non-portable.

Even if you go for copying chunks followed by decompression, it still requires two kmaps and kunmaps. Each of these require one local TLB invlpg. So, a total of 2 local maps + unmaps even with this approach.

That may be true for i386, but on a modern (non-highmem) machine those kmaps/kunmaps are free and "pair mappings" in the TLB are still expensive and not very portable. Doesn't make sense to me to design for better performance on highmem and poorer performance on non-highmem.

Quoted 4 lines

The only additional requirement of zsmalloc is that it requires two mappings which are virtually contiguous. The cost is the same in both approaches but the current zsmalloc approach presents a much cleaner interface.

OK, it's your code and I'm just making a suggestion. I will shut up now ;-)

Dan

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

#20 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 31 lines · Dan Magenheimer
Quoted 31 lines

From: Nitin Gupta [mailto:[email protected]]
Subject: Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 26 lines · Dan Magenheimer
Quoted 11 lines

From: Seth Jennings [mailto:[email protected]]

Quoted 9 lines

The decompression path calls lzo1x directly and it would be a huge pain to make lzo1x smart about page boundaries. BUT since we know that the decompressed result will always fit into a page (actually exactly a page), you COULD do an extra copy to the end of the target page (using the same smart- about-page-boundaries copying code from above) and then do in-place decompression, knowing that the decompression will not cross a page boundary. So, with the extra copy, the "pair mapping" can be avoided for decompression as well.

Quoted 6 lines

This is an interesting thought.

But this does result in a copy in the decompression (i.e. page fault) path, where right now, it is copy free. The compressed data is decompressed directly from its zsmalloc allocation to the page allocated in the fault path.

The page fault occurs as soon as the lzo1x compression code starts anyway, as do all the cache faults... both just occur earlier, so the only additional cost is the actual cpu instructions to move the sequence of (compressed) bytes from the zsmalloc-allocated area to the end of the target page.

TLB operations can be very expensive, not to mention (as the subject of this thread attests) non-portable.

Quoted 9 lines
Quoted 3 lines

Even if you go for copying chunks followed by decompression, it still requires two kmaps and kunmaps. Each of these require one local TLB invlpg. So, a total of 2 local maps + unmaps even with this approach.

That may be true for i386, but on a modern (non-highmem) machine those kmaps/kunmaps are free and "pair mappings" in the TLB are still expensive and not very portable. Doesn't make sense to me to design for better performance on highmem and poorer performance on non-highmem.

True, but it seem hard to believe that mapping+unmappig+two local TLB invlpg's will be more costly than copying, on average, PAGE_SIZE/2 data.

Anyways, I just looked up the LZO documentation and it supposedly allows in place decompression (hopefully we didn't mess up this feature during kernel port). Considering cache effects, this may really make copying overhead much less than expected. Additionally, in case we go for copying approach, we can further simplify compaction since any client can never directly reference pool memory.

Quoted 7 lines
Quoted 4 lines

The only additional requirement of zsmalloc is that it requires two mappings which are virtually contiguous. The cost is the same in both approaches but the current zsmalloc approach presents a much cleaner interface.

OK, it's your code and I'm just making a suggestion. I will shut up now ;-)

I'm always glad to hear your opinions and was just trying to discuss the points you raised. I apologize if I sounded rude.

Thanks,
Nitin

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

#21 lore raw

Re: [PATCH v2 3/3] x86: Support local_flush_tlb_kernel_range

Quoted 9 lines · Nitin Gupta
Quoted 4 lines · Dan Magenheimer

OK, it's your code and I'm just making a suggestion. I will shut up now ;-)

I'm always glad to hear your opinions and was just trying to discuss the points you raised. I apologize if I sounded rude.

Same here. It's always good to go back and rethink your assumptions. Thanks Dan!

Thanks,
Seth