linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] kref and paasthrough cleanup
       [not found] <CGME20210414051733epcas5p31d0a4727a2c05b76bcf7ee75c290aaef@epcas5p3.samsung.com>
@ 2021-04-14  5:16 ` Kanchan Joshi
       [not found]   ` <CGME20210414051743epcas5p3f5371b68b066e5093d91f598b0803e9c@epcas5p3.samsung.com>
       [not found]   ` <CGME20210414051747epcas5p265826317a971aaa3337efb6472a9df7c@epcas5p2.samsung.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Kanchan Joshi @ 2021-04-14  5:16 UTC (permalink / raw)
  To: hch, kbusch, axboe, sagi, chaitanya.kulkarni; +Cc: linux-nvme, Kanchan Joshi

First patch is to avoid opencoding ns->kref, while second one gets rid
of a memset in passthrough io path.

Kanchan Joshi (2):
  nvme: add nvme_get_ns helper
  nvme: avoid memset for passthrough requests

 drivers/nvme/host/core.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

-- 
2.25.1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] nvme: add nvme_get_ns helper
       [not found]   ` <CGME20210414051743epcas5p3f5371b68b066e5093d91f598b0803e9c@epcas5p3.samsung.com>
@ 2021-04-14  5:16     ` Kanchan Joshi
  0 siblings, 0 replies; 5+ messages in thread
From: Kanchan Joshi @ 2021-04-14  5:16 UTC (permalink / raw)
  To: hch, kbusch, axboe, sagi, chaitanya.kulkarni; +Cc: linux-nvme, Kanchan Joshi

Add a helper to avoid opencoding ns->kref increment.
Decrement is already done via nvme_put_ns helper.

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
 drivers/nvme/host/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 288ac47ff5b4..ea5b40e469d6 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -572,6 +572,11 @@ static void nvme_free_ns(struct kref *kref)
 	kfree(ns);
 }
 
+static inline bool nvme_get_ns(struct nvme_ns *ns)
+{
+	return kref_get_unless_zero(&ns->kref);
+}
+
 void nvme_put_ns(struct nvme_ns *ns)
 {
 	kref_put(&ns->kref, nvme_free_ns);
@@ -1489,7 +1494,7 @@ static int nvme_ns_open(struct nvme_ns *ns)
 	/* should never be called due to GENHD_FL_HIDDEN */
 	if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head)))
 		goto fail;
-	if (!kref_get_unless_zero(&ns->kref))
+	if (!nvme_get_ns(ns))
 		goto fail;
 	if (!try_module_get(ns->ctrl->ops->module))
 		goto fail_put_ns;
@@ -3544,7 +3549,7 @@ struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 	down_read(&ctrl->namespaces_rwsem);
 	list_for_each_entry(ns, &ctrl->namespaces, list) {
 		if (ns->head->ns_id == nsid) {
-			if (!kref_get_unless_zero(&ns->kref))
+			if (!nvme_get_ns(ns))
 				continue;
 			ret = ns;
 			break;
-- 
2.25.1


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] nvme: avoid memset for passthrough requests
       [not found]   ` <CGME20210414051747epcas5p265826317a971aaa3337efb6472a9df7c@epcas5p2.samsung.com>
