linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page()
@ 2022-06-18  9:19 Fabio M. De Francesco
  2022-06-30 22:21 ` Ira Weiny
  2022-07-07 21:18 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Fabio M. De Francesco @ 2022-06-18  9:19 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Nick Terrell, Chris Down,
	Filipe Manana, Qu Wenruo, Nikolay Borisov, Gabriel Niebler,
	linux-btrfs, linux-kernel
  Cc: Fabio M. De Francesco, Ira Weiny

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_decompress_bio()
because in this function the mappings are per thread and are not visible
in other contexts.

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

Suggested-by: Ira Weiny <ira.weiny@intel.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---
 fs/btrfs/zlib.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 2cd4f6fb1537..966e17cea981 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -284,7 +284,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 	unsigned long buf_start;
 	struct page **pages_in = cb->compressed_pages;
 
-	data_in = kmap(pages_in[page_in_index]);
+	data_in = kmap_local_page(pages_in[page_in_index]);
 	workspace->strm.next_in = data_in;
 	workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);
 	workspace->strm.total_in = 0;
@@ -306,7 +306,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 
 	if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) {
 		pr_warn("BTRFS: inflateInit failed\n");
-		kunmap(pages_in[page_in_index]);
+		kunmap_local(data_in);
 		return -EIO;
 	}
 	while (workspace->strm.total_in < srclen) {
@@ -333,13 +333,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 
 		if (workspace->strm.avail_in == 0) {
 			unsigned long tmp;
-			kunmap(pages_in[page_in_index]);
+			kunmap_local(data_in);
 			page_in_index++;
 			if (page_in_index >= total_pages_in) {
 				data_in = NULL;
 				break;
 			}
-			data_in = kmap(pages_in[page_in_index]);
+			data_in = kmap_local_page(pages_in[page_in_index]);
 			workspace->strm.next_in = data_in;
 			tmp = srclen - workspace->strm.total_in;
 			workspace->strm.avail_in = min(tmp, PAGE_SIZE);
@@ -352,7 +352,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
 done:
 	zlib_inflateEnd(&workspace->strm);
 	if (data_in)
-		kunmap(pages_in[page_in_index]);
+		kunmap_local(data_in);
 	if (!ret)
 		zero_fill_bio(cb->orig_bio);
 	return ret;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page()
  2022-06-18  9:19 [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page() Fabio M. De Francesco
@ 2022-06-30 22:21 ` Ira Weiny
  2022-07-07 21:18 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Ira Weiny @ 2022-06-30 22:21 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Nick Terrell, Chris Down,
	Filipe Manana, Qu Wenruo, Nikolay Borisov, Gabriel Niebler,
	linux-btrfs, linux-kernel

On Sat, Jun 18, 2022 at 11:19:01AM +0200, 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_decompress_bio()
> because in this function the mappings are per thread and are not visible
> in other contexts.
> 
> Tested with xfstests on QEMU + KVM 32-bits VM with 4GB of RAM and
> HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".
> 
> Suggested-by: Ira Weiny <ira.weiny@intel.com>

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> Reviewed-by: Qu Wenruo <wqu@suse.com>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
> ---
>  fs/btrfs/zlib.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
> index 2cd4f6fb1537..966e17cea981 100644
> --- a/fs/btrfs/zlib.c
> +++ b/fs/btrfs/zlib.c
> @@ -284,7 +284,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
>  	unsigned long buf_start;
>  	struct page **pages_in = cb->compressed_pages;
>  
> -	data_in = kmap(pages_in[page_in_index]);
> +	data_in = kmap_local_page(pages_in[page_in_index]);
>  	workspace->strm.next_in = data_in;
>  	workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE);
>  	workspace->strm.total_in = 0;
> @@ -306,7 +306,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
>  
>  	if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) {
>  		pr_warn("BTRFS: inflateInit failed\n");
> -		kunmap(pages_in[page_in_index]);
> +		kunmap_local(data_in);
>  		return -EIO;
>  	}
>  	while (workspace->strm.total_in < srclen) {
> @@ -333,13 +333,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
>  
>  		if (workspace->strm.avail_in == 0) {
>  			unsigned long tmp;
> -			kunmap(pages_in[page_in_index]);
> +			kunmap_local(data_in);
>  			page_in_index++;
>  			if (page_in_index >= total_pages_in) {
>  				data_in = NULL;
>  				break;
>  			}
> -			data_in = kmap(pages_in[page_in_index]);
> +			data_in = kmap_local_page(pages_in[page_in_index]);
>  			workspace->strm.next_in = data_in;
>  			tmp = srclen - workspace->strm.total_in;
>  			workspace->strm.avail_in = min(tmp, PAGE_SIZE);
> @@ -352,7 +352,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)
>  done:
>  	zlib_inflateEnd(&workspace->strm);
>  	if (data_in)
> -		kunmap(pages_in[page_in_index]);
> +		kunmap_local(data_in);
>  	if (!ret)
>  		zero_fill_bio(cb->orig_bio);
>  	return ret;
> -- 
> 2.36.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page()
  2022-06-18  9:19 [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page() Fabio M. De Francesco
  2022-06-30 22:21 ` Ira Weiny
@ 2022-07-07 21:18 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2022-07-07 21:18 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Chris Mason, Josef Bacik, David Sterba, Nick Terrell, Chris Down,
	Filipe Manana, Qu Wenruo, Nikolay Borisov, Gabriel Niebler,
	linux-btrfs, linux-kernel, Ira Weiny

On Sat, Jun 18, 2022 at 11:19:01AM +0200, 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_decompress_bio()
> because in this function the mappings are per thread and are not visible
> in other contexts.
> 
> Tested with xfstests on QEMU + KVM 32-bits VM with 4GB of RAM and
> HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress".
> 
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

Added to the kmap patches, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-07 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-18  9:19 [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page() Fabio M. De Francesco
2022-06-30 22:21 ` Ira Weiny
2022-07-07 21:18 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).