linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page()
@ 2022-07-17  8:36 Fabio M. De Francesco
  2022-07-18  5:14 ` Christoph Hellwig
  2022-07-24 10:25 ` Chao Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Fabio M. De Francesco @ 2022-07-17  8:36 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, Nick Terrell, linux-f2fs-devel, linux-kernel
  Cc: Fabio M. De Francesco, Christoph Hellwig, Ira Weiny

f2fs_copy_page() is a wrapper around two kmap() + one memcpy() from/to
the mapped pages. It unnecessarily duplicates a kernel API and it makes
use of kmap(), which is being deprecated in favor of kmap_local_page().

Two main problems with kmap(): (1) It comes with an overhead as mapping
space is restricted and protected by a global lock for synchronization and
(2) it also requires global TLB invalidation when the kmap’s pool wraps
and it might block when the mapping space is fully utilized until a slot
becomes available.

With kmap_local_page() the mappings are per thread, CPU local, can take
page faults, and can be called from any context (including interrupts).
It is faster than kmap() in kernels with HIGHMEM enabled. Therefore, its
use in __clone_blkaddrs() is safe and should be preferred.

Delete f2fs_copy_page() and use a plain memcpy_page() in the only one
site calling the removed function. memcpy_page() avoids open coding two
kmap_local_page() + one memcpy() between the two kernel virtual addresses.

Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>
---

This patch extends the scope and replaces "f2fs: Use memcpy_page() in
f2fs_copy_page()", as suggested by Christoph Hellwig (thanks!):
https://lore.kernel.org/lkml/YtOyWOKFN9ramUyb@infradead.org/

 fs/f2fs/f2fs.h | 10 ----------
 fs/f2fs/file.c |  2 +-
 2 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index d9bbecd008d2..52be3e23ae7c 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2696,16 +2696,6 @@ static inline struct page *f2fs_pagecache_get_page(
 	return pagecache_get_page(mapping, index, fgp_flags, gfp_mask);
 }
 
-static inline void f2fs_copy_page(struct page *src, struct page *dst)
-{
-	char *src_kaddr = kmap(src);
-	char *dst_kaddr = kmap(dst);
-
-	memcpy(dst_kaddr, src_kaddr, PAGE_SIZE);
-	kunmap(dst);
-	kunmap(src);
-}
-
 static inline void f2fs_put_page(struct page *page, int unlock)
 {
 	if (!page)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index bd14cef1b08f..8d984aeb270f 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1278,7 +1278,7 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
 				f2fs_put_page(psrc, 1);
 				return PTR_ERR(pdst);
 			}
-			f2fs_copy_page(psrc, pdst);
+			memcpy_page(pdst, 0, psrc, 0, PAGE_SIZE);
 			set_page_dirty(pdst);
 			f2fs_put_page(pdst, 1);
 			f2fs_put_page(psrc, 1);
-- 
2.37.1


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

* Re: [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page()
  2022-07-17  8:36 [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page() Fabio M. De Francesco
@ 2022-07-18  5:14 ` Christoph Hellwig
  2022-07-24 10:25 ` Chao Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2022-07-18  5:14 UTC (permalink / raw)
  To: Fabio M. De Francesco
  Cc: Jaegeuk Kim, Chao Yu, Nick Terrell, linux-f2fs-devel,
	linux-kernel, Christoph Hellwig, Ira Weiny

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page()
  2022-07-17  8:36 [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page() Fabio M. De Francesco
  2022-07-18  5:14 ` Christoph Hellwig
@ 2022-07-24 10:25 ` Chao Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2022-07-24 10:25 UTC (permalink / raw)
  To: Fabio M. De Francesco, Jaegeuk Kim, Nick Terrell,
	linux-f2fs-devel, linux-kernel
  Cc: Christoph Hellwig, Ira Weiny

On 2022/7/17 16:36, Fabio M. De Francesco wrote:
> f2fs_copy_page() is a wrapper around two kmap() + one memcpy() from/to
> the mapped pages. It unnecessarily duplicates a kernel API and it makes
> use of kmap(), which is being deprecated in favor of kmap_local_page().
> 
> Two main problems with kmap(): (1) It comes with an overhead as mapping
> space is restricted and protected by a global lock for synchronization and
> (2) it also requires global TLB invalidation when the kmap’s pool wraps
> and it might block when the mapping space is fully utilized until a slot
> becomes available.
> 
> With kmap_local_page() the mappings are per thread, CPU local, can take
> page faults, and can be called from any context (including interrupts).
> It is faster than kmap() in kernels with HIGHMEM enabled. Therefore, its
> use in __clone_blkaddrs() is safe and should be preferred.
> 
> Delete f2fs_copy_page() and use a plain memcpy_page() in the only one
> site calling the removed function. memcpy_page() avoids open coding two
> kmap_local_page() + one memcpy() between the two kernel virtual addresses.
> 
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Suggested-by: Ira Weiny <ira.weiny@intel.com>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

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

end of thread, other threads:[~2022-07-24 10:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-17  8:36 [PATCH] f2fs: Delete f2fs_copy_page() and replace with memcpy_page() Fabio M. De Francesco
2022-07-18  5:14 ` Christoph Hellwig
2022-07-24 10:25 ` Chao Yu

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).