All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvmet: only allocate a single slab for bvecs
@ 2022-11-07 14:00 Christoph Hellwig
  2022-11-07 16:36 ` Keith Busch
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-11-07 14:00 UTC (permalink / raw)
  To: sagi, kch; +Cc: linux-nvme

There is no need to have a separate slab cache for each namespaces,
and having separate ones creates duplicate debugs file names as well.

Fixes: d5eff33ee6f8 ("nvmet: add simple file backed ns support")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/target/core.c        | 22 ++++++++++++++--------
 drivers/nvme/target/io-cmd-file.c | 16 +++-------------
 drivers/nvme/target/nvmet.h       |  3 ++-
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index aecb5853f8da4..683b75a992b3d 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -15,6 +15,7 @@
 
 #include "nvmet.h"
 
+struct kmem_cache *nvmet_bvec_cache;
 struct workqueue_struct *buffered_io_wq;
 struct workqueue_struct *zbd_wq;
 static const struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
@@ -1631,26 +1632,28 @@ void nvmet_subsys_put(struct nvmet_subsys *subsys)
 
 static int __init nvmet_init(void)
 {
-	int error;
+	int error = -ENOMEM;
 
 	nvmet_ana_group_enabled[NVMET_DEFAULT_ANA_GRPID] = 1;
 
+	nvmet_bvec_cache = kmem_cache_create("nvmet-bvec",
+			NVMET_MAX_MPOOL_BVEC * sizeof(struct bio_vec), 0,
+			SLAB_HWCACHE_ALIGN, NULL);
+	if (!nvmet_bvec_cache)
+		return -ENOMEM;
+
 	zbd_wq = alloc_workqueue("nvmet-zbd-wq", WQ_MEM_RECLAIM, 0);
 	if (!zbd_wq)
-		return -ENOMEM;
+		goto out_destroy_bvec_cache;
 
 	buffered_io_wq = alloc_workqueue("nvmet-buffered-io-wq",
 			WQ_MEM_RECLAIM, 0);
-	if (!buffered_io_wq) {
-		error = -ENOMEM;
+	if (!buffered_io_wq)
 		goto out_free_zbd_work_queue;
-	}
 
 	nvmet_wq = alloc_workqueue("nvmet-wq", WQ_MEM_RECLAIM, 0);
-	if (!nvmet_wq) {
-		error = -ENOMEM;
+	if (!nvmet_wq)
 		goto out_free_buffered_work_queue;
-	}
 
 	error = nvmet_init_discovery();
 	if (error)
@@ -1669,6 +1672,8 @@ static int __init nvmet_init(void)
 	destroy_workqueue(buffered_io_wq);
 out_free_zbd_work_queue:
 	destroy_workqueue(zbd_wq);
+out_destroy_bvec_cache:
+	kmem_cache_destroy(nvmet_bvec_cache);
 	return error;
 }
 
@@ -1680,6 +1685,7 @@ static void __exit nvmet_exit(void)
 	destroy_workqueue(nvmet_wq);
 	destroy_workqueue(buffered_io_wq);
 	destroy_workqueue(zbd_wq);
+	kmem_cache_destroy(nvmet_bvec_cache);
 
 	BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_entry) != 1024);
 	BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_hdr) != 1024);
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 64b47e2a46330..e55ec6fefd7f4 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -11,7 +11,6 @@
 #include <linux/fs.h>
 #include "nvmet.h"
 
-#define NVMET_MAX_MPOOL_BVEC		16
 #define NVMET_MIN_MPOOL_OBJ		16
 
 void nvmet_file_ns_revalidate(struct nvmet_ns *ns)
@@ -26,8 +25,6 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns)
 			flush_workqueue(buffered_io_wq);
 		mempool_destroy(ns->bvec_pool);
 		ns->bvec_pool = NULL;
-		kmem_cache_destroy(ns->bvec_cache);
-		ns->bvec_cache = NULL;
 		fput(ns->file);
 		ns->file = NULL;
 	}
@@ -59,16 +56,8 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 	ns->blksize_shift = min_t(u8,
 			file_inode(ns->file)->i_blkbits, 12);
 
-	ns->bvec_cache = kmem_cache_create("nvmet-bvec",
-			NVMET_MAX_MPOOL_BVEC * sizeof(struct bio_vec),
-			0, SLAB_HWCACHE_ALIGN, NULL);
-	if (!ns->bvec_cache) {
-		ret = -ENOMEM;
-		goto err;
-	}
-
 	ns->bvec_pool = mempool_create(NVMET_MIN_MPOOL_OBJ, mempool_alloc_slab,
-			mempool_free_slab, ns->bvec_cache);
+			mempool_free_slab, nvmet_bvec_cache);
 
 	if (!ns->bvec_pool) {
 		ret = -ENOMEM;
@@ -77,9 +66,10 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 
 	return ret;
 err:
+	fput(ns->file);
+	ns->file = NULL;
 	ns->size = 0;
 	ns->blksize_shift = 0;
-	nvmet_file_ns_disable(ns);
 	return ret;
 }
 
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index dfe3894205aa7..bda1c1f71f394 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -77,7 +77,6 @@ struct nvmet_ns {
 
 	struct completion	disable_done;
 	mempool_t		*bvec_pool;
-	struct kmem_cache	*bvec_cache;
 
 	int			use_p2pmem;
 	struct pci_dev		*p2p_dev;
@@ -393,6 +392,8 @@ struct nvmet_req {
 	u64			error_slba;
 };
 
+#define NVMET_MAX_MPOOL_BVEC		16
+extern struct kmem_cache *nvmet_bvec_cache;
 extern struct workqueue_struct *buffered_io_wq;
 extern struct workqueue_struct *zbd_wq;
 extern struct workqueue_struct *nvmet_wq;
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvmet: only allocate a single slab for bvecs
  2022-11-07 14:00 [PATCH] nvmet: only allocate a single slab for bvecs Christoph Hellwig
@ 2022-11-07 16:36 ` Keith Busch
  2022-11-07 17:08 ` Martin K. Petersen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Keith Busch @ 2022-11-07 16:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, kch, linux-nvme

Looks good.

Reviewed-by: Keith Busch <kbusch@kernel.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvmet: only allocate a single slab for bvecs
  2022-11-07 14:00 [PATCH] nvmet: only allocate a single slab for bvecs Christoph Hellwig
  2022-11-07 16:36 ` Keith Busch
