linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kanchan Joshi <joshi.k@samsung.com>
To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org,
	linux-ext4@vger.kernel.org
Cc: prakash.v@samsung.com, anshul@samsung.com,
	Kanchan Joshi <joshi.k@samsung.com>
Subject: [PATCH v5 4/7] block: introduce write-hint to stream-id conversion
Date: Thu, 25 Apr 2019 16:49:59 +0530	[thread overview]
Message-ID: <1556191202-3245-5-git-send-email-joshi.k@samsung.com> (raw)
In-Reply-To: <1556191202-3245-1-git-send-email-joshi.k@samsung.com>

This patch moves write-hint-to-stream-id conversion in block-layer.
Earlier this was done by driver (nvme). For user write-hints, conversion
is of the form "streamid = write-hint - 1". For kernel write-hints,
streams are allocated in top-to-bottom fashion. This has the effect of
mapping user-hints to lower range of stream-ids and kernel-hints to upper
range of stream-ids.
Conversion takes stream limit (maintained in request queue) into
account. Write-hints beyond the exposed limit turn to 0.
A new field 'streamid' has been added in request, while 'write-hint'
field has been removed. For merging checks, 'bi_write_hint' (of bio) is
used instead.

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
 block/blk-core.c         | 29 ++++++++++++++++++++++++++++-
 block/blk-merge.c        |  4 ++--
 drivers/nvme/host/core.c |  7 ++-----
 include/linux/blkdev.h   |  2 +-
 4 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index a55389b..0485c20 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -730,6 +730,33 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
 	return false;
 }
 
