* [PATCH] zram: use copy_page for full page copy
@ 2024-06-13 0:04 Jisheng Zhang
2024-06-13 3:17 ` Sergey Senozhatsky
2024-06-14 5:25 ` Christoph Hellwig
0 siblings, 2 replies; 10+ messages in thread
From: Jisheng Zhang @ 2024-06-13 0:04 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe; +Cc: linux-kernel, linux-block
commit 42e99bd975fd ("zram: optimize memory operations with
clear_page()/copy_page()") optimize page copy/clean operations, but
then commit d72e9a7a93e4 ("zram: do not use copy_page with non-page
aligned address") removes the optimization because there's memory
corruption at that time, the reason was well explained. But after
commit 1f7319c74275 ("zram: partial IO refactoring"), partial IO uses
alloc_page() instead of kmalloc to allocate a page, so we can bring
back the optimization.
commit 80ba4caf8ba9 ("zram: use copy_page for full page copy") brings
back partial optimization, missed one point in zram_write_page().
optimize the full page copying in zram_write_page() with copy_page()
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
---
drivers/block/zram/zram_drv.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 3acd7006ad2c..4b2b5098062f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1478,11 +1478,13 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
src = zstrm->buffer;
- if (comp_len == PAGE_SIZE)
+ if (comp_len == PAGE_SIZE) {
src = kmap_local_page(page);
- memcpy(dst, src, comp_len);
- if (comp_len == PAGE_SIZE)
+ copy_page(dst, src);
kunmap_local(src);
+ } else {
+ memcpy(dst, src, comp_len);
+ }
zcomp_stream_put(zram->comps[ZRAM_PRIMARY_COMP]);
zs_unmap_object(zram->mem_pool, handle);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] zram: use copy_page for full page copy
2024-06-13 0:04 [PATCH] zram: use copy_page for full page copy Jisheng Zhang
@ 2024-06-13 3:17 ` Sergey Senozhatsky
2024-06-13 12:58 ` Jisheng Zhang
2024-06-14 5:25 ` Christoph Hellwig
1 sibling, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2024-06-13 3:17 UTC (permalink / raw)
To: Jisheng Zhang
Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, linux-kernel,
linux-block
On (24/06/13 08:04), Jisheng Zhang wrote:
> commit 42e99bd975fd ("zram: optimize memory operations with
> clear_page()/copy_page()") optimize page copy/clean operations, but
> then commit d72e9a7a93e4 ("zram: do not use copy_page with non-page
> aligned address") removes the optimization because there's memory
> corruption at that time, the reason was well explained. But after
> commit 1f7319c74275 ("zram: partial IO refactoring"), partial IO uses
> alloc_page() instead of kmalloc to allocate a page, so we can bring
> back the optimization.
>
> commit 80ba4caf8ba9 ("zram: use copy_page for full page copy") brings
> back partial optimization, missed one point in zram_write_page().
> optimize the full page copying in zram_write_page() with copy_page()
Is copy_page() really more optimal than memcpy(PAGE_SIZE)?
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH] zram: use copy_page for full page copy
2024-06-13 3:17 ` Sergey Senozhatsky
@ 2024-06-13 12:58 ` Jisheng Zhang
0 siblings, 0 replies; 10+ messages in thread
From: Jisheng Zhang @ 2024-06-13 12:58 UTC (permalink / raw)
To: Sergey Senozhatsky; +Cc: Minchan Kim, Jens Axboe, linux-kernel, linux-block
On Thu, Jun 13, 2024 at 12:17:31PM +0900, Sergey Senozhatsky wrote:
> On (24/06/13 08:04), Jisheng Zhang wrote:
> > commit 42e99bd975fd ("zram: optimize memory operations with
> > clear_page()/copy_page()") optimize page copy/clean operations, but
> > then commit d72e9a7a93e4 ("zram: do not use copy_page with non-page
> > aligned address") removes the optimization because there's memory
> > corruption at that time, the reason was well explained. But after
> > commit 1f7319c74275 ("zram: partial IO refactoring"), partial IO uses
> > alloc_page() instead of kmalloc to allocate a page, so we can bring
> > back the optimization.
> >
> > commit 80ba4caf8ba9 ("zram: use copy_page for full page copy") brings
> > back partial optimization, missed one point in zram_write_page().
> > optimize the full page copying in zram_write_page() with copy_page()
>
> Is copy_page() really more optimal than memcpy(PAGE_SIZE)?
I think yes copy_page performs better than memcpy(PAGE_SIZE)
commit afb2d666d025 ("zsmalloc: use copy_page for full page copy")
also shows the result.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] zram: use copy_page for full page copy
2024-06-13 0:04 [PATCH] zram: use copy_page for full page copy Jisheng Zhang
2024-06-13 3:17 ` Sergey Senozhatsky
@ 2024-06-14 5:25 ` Christoph Hellwig
2024-06-14 5:31 ` Sergey Senozhatsky
1 sibling, 1 reply; 10+ messages in thread
From: Christoph Hellwig @ 2024-06-14 5:25 UTC (permalink / raw)
To: Jisheng Zhang
Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, linux-kernel,
linux-block
On Thu, Jun 13, 2024 at 08:04:22AM +0800, Jisheng Zhang wrote:
> commit 42e99bd975fd ("zram: optimize memory operations with
> clear_page()/copy_page()") optimize page copy/clean operations, but
> then commit d72e9a7a93e4 ("zram: do not use copy_page with non-page
> aligned address") removes the optimization because there's memory
> corruption at that time, the reason was well explained. But after
> commit 1f7319c74275 ("zram: partial IO refactoring"), partial IO uses
> alloc_page() instead of kmalloc to allocate a page, so we can bring
> back the optimization.
>
> commit 80ba4caf8ba9 ("zram: use copy_page for full page copy") brings
> back partial optimization, missed one point in zram_write_page().
> optimize the full page copying in zram_write_page() with copy_page()
>
> Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> ---
> drivers/block/zram/zram_drv.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 3acd7006ad2c..4b2b5098062f 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1478,11 +1478,13 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
> dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
>
> src = zstrm->buffer;
> - if (comp_len == PAGE_SIZE)
> + if (comp_len == PAGE_SIZE) {
> src = kmap_local_page(page);
> - memcpy(dst, src, comp_len);
> - if (comp_len == PAGE_SIZE)
> + copy_page(dst, src);
> kunmap_local(src);
> + } else {
> + memcpy(dst, src, comp_len);
> + }
I know this is pre-existing code, but why do we need to kmap
for comp_len == PAGE_SIZE and not for the other cases? Something
feels really obsfucated here.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH] zram: use copy_page for full page copy
2024-06-14 5:25 ` Christoph Hellwig
@ 2024-06-14 5:31 ` Sergey Senozhatsky
0 siblings, 0 replies; 10+ messages in thread
From: Sergey Senozhatsky @ 2024-06-14 5:31 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Jisheng Zhang, Minchan Kim, Sergey Senozhatsky, Jens Axboe,
linux-kernel, linux-block
On (24/06/13 22:25), Christoph Hellwig wrote:
> On Thu, Jun 13, 2024 at 08:04:22AM +0800, Jisheng Zhang wrote:
> > commit 42e99bd975fd ("zram: optimize memory operations with
> > clear_page()/copy_page()") optimize page copy/clean operations, but
> > then commit d72e9a7a93e4 ("zram: do not use copy_page with non-page
> > aligned address") removes the optimization because there's memory
> > corruption at that time, the reason was well explained. But after
> > commit 1f7319c74275 ("zram: partial IO refactoring"), partial IO uses
> > alloc_page() instead of kmalloc to allocate a page, so we can bring
> > back the optimization.
> >
> > commit 80ba4caf8ba9 ("zram: use copy_page for full page copy") brings
> > back partial optimization, missed one point in zram_write_page().
> > optimize the full page copying in zram_write_page() with copy_page()
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> > drivers/block/zram/zram_drv.c | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 3acd7006ad2c..4b2b5098062f 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -1478,11 +1478,13 @@ static int zram_write_page(struct zram *zram, struct page *page, u32 index)
> > dst = zs_map_object(zram->mem_pool, handle, ZS_MM_WO);
> >
> > src = zstrm->buffer;
> > - if (comp_len == PAGE_SIZE)
> > + if (comp_len == PAGE_SIZE) {
> > src = kmap_local_page(page);
> > - memcpy(dst, src, comp_len);
> > - if (comp_len == PAGE_SIZE)
> > + copy_page(dst, src);
> > kunmap_local(src);
> > + } else {
> > + memcpy(dst, src, comp_len);
> > + }
>
> I know this is pre-existing code, but why do we need to kmap
> for comp_len == PAGE_SIZE and not for the other cases? Something
> feels really obsfucated here.
It is tricky a little.
If we managed to compress page (size < zsmalloc uncompressible watermark)
then src is per-CPU buffer with compressed data. Otherwise src is original
page (with uncompressed data).
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH] zram: use copy_page for full page copy
@ 2023-10-07 7:05 Mark-PK Tsai
2023-10-08 4:38 ` Sergey Senozhatsky
2024-02-05 6:50 ` Sergey Senozhatsky
0 siblings, 2 replies; 10+ messages in thread
From: Mark-PK Tsai @ 2023-10-07 7:05 UTC (permalink / raw)
To: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Matthias Brugger,
AngeloGioacchino Del Regno
Cc: yj.chiang, Mark-PK Tsai, linux-kernel, linux-block,
linux-arm-kernel, linux-mediatek
Some architectures, such as arm, have implemented
optimized copy_page for full page copying.
Replace the full page memcpy with copy_page to
take advantage of the optimization.
Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
---
drivers/block/zram/zram_drv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d77d3664ca08..58700dd73d1d 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1338,7 +1338,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
if (size == PAGE_SIZE) {
dst = kmap_atomic(page);
- memcpy(dst, src, PAGE_SIZE);
+ copy_page(dst, src);
kunmap_atomic(dst);
ret = 0;
} else {
--
2.18.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH] zram: use copy_page for full page copy
2023-10-07 7:05 Mark-PK Tsai
@ 2023-10-08 4:38 ` Sergey Senozhatsky
2024-02-05 6:43 ` Mark-PK Tsai (蔡沛剛)
2024-02-05 6:50 ` Sergey Senozhatsky
1 sibling, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2023-10-08 4:38 UTC (permalink / raw)
To: Mark-PK Tsai
Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Matthias Brugger,
AngeloGioacchino Del Regno, yj.chiang, linux-kernel, linux-block,
linux-arm-kernel, linux-mediatek
On (23/10/07 15:05), Mark-PK Tsai wrote:
>
> Some architectures, such as arm, have implemented
> optimized copy_page for full page copying.
>
> Replace the full page memcpy with copy_page to
> take advantage of the optimization.
>
> Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] zram: use copy_page for full page copy
2023-10-08 4:38 ` Sergey Senozhatsky
@ 2024-02-05 6:43 ` Mark-PK Tsai (蔡沛剛)
2024-02-05 6:48 ` Sergey Senozhatsky
0 siblings, 1 reply; 10+ messages in thread
From: Mark-PK Tsai (蔡沛剛) @ 2024-02-05 6:43 UTC (permalink / raw)
To: senozhatsky@chromium.org
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
linux-mediatek@lists.infradead.org, axboe@kernel.dk,
minchan@kernel.org, linux-arm-kernel@lists.infradead.org,
YJ Chiang (江英杰), matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com
On Sun, 2023-10-08 at 13:38 +0900, Sergey Senozhatsky wrote:
>
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> On (23/10/07 15:05), Mark-PK Tsai wrote:
> >
> > Some architectures, such as arm, have implemented
> > optimized copy_page for full page copying.
> >
> > Replace the full page memcpy with copy_page to
> > take advantage of the optimization.
> >
> > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
>
> Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
I guess this patch may have been overlooked.
Could someone please help to review it?
Thanks,
Mark
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] zram: use copy_page for full page copy
2024-02-05 6:43 ` Mark-PK Tsai (蔡沛剛)
@ 2024-02-05 6:48 ` Sergey Senozhatsky
0 siblings, 0 replies; 10+ messages in thread
From: Sergey Senozhatsky @ 2024-02-05 6:48 UTC (permalink / raw)
To: Mark-PK Tsai (蔡沛剛)
Cc: senozhatsky@chromium.org, linux-kernel@vger.kernel.org,
linux-block@vger.kernel.org, linux-mediatek@lists.infradead.org,
axboe@kernel.dk, minchan@kernel.org,
linux-arm-kernel@lists.infradead.org,
YJ Chiang (江英杰), matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com
On (24/02/05 06:43), Mark-PK Tsai (蔡沛剛) wrote:
> On Sun, 2023-10-08 at 13:38 +0900, Sergey Senozhatsky wrote:
> >
> > External email : Please do not click links or open attachments until
> > you have verified the sender or the content.
> > On (23/10/07 15:05), Mark-PK Tsai wrote:
> > >
> > > Some architectures, such as arm, have implemented
> > > optimized copy_page for full page copying.
> > >
> > > Replace the full page memcpy with copy_page to
> > > take advantage of the optimization.
> > >
> > > Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
> >
> > Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
>
> I guess this patch may have been overlooked.
> Could someone please help to review it?
Oh, yes. Let me take care of that.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] zram: use copy_page for full page copy
2023-10-07 7:05 Mark-PK Tsai
2023-10-08 4:38 ` Sergey Senozhatsky
@ 2024-02-05 6:50 ` Sergey Senozhatsky
1 sibling, 0 replies; 10+ messages in thread
From: Sergey Senozhatsky @ 2024-02-05 6:50 UTC (permalink / raw)
To: Andrew Morton, Mark-PK Tsai
Cc: Minchan Kim, Sergey Senozhatsky, Jens Axboe, Matthias Brugger,
AngeloGioacchino Del Regno, yj.chiang, linux-kernel, linux-block,
linux-arm-kernel, linux-mediatek
Cc-ing Andrew on this
On (23/10/07 15:05), Mark-PK Tsai wrote:
> Some architectures, such as arm, have implemented
> optimized copy_page for full page copying.
>
> Replace the full page memcpy with copy_page to
> take advantage of the optimization.
>
> Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
> drivers/block/zram/zram_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index d77d3664ca08..58700dd73d1d 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1338,7 +1338,7 @@ static int zram_read_from_zspool(struct zram *zram, struct page *page,
> src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
> if (size == PAGE_SIZE) {
> dst = kmap_atomic(page);
> - memcpy(dst, src, PAGE_SIZE);
> + copy_page(dst, src);
> kunmap_atomic(dst);
> ret = 0;
> } else {
> --
> 2.18.0
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-06-14 5:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 0:04 [PATCH] zram: use copy_page for full page copy Jisheng Zhang
2024-06-13 3:17 ` Sergey Senozhatsky
2024-06-13 12:58 ` Jisheng Zhang
2024-06-14 5:25 ` Christoph Hellwig
2024-06-14 5:31 ` Sergey Senozhatsky
-- strict thread matches above, loose matches on Subject: below --
2023-10-07 7:05 Mark-PK Tsai
2023-10-08 4:38 ` Sergey Senozhatsky
2024-02-05 6:43 ` Mark-PK Tsai (蔡沛剛)
2024-02-05 6:48 ` Sergey Senozhatsky
2024-02-05 6:50 ` Sergey Senozhatsky
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).