@ 2021-04-14  5:16     ` Kanchan Joshi
  2021-04-14  6:08       ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Kanchan Joshi @ 2021-04-14  5:16 UTC (permalink / raw)
  To: hch, kbusch, axboe, sagi, chaitanya.kulkarni; +Cc: linux-nvme, Kanchan Joshi

nvme_clear_nvme_request() clears the nvme_command, which is unncessary for
passthrough requests as nvme_command is overwritten immediately.
Change nvme_clear_nvme_request() so that double memset for passthrough
requests is avoided.

Signed-off-by: Kanchan Joshi <joshi.k@samsung.com>
---
 drivers/nvme/host/core.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index ea5b40e469d6..5f6b742aa32c 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -583,14 +583,13 @@ void nvme_put_ns(struct nvme_ns *ns)
 }
 EXPORT_SYMBOL_NS_GPL(nvme_put_ns, NVME_TARGET_PASSTHRU);
 
-static inline void nvme_clear_nvme_request(struct request *req)
+static inline void nvme_clear_nvme_request(struct request *req, bool clear_cmd)
 {
-	struct nvme_command *cmd = nvme_req(req)->cmd;
-
-	memset(cmd, 0, sizeof(*cmd));
 	nvme_req(req)->retries = 0;
 	nvme_req(req)->flags = 0;
 	req->rq_flags |= RQF_DONTPREP;
+	if (clear_cmd)
+		memset(nvme_req(req)->cmd, 0, sizeof(struct nvme_command));
 }
 
 static inline unsigned int nvme_req_op(struct nvme_command *cmd)
@@ -610,7 +609,7 @@ static inline void nvme_init_request(struct request *req,
 	cmd->common.flags &= ~NVME_CMD_SGL_ALL;
 
 	req->cmd_flags |= REQ_FAILFAST_DRIVER;
-	nvme_clear_nvme_request(req);
+	nvme_clear_nvme_request(req, false);
 	memcpy(nvme_req(req)->cmd, cmd, sizeof(*cmd));
 }
 
@@ -900,7 +899,7 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req)
 	blk_status_t ret = BLK_STS_OK;
 
 	if (!(req->rq_flags & RQF_DONTPREP))
-		nvme_clear_nvme_request(req);
+		nvme_clear_nvme_request(req, true);
 
 	switch (req_op(req)) {
 	case REQ_OP_DRV_IN:
-- 
2.25.1


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] nvme: avoid memset for passthrough requests
  2021-04-14  5:16     ` [PATCH 2/2] nvme: avoid memset for passthrough requests Kanchan Joshi
@ 2021-04-14  6:08       ` Christoph Hellwig
  2021-04-14 16:27         ` Kanchan Joshi
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2021-04-14  6:08 UTC (permalink / raw)
  To: Kanchan Joshi; +Cc: hch, kbusch, axboe, sagi, chaitanya.kulkarni, linux-nvme

On Wed, Apr 14, 2021 at 10:46:29AM +0530, Kanchan Joshi wrote:
> nvme_clear_nvme_request() clears the nvme_command, which is unncessary for
> passthrough requests as nvme_command is overwritten immediately.
> Change nvme_clear_nvme_request() so that double memset for passthrough
> requests is avoided.

Please just move the memset to the one caller that wants ->cmd zeroed.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] nvme: avoid memset for passthrough requests
  2021-04-14  6:08       ` Christoph Hellwig
@ 2021-04-14 16:27         ` Kanchan Joshi
  0 siblings, 0 replies; 5+ messages in thread
From: Kanchan Joshi @ 2021-04-14 16:27 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Kanchan Joshi, Keith Busch, Jens Axboe, Sagi Grimberg,
	Chaitanya Kulkarni, linux-nvme

On Wed, Apr 14, 2021 at 11:46 AM Christoph Hellwig <hch@lst.de> wrote:
>
> On Wed, Apr 14, 2021 at 10:46:29AM +0530, Kanchan Joshi wrote:
> > nvme_clear_nvme_request() clears the nvme_command, which is unncessary for
> > passthrough requests as nvme_command is overwritten immediately.
> > Change nvme_clear_nvme_request() so that double memset for passthrough
> > requests is avoided.
>
> Please just move the memset to the one caller that wants ->cmd zeroed.
>
Fine, I'll do it that way.


-- 
Kanchan

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-14 16:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210414051733epcas5p31d0a4727a2c05b76bcf7ee75c290aaef@epcas5p3.samsung.com>
2021-04-14  5:16 ` [PATCH 0/2] kref and paasthrough cleanup Kanchan Joshi
     [not found]   ` <CGME20210414051743epcas5p3f5371b68b066e5093d91f598b0803e9c@epcas5p3.samsung.com>
2021-04-14  5:16     ` [PATCH 1/2] nvme: add nvme_get_ns helper Kanchan Joshi
     [not found]   ` <CGME20210414051747epcas5p265826317a971aaa3337efb6472a9df7c@epcas5p2.samsung.com>
2021-04-14  5:16     ` [PATCH 2/2] nvme: avoid memset for passthrough requests Kanchan Joshi
2021-04-14  6:08       ` Christoph Hellwig
2021-04-14 16:27         ` Kanchan Joshi

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).