All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matias Bjørling" <mb@lightnvm.io>
To: axboe@fb.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Javier González" <javier@javigon.com>,
	"Javier González" <javier@cnexlabs.com>,
	"Matias Bjørling" <mb@lightnvm.io>
Subject: [GIT PULL 40/45] lightnvm: pblk: move ring buffer alloc/free rb init
Date: Tue,  9 Oct 2018 13:12:10 +0200	[thread overview]
Message-ID: <20181009111215.7653-41-mb@lightnvm.io> (raw)
In-Reply-To: <20181009111215.7653-1-mb@lightnvm.io>

From: Javier González <javier@javigon.com>

pblk's read/write buffer currently takes a buffer and its size and uses
it to create the metadata around it to use it as a ring buffer. This
puts the responsibility of allocating/freeing ring buffer memory on the
ring buffer user. Instead, move it inside of the ring buffer helpers
(pblk-rb.c). This simplifies creation/destruction routines.

Signed-off-by: Javier González <javier@cnexlabs.com>
Signed-off-by: Matias Bjørling <mb@lightnvm.io>
---
 drivers/lightnvm/pblk-init.c | 18 ++----------
 drivers/lightnvm/pblk-rb.c   | 53 ++++++++++++++++++++++--------------
 drivers/lightnvm/pblk.h      |  7 ++---
 3 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c
index f84c428a76f1..b2c49fc006c9 100644
--- a/drivers/lightnvm/pblk-init.c
+++ b/drivers/lightnvm/pblk-init.c
@@ -185,17 +185,14 @@ static void pblk_rwb_free(struct pblk *pblk)
 	if (pblk_rb_tear_down_check(&pblk->rwb))
 		pblk_err(pblk, "write buffer error on tear down\n");
 
-	pblk_rb_data_free(&pblk->rwb);
-	vfree(pblk_rb_entries_ref(&pblk->rwb));
+	pblk_rb_free(&pblk->rwb);
 }
 
 static int pblk_rwb_init(struct pblk *pblk)
 {
 	struct nvm_tgt_dev *dev = pblk->dev;
 	struct nvm_geo *geo = &dev->geo;
-	struct pblk_rb_entry *entries;
-	unsigned long nr_entries, buffer_size;
-	unsigned int power_size, power_seg_sz;
+	unsigned long buffer_size;
 	int pgs_in_buffer;
 
 	pgs_in_buffer = max(geo->mw_cunits, geo->ws_opt) * geo->all_luns;
@@ -205,16 +202,7 @@ static int pblk_rwb_init(struct pblk *pblk)
 	else
 		buffer_size = pgs_in_buffer;
 
-	nr_entries = pblk_rb_calculate_size(buffer_size);
-
-	entries = vzalloc(array_size(nr_entries, sizeof(struct pblk_rb_entry)));
-	if (!entries)
-		return -ENOMEM;
-
-	power_size = get_count_order(nr_entries);
-	power_seg_sz = get_count_order(geo->csecs);
-
-	return pblk_rb_init(&pblk->rwb, entries, power_size, power_seg_sz);
+	return pblk_rb_init(&pblk->rwb, buffer_size, geo->csecs);
 }
 
 /* Minimum pages needed within a lun */
diff --git a/drivers/lightnvm/pblk-rb.c b/drivers/lightnvm/pblk-rb.c
index e46d8cb9d28b..f653faa6a9ed 100644
--- a/drivers/lightnvm/pblk-rb.c
+++ b/drivers/lightnvm/pblk-rb.c
@@ -23,7 +23,7 @@
 
 static DECLARE_RWSEM(pblk_rb_lock);
 
-void pblk_rb_data_free(struct pblk_rb *rb)
+static void pblk_rb_data_free(struct pblk_rb *rb)
 {
 	struct pblk_rb_pages *p, *t;
 
@@ -36,22 +36,46 @@ void pblk_rb_data_free(struct pblk_rb *rb)
 	up_write(&pblk_rb_lock);
 }
 