@ 2022-11-07 17:08 ` Martin K. Petersen
  2022-11-08  3:52 ` Chaitanya Kulkarni
  2022-11-09 17:46 ` Sagi Grimberg
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2022-11-07 17:08 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sagi, kch, linux-nvme


Christoph,

> There is no need to have a separate slab cache for each namespaces,

s/namespaces/namespace/

Otherwise OK.

> and having separate ones creates duplicate debugs file names as well.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvmet: only allocate a single slab for bvecs
  2022-11-07 14:00 [PATCH] nvmet: only allocate a single slab for bvecs Christoph Hellwig
  2022-11-07 16:36 ` Keith Busch
  2022-11-07 17:08 ` Martin K. Petersen
@ 2022-11-08  3:52 ` Chaitanya Kulkarni
  2022-11-09 17:46 ` Sagi Grimberg
  3 siblings, 0 replies; 5+ messages in thread
From: Chaitanya Kulkarni @ 2022-11-08  3:52 UTC (permalink / raw)
  To: Christoph Hellwig, sagi, Chaitanya Kulkarni; +Cc: linux-nvme

On 11/7/22 06:00, Christoph Hellwig wrote:
> There is no need to have a separate slab cache for each namespaces,
> and having separate ones creates duplicate debugs file names as well.
> 
> Fixes: d5eff33ee6f8 ("nvmet: add simple file backed ns support")
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Thanks a lot for fixing this ...

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] nvmet: only allocate a single slab for bvecs
  2022-11-07 14:00 [PATCH] nvmet: only allocate a single slab for bvecs Christoph Hellwig
                   ` (2 preceding siblings ...)
  2022-11-08  3:52 ` Chaitanya Kulkarni
@ 2022-11-09 17:46 ` Sagi Grimberg
  3 siblings, 0 replies; 5+ messages in thread
From: Sagi Grimberg @ 2022-11-09 17:46 UTC (permalink / raw)
  To: Christoph Hellwig, kch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-09 17:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07 14:00 [PATCH] nvmet: only allocate a single slab for bvecs Christoph Hellwig
2022-11-07 16:36 ` Keith Busch
2022-11-07 17:08 ` Martin K. Petersen
2022-11-08  3:52 ` Chaitanya Kulkarni
2022-11-09 17:46 ` Sagi Grimberg

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.