Skip to contentSkip to conversation

staging: erofs: introduce percpu map areas

PATCH New Gao Xiang 1 participant 2 messages Dec 4, 2018 Staging

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v2 1/2 staging: erofs: introduce percpu map areas

There is a need for decompress algorithms to work in continuous virtual memory areas. However, vmap or vm_map_ram will also repeatly (un)allocate vm_areas over and over again (vmap_area_lock is needed), which takes much overhead.

Let's introduce percpu vm areas as what zsmalloc does, expect that erofs needs mapping more pages at once, therefore only VM mapping is performed.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>

---
change log v2:
- fix wrong erofs_vmap()' to erofs_pcpumap'

 drivers/staging/erofs/internal.h      |   8 +++
 drivers/staging/erofs/super.c         |   7 +++
 drivers/staging/erofs/unzip_vle.c     |   8 +--
 drivers/staging/erofs/unzip_vle_lz4.c |  28 +++++----
 drivers/staging/erofs/utils.c         | 113 ++++++++++++++++++++++++++++++++++
 5 files changed, 149 insertions(+), 15 deletions(-)
drivers/staging/erofs/internal.h +8 -0
index e049d00c087a..69ec5dc9e332 100644
@@ -612,8 +612,16 @@ static inline void erofs_vunmap(const void *mem, unsigned int count)
 }
 
 /* utils.c */
+#define EROFS_FS_PERCPU_VM_PAGES	128
+
 extern struct page *erofs_allocpage(struct list_head *pool, gfp_t gfp);
 
+void *erofs_pcpumap(struct page **pages, unsigned int nr_pages);
+void erofs_pcpuunmap(void);
+
+int __init erofs_register_cpu_notifier(void);
+void erofs_unregister_cpu_notifier(void);
+
 extern void erofs_register_super(struct super_block *sb);
 extern void erofs_unregister_super(struct super_block *sb);
 
drivers/staging/erofs/super.c +7 -0
index 1ab3553c839b..8bdc3b7dbcc3 100644
@@ -560,6 +560,10 @@ static int __init erofs_module_init(void)
 	erofs_check_ondisk_layout_definitions();
 	infoln("initializing erofs " EROFS_VERSION);
 
+	err = erofs_register_cpu_notifier();
+	if (err)
+		goto cpu_notifier_err;
+
 	err = erofs_init_inode_cache();
 	if (err)
 		goto icache_err;
@@ -586,6 +590,8 @@ static int __init erofs_module_init(void)
 shrinker_err:
 	erofs_exit_inode_cache();
 icache_err:
+	erofs_unregister_cpu_notifier();
+cpu_notifier_err:
 	return err;
 }
 
@@ -595,6 +601,7 @@ static void __exit erofs_module_exit(void)
 	z_erofs_exit_zip_subsystem();
 	unregister_shrinker(&erofs_shrinker_info);
 	erofs_exit_inode_cache();
+	erofs_unregister_cpu_notifier();
 	infoln("successfully finalize erofs");
 }
 
drivers/staging/erofs/unzip_vle.c +4 -4
index 929815705b98..695f342d0509 100644
@@ -1010,12 +1010,12 @@ static int z_erofs_vle_unzip(struct super_block *sb,
 	}
 
 skip_allocpage:
-	vout = erofs_vmap(pages, nr_pages);
+	vout = erofs_pcpumap(pages, nr_pages);
 
-	err = z_erofs_vle_unzip_vmap(compressed_pages,
-		clusterpages, vout, llen, work->pageofs, overlapped);
+	err = z_erofs_vle_unzip_vmap(compressed_pages, clusterpages,
+				     vout, llen, work->pageofs, overlapped);
 
