linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>, Nick Terrell <terrelln@fb.com>,
	Chris Down <chris@chrisdown.name>, Qu Wenruo <wqu@suse.com>,
	Filipe Manana <fdmanana@suse.com>,
	Gabriel Niebler <gniebler@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ira Weiny <ira.weiny@intel.com>, David Sterba <dsterba@suse.cz>
Subject: Re: [PATCH] btrfs: Replace kmap_atomic() with kmap_local_page()
Date: Thu, 7 Jul 2022 23:32:01 +0200	[thread overview]
Message-ID: <20220707213201.GR15169@twin.jikos.cz> (raw)
In-Reply-To: <20220627174849.29962-1-fmdefrancesco@gmail.com>

On Mon, Jun 27, 2022 at 07:48:49PM +0200, Fabio M. De Francesco wrote:
> kmap_atomic() is being deprecated in favor of kmap_local_page() where it
> is feasible. With kmap_local_page() mappings are per thread, CPU local,
> and not globally visible.
> 
> As far as I can see, the kmap_atomic() calls in compression.c and in
> inode.c can be safely converted.
> 
> Above all else, David Sterba has confirmed that "The context in
> check_compressed_csum is atomic [...]" and that "kmap_atomic() in inode.c
> [...] also can be replaced by kmap_local_page().".[1]
> 
> Therefore, convert all kmap_atomic() calls currently still left in fs/btrfs
> to kmap_local_page().
> 
> Tested with xfstests on a QEMU + KVM 32-bits VM with 4GB RAM and booting a
> kernel with HIGHMEM64GB enabled.
> 
> [1] https://lore.kernel.org/linux-btrfs/20220601132545.GM20
> 633@twin.jikos.cz/
> 
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Suggested-by: David Sterba <dsterba@suse.cz>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

Added to the kmap patches, thanks.

> ---
> 
> Tests of groups "quick" and "compress" output several errors largely due
> to memory leaks and shift-out-of-bounds. However, these errors are exactly
> the same which are output without this and other conversions of mine to use
> kmap_local_page(). Therefore, it looks like these changes don't introduce
> regressions.
> 
> The previous RFC PATCH can be ignored:
> https://lore.kernel.org/lkml/20220624084215.7287-1-fmdefrancesco@gmail.com/
> 
> With this patch, in fs/btrfs there are no longer call sites of kmap() and
> kmap_atomic().
> 
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -332,9 +332,9 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
>  			cur_size = min_t(unsigned long, compressed_size,
>  				       PAGE_SIZE);
>  
> -			kaddr = kmap_atomic(cpage);
> +			kaddr = kmap_local_page(cpage);

After some cleanups and simplifications in checksumming functions (that
mapped the buffers) only kmap_atomic in insert_inline_extent remains, so
the final patch will be a bit shorter.

>  			write_extent_buffer(leaf, kaddr, ptr, cur_size);
> -			kunmap_atomic(kaddr);
> +			kunmap_local(kaddr);
>  
>  			i++;
>  			ptr += cur_size;
> @@ -345,9 +345,9 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
>  	} else {
>  		page = find_get_page(inode->vfs_inode.i_mapping, 0);
>  		btrfs_set_file_extent_compression(leaf, ei, 0);
> -		kaddr = kmap_atomic(page);
> +		kaddr = kmap_local_page(page);
>  		write_extent_buffer(leaf, kaddr, ptr, size);
> -		kunmap_atomic(kaddr);
> +		kunmap_local(kaddr);
>  		put_page(page);
>  	}
>  	btrfs_mark_buffer_dirty(leaf);

      parent reply	other threads:[~2022-07-07 21:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 17:48 [PATCH] btrfs: Replace kmap_atomic() with kmap_local_page() Fabio M. De Francesco
2022-06-30 15:46 ` Ira Weiny
2022-07-07 21:32 ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220707213201.GR15169@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=chris@chrisdown.name \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=fmdefrancesco@gmail.com \
    --cc=gniebler@suse.com \
    --cc=ira.weiny@intel.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=terrelln@fb.com \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).