+enum rw_hint blk_write_hint_to_streamid(struct request *req,
+					struct bio *bio)
+{
+	enum rw_hint streamid, write_hint, nr_streams;
+	struct request_queue *q = req->q;
+
+	nr_streams = q->limits.nr_streams;
+
+	write_hint = bio->bi_write_hint;
+
+	if (!nr_streams || write_hint == WRITE_LIFE_NOT_SET ||
+	    write_hint == WRITE_LIFE_NONE)
+		streamid = 0;
+	else if (write_hint < WRITE_LIFE_KERN_MIN) { /*user-space hints*/
+		streamid = write_hint - 1;
+		if (streamid > nr_streams)
+			streamid = 0;
+	} else { /* kernel hints */
+		streamid = write_hint - WRITE_LIFE_KERN_MIN + 1;
+		if (streamid > (nr_streams - BLK_MAX_USER_HINTS))
+			streamid = 0;
+		else
+			streamid = nr_streams - streamid + 1;
+	}
+	return streamid;
+}
+
 void blk_init_request_from_bio(struct request *req, struct bio *bio)
 {
 	if (bio->bi_opf & REQ_RAHEAD)
@@ -737,7 +764,7 @@ void blk_init_request_from_bio(struct request *req, struct bio *bio)
 
 	req->__sector = bio->bi_iter.bi_sector;
 	req->ioprio = bio_prio(bio);
-	req->write_hint = bio->bi_write_hint;
+	req->streamid = blk_write_hint_to_streamid(req, bio);
 	blk_rq_bio_prep(req->q, req, bio);
 }
 EXPORT_SYMBOL_GPL(blk_init_request_from_bio);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 1c9d4f0..1435634 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -832,7 +832,7 @@ static struct request *attempt_merge(struct request_queue *q,
 	 * Don't allow merge of different write hints, or for a hint with
 	 * non-hint IO.
 	 */
-	if (req->write_hint != next->write_hint)
+	if (req->bio->bi_write_hint != next->bio->bi_write_hint)
 		return NULL;
 
 	if (req->ioprio != next->ioprio)
@@ -964,7 +964,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
 	 * Don't allow merge of different write hints, or for a hint with
 	 * non-hint IO.
 	 */
-	if (rq->write_hint != bio->bi_write_hint)
+	if (rq->bio->bi_write_hint != bio->bi_write_hint)
 		return false;
 
 	if (rq->ioprio != bio_prio(bio))
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 2c43e12..f3000d9 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -530,12 +530,9 @@ static void nvme_assign_write_stream(struct nvme_ctrl *ctrl,
 				     struct request *req, u16 *control,
 				     u32 *dsmgmt)
 {
-	enum rw_hint streamid = req->write_hint;
+	enum rw_hint streamid = req->streamid;
 
-	if (streamid == WRITE_LIFE_NOT_SET || streamid == WRITE_LIFE_NONE)
-		streamid = 0;
-	else {
-		streamid--;
+	if (streamid != 0) {
 		if (WARN_ON_ONCE(streamid > ctrl->nr_streams))
 			return;
 
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 5b6cb9747..9cf8a40 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -216,7 +216,7 @@ struct request {
 	unsigned short nr_integrity_segments;
 #endif
 
-	unsigned short write_hint;
+	unsigned short streamid;
 	unsigned short ioprio;
 
 	unsigned int extra_len;	/* length of alignment and padding */
-- 
2.7.4


  parent reply	other threads:[~2019-04-25 11:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190425112347epcas2p1f7be48b8f0d2203252b8c9dd510c1b61@epcas2p1.samsung.com>
2019-04-25 11:19 ` [PATCH v5 0/7] Extend write-hint framework, and add write-hint for Ext4 journal Kanchan Joshi
     [not found]   ` <CGME20190425112351epcas2p209fdb12872bdcdcb11afd7b6e196b85e@epcas2p2.samsung.com>
2019-04-25 11:19     ` [PATCH v5 1/7] fs: introduce write-hint start point for in-kernel hints Kanchan Joshi
     [not found]   ` <CGME20190425112355epcas2p11e197c8fc33698feb7150d1f4148407e@epcas2p1.samsung.com>
2019-04-25 11:19     ` [PATCH v5 2/7] block: increase stream count for in-kernel use Kanchan Joshi
     [not found]   ` <CGME20190425112358epcas1p13da4f182241366c309cb2c76df3fb048@epcas1p1.samsung.com>
2019-04-25 11:19     ` [PATCH v5 3/7] block: introduce API to register stream information with block-layer Kanchan Joshi
     [not found]   ` <CGME20190425112400epcas1p26e7634f95a185a83c31470006d291161@epcas1p2.samsung.com>
2019-04-25 11:19     ` Kanchan Joshi [this message]
     [not found]   ` <CGME20190425112403epcas1p13006198cda351a08c8403c2b85c9f102@epcas1p1.samsung.com>
2019-04-25 11:20     ` [PATCH v5 5/7] nvme: register stream info with block layer Kanchan Joshi
     [not found]   ` <CGME20190425112406epcas1p4a54b2c5d15ae42a53ff3c206cf7a7892@epcas1p4.samsung.com>
2019-04-25 11:20     ` [PATCH v5 6/7] fs: introduce APIs to enable passing write-hint with buffer-head Kanchan Joshi
     [not found]   ` <CGME20190425112408epcas2p2ddba9fdf175645dd2647da191eac5e1c@epcas2p2.samsung.com>
2019-04-25 11:20     ` [PATCH v5 7/7] fs/ext4,jbd2: add support for sending write-hint with journal Kanchan Joshi
2019-05-10  5:31   ` [PATCH v5 0/7] Extend write-hint framework, and add write-hint for Ext4 journal kanchan
2019-05-10 17:02   ` Christoph Hellwig
2019-05-17  5:31     ` kanchan
2019-05-20 14:27       ` 'Christoph Hellwig'
2019-05-21  8:25         ` Jan Kara
2019-05-21  8:28           ` 'Christoph Hellwig'
2019-05-22 10:25             ` Jan Kara
2019-06-26 12:47               ` kanchan
2019-06-28  7:25                 ` 'Christoph Hellwig'

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=1556191202-3245-5-git-send-email-joshi.k@samsung.com \
    --to=joshi.k@samsung.com \
    --cc=anshul@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=prakash.v@samsung.com \
    /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).