linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Jisheng Zhang <jszhang@kernel.org>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Jens Axboe <axboe@kernel.dk>,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org
Subject: Re: [PATCH] zram: use copy_page for full page copy
Date: Fri, 14 Jun 2024 14:31:08 +0900	[thread overview]
Message-ID: <20240614053108.GC479513@google.com> (raw)
In-Reply-To: <ZmvUMPc1eEOwUo7h@infradead.org>

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

  reply	other threads:[~2024-06-14  5:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
  -- 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

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=20240614053108.GC479513@google.com \
    --to=senozhatsky@chromium.org \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=jszhang@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@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).