All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Ming Lei <ming.lei@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/6] block: manage bio slab cache by xarray
Date: Mon, 4 Jan 2021 09:54:21 +0100	[thread overview]
Message-ID: <20210104085421.GA28949@lst.de> (raw)
In-Reply-To: <20201230003255.3450874-2-ming.lei@redhat.com>

On Wed, Dec 30, 2020 at 08:32:50AM +0800, Ming Lei wrote:
> Managing bio slab cache via xarray by using slab cache size as xarray index, and

Overly long line in the commit log above.

> +static struct bio_slab *create_bio_slab(unsigned int size)
> +{
> +	struct bio_slab *bslab = kzalloc(sizeof(*bslab), GFP_KERNEL);
> +	if (!bslab)
> +		return NULL;

Missing whitespace after the variable declaration.

> +
> +	snprintf(bslab->name, sizeof(bslab->name), "bio-%d", size);
> +	bslab->slab = kmem_cache_create(bslab->name, size,
> +			ARCH_KMALLOC_MINALIGN, SLAB_HWCACHE_ALIGN, NULL);
> +	if (bslab->slab) {
> +		bslab->slab_ref = 1;
> +		bslab->slab_size = size;
> +	} else {
> +		kfree(bslab);
> +		bslab = NULL;
> +	}
> +	return bslab;
> +}

I'd simply this to:

	if (!bslab->slab) {
		kfree(bslab);
		return NULL;
	}

	bslab->slab_ref = 1;
	bslab->slab_size = size;
	return bslab;
}

>  
>  static struct kmem_cache *bio_find_or_create_slab(unsigned int extra_size)
>  {
>  	unsigned int sz = sizeof(struct bio) + extra_size;
>  	struct kmem_cache *slab = NULL;
> +	struct bio_slab *bslab;
>  
>  	mutex_lock(&bio_slab_lock);
> +	bslab = xa_load(&bio_slabs, sz);
> +	if (bslab) {
> +		slab = bslab->slab;
> +		bslab->slab_ref++;
> +	} else {
> +		bslab = create_bio_slab(sz);
> +		if(bslab && !xa_err(xa_store(&bio_slabs, sz, bslab,
> +						GFP_KERNEL)))

Missing whitespace after the "if"

But more importantly, I'd expect the xa_store to go into create_bio_slab
to make the code a little more readable and to consolidate the error
handling.  Also we really shouldn't need the slab local variable in
this function.

>  static void bio_put_slab(struct bio_set *bs)
>  {
>  	struct bio_slab *bslab = NULL;
> +	unsigned int slab_size = bs->front_pad + sizeof(struct bio) +
> +		BIO_INLINE_VECS * sizeof(struct bio_vec);

This calculation would look nice factored out into a little helper with
a comment explaining it.

  reply	other threads:[~2021-01-04  8:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30  0:32 [PATCH 0/6] block: improvement on bioset & bvec allocation Ming Lei
2020-12-30  0:32 ` [PATCH 1/6] block: manage bio slab cache by xarray Ming Lei
2021-01-04  8:54   ` Christoph Hellwig [this message]
2020-12-30  0:32 ` [PATCH 2/6] block: don't pass BIOSET_NEED_BVECS for q->bio_split Ming Lei
2021-01-04 18:13   ` Christoph Hellwig
2020-12-30  0:32 ` [PATCH 3/6] block: don't allocate inline bvecs if this bioset needn't bvecs Ming Lei
2021-01-04  8:55   ` Christoph Hellwig
2020-12-30  0:32 ` [PATCH 4/6] block: set .bi_max_vecs as actual allocated vector number Ming Lei
2021-01-04  8:55   ` Christoph Hellwig
2020-12-30  0:32 ` [PATCH 5/6] block: move three bvec helpers declaration into private helper Ming Lei
2021-01-04  8:56   ` Christoph Hellwig
2020-12-30  0:32 ` [PATCH 6/6] bcache: don't pass BIOSET_NEED_BVECS for the 'bio_set' embedded in 'cache_set' Ming Lei
2021-01-04  8:57   ` Christoph Hellwig

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=20210104085421.GA28949@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.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.