Skip to contentSkip to conversation

btrfs: Convert zlib_compress_pages() to use kmap_local_page()

PATCH In review Fabio M. De Francesco 2 participants 5 messages Jun 18, 2022 – Jun 27, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Convert zlib_compress_pages() to use kmap_local_page()

The use of kmap() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mapping is per thread, CPU local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in zlib_compress_pages() because in this function the mappings are per thread and are not visible in other contexts.

Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".

---

This patch builds only on top of
"[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu Wenruo".
https://lore.kernel.org/linux-btrfs/d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/

 fs/btrfs/zlib.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
fs/btrfs/zlib.c +9 -9
index 966e17cea981..4496dd30bd71 100644
@@ -160,7 +160,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 		ret = -ENOMEM;
 		goto out;
 	}
-	cpage_out = kmap(out_page);
+	cpage_out = kmap_local_page(out_page);
 	pages[0] = out_page;
 	nr_pages = 1;
 
@@ -198,9 +198,9 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 		 * the stream end if required
 		 */
 		if (workspace->strm.avail_out == 0) {
-			kunmap(out_page);
+			kunmap_local(cpage_out);
 			if (nr_pages == nr_dest_pages) {
-				out_page = NULL;
+				cpage_out = NULL;
 				ret = -E2BIG;
 				goto out;
 			}
@@ -209,7 +209,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 				ret = -ENOMEM;
 				goto out;
 			}
-			cpage_out = kmap(out_page);
+			cpage_out = kmap_local_page(out_page);
 			pages[nr_pages] = out_page;
 			nr_pages++;
 			workspace->strm.avail_out = PAGE_SIZE;
@@ -236,9 +236,9 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 			goto out;
 		} else if (workspace->strm.avail_out == 0) {
 			/* get another page for the stream end */
-			kunmap(out_page);
+			kunmap_local(cpage_out);
 			if (nr_pages == nr_dest_pages) {
-				out_page = NULL;
+				cpage_out = NULL;
 				ret = -E2BIG;
 				goto out;
 			}
@@ -247,7 +247,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 				ret = -ENOMEM;
 				goto out;
 			}
-			cpage_out = kmap(out_page);
+			cpage_out = kmap_local_page(out_page);
 			pages[nr_pages] = out_page;
 			nr_pages++;
 			workspace->strm.avail_out = PAGE_SIZE;
@@ -266,8 +266,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
 	*total_in = workspace->strm.total_in;
 out:
 	*out_pages = nr_pages;
-	if (out_page)
-		kunmap(out_page);
+	if (cpage_out)
+		kunmap_local(cpage_out);
 	return ret;
 }
 
Signature · 1 line
2.36.1
#1 lore raw
Quoted 5 lines · On sabato 18 giugno 2022 11:27:52 CEST Fabio M. De Francesco wrote:

The use of kmap() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mapping is per thread, CPU local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in

zlib_compress_pages()

Quoted 6 lines

because in this function the mappings are per thread and are not visible in other contexts.

Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".

Quoted 7 lines

---

This patch builds only on top of
"[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu

Wenruo".

Quoted 1 line

https://lore.kernel.org/linux-btrfs/

d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/

Quoted 1 line

I've seen that Qu sent a v2 of the above patch. However David thinks that it is better not to map pages allocated in zlib.c for output (out_page) since they cannot come from highmem because of "alloc_page(GFP_NOFS);".

@David:

I suppose that, since it builds _only_ on top of the refactor submitted by Qu, I'll have to wait and see what you decide.

If you don't want kmap_local_page() and prefer using page_address() on "out_page", please drop this patch and let me know, so that I can send a new patch which will be in accordance to your preference.

Thanks,

Fabio

#2 lore raw
Quoted 29 lines · Fabio M. De Francesco
Quoted 5 lines · On sabato 18 giugno 2022 11:27:52 CEST Fabio M. De Francesco wrote:

The use of kmap() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mapping is per thread, CPU local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in

zlib_compress_pages()

Quoted 6 lines

because in this function the mappings are per thread and are not visible in other contexts.

Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".

Quoted 7 lines

---

This patch builds only on top of
"[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu

Wenruo".

Quoted 1 line

https://lore.kernel.org/linux-btrfs/

d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/

Quoted 1 line

I've seen that Qu sent a v2 of the above patch. However David thinks that it is better not to map pages allocated in zlib.c for output (out_page) since they cannot come from highmem because of "alloc_page(GFP_NOFS);".

Quoted 8 lines

@David:

