public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: John Garry <john.g.garry@oracle.com>,
	Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, "yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH 2/2] block: remove the bi_inline_vecs variable sized array from struct bio
Date: Thu, 11 Sep 2025 08:12:21 +0200	[thread overview]
Message-ID: <20250911061221.GC12964@lst.de> (raw)
In-Reply-To: <8257e4d7-cf2e-6913-06fd-f11c2f94f38a@huaweicloud.com>

On Tue, Sep 09, 2025 at 04:40:33PM +0800, Yu Kuai wrote:
> Hi,
>
> 在 2025/09/09 16:16, John Garry 写道:
>>> diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c
>>> index 4fc80c6d5b31..73918e55bf04 100644
>>> --- a/drivers/md/bcache/movinggc.c
>>> +++ b/drivers/md/bcache/movinggc.c
>>> @@ -145,9 +145,9 @@ static void read_moving(struct cache_set *c)
>>>               continue;
>>>           }
>>> -        io = kzalloc(struct_size(io, bio.bio.bi_inline_vecs,
>>> -                     DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS)),
>>> -                 GFP_KERNEL);
>>> +        io = kzalloc(sizeof(*io) + sizeof(struct bio_vec) *
>>> +                DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS),
>>> +                GFP_KERNEL);
>>
>> this seems a common pattern, so maybe another helper (which could be used 
>> by bio_kmalloc)? I am not advocating it, but just putting the idea out 
>> there... too many helpers makes it messy IMHO
>
> Not sure how to do this, do you mean a marco to pass in the base
> structure type, nr_vecs and the gfp_mask?

It's not a very common pattern, and should be even less common.
If a driver / file system wants to embed a bio into its own structure
but dynamically allocate the bio_vecs, it can simply use kmalloc_array,
or add a bio_vec VLA to its own structure and use struct_size on that.


  parent reply	other threads:[~2025-09-11  6:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 10:56 remove the bi_inline_vecs field struct bio Christoph Hellwig
2025-09-08 10:56 ` [PATCH 1/2] block: add a bio_init_inline helper Christoph Hellwig
2025-09-09  8:34   ` Yu Kuai
2025-09-09  8:43   ` John Garry
2025-09-11  6:10     ` Christoph Hellwig
2025-09-08 10:56 ` [PATCH 2/2] block: remove the bi_inline_vecs variable sized array from struct bio Christoph Hellwig
2025-09-09  8:16   ` John Garry
2025-09-09  8:40     ` Yu Kuai
2025-09-09  8:55       ` John Garry
2025-09-09  9:10         ` Yu Kuai
2025-09-11  6:12       ` Christoph Hellwig [this message]
2025-09-11  6:07     ` Christoph Hellwig
2025-09-09 13:32 ` remove the bi_inline_vecs field " Jens Axboe

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=20250911061221.GC12964@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=john.g.garry@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox