diff mbox series

[05/17] fs/btrfs: Convert to memzero_page()

Message ID 20201124060755.1405602-6-ira.weiny@intel.com (mailing list archive)
State New, archived
Headers show
Series kmap: Create mem*_page interfaces | expand

Commit Message

Ira Weiny Nov. 24, 2020, 6:07 a.m. UTC
From: Ira Weiny <ira.weiny@intel.com>

Remove the kmap/memset()/kunmap pattern and use the new memzero_page()
call where possible.

Cc: Chris Mason <clm@fb.com>
Cc: Josef Bacik <josef@toxicpanda.com>
Cc: David Sterba <dsterba@suse.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 fs/btrfs/inode.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

Comments

David Sterba Nov. 24, 2020, 2:12 p.m. UTC | #1
On Mon, Nov 23, 2020 at 10:07:43PM -0800, ira.weiny@intel.com wrote:
> From: Ira Weiny <ira.weiny@intel.com>
> 
> Remove the kmap/memset()/kunmap pattern and use the new memzero_page()
> call where possible.
> 
> Cc: Chris Mason <clm@fb.com>
> Cc: Josef Bacik <josef@toxicpanda.com>
> Cc: David Sterba <dsterba@suse.com>
> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> ---
>  fs/btrfs/inode.c | 21 +++++----------------

The patch converts the pattern only in inode.c, but there's more in
compression.c, extent_io.c, zlib.c,d zstd.c (kmap_atomic) and reflink.c,
send.c (kmap).
Ira Weiny Nov. 24, 2020, 7:25 p.m. UTC | #2
On Tue, Nov 24, 2020 at 03:12:44PM +0100, David Sterba wrote:
> On Mon, Nov 23, 2020 at 10:07:43PM -0800, ira.weiny@intel.com wrote:
> > From: Ira Weiny <ira.weiny@intel.com>
> > 
> > Remove the kmap/memset()/kunmap pattern and use the new memzero_page()
> > call where possible.
> > 
> > Cc: Chris Mason <clm@fb.com>
> > Cc: Josef Bacik <josef@toxicpanda.com>
> > Cc: David Sterba <dsterba@suse.com>
> > Signed-off-by: Ira Weiny <ira.weiny@intel.com>
> > ---
> >  fs/btrfs/inode.c | 21 +++++----------------
> 
> The patch converts the pattern only in inode.c, but there's more in
> compression.c, extent_io.c, zlib.c,d zstd.c (kmap_atomic) and reflink.c,
> send.c (kmap).

Thanks...  not sure how I missed reflink.c and send.c.

I'll add them in v2.

Thanks!
Ira
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index da58c58ef9aa..b0bcf9493236 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -590,17 +590,12 @@  static noinline int compress_file_range(struct async_chunk *async_chunk)
 		if (!ret) {
 			unsigned long offset = offset_in_page(total_compressed);
 			struct page *page = pages[nr_pages - 1];
-			char *kaddr;
 
 			/* zero the tail end of the last page, we might be
 			 * sending it down to disk
 			 */
-			if (offset) {
-				kaddr = kmap_atomic(page);
-				memset(kaddr + offset, 0,
-				       PAGE_SIZE - offset);
-				kunmap_atomic(kaddr);
-			}
+			if (offset)
+				memzero_page(page, offset, PAGE_SIZE - offset);
 			will_compress = 1;
 		}
 	}
@@ -6485,11 +6480,8 @@  static noinline int uncompress_inline(struct btrfs_path *path,
 	 * cover that region here.
 	 */
 
-	if (max_size + pg_offset < PAGE_SIZE) {
-		char *map = kmap(page);
-		memset(map + pg_offset + max_size, 0, PAGE_SIZE - max_size - pg_offset);
-		kunmap(page);
-	}
+	if (max_size + pg_offset < PAGE_SIZE)
+		memzero_page(page, pg_offset + max_size, PAGE_SIZE - max_size - pg_offset);
 	kfree(tmp);
 	return ret;
 }
@@ -8245,7 +8237,6 @@  vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
 	struct btrfs_ordered_extent *ordered;
 	struct extent_state *cached_state = NULL;
 	struct extent_changeset *data_reserved = NULL;
-	char *kaddr;
 	unsigned long zero_start;
 	loff_t size;
 	vm_fault_t ret;
@@ -8352,10 +8343,8 @@  vm_fault_t btrfs_page_mkwrite(struct vm_fault *vmf)
 		zero_start = PAGE_SIZE;
 
 	if (zero_start != PAGE_SIZE) {
-		kaddr = kmap(page);
-		memset(kaddr + zero_start, 0, PAGE_SIZE - zero_start);
+		memzero_page(page, zero_start, PAGE_SIZE - zero_start);
 		flush_dcache_page(page);
-		kunmap(page);
 	}
 	ClearPageChecked(page);
 	set_page_dirty(page);