linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ira.weiny@intel.com
To: Andrew Morton <akpm@linux-foundation.org>,
	David Sterba <dsterba@suse.cz>
Cc: Ira Weiny <ira.weiny@intel.com>,
	clm@fb.com, josef@toxicpanda.com,
	Christoph Hellwig <hch@infradead.org>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH V2 7/8] btrfs: use copy_highpage() instead of 2 kmaps()
Date: Tue,  9 Feb 2021 22:22:20 -0800	[thread overview]
Message-ID: <20210210062221.3023586-8-ira.weiny@intel.com> (raw)
In-Reply-To: <20210210062221.3023586-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

There are many places where kmap/memove/kunmap patterns occur.

This pattern exists in the core common function copy_highpage().

Use copy_highpage to avoid open coding the use of kmap and leverages the
core functions use of kmap_local_page().

Development of this patch was aided by the following coccinelle script:

// <smpl>
// SPDX-License-Identifier: GPL-2.0-only
// Find kmap/copypage/kunmap pattern and replace with copy_highpage calls
//
// NOTE: The expressions in the copy page version of this kmap pattern are
// overly complex and so these all need individual attention.
//
// Confidence: Low
// Copyright: (C) 2021 Intel Corporation
// URL: http://coccinelle.lip6.fr/
// Comments:
// Options:

//
// Then a copy_page where we have 2 pages involved.
//
@ copy_page_rule @
expression page, page2, To, From, Size;
identifier ptr, ptr2;
type VP, VP2;
@@

/* kmap */
(
-VP ptr = kmap(page);
...
-VP2 ptr2 = kmap(page2);
|
-VP ptr = kmap_atomic(page);
...
-VP2 ptr2 = kmap_atomic(page2);
|
-ptr = kmap(page);
...
-ptr2 = kmap(page2);
|
-ptr = kmap_atomic(page);
...
-ptr2 = kmap_atomic(page2);
)

// 1 or more copy versions of the entire page
<+...
(
-copy_page(To, From);
+copy_highpage(To, From);
|
-memmove(To, From, Size);
+memmoveExtra(To, From, Size);
)
...+>

/* kunmap */
(
-kunmap(page2);
...
-kunmap(page);
|
-kunmap(page);
...
-kunmap(page2);
|
-kmap_atomic(ptr2);
...
-kmap_atomic(ptr);
)

// Remove any pointers left unused
@
depends on copy_page_rule
@
identifier copy_page_rule.ptr;
identifier copy_page_rule.ptr2;
type VP, VP1;
type VP2, VP21;
@@

-VP ptr;
	... when != ptr;
? VP1 ptr;
-VP2 ptr2;
	... when != ptr2;
? VP21 ptr2;

// </smpl>

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

---
Changes from v1:
	Update commit message per David
		https://lore.kernel.org/lkml/20210209151442.GU1993@suse.cz/
---
 fs/btrfs/raid56.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index dbf52f1a379d..7c3f6dc918c1 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -250,8 +250,6 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
 static void cache_rbio_pages(struct btrfs_raid_bio *rbio)
 {
 	int i;
-	char *s;
-	char *d;
 	int ret;
 
 	ret = alloc_rbio_pages(rbio);
@@ -262,13 +260,7 @@ static void cache_rbio_pages(struct btrfs_raid_bio *rbio)
 		if (!rbio->bio_pages[i])
 			continue;
 
-		s = kmap(rbio->bio_pages[i]);
-		d = kmap(rbio->stripe_pages[i]);
-
-		copy_page(d, s);
-
-		kunmap(rbio->bio_pages[i]);
-		kunmap(rbio->stripe_pages[i]);
+		copy_highpage(rbio->stripe_pages[i], rbio->bio_pages[i]);
 		SetPageUptodate(rbio->stripe_pages[i]);
 	}
 	set_bit(RBIO_CACHE_READY_BIT, &rbio->flags);
-- 
2.28.0.rc0.12.gb6a658bd00c9


  parent reply	other threads:[~2021-02-10  6:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-10  6:22 [PATCH V2 0/8] btrfs: convert kmaps to core page calls ira.weiny
2021-02-10  6:22 ` [PATCH V2 1/8] mm/highmem: Lift memcpy_[to|from]_page to core ira.weiny
2021-02-10  6:33   ` Chaitanya Kulkarni
2021-02-10 12:53   ` Christoph Hellwig
2021-02-10  6:22 ` [PATCH V2 2/8] mm/highmem: Convert memcpy_[to|from]_page() to kmap_local_page() ira.weiny
2021-02-10  6:37   ` Chaitanya Kulkarni
2021-02-10 12:54   ` Christoph Hellwig
2021-02-10  6:22 ` [PATCH V2 3/8] mm/highmem: Introduce memcpy_page(), memmove_page(), and memset_page() ira.weiny
2021-02-10  6:46   ` Chaitanya Kulkarni
2021-02-10 12:54   ` Christoph Hellwig
2021-02-10  6:22 ` [PATCH V2 4/8] mm/highmem: Add VM_BUG_ON() to mem*_page() calls ira.weiny
2021-02-10  6:57   ` Chaitanya Kulkarni
2021-02-10 16:31     ` Ira Weiny
2021-02-10 12:55   ` Christoph Hellwig
2021-02-10 16:29     ` Ira Weiny
2021-02-10 16:41       ` Christoph Hellwig
2021-02-10 17:04         ` Ira Weiny
2021-02-10 18:56       ` Matthew Wilcox
2021-02-10 21:22         ` Ira Weiny
2021-02-11 18:52           ` David Sterba
2021-02-10 17:49   ` [PATCH V2.1] " ira.weiny
2021-02-10  6:22 ` [PATCH V2 5/8] iov_iter: Remove memzero_page() in favor of zero_user() ira.weiny
2021-02-10 12:55   ` Christoph Hellwig
2021-02-10  6:22 ` [PATCH V2 6/8] btrfs: use memcpy_[to|from]_page() and kmap_local_page() ira.weiny
2021-02-10 12:56   ` Christoph Hellwig
2021-02-10  6:22 ` ira.weiny [this message]
2021-02-10 12:56   ` [PATCH V2 7/8] btrfs: use copy_highpage() instead of 2 kmaps() Christoph Hellwig
2021-02-10  6:22 ` [PATCH V2 8/8] btrfs: convert to zero_user() ira.weiny
2021-02-10 12:57   ` Christoph Hellwig
2021-02-11 19:38 ` [PATCH V2 0/8] btrfs: convert kmaps to core page calls David Sterba
2021-02-11 21:32   ` Ira Weiny

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=20210210062221.3023586-8-ira.weiny@intel.com \
    --to=ira.weiny@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=hch@infradead.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).