From: "Matias Bjørling" <mb@lightnvm.io>
To: hans.ml.holmberg@owltronix.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
javier@cnexlabs.com, hans.holmberg@cnexlabs.com
Subject: Re: [PATCH 4/7] lightnvm: pblk: move global caches to module init/exit
Date: Wed, 29 Aug 2018 15:29:02 +0200 [thread overview]
Message-ID: <92a2b562-c485-47ff-7aa9-5aa82b992e40@lightnvm.io> (raw)
In-Reply-To: <1535545414-550-5-git-send-email-hans.ml.holmberg@owltronix.com>
On 08/29/2018 02:23 PM, Hans Holmberg wrote:
> From: Hans Holmberg <hans.holmberg@cnexlabs.com>
>
> Pblk's global caches should not be initialized every time
> a pblk instance is created, so move the creation and destruction
> of the caches to module init/exit.
>
> Also remove the global pblk lock as it is no longer needed after
> the move.
>
The original goal was to not allocate memory for the caches unless a
pblk instance was initialized. This instead uses up memory without pblk
being used, which I don't think is a good idea.
> Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
> ---
> drivers/lightnvm/pblk-init.c | 42 ++++++++++++++++++++----------------------
> 1 file changed, 20 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
> index 76a4a271b9cf..0be64220b5d8 100644
> --- a/drivers/lightnvm/pblk-init.c
> +++ b/drivers/lightnvm/pblk-init.c
> @@ -27,7 +27,6 @@ MODULE_PARM_DESC(write_buffer_size, "number of entries in a write buffer");
>
> static struct kmem_cache *pblk_ws_cache, *pblk_rec_cache, *pblk_g_rq_cache,
> *pblk_w_rq_cache;
> -static DECLARE_RWSEM(pblk_lock);
> struct bio_set pblk_bio_set;
>
> static int pblk_rw_io(struct request_queue *q, struct pblk *pblk,
> @@ -306,21 +305,17 @@ static int pblk_set_addrf(struct pblk *pblk)
> return 0;
> }
>
> -static int pblk_init_global_caches(struct pblk *pblk)
> +static int pblk_init_global_caches(void)
> {
> - down_write(&pblk_lock);
> pblk_ws_cache = kmem_cache_create("pblk_blk_ws",
> sizeof(struct pblk_line_ws), 0, 0, NULL);
> - if (!pblk_ws_cache) {
> - up_write(&pblk_lock);
> + if (!pblk_ws_cache)
> return -ENOMEM;
> - }
>
> pblk_rec_cache = kmem_cache_create("pblk_rec",
> sizeof(struct pblk_rec_ctx), 0, 0, NULL);
> if (!pblk_rec_cache) {
> kmem_cache_destroy(pblk_ws_cache);
> - up_write(&pblk_lock);
> return -ENOMEM;
> }
>
> @@ -329,7 +324,6 @@ static int pblk_init_global_caches(struct pblk *pblk)
> if (!pblk_g_rq_cache) {
> kmem_cache_destroy(pblk_ws_cache);
> kmem_cache_destroy(pblk_rec_cache);
> - up_write(&pblk_lock);
> return -ENOMEM;
> }
>
> @@ -339,15 +333,13 @@ static int pblk_init_global_caches(struct pblk *pblk)
> kmem_cache_destroy(pblk_ws_cache);
> kmem_cache_destroy(pblk_rec_cache);
> kmem_cache_destroy(pblk_g_rq_cache);
> - up_write(&pblk_lock);
> return -ENOMEM;
> }
> - up_write(&pblk_lock);
>
> return 0;
> }
>
> -static void pblk_free_global_caches(struct pblk *pblk)
> +static void pblk_free_global_caches(void)
> {
> kmem_cache_destroy(pblk_ws_cache);
> kmem_cache_destroy(pblk_rec_cache);
> @@ -381,13 +373,10 @@ static int pblk_core_init(struct pblk *pblk)
> if (!pblk->pad_dist)
> return -ENOMEM;
>
> - if (pblk_init_global_caches(pblk))
> - goto fail_free_pad_dist;
> -
> /* Internal bios can be at most the sectors signaled by the device. */
> ret = mempool_init_page_pool(&pblk->page_bio_pool, NVM_MAX_VLBA, 0);
> if (ret)
> - goto free_global_caches;
> + goto free_pad_dist;
>
> ret = mempool_init_slab_pool(&pblk->gen_ws_pool, PBLK_GEN_WS_POOL_SIZE,
> pblk_ws_cache);
> @@ -455,9 +444,7 @@ static int pblk_core_init(struct pblk *pblk)
> mempool_exit(&pblk->gen_ws_pool);
> free_page_bio_pool:
> mempool_exit(&pblk->page_bio_pool);
> -free_global_caches:
> - pblk_free_global_caches(pblk);
> -fail_free_pad_dist:
> +free_pad_dist:
> kfree(pblk->pad_dist);
> return -ENOMEM;
> }
> @@ -480,7 +467,6 @@ static void pblk_core_free(struct pblk *pblk)
> mempool_exit(&pblk->e_rq_pool);
> mempool_exit(&pblk->w_rq_pool);
>
> - pblk_free_global_caches(pblk);
> kfree(pblk->pad_dist);
> }
>
> @@ -1067,7 +1053,6 @@ static void pblk_exit(void *private, bool graceful)
> {
> struct pblk *pblk = private;
>
> - down_write(&pblk_lock);
> pblk_gc_exit(pblk, graceful);
> pblk_tear_down(pblk, graceful);
>
> @@ -1076,7 +1061,6 @@ static void pblk_exit(void *private, bool graceful)
> #endif
>
> pblk_free(pblk);
> - up_write(&pblk_lock);
> }
>
> static sector_t pblk_capacity(void *private)
> @@ -1237,9 +1221,22 @@ static int __init pblk_module_init(void)
> ret = bioset_init(&pblk_bio_set, BIO_POOL_SIZE, 0, 0);
> if (ret)
> return ret;
> +
> ret = nvm_register_tgt_type(&tt_pblk);
> if (ret)
> - bioset_exit(&pblk_bio_set);
> + goto fail_exit_bioset;
> +
> + ret = pblk_init_global_caches();
> + if (ret)
> + goto fail_unregister_tgt_type;
> +
> + return 0;
> +
> +fail_unregister_tgt_type:
> + nvm_unregister_tgt_type(&tt_pblk);
> +fail_exit_bioset:
> + bioset_exit(&pblk_bio_set);
> +
> return ret;
> }
>
> @@ -1247,6 +1244,7 @@ static void pblk_module_exit(void)
> {
> bioset_exit(&pblk_bio_set);
> nvm_unregister_tgt_type(&tt_pblk);
> + pblk_free_global_caches();
> }
>
> module_init(pblk_module_init);
>
next prev parent reply other threads:[~2018-08-29 13:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-29 12:23 [PATCH 0/7] pblk fixes Hans Holmberg
2018-08-29 12:23 ` [PATCH 1/7] lightnvm: introduce nvm_rq_to_ppa_list Hans Holmberg
2018-08-29 12:23 ` [PATCH 2/7] lightnvm: pblk: fix mapping issue on failed writes Hans Holmberg
2018-08-29 13:23 ` Matias Bjørling
2018-08-29 14:51 ` Hans Holmberg
2018-08-29 12:23 ` [PATCH 3/7] lightnvm: pblk: allocate line map bitmaps using a mempool Hans Holmberg
2018-08-29 12:23 ` [PATCH 4/7] lightnvm: pblk: move global caches to module init/exit Hans Holmberg
2018-08-29 13:29 ` Matias Bjørling [this message]
2018-08-29 15:06 ` Hans Holmberg
2018-08-31 10:02 ` Hans Holmberg
2018-08-29 12:23 ` [PATCH 5/7] lightnvm: pblk: remove unused parameters in pblk_up_rq Hans Holmberg
2018-08-29 12:23 ` [PATCH 6/7] lightnvm: pblk: fix up prints in pblk_read_check_rand Hans Holmberg
2018-08-29 12:23 ` [PATCH 7/7] lightnvm: pblk: fix write amplificiation calculation Hans Holmberg
2018-08-29 13:31 ` [PATCH 0/7] pblk fixes Matias Bjørling
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=92a2b562-c485-47ff-7aa9-5aa82b992e40@lightnvm.io \
--to=mb@lightnvm.io \
--cc=hans.holmberg@cnexlabs.com \
--cc=hans.ml.holmberg@owltronix.com \
--cc=javier@cnexlabs.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.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
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®