All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ira Weiny <ira.weiny@intel.com>
To: <dsterba@suse.cz>, Qu Wenruo <wqu@suse.com>,
	<linux-btrfs@vger.kernel.org>,
	"Fabio M . De Francesco" <fmdefrancesco@gmail.com>
Subject: Re: [PATCH v2] btrfs: zlib: refactor how we prepare the buffers
Date: Tue, 21 Jun 2022 10:18:12 -0700	[thread overview]
Message-ID: <YrH9VNQnVqHgUKAC@iweiny-desk3> (raw)
In-Reply-To: <20220621131521.GW20633@twin.jikos.cz>

On Tue, Jun 21, 2022 at 03:15:21PM +0200, David Sterba wrote:
> On Tue, Jun 21, 2022 at 01:59:46PM +0800, Qu Wenruo wrote:
> > Inspired by recent kmap() change from Fabio M. De Francesco.
> > 
> > There are some weird behavior in zlib_compress_pages(), mostly around how
> > we prepare the input and output buffers.
> > 
> > [BEFORE]
> > - We hold a page mapped for a long time
> >   This is making it much harder to convert kmap() to kmap_local_page(),
> >   as such long mapped page can lead to nested mapped page.
> > 
> > - Different paths in the name of "optimization"
> >   When we ran out of input buffer, we will grab the new input with two
> >   different paths:
> > 
> >   * If there are more than one pages left, we copy the content into the
> >     input buffer.
> >     This behavior is introduced mostly for S390, as that arch needs
> >     multiple pages as input buffer for hardware decompression.
> > 
> >   * If there is only one page left, we use that page from page cache
> >     directly without copying the content.
> > 
> >   This is making page map/unmap much harder, especially due the latter
> >   case.
> > 
> > - Input and output pages can be unmapped at different timing
> >   This make it almost impossible to convert the kmap() into
> >   kmap_local_page().
> > 
> >   As kmap_local_page() have strict requirement on the sequence of nested
> >   kmap:
> >                    OK              |            BAD
> >   ---------------------------------+---------------------------------
> >   in = kmap_local_page(in_page);   | in = kmap_local_page(in_page);
> >   out = kmap_local_page(out_page); | out = kmap_local_page(out_page);
> 
> The input pages come from page cache and could be allocated from
> highmem but the output pages are allocated by us and only with GFP_NOFS
> so they don't need to be kmapped at all, right?

How important is it to optimize the HIGHMEM systems?

On !HIGHMEM systems the kmap_local_page() calls fall out anyway.

Ira

> 
> I sent the patches to remove kmap from the compression code but it was
> buggy as it removed it from the input pages too. The revert was complete
> so we get back to a known state but the output pages do not have to be
> mapped. With that removed it should be straightforward to use kmap_local
> without any nesting.

  reply	other threads:[~2022-06-21 17:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  5:59 [PATCH v2] btrfs: zlib: refactor how we prepare the buffers Qu Wenruo
2022-06-21  8:06 ` Qu Wenruo
2022-06-21 13:15 ` David Sterba
2022-06-21 17:18   ` Ira Weiny [this message]
2022-06-21 18:19     ` David Sterba
2022-06-21 22:53       ` Qu Wenruo
2022-06-22 19:50         ` David Sterba

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=YrH9VNQnVqHgUKAC@iweiny-desk3 \
    --to=ira.weiny@intel.com \
    --cc=dsterba@suse.cz \
    --cc=fmdefrancesco@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.