I suppose that, since it builds _only_ on top of the refactor submitted by Qu, I'll have to wait and see what you decide.

If you don't want kmap_local_page() and prefer using page_address() on "out_page", please drop this patch and let me know, so that I can send a new patch which will be in accordance to your preference.

And that would also make the convert much easier for kmap_local_page() of input pages.

I'll hold the refactor patch after all the kmap code is converted.

Thanks,
Qu

Quoted 6 lines

Thanks,

Fabio

#3 lore raw
Quoted 19 lines · On domenica 26 giugno 2022 01:03:55 CEST Qu Wenruo wrote:
Quoted 17 lines · Fabio M. De Francesco
Quoted 16 lines · On sabato 18 giugno 2022 11:27:52 CEST Fabio M. De Francesco wrote:

The use of kmap() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mapping is per thread, CPU local and not globally visible.

Therefore, use kmap_local_page() / kunmap_local() in zlib_compress_pages() because in this function the mappings are per thread and are not visible in other contexts.

Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".

---

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This patch builds only on top of
"[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu Wenruo".
https://lore.kernel.org/linux-btrfs/

d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

I've seen that Qu sent a v2 of the above patch. However David thinks that it is better not to map pages allocated in zlib.c for output (out_page) since they cannot come from highmem because of "alloc_page(GFP_NOFS);".

Quoted 8 lines
Quoted 8 lines

@David:

I suppose that, since it builds _only_ on top of the refactor submitted by
Qu, I'll have to wait and see what you decide.

If you don't want kmap_local_page() and prefer using page_address() on "out_page", please drop this patch and let me know, so that I can send

a

Quoted 6 lines
Quoted 1 line

new patch which will be in accordance to your preference.

And that would also make the convert much easier for kmap_local_page() of input pages.

I'll hold the refactor patch after all the kmap code is converted.

Thanks Qu,

I have already made a patch to zlib_compress_pages() in accordance to what David asked for, but I cannot compile and test it.

With last week update of Tumbleweed, openSUSE dropped GCC-10 for x86_32, so we've been left only with GCC-7. With GCC-7 I cannot any longer build 5.19.rc3 because it fails somewhere in drm/i915 (where code has not changed since April 2022).

I suppose it's just a mistake which they will fix within few days.

I'm pretty sure that my patch works properly, however I'm not comfortable to submit it with no successful build and tests.

Again thanks,

Fabio

#4 lore raw
In reply to Qu Wenruo
Quoted 4 lines · On domenica 26 giugno 2022 01:03:55 CEST Qu Wenruo wrote:
Quoted 2 lines · Fabio M. De Francesco
Quoted 1 line · On sabato 18 giugno 2022 11:27:52 CEST Fabio M. De Francesco wrote:

The use of kmap() is being deprecated in favor of kmap_local_page().

With

Quoted 1 line
Quoted 1 line
Quoted 1 line

kmap_local_page(), the mapping is per thread, CPU local and not

globally

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

visible.

Therefore, use kmap_local_page() / kunmap_local() in

zlib_compress_pages()

Quoted 1 line

because in this function the mappings are per thread and are not

visible

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

in other contexts.

Tested with xfstests on QEMU + KVM 32-bit VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".

---

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

This patch builds only on top of
"[PATCH] btrfs: zlib: refactor how we prepare the input buffer" by Qu

Wenruo".

Quoted 1 line

https://lore.kernel.org/linux-btrfs/

d0bfc791b5509df7b9ad44e41ada197d1b3149b3.1655519730.git.wqu@suse.com/

Quoted 1 line

I've seen that Qu sent a v2 of the above patch. However David thinks

that

Quoted 6 lines
Quoted 6 lines

it is better not to map pages allocated in zlib.c for output (out_page) since they cannot come from highmem because of "alloc_page(GFP_NOFS);".

@David:

I suppose that, since it builds _only_ on top of the refactor submitted

by

Quoted 4 lines
Quoted 4 lines

Qu, I'll have to wait and see what you decide.

If you don't want kmap_local_page() and prefer using page_address() on "out_page", please drop this patch and let me know, so that I can send

a

Quoted 9 lines
Quoted 1 line

new patch which will be in accordance to your preference.

And that would also make the convert much easier for kmap_local_page() of input pages.

I'll hold the refactor patch after all the kmap code is converted.

Thanks,
Qu

Thanks for holding the refactor patch for the time I needed.

Now zlib.c is converted to kmap_local_page() and tested:
https://lore.kernel.org/lkml/[email protected]/

Again thanks,

Fabio