linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Holmberg <hans@owltronix.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Matias Bjørling" <m@bjorling.me>
Cc: "Hans Holmberg" <hans.holmberg@cnexlabs.com>,
	"Javier González" <javier@cnexlabs.com>
Subject: [PATCH v2] lightnvm: pblk: clear flush point on completed writes
Date: Thu, 28 Dec 2017 14:19:52 +0100	[thread overview]
Message-ID: <1514467192-5694-1-git-send-email-hans.holmberg@cnexlabs.com> (raw)
In-Reply-To: <20171220172205.26464-15-m@bjorling.me>

Move completion of syncs and clearing of flush points to the
write completion path - this ensures that the data has been
comitted to the media before completing bios containing syncs.

Signed-off-by: Hans Holmberg <hans.holmberg@cnexlabs.com>
Signed-off-by: Javier González <javier@cnexlabs.com>
---

Changes since v1:

* Fixed an off-by one issue when clearing flush points

 drivers/lightnvm/pblk-rb.c    | 58 +++++++++++++++++++++----------------------
 drivers/lightnvm/pblk-write.c | 17 ++++++++++++-
 2 files changed, 44 insertions(+), 31 deletions(-)

diff --git a/drivers/lightnvm/pblk-rb.c b/drivers/lightnvm/pblk-rb.c
index 2c61d74..fe5465d 100644
--- a/drivers/lightnvm/pblk-rb.c
+++ b/drivers/lightnvm/pblk-rb.c
@@ -353,17 +353,17 @@ static int pblk_rb_flush_point_set(struct pblk_rb *rb, struct bio *bio,
 				  unsigned int pos)
 {
 	struct pblk_rb_entry *entry;
-	unsigned int subm, flush_point;
+	unsigned int sync, flush_point;
 
-	subm = READ_ONCE(rb->subm);
+	sync = READ_ONCE(rb->sync);
+
+	if (pos == sync)
+		return 0;
 
 #ifdef CONFIG_NVM_DEBUG
 	atomic_inc(&rb->inflight_flush_point);
 #endif
 
-	if (pos == subm)
-		return 0;
-
 	flush_point = (pos == 0) ? (rb->nr_entries - 1) : (pos - 1);
 	entry = &rb->entries[flush_point];
 
@@ -604,22 +604,6 @@ unsigned int pblk_rb_read_to_bio(struct pblk_rb *rb, struct nvm_rq *rqd,
 			return NVM_IO_ERR;
 		}
 
-		if (flags & PBLK_FLUSH_ENTRY) {
-			unsigned int flush_point;
-
-			flush_point = READ_ONCE(rb->flush_point);
-			if (flush_point == pos) {
-				/* Protect flush points */
-				smp_store_release(&rb->flush_point,
-							EMPTY_ENTRY);
-			}
-
-			flags &= ~PBLK_FLUSH_ENTRY;
-#ifdef CONFIG_NVM_DEBUG
-			atomic_dec(&rb->inflight_flush_point);
-#endif
-		}
-
 		flags &= ~PBLK_WRITTEN_DATA;
 		flags |= PBLK_SUBMITTED_ENTRY;
 
@@ -735,15 +719,24 @@ void pblk_rb_sync_end(struct pblk_rb *rb, unsigned long *flags)
 
 unsigned int pblk_rb_sync_advance(struct pblk_rb *rb, unsigned int nr_entries)
 {
-	unsigned int sync;
-	unsigned int i;
-
+	unsigned int sync, flush_point;
 	lockdep_assert_held(&rb->s_lock);
 
 	sync = READ_ONCE(rb->sync);
+	flush_point = READ_ONCE(rb->flush_point);
 
-	for (i = 0; i < nr_entries; i++)
-		sync = (sync + 1) & (rb->nr_entries - 1);
+	if (flush_point != EMPTY_ENTRY) {
+		unsigned int secs_to_flush;
+
+		secs_to_flush = pblk_rb_ring_count(flush_point, sync,
+					rb->nr_entries);
+		if (secs_to_flush < nr_entries) {
+			/* Protect flush points */
+			smp_store_release(&rb->flush_point, EMPTY_ENTRY);
+		}
+	}
+
+	sync = (sync + nr_entries) & (rb->nr_entries - 1);
 
 	/* Protect from counts */
 	smp_store_release(&rb->sync, sync);
@@ -751,22 +744,27 @@ unsigned int pblk_rb_sync_advance(struct pblk_rb *rb, unsigned int nr_entries)
 	return sync;
 }
 
+/* Calculate how many sectors to submit up to the current flush point. */
 unsigned int pblk_rb_flush_point_count(struct pblk_rb *rb)
 {
-	unsigned int subm, flush_point;
-	unsigned int count;
+	unsigned int subm, sync, flush_point;
+	unsigned int submitted, to_flush;
 
 	/* Protect flush points */
 	flush_point = smp_load_acquire(&rb->flush_point);
 	if (flush_point == EMPTY_ENTRY)
 		return 0;
 
+	/* Protect syncs */
+	sync = smp_load_acquire(&rb->sync);
+
 	subm = READ_ONCE(rb->subm);
+	submitted = pblk_rb_ring_count(subm, sync, rb->nr_entries);
 
 	/* The sync point itself counts as a sector to sync */
-	count = pblk_rb_ring_count(flush_point, subm, rb->nr_entries) + 1;
+	to_flush = pblk_rb_ring_count(flush_point, sync, rb->nr_entries) + 1;
 
-	return count;
+	return (submitted < to_flush) ? (to_flush - submitted) : 0;
 }
 
 /*
diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c
index 018af87..aae86ed 100644
--- a/drivers/lightnvm/pblk-write.c
+++ b/drivers/lightnvm/pblk-write.c
@@ -21,13 +21,28 @@ static unsigned long pblk_end_w_bio(struct pblk *pblk, struct nvm_rq *rqd,
 				    struct pblk_c_ctx *c_ctx)
 {
 	struct bio *original_bio;
+	struct pblk_rb *rwb = &pblk->rwb;
 	unsigned long ret;
 	int i;
 
 	for (i = 0; i < c_ctx->nr_valid; i++) {
 		struct pblk_w_ctx *w_ctx;
+		int pos = c_ctx->sentry + i;
+		int flags;
+
+		w_ctx = pblk_rb_w_ctx(rwb, pos);
+		flags = READ_ONCE(w_ctx->flags);
+
+		if (flags & PBLK_FLUSH_ENTRY) {
+			flags &= ~PBLK_FLUSH_ENTRY;
+			/* Release flags on context. Protect from writes */
+			smp_store_release(&w_ctx->flags, flags);
+
+#ifdef CONFIG_NVM_DEBUG
+			atomic_dec(&rwb->inflight_flush_point);
+#endif
+		}
 
