Linux-Raid Archives on lore.kernel.org
 help / color / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Song Liu <song@kernel.org>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-block@vger.kernel.org, linux-raid@vger.kernel.org
Subject: [PATCH 05/11] block: remove the 1 and 4 vec bvec_slabs entries
Date: Tue,  2 Feb 2021 18:19:23 +0100
Message-ID: <20210202171929.1504939-6-hch@lst.de> (raw)
In-Reply-To: <20210202171929.1504939-1-hch@lst.de>

All bios with up to 4 bvecs use the inline bvecs in the bio itself, so
don't bother to define bvec_slabs entries for them.  Also decruftify
the bvec_slabs definition and initialization while we're at it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/bio.c | 53 ++++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 37 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 321b3479a154da..ae241252ea14e5 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -25,23 +25,17 @@
 #include "blk.h"
 #include "blk-rq-qos.h"
 
-struct biovec_slab {
+static struct biovec_slab {
 	int nr_vecs;
 	char *name;
 	struct kmem_cache *slab;
+} bvec_slabs[] __read_mostly = {
+	{ .nr_vecs = 16, .name = "biovec-16" },
+	{ .nr_vecs = 64, .name = "biovec-64" },
+	{ .nr_vecs = 128, .name = "biovec-128" },
+	{ .nr_vecs = BIO_MAX_PAGES, .name = "biovec-max" },
 };
 
-/*
- * if you change this list, also change bvec_alloc or things will
- * break badly! cannot be bigger than what you can fit into an
- * unsigned short
- */
-#define BV(x, n) { .nr_vecs = x, .name = "biovec-"#n }
-static struct biovec_slab bvec_slabs[BVEC_POOL_NR] __read_mostly = {
-	BV(1, 1), BV(4, 4), BV(16, 16), BV(64, 64), BV(128, 128), BV(BIO_MAX_PAGES, max),
-};
-#undef BV
-
 /*
  * fs_bio_set is the bio_set containing bio and iovec memory pools used by
  * IO code that does not need private memory pools.
@@ -176,12 +170,7 @@ struct bio_vec *bvec_alloc(gfp_t gfp_mask, int nr, unsigned long *idx,
 	 * see comment near bvec_array define!
 	 */
 	switch (nr) {
-	case 1:
-		*idx = 0;
-		break;
-	case 2 ... 4:
-		*idx = 1;
-		break;
+	/* smaller bios use inline vecs */
 	case 5 ... 16:
 		*idx = 2;
 		break;
@@ -1613,31 +1602,21 @@ int bioset_init_from_src(struct bio_set *bs, struct bio_set *src)
 }
 EXPORT_SYMBOL(bioset_init_from_src);
 
-static void __init biovec_init_slabs(void)
+static int __init init_bio(void)
 {
 	int i;
 
-	for (i = 0; i < BVEC_POOL_NR; i++) {
-		int size;
-		struct biovec_slab *bvs = bvec_slabs + i;
-
-		if (bvs->nr_vecs <= BIO_INLINE_VECS) {
-			bvs->slab = NULL;
-			continue;
-		}
-
-		size = bvs->nr_vecs * sizeof(struct bio_vec);
-		bvs->slab = kmem_cache_create(bvs->name, size, 0,
-                                SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
-	}
-}
-
-static int __init init_bio(void)
-{
 	BUILD_BUG_ON(BIO_FLAG_LAST > BVEC_POOL_OFFSET);
 
 	bio_integrity_init();
-	biovec_init_slabs();
+
+	for (i = 0; i < ARRAY_SIZE(bvec_slabs); i++) {
+		struct biovec_slab *bvs = bvec_slabs + i;
+
+		bvs->slab = kmem_cache_create(bvs->name,
+				bvs->nr_vecs * sizeof(struct bio_vec), 0,
+				SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+	}
 
 	if (bioset_init(&fs_bio_set, BIO_POOL_SIZE, 0, BIOSET_NEED_BVECS))
 		panic("bio: can't allocate bios\n");
-- 
2.29.2


  parent reply index

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02 17:19 cleanup bvec allocation Christoph Hellwig
2021-02-02 17:19 ` [PATCH 01/11] block: reuse BIO_INLINE_VECS for integrity bvecs Christoph Hellwig
2021-02-02 17:19 ` [PATCH 02/11] block: move struct biovec_slab to bio.c Christoph Hellwig
2021-02-02 17:19 ` [PATCH 03/11] block: factor out a bvec_alloc_gfp helper Christoph Hellwig
2021-02-02 17:19 ` [PATCH 04/11] block: streamline bvec_alloc Christoph Hellwig
2021-02-02 17:19 ` Christoph Hellwig [this message]
2021-02-02 17:19 ` [PATCH 06/11] block: turn the nr_iovecs argument to bio_alloc* into an unsigned short Christoph Hellwig
2021-02-02 17:19 ` [PATCH 07/11] block: remove a layer of indentation in bio_iov_iter_get_pages Christoph Hellwig
2021-02-02 17:19 ` [PATCH 08/11] block: set BIO_NO_PAGE_REF in bio_iov_bvec_set Christoph Hellwig
2021-02-02 17:19 ` [PATCH 09/11] block: mark the bio as cloned " Christoph Hellwig
2021-02-02 17:19 ` [PATCH 10/11] md/raid10: remove dead code in reshape_request Christoph Hellwig
2021-02-04 17:57   ` Song Liu
2021-02-02 17:19 ` [PATCH 11/11] block: use bi_max_vecs to find the bvec pool Christoph Hellwig
2021-02-07 16:21 ` cleanup bvec allocation Christoph Hellwig
2021-02-08 15:33 ` 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=20210202171929.1504939-6-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=song@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

Linux-Raid Archives on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-raid/0 linux-raid/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-raid linux-raid/ https://lore.kernel.org/linux-raid \
		linux-raid@vger.kernel.org
	public-inbox-index linux-raid

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-raid


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git