+void pblk_rb_free(struct pblk_rb *rb)
+{
+	pblk_rb_data_free(rb);
+	vfree(rb->entries);
+}
+
+/*
+ * pblk_rb_calculate_size -- calculate the size of the write buffer
+ */
+static unsigned int pblk_rb_calculate_size(unsigned int nr_entries)
+{
+	/* Alloc a write buffer that can at least fit 128 entries */
+	return (1 << max(get_count_order(nr_entries), 7));
+}
+
 /*
  * Initialize ring buffer. The data and metadata buffers must be previously
  * allocated and their size must be a power of two
  * (Documentation/core-api/circular-buffers.rst)
  */
-int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
-		 unsigned int power_size, unsigned int power_seg_sz)
+int pblk_rb_init(struct pblk_rb *rb, unsigned int size, unsigned int seg_size)
 {
 	struct pblk *pblk = container_of(rb, struct pblk, rwb);
+	struct pblk_rb_entry *entries;
 	unsigned int init_entry = 0;
-	unsigned int alloc_order = power_size;
 	unsigned int max_order = MAX_ORDER - 1;
-	unsigned int order, iter;
+	unsigned int power_size, power_seg_sz;
+	unsigned int alloc_order, order, iter;
+	unsigned int nr_entries;
+
+	nr_entries = pblk_rb_calculate_size(size);
+	entries = vzalloc(array_size(nr_entries, sizeof(struct pblk_rb_entry)));
+	if (!entries)
+		return -ENOMEM;
+
+	power_size = get_count_order(size);
+	power_seg_sz = get_count_order(seg_size);
 
 	down_write(&pblk_rb_lock);
-	rb->entries = rb_entry_base;
+	rb->entries = entries;
 	rb->seg_size = (1 << power_seg_sz);
 	rb->nr_entries = (1 << power_size);
 	rb->mem = rb->subm = rb->sync = rb->l2p_update = 0;
@@ -62,6 +86,7 @@ int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
 
 	INIT_LIST_HEAD(&rb->pages);
 
+	alloc_order = power_size;
 	if (alloc_order >= max_order) {
 		order = max_order;
 		iter = (1 << (alloc_order - max_order));
@@ -80,6 +105,7 @@ int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
 		page_set = kmalloc(sizeof(struct pblk_rb_pages), GFP_KERNEL);
 		if (!page_set) {
 			up_write(&pblk_rb_lock);
+			vfree(entries);
 			return -ENOMEM;
 		}
 
@@ -89,6 +115,7 @@ int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
 			kfree(page_set);
 			pblk_rb_data_free(rb);
 			up_write(&pblk_rb_lock);
+			vfree(entries);
 			return -ENOMEM;
 		}
 		kaddr = page_address(page_set->pages);
@@ -125,20 +152,6 @@ int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
 	return 0;
 }
 
