From: Joe Perches <joe@perches.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
Juergen Gross <jgross@suse.com>,
boris.ostrovsky@oracle.com, sstabellini@kernel.org,
roger.pau@citrix.com, axboe@kernel.dk
Cc: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] xen-blkfront: Use the bitmap API when applicable
Date: Thu, 02 Dec 2021 19:03:32 -0800 [thread overview]
Message-ID: <863f2cddacac590d581cda09d548ee0a652df8a1.camel@perches.com> (raw)
In-Reply-To: <3d71577f-dabe-6e1a-4b03-2a44f304b702@wanadoo.fr>
On Thu, 2021-12-02 at 20:07 +0100, Christophe JAILLET wrote:
> Le 02/12/2021 à 19:16, Joe Perches a écrit :
> > On Thu, 2021-12-02 at 19:12 +0100, Christophe JAILLET wrote:
> > > Le 02/12/2021 à 07:12, Juergen Gross a écrit :
> > > > On 01.12.21 22:10, Christophe JAILLET wrote:
> > > > > Use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid
> > > > > some open-coded arithmetic in allocator arguments.
> > > > >
> > > > > Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
> > > > > consistency.
> > > > >
> > > > > Use 'bitmap_copy()' to avoid an explicit 'memcpy()'
> > []
> > > > > diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> > []
> > > > > @@ -442,16 +442,14 @@ static int xlbd_reserve_minors(unsigned int
> > > > > minor, unsigned int nr)
> > > > > if (end > nr_minors) {
> > > > > unsigned long *bitmap, *old;
> > > > > - bitmap = kcalloc(BITS_TO_LONGS(end), sizeof(*bitmap),
> > > > > - GFP_KERNEL);
> > > > > + bitmap = bitmap_zalloc(end, GFP_KERNEL);
> > > > > if (bitmap == NULL)
> > > > > return -ENOMEM;
> > > > > spin_lock(&minor_lock);
> > > > > if (end > nr_minors) {
> > > > > old = minors;
> > > > > - memcpy(bitmap, minors,
> > > > > - BITS_TO_LONGS(nr_minors) * sizeof(*bitmap));
> > > > > + bitmap_copy(bitmap, minors, nr_minors);
> > > > > minors = bitmap;
> > > > > nr_minors = BITS_TO_LONGS(end) * BITS_PER_LONG;
> >
> > nr_minors = end;
> > ?
> >
>
> No,
> My understanding of the code is that if we lack space (end > nr_minors),
> we need to allocate more. In such a case, we want to keep track of what
> we have allocated, not what we needed.
> The "padding" bits in the "long align" allocation, can be used later.
>
> first call
> ----------
> end = 65
> nr_minors = 63
>
> --> we need some space
> --> we allocate 2 longs = 128 bits
> --> we now use 65 bits of these 128 bits
or 96, 32 or 64 bit longs remember.
>
> new call
> --------
> end = 68
> nr_minors = 128 (from previous call)
The initial allocation is now bitmap_zalloc which
specifies only bits and the nr_minors is then in
BITS_TO_LONGS(bits) * BITS_PER_LONG
Perhaps that assumes too much about the internal
implementation of bitmap_alloc
next prev parent reply other threads:[~2021-12-03 3:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-01 21:10 Christophe JAILLET
2021-12-02 6:12 ` Juergen Gross
2021-12-02 18:12 ` Christophe JAILLET
2021-12-02 18:16 ` Joe Perches
2021-12-02 19:07 ` Christophe JAILLET
2021-12-03 3:03 ` Joe Perches [this message]
2021-12-03 15:54 ` Christophe JAILLET
2021-12-03 16:10 ` Joe Perches
2021-12-03 21:04 ` Boris Ostrovsky
2021-12-04 6:57 ` Christophe JAILLET
2021-12-04 7:05 ` Joe Perches
2021-12-06 13:31 ` Boris Ostrovsky
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=863f2cddacac590d581cda09d548ee0a652df8a1.camel@perches.com \
--to=joe@perches.com \
--cc=axboe@kernel.dk \
--cc=boris.ostrovsky@oracle.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=jgross@suse.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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
all inboxes | Powered by JetHome®