[RFC PATCH v3 2/3] nvme: keep nvme_command instead of pointer to it
Kanchan Joshi
joshi.k at samsung.com
Tue Mar 16 14:01:25 GMT 2021
nvme_req structure originally contained a pointer to nvme_command.
Change nvme_req structure to keep the command itself.
This helps in avoiding hot-path memory-allocation for async-passthrough.
Signed-off-by: Anuj Gupta <anuj20.g at samsung.com>
Signed-off-by: Kanchan Joshi <joshi.k at samsung.com>
---
drivers/nvme/host/core.c | 6 +++---
drivers/nvme/host/fabrics.c | 4 ++--
drivers/nvme/host/lightnvm.c | 16 +++++-----------
drivers/nvme/host/nvme.h | 2 +-
4 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index e68a8c4ac5a6..46c1bb7a89f0 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -596,7 +596,7 @@ static inline void nvme_init_request(struct request *req,
req->cmd_flags |= REQ_FAILFAST_DRIVER;
nvme_clear_nvme_request(req);
- nvme_req(req)->cmd = cmd;
+ nvme_req(req)->cmd = *cmd;
}
struct request *nvme_alloc_request(struct request_queue *q,
@@ -728,7 +728,7 @@ static void nvme_assign_write_stream(struct nvme_ctrl *ctrl,
static void nvme_setup_passthrough(struct request *req,
struct nvme_command *cmd)
{
- memcpy(cmd, nvme_req(req)->cmd, sizeof(*cmd));
+ memcpy(cmd, &nvme_req(req)->cmd, sizeof(*cmd));
/* passthru commands should let the driver set the SGL flags */
cmd->common.flags &= ~NVME_CMD_SGL_ALL;
}
@@ -1128,7 +1128,7 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
void nvme_execute_passthru_rq(struct request *rq)
{
- struct nvme_command *cmd = nvme_req(rq)->cmd;
+ struct nvme_command *cmd = &nvme_req(rq)->cmd;
struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
struct nvme_ns *ns = rq->q->queuedata;
struct gendisk *disk = ns ? ns->disk : NULL;
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 5dfd806fc2d2..c374dcf6595e 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -578,8 +578,8 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
*/
switch (ctrl->state) {
case NVME_CTRL_CONNECTING:
- if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(req->cmd) &&
- req->cmd->fabrics.fctype == nvme_fabrics_type_connect)
+ if (blk_rq_is_passthrough(rq) && nvme_is_fabrics(&req->cmd) &&
+ req->cmd.fabrics.fctype == nvme_fabrics_type_connect)
return true;
break;
default:
diff --git a/drivers/nvme/host/lightnvm.c b/drivers/nvme/host/lightnvm.c
index b705988629f2..5f4d7f0f5d8d 100644
--- a/drivers/nvme/host/lightnvm.c
+++ b/drivers/nvme/host/lightnvm.c
@@ -640,7 +640,6 @@ static void nvme_nvm_end_io(struct request *rq, blk_status_t status)
rqd->error = nvme_req(rq)->status;
nvm_end_io(rqd);
- kfree(nvme_req(rq)->cmd);
blk_mq_free_request(rq);
}
@@ -672,25 +671,21 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd,
{
struct nvm_geo *geo = &dev->geo;
struct request_queue *q = dev->q;
- struct nvme_nvm_command *cmd;
+ struct nvme_nvm_command cmd;
struct request *rq;
int ret;
- cmd = kzalloc(sizeof(struct nvme_nvm_command), GFP_KERNEL);
- if (!cmd)
- return -ENOMEM;
-
- rq = nvme_nvm_alloc_request(q, rqd, cmd);
+ rq = nvme_nvm_alloc_request(q, rqd, &cmd);
if (IS_ERR(rq)) {
ret = PTR_ERR(rq);
- goto err_free_cmd;
+ goto err_cmd;
}
if (buf) {
ret = blk_rq_map_kern(q, rq, buf, geo->csecs * rqd->nr_ppas,
GFP_KERNEL);
if (ret)
- goto err_free_cmd;
+ goto err_cmd;
}
rq->end_io_data = rqd;
@@ -699,8 +694,7 @@ static int nvme_nvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd,
return 0;
-err_free_cmd:
- kfree(cmd);
+err_cmd:
return ret;
}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 07b34175c6ce..0254aa611dfa 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -157,7 +157,7 @@ enum nvme_quirks {
* this structure as the first member of their request-private data.
*/
struct nvme_request {
- struct nvme_command *cmd;
+ struct nvme_command cmd;
union nvme_result result;
u8 retries;
u8 flags;
--
2.25.1
More information about the Linux-nvme
mailing list