-/*
- * pblk_rb_calculate_size -- calculate the size of the write buffer
- */
-unsigned int pblk_rb_calculate_size(unsigned int nr_entries)
-{
-	/* Alloc a write buffer that can at least fit 128 entries */
-	return (1 << max(get_count_order(nr_entries), 7));
-}
-
-void *pblk_rb_entries_ref(struct pblk_rb *rb)
-{
-	return rb->entries;
-}
-
 static void clean_wctx(struct pblk_w_ctx *w_ctx)
 {
 	int flags;
diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h
index 7660811aa8af..0f98ea24ee59 100644
--- a/drivers/lightnvm/pblk.h
+++ b/drivers/lightnvm/pblk.h
@@ -734,10 +734,7 @@ struct pblk_line_ws {
 /*
  * pblk ring buffer operations
  */
-int pblk_rb_init(struct pblk_rb *rb, struct pblk_rb_entry *rb_entry_base,
-		 unsigned int power_size, unsigned int power_seg_sz);
-unsigned int pblk_rb_calculate_size(unsigned int nr_entries);
-void *pblk_rb_entries_ref(struct pblk_rb *rb);
+int pblk_rb_init(struct pblk_rb *rb, unsigned int size, unsigned int seg_sz);
 int pblk_rb_may_write_user(struct pblk_rb *rb, struct bio *bio,
 			   unsigned int nr_entries, unsigned int *pos);
 int pblk_rb_may_write_gc(struct pblk_rb *rb, unsigned int nr_entries,
@@ -771,7 +768,7 @@ unsigned int pblk_rb_wrap_pos(struct pblk_rb *rb, unsigned int pos);
 
 int pblk_rb_tear_down_check(struct pblk_rb *rb);
 int pblk_rb_pos_oob(struct pblk_rb *rb, u64 pos);
-void pblk_rb_data_free(struct pblk_rb *rb);
+void pblk_rb_free(struct pblk_rb *rb);
 ssize_t pblk_rb_sysfs(struct pblk_rb *rb, char *buf);
 
 /*
-- 
2.17.1

  parent reply	other threads:[~2018-10-09 18:31 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-09 11:11 [GIT PULL 00/45] lightnvm updates for 4.20 Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 01/45] lightnvm: remove dependencies on BLK_DEV_NVME and PCI Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 02/45] lightnvm: combine 1.2 and 2.0 command flags Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 03/45] lightnvm: pblk: fix rqd.error return value in pblk_blk_erase_sync Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 04/45] lightnvm: move device L2P detection to core Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 05/45] lightnvm: pblk: fix race condition on metadata I/O Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 06/45] lightnvm: move bad block and chunk state logic to core Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 07/45] lightnvm: pblk: unify vector max req constants Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 08/45] lightnvm: pblk: fix incorrect min_write_pgs Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 09/45] lightnvm: pblk: remove size and out of bounds read check Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 10/45] lightnvm: pblk: refactor put line fn on read completion Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 11/45] lightnvm: pblk: add helpers for chunk addresses Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 12/45] lightnvm: pblk: improve line helpers Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 13/45] lightnvm: pblk: fix comment typo Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 14/45] lightnvm: pblk: remove unused variable Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 15/45] lightnvm: pblk: guarantee emeta on line close Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 16/45] lightnvm: introduce nvm_rq_to_ppa_list Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 17/45] lightnvm: pblk: allocate line map bitmaps using a mempool Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 18/45] lightnvm: pblk: remove unused parameters in pblk_up_rq Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 19/45] lightnvm: pblk: fix up prints in pblk_read_check_rand Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 20/45] lightnvm: pblk: fix write amplificiation calculation Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 21/45] lightnvm: pblk: remove debug from pblk_[down/up]_page Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 22/45] lightnvm: pblk: add trace events for chunk states Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 23/45] lightnvm: pblk: add trace events for line state changes Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 24/45] lightnvm: pblk: add trace events for pblk " Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 25/45] lightnvm: pblk: add tracing for chunk resets Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 26/45] lightnvm: move ppa transformations to core Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 27/45] lightnvm: pblk: calculate line pad distance in helper Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 28/45] lightnvm: pblk: stop recreating global caches Matias Bjørling
2018-10-09 11:11 ` [GIT PULL 29/45] lightnvm: pblk: fix mapping issue on failed writes Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 30/45] lightnvm: pblk: fix two sleep-in-atomic-context bugs Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 31/45] lightnvm: use internal allocation for chunk log page Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 32/45] lightnvm: pblk: encapsulate rqd dma allocations Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 33/45] lightnvm: pblk: refactor metadata paths Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 34/45] lightnvm: pblk: take write semaphore on metadata Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 35/45] lightnvm: pblk: recover open lines on 2.0 devices Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 36/45] lightnvm: pblk: add SPDX license tag Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 37/45] lightnvm: pblk: fix race on sysfs line state Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 38/45] lightnvm: pblk: remove unused function Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 39/45] lightnvm: pblk: encapsulate rb pointer operations Matias Bjørling
2018-10-09 11:12 ` Matias Bjørling [this message]
2018-10-09 11:12 ` [GIT PULL 41/45] lightnvm: pblk: guarantee mw_cunits on read buffer Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 42/45] lightnvm: do no update csecs and sos on 1.2 Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 43/45] lightnvm: pblk: fix error handling of pblk_lines_init() Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 44/45] lightnvm: pblk: consider max hw sectors supported for max_write_pgs Matias Bjørling
2018-10-09 11:12 ` [GIT PULL 45/45] lightnvm: pblk: guarantee that backpointer is respected on writer stall Matias Bjørling
2018-10-09 14:25 ` [GIT PULL 00/45] lightnvm updates for 4.20 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=20181009111215.7653-41-mb@lightnvm.io \
    --to=mb@lightnvm.io \
    --cc=axboe@fb.com \
    --cc=javier@cnexlabs.com \
    --cc=javier@javigon.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 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.