nvmet: only allocate a single slab for bvecs
Subsystems (2)
Christoph Hellwig
maintainerPATCH 1/1 nvmet: only allocate a single slab for bvecs
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 <[email protected]>
--- 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(-)
drivers/nvme/target/core.c +14 -8
@@ -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 );
drivers/nvme/target/io-cmd-file.c +3 -13
@@ -11,7 +11,6 @@#include <linux/fs.h> #include "nvmet.h" -#define NVMET_MAX_MPOOL_BVEC 16#define NVMET_MIN_MPOOL_OBJ 16void 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; }
drivers/nvme/target/nvmet.h +2 -1
@@ -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;
Signature · 1 line
2.30.2
Looks good.
Reviewed-by Keith Busch <[email protected]>
Christoph,
Quoted 1 line
There is no need to have a separate slab cache for each namespaces,
s/namespaces/namespace/
Otherwise OK.
Quoted 1 line
and having separate ones creates duplicate debugs file names as well.
Reviewed-by Martin K. Petersen <[email protected]>
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Quoted 6 lines · Christoph Hellwig
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 <[email protected]>---
Thanks a lot for fixing this ...
Reviewed-by Chaitanya Kulkarni <[email protected]>
-ck
Reviewed-by Sagi Grimberg <[email protected]>