-		w_ctx = pblk_rb_w_ctx(&pblk->rwb, c_ctx->sentry + i);
 		while ((original_bio = bio_list_pop(&w_ctx->bios)))
 			bio_endio(original_bio);
 	}
-- 
2.7.4

  reply	other threads:[~2017-12-28 13:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-20 17:21 [PATCH 00/25] Updates to lightnvm and pblk Matias Bjørling
2017-12-20 17:21 ` [PATCH 01/25] null_blk: remove lightnvm support Matias Bjørling
2017-12-20 17:21 ` [PATCH 02/25] lightnvm: remove rrpc Matias Bjørling
2017-12-20 17:21 ` [PATCH 03/25] lightnvm: use internal pblk methods Matias Bjørling
2017-12-20 17:21 ` [PATCH 04/25] lightnvm: remove hybrid ocssd 1.2 support Matias Bjørling
2017-12-20 17:21 ` [PATCH 05/25] lightnvm: remove unnecessary field from nvm_rq Matias Bjørling
2017-12-20 17:21 ` [PATCH 06/25] lightnvm: remove lower page tables Matias Bjørling
2017-12-20 17:21 ` [PATCH 07/25] lightnvm: make geometry structures 2.0 ready Matias Bjørling
2017-12-20 17:21 ` [PATCH 08/25] lightnvm: refactor target type lookup Matias Bjørling
2017-12-20 17:21 ` [PATCH 09/25] lightnvm: guarantee target unique name across devs Matias Bjørling
2017-12-20 17:21 ` [PATCH 10/25] lightnvm: pblk: compress and reorder helper functions Matias Bjørling
2017-12-20 17:21 ` [PATCH 11/25] lightnvm: pblk: remove pblk_for_each_lun helper Matias Bjørling
2017-12-20 17:21 ` [PATCH 12/25] lightnvm: pblk: refactor emeta consistency check Matias Bjørling
2017-12-20 17:21 ` [PATCH 13/25] lightnvm: pblk: rename sync_point to flush_point Matias Bjørling
2017-12-20 17:21 ` [PATCH 14/25] lightnvm: pblk: clear flush point on completed writes Matias Bjørling
2017-12-28 13:19   ` Hans Holmberg [this message]
2017-12-20 17:21 ` [PATCH 15/25] lightnvm: pblk: prevent premature sync point resets Matias Bjørling
2017-12-20 17:21 ` [PATCH 16/25] lightnvm: pblk: remove pblk_gc_stop Matias Bjørling
2017-12-20 17:21 ` [PATCH 17/25] lightnvm: pblk: use exact free block counter in RL Matias Bjørling
2017-12-20 17:21 ` [PATCH 18/25] lightnvm: set target over-provision on create ioctl Matias Bjørling
2017-12-20 17:21 ` [PATCH 19/25] lightnvm: pblk: ignore high ecc errors on recovery Matias Bjørling
2017-12-20 17:22 ` [PATCH 20/25] lightnvm: pblk: do not log recovery read errors Matias Bjørling
2017-12-20 17:22 ` [PATCH 21/25] lightnvm: pblk: ensure kthread alloc. before kicking it Matias Bjørling
2017-12-20 17:22 ` [PATCH 22/25] lightnvm: pblk: free write buffer on init failure Matias Bjørling
2017-12-20 17:22 ` [PATCH 23/25] lightnvm: pblk: print instance name on instance info Matias Bjørling
2017-12-20 17:22 ` [PATCH 24/25] lightnvm: pblk: add iostat support Matias Bjørling
2017-12-20 17:22 ` [PATCH 25/25] lightnvm: pblk: refactor pblk_ppa_comp function 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=1514467192-5694-1-git-send-email-hans.holmberg@cnexlabs.com \
    --to=hans@owltronix.com \
    --cc=hans.holmberg@cnexlabs.com \
    --cc=javier@cnexlabs.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m@bjorling.me \
    /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;
as well as URLs for NNTP newsgroup(s).