-	erofs_vunmap(vout, nr_pages);
+	erofs_pcpuunmap();
 
 out:
 	for (i = 0; i < nr_pages; ++i) {
drivers/staging/erofs/unzip_vle_lz4.c +17 -11
index de0a5d1365a4..2bf09daac206 100644
@@ -195,6 +195,20 @@ int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
 	unsigned int i;
 	int ret;
 
+	/* dst and src buffers aren't overlapped (ex, cached decompression) */
+	if (!overlapped) {
+		if (clusterpages == 1)
+			vin = kmap_atomic(compressed_pages[0]);
+		else
+			/*
+			 * Note that only clusterpages == 1 is supported now,
+			 * no need to optimize (ex, compressed percpu vm areas
+			 * for clusterpages > 1) this case in the short term,
+			 * fall back to the overlapped case as a simplication.
+			 */
+			overlapped = true;
+	}
+
 	if (overlapped) {
 		preempt_disable();
 		vin = erofs_pcpubuf[smp_processor_id()].data;
@@ -205,10 +219,6 @@ int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
 			memcpy(vin + PAGE_SIZE * i, t, PAGE_SIZE);
 			kunmap_atomic(t);
 		}
-	} else if (clusterpages == 1) {
-		vin = kmap_atomic(compressed_pages[0]);
-	} else {
-		vin = erofs_vmap(compressed_pages, clusterpages);
 	}
 
 	ret = z_erofs_unzip_lz4(vin, vout + pageofs,
@@ -216,14 +226,10 @@ int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
 	if (ret > 0)
 		ret = 0;
 
-	if (!overlapped) {
-		if (clusterpages == 1)
-			kunmap_atomic(vin);
-		else
-			erofs_vunmap(vin, clusterpages);
-	} else {
+	if (overlapped)
 		preempt_enable();
-	}
+	else
+		kunmap_atomic(vin);
 	return ret;
 }
 
drivers/staging/erofs/utils.c +113 -0

125 lines not on this page · raw message

Signature · 1 line
2.14.4
author
#1 lore raw

PATCH v2 2/2 staging: erofs: replace old percpu buffers decompression

After introducing percpu map areas, let's remove the current percpu buffers approach for two reasons:

1) It's ineffective since the buffer size for each cpu is 4 * PAGE_SIZE, and an extra memcpy will be performed after decompressing into the specific percpu buffer, and it will also fall back to vmap approach if decompression size is larger than 4 * PAGE_SIZE; Note that percpu map areas win in all cases for mobile platforms (ex, ARM), even if the decompressed size is very small, but I have to admit that a copy-based decompression method is still useful in some platforms (eg, X86 according to [1]) for small decompressed sizes;

2) It has high coupling of erofs compression code and it is not as clean as expected.

Anyway, a more cleaned hybird (memcpy for small decompressed size) approach will be introduced independently for those platforms, that is another story. Let's drop the current percpu buffers approach for now.

[1] https://lkml.org/lkml/2013/2/5/852

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 drivers/staging/erofs/unzip_vle.c     |  7 ----
 drivers/staging/erofs/unzip_vle.h     |  5 ---
 drivers/staging/erofs/unzip_vle_lz4.c | 71 +----------------------------------
 3 files changed, 1 insertion(+), 82 deletions(-)
drivers/staging/erofs/unzip_vle.c +0 -7
index 695f342d0509..24f05701ea40 100644
@@ -991,12 +991,6 @@ static int z_erofs_vle_unzip(struct super_block *sb,
 	if (llen > grp->llen)
 		llen = grp->llen;
 
-	err = z_erofs_vle_unzip_fast_percpu(compressed_pages,
-		clusterpages, pages, llen, work->pageofs,
-		z_erofs_onlinepage_endio);
-	if (err != -ENOTSUPP)
-		goto out_percpu;
-
 	if (sparsemem_pages >= nr_pages) {
 		BUG_ON(sparsemem_pages > nr_pages);
 		goto skip_allocpage;
@@ -1032,7 +1026,6 @@ static int z_erofs_vle_unzip(struct super_block *sb,
 		z_erofs_onlinepage_endio(page);
 	}
 
-out_percpu:
 	for (i = 0; i < clusterpages; ++i) {
 		page = compressed_pages[i];
 
drivers/staging/erofs/unzip_vle.h +0 -5
index 9517ace352a4..7b61fa3b0e75 100644
@@ -222,11 +222,6 @@ extern int z_erofs_vle_plain_copy(struct page **compressed_pages,
 	unsigned clusterpages, struct page **pages,
 	unsigned nr_pages, unsigned short pageofs);
 
-extern int z_erofs_vle_unzip_fast_percpu(struct page **compressed_pages,
-	unsigned clusterpages, struct page **pages,
-	unsigned outlen, unsigned short pageofs,
-	void (*endio)(struct page *));
-
 extern int z_erofs_vle_unzip_vmap(struct page **compressed_pages,
 	unsigned clusterpages, void *vaddr, unsigned llen,
 	unsigned short pageofs, bool overlapped);
drivers/staging/erofs/unzip_vle_lz4.c +1 -70

84 lines not on this page · raw message

Signature · 1 line
2.14.4