From: Keith Busch <kbusch@kernel.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Keith Busch <kbusch@meta.com>,
dm-devel@lists.linux.dev, linux-block@vger.kernel.org,
snitzer@kernel.org
Subject: Re: [RESEND PATCHv3 2/2] dm-crypt: dynamic scatterlist for many segments
Date: Wed, 18 Mar 2026 11:01:14 -0600 [thread overview]
Message-ID: <abraWvuLlTjHF-9q@kbusch-mbp> (raw)
In-Reply-To: <08fbfa54-0e19-82b5-01ba-216a4202d2e5@redhat.com>
On Wed, Mar 18, 2026 at 05:34:47PM +0100, Mikulas Patocka wrote:
> On Mon, 16 Mar 2026, Keith Busch wrote:
> > +static int crypt_build_sgl(struct crypt_config *cc, struct scatterlist **psg,
> > struct bvec_iter *iter, struct bio *bio,
> > int max_segs)
> > {
> > unsigned int bytes = cc->sector_size;
> > + struct scatterlist *sg = *psg;
> > struct bvec_iter tmp = *iter;
> > int segs, i = 0;
> >
> > bio_advance_iter(bio, &tmp, bytes);
> > segs = tmp.bi_idx - iter->bi_idx + !!tmp.bi_bvec_done;
> > - if (segs > max_segs)
> > - return -EIO;
> > + if (segs > max_segs) {
> > + sg = kmalloc_array(segs, sizeof(struct scatterlist), GFP_NOIO);
> > + if (!sg)
> > + return -ENOMEM;
> > + }
> >
> > sg_init_table(sg, segs);
> > do {
>
> GFP_NOIO allocations may be unavailable when you are swapping to the
> dm-crypt device and the machine runs out of memory temporarily. There
> should be:
>
> sg = kmalloc_array(segs, sizeof(struct scatterlist), GFP_NOWAIT | __GFP_NOMEMALLOC);
>
> and if it fails, allocate "sg" from a mempool with GFP_NOIO (mempool_alloc
> with GFP_NOIO can't fail, it waits until someone frees some entries into
> the mempool).
Thanks for the suggestion, this sounds good. Just to note, the use case
for swap always writes out pages, so it's always aligned and would never
take this path. The use case in mind where this path could happen is
just for zero-copy direct io applications.
But even then, the only thing I know of that really wants this has an
offset that straddles two pages per block, so I never need more than 2
segments, and the inline scatterlist has four. There's just currently no
way for the block layer to report a max-segments-per-block limit, so I'm
including this patch to be consistent with the reportable limits.
next prev parent reply other threads:[~2026-03-18 17:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 15:02 [RESEND PATCHv3 1/2] dm-crypt: allow unaligned bio_vecs for direct io Keith Busch
2026-03-16 15:09 ` [RESEND PATCHv3 2/2] dm-crypt: dynamic scatterlist for many segments Keith Busch
2026-03-18 16:34 ` Mikulas Patocka
2026-03-18 17:01 ` Keith Busch [this message]
2026-03-18 17:40 ` Mikulas Patocka
2026-03-18 17:53 ` Keith Busch
2026-03-18 18:16 ` Mikulas Patocka
2026-03-18 18:32 ` Keith Busch
2026-03-18 18:41 ` Mikulas Patocka
2026-03-16 15:09 ` [RESEND PATCHv3 0/2] dm-crypt: support relaxed memory alignment Keith Busch
2026-03-18 16:19 ` [RESEND PATCHv3 1/2] dm-crypt: allow unaligned bio_vecs for direct io Mikulas Patocka
2026-03-18 17:40 ` Keith Busch
2026-03-18 18:06 ` Mikulas Patocka
2026-03-18 18:35 ` Keith Busch
2026-03-25 18:34 ` Keith Busch
-- strict thread matches above, loose matches on Subject: below --
2026-01-14 15:49 [RESEND PATCHv3 0/2] dm-crypt: support relaxed memory alignment Keith Busch
2026-01-14 15:49 ` [RESEND PATCHv3 2/2] dm-crypt: dynamic scatterlist for many segments Keith Busch
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=abraWvuLlTjHF-9q@kbusch-mbp \
--to=kbusch@kernel.org \
--cc=dm-devel@lists.linux.dev \
--cc=kbusch@meta.com \
--cc=linux-block@vger.kernel.org \
--cc=mpatocka@redhat.com \
--cc=snitzer@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