From: Christoph Hellwig <hch@infradead.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Qu Wenruo <quwenruo.btrfs@gmx.com>,
Linux Memory Management List <linux-mm@kvack.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
linux-fsdevel@vger.kernel.org,
linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: Proper way to copy de-compressed data into a bio, in folio style?
Date: Thu, 3 Apr 2025 23:16:20 -0700 [thread overview]
Message-ID: <Z-95NPq_JCQb84XZ@infradead.org> (raw)
In-Reply-To: <Z-7I9hOcGzQMV3hq@casper.infradead.org>
On Thu, Apr 03, 2025 at 06:44:22PM +0100, Matthew Wilcox wrote:
> > On the other hand, I'm having some internal code to convert a bio_vec
> > into a folio and offset inside the folio already.
> > Thus I'm wondering can we provide something like bio_for_each_folio()?
> > Or is it too niche that only certain fs can benefit from?
>
> I don't understand your requirements. but doing something different that
> fills in a folio_iter along the lines of bio_for_each_folio_all()
> would make sense.
>
Looking at btrfs_decompress_buf2page it uses bio_iter_iovec, which is
the building block use by bio_for_each_segment to build segments, that
is bvecs that are constrained to PAGE_SIZE boundaries. In this for
a good reason as it then wants to copy into them with a single kmap
mapping.
This means that bv_offset is always less than PAGE_SIZE for these
generated bio_vecs.
In the short run I'd suggest to just keep using the existing open-coded
bio_for_each_segment-like loop so that each iteration covers a PAGE_SIZE
granularity chunk. Just stop messing th the bvec fields directly and
use bvec_kmap_local to map the destination and do a plain memcpy into
that instead of using memcpy_to_page.
In the long run it would be great to just rewrite the low-level
decompressors to work on an iov_iter as output and remove the need
for the extra data copy entirely, but if that can't happen we'll
just need for figure out how we can do useful kmaps larger than
PAGE_SIZE or stop allowing highmem pages for btrfs and then switch to
a folio based iterator.
prev parent reply other threads:[~2025-04-04 6:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-31 8:15 Proper way to copy de-compressed data into a bio, in folio style? Qu Wenruo
2025-04-03 17:44 ` Matthew Wilcox
2025-04-04 6:16 ` Christoph Hellwig [this message]
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=Z-95NPq_JCQb84XZ@infradead.org \
--to=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=willy@infradead.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).