All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
To: linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, logang@deltatee.com, hch@lst.de,
	Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>,
	sagi@grimberg.me
Subject: [PATCH V2 12/12] nvmet: use inline bio for passthru fast path
Date: Mon, 31 Aug 2020 15:27:07 -0700	[thread overview]
Message-ID: <20200831222707.35611-13-chaitanya.kulkarni@wdc.com> (raw)
In-Reply-To: <20200831222707.35611-1-chaitanya.kulkarni@wdc.com>

In nvmet_passthru_execute_cmd() which is a high frequency function
it uses bio_alloc() which leads to memory allocation from the fs pool
for each I/O.

For NVMeoF nvmet_req we already have inline_bvec allocated as a part of
request allocation that can be used with preallocated bio when we
already know the size of request before bio allocation with bio_alloc(),
which we already do.

Introduce a bio member for the nvmet_req passthru anon union. In the
fast path, check if we can get away with inline bvec and bio from
nvmet_req with bio_init() call before actually allocating from the
bio_alloc().

This will be useful to avoid any new memory allocation under high
memory pressure situation and get rid of any extra work of
allocation (bio_alloc()) vs initialization (bio_init()) when
transfer len is < NVMET_MAX_INLINE_DATA_LEN that user can configure at
compile time.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/nvmet.h    |  1 +
 drivers/nvme/target/passthru.c | 21 ++++++++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 477439acb8e1..6b1430f8ac78 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -331,6 +331,7 @@ struct nvmet_req {
 			struct work_struct      work;
 		} f;
 		struct {
+			struct bio		inline_bio;
 			struct request		*rq;
 			struct work_struct      work;
 			bool			use_workqueue;
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 89d848006bd5..ff39f0635451 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -179,6 +179,14 @@ static void nvmet_passthru_req_done(struct request *rq,
 	blk_mq_free_request(rq);
 }
 
+static void nvmet_passthru_bio_done(struct bio *bio)
+{
+	struct nvmet_req *req = bio->bi_private;
+
+	if (bio != &req->p.inline_bio)
+		bio_put(bio);
+}
+
 static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
 {
 	unsigned int op_flags = 0;
@@ -190,14 +198,21 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
 	if (req->cmd->common.opcode == nvme_cmd_flush)
 		op_flags = REQ_FUA;
 
-	bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
-	bio->bi_end_io = bio_put;
+	if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
+		bio = &req->p.inline_bio;
+		bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
+	} else {
+		bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
+	}
+
+	bio->bi_end_io = nvmet_passthru_bio_done;
 	bio->bi_opf = req_op(rq) | op_flags;
+	bio->bi_private = req;
 
 	for_each_sg(req->sg, sg, req->sg_cnt, i) {
 		if (bio_add_pc_page(rq->q, bio, sg_page(sg), sg->length,
 				    sg->offset) < sg->length) {
-			bio_put(bio);
+			nvmet_passthru_bio_done(bio);
 			return -EINVAL;
 		}
 		sg_cnt--;
-- 
2.22.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

  parent reply	other threads:[~2020-08-31 22:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 22:26 [PATCH V2 00/12] nvmet: passthru fixes and improvements Chaitanya Kulkarni
2020-08-31 22:26 ` [PATCH V2 01/12] nvme-core: annotate nvme_alloc_request() Chaitanya Kulkarni
2020-09-01  1:56   ` Baolin Wang
2020-09-01 17:21     ` Sagi Grimberg
2020-09-01 21:16       ` Chaitanya Kulkarni
2020-09-02  3:28       ` Chaitanya Kulkarni
2020-09-02 22:02       ` Chaitanya Kulkarni
2020-09-03 16:17   ` Christoph Hellwig
2020-09-03 19:40     ` Chaitanya Kulkarni
2020-09-08  8:57       ` Christoph Hellwig
2020-08-31 22:26 ` [PATCH V2 02/12] nvmet: for pt I/O commands use likely for ns check Chaitanya Kulkarni
2020-09-03 16:18   ` Christoph Hellwig
2020-09-03 18:21     ` Chaitanya Kulkarni
2020-08-31 22:26 ` [PATCH V2 03/12] nvmet: use consistent type with id->nlbaf Chaitanya Kulkarni
2020-09-01 15:55   ` Keith Busch
2020-09-01 21:17     ` Chaitanya Kulkarni
2020-09-01 21:31       ` Logan Gunthorpe
2020-09-01 22:03       ` Keith Busch
2020-08-31 22:26 ` [PATCH V2 04/12] nvmet: use consistent type for op_flag Chaitanya Kulkarni
2020-09-03 16:20   ` Christoph Hellwig
2020-09-03 18:35     ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 05/12] nvmet: use unlikely for uncommon commands Chaitanya Kulkarni
2020-09-03 16:20   ` Christoph Hellwig
2020-09-03 18:37     ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 06/12] nvmet: remove op_flags for write commands Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 07/12] nvmet: decouple nvme_ctrl_get_by_path() Chaitanya Kulkarni
2020-09-01 17:00   ` Logan Gunthorpe
2020-08-31 22:27 ` [PATCH V2 08/12] nvmet: move get/put ctrl into dev open/release Chaitanya Kulkarni
2020-09-01 17:02   ` Logan Gunthorpe
2020-09-01 17:18     ` Sagi Grimberg
2020-09-02  0:31       ` Chaitanya Kulkarni
2020-09-03 16:21       ` Christoph Hellwig
2020-09-03 18:22         ` Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 09/12] nvmet: fix nvme module ref count Oops Chaitanya Kulkarni
2020-09-01 17:23   ` Logan Gunthorpe
2020-08-31 22:27 ` [PATCH V2 10/12] block: move blk_rq_bio_prep() to linux/blk-mq.h Chaitanya Kulkarni
2020-08-31 22:27 ` [PATCH V2 11/12] nvmet: use minimized version of blk_rq_append_bio Chaitanya Kulkarni
2020-09-03 16:23   ` Christoph Hellwig
2020-09-03 18:23     ` Chaitanya Kulkarni
2020-08-31 22:27 ` Chaitanya Kulkarni [this message]
2020-09-01 17:29   ` [PATCH V2 12/12] nvmet: use inline bio for passthru fast path Logan Gunthorpe
2020-09-02  0:39     ` Chaitanya Kulkarni
2020-09-02 15:41       ` Logan Gunthorpe
2020-09-02 21:04         ` Chaitanya Kulkarni

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=20200831222707.35611-13-chaitanya.kulkarni@wdc.com \
    --to=chaitanya.kulkarni@wdc.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=logang@deltatee.com \
    --cc=sagi@grimberg.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 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.