nvmet: avoid unnecessary fsync and flush bio
Subsystems (2)
PATCH 1/1 nvmet: avoid unnecessary fsync and flush bio
For none buffered_io file backend and no volatile write cache block device backend, fsync and flush bio are both unnecessary, avoid to do that.
--- drivers/nvme/target/io-cmd-bdev.c | 11 +++++++++++ drivers/nvme/target/io-cmd-file.c | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/nvme/target/io-cmd-bdev.c +11 -0
@@ -333,10 +333,16 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)static void nvmet_bdev_execute_flush (struct nvmet_req *req) {struct bio *bio = &req->b.inline_bio; +struct request_queue *q = req->ns->bdev->bd_queue;if (!nvmet_check_transfer_len (req,0 ))return ; +if (!test_bit (QUEUE_FLAG_WC , &q->queue_flags)) { +nvmet_req_complete (req,NVME_SC_SUCCESS ); +return ; + } +bio_init (bio, req->ns->bdev, req->inline_bvec,ARRAY_SIZE (req->inline_bvec),REQ_OP_WRITE |REQ_PREFLUSH ); bio->bi_private = req;
@@ -347,6 +353,11 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)u16 nvmet_bdev_flush (struct nvmet_req *req) { +struct request_queue *q = req->ns->bdev->bd_queue; + +if (!test_bit (QUEUE_FLAG_WC , &q->queue_flags)) +return 0 ; +if (blkdev_issue_flush (req->ns->bdev))return NVME_SC_INTERNAL |NVME_SC_DNR ;return 0 ;
drivers/nvme/target/io-cmd-file.c +4 -1
@@ -268,7 +268,10 @@ static void nvmet_file_execute_rw(struct nvmet_req *req)u16 nvmet_file_flush (struct nvmet_req *req) { -return errno_to_nvme_status (req,vfs_fsync (req->ns->file,1 )); +if (req->ns->buffered_io) +return errno_to_nvme_status (req,vfs_fsync (req->ns->file,1 )); +else +return errno_to_nvme_status (req,0 ); }static void nvmet_file_flush_work (struct work_struct *w)
Signature · 1 line
1.8.3.1
Christoph Hellwig
maintainerdrivers/nvme/target/io-cmd-bdev.c static void nvmet_bdev_execute_rw(struct nvmet_req *req) · line 341
Quoted 10 lines · Guixin Liu
drivers/nvme/target/io-cmd-bdev.c +2
-0@@ -333,10 +333,16 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)static void nvmet_bdev_execute_flush (struct nvmet_req *req) {struct bio *bio = &req->b.inline_bio; +struct request_queue *q = req->ns->bdev->bd_queue;if (!nvmet_check_transfer_len (req,0 ))return ; +if (!test_bit (QUEUE_FLAG_WC , &q->queue_flags)) {
This should be using a bdev_write_cache.
But more importantly: if the backend does not have a volatile write cache, and we should not even receive flushes from the remote side.
drivers/nvme/target/io-cmd-file.c static void nvmet_file_execute_rw(struct nvmet_req *req) · line 274
Quoted 4 lines
drivers/nvme/target/io-cmd-file.c +4
-0+if (req->ns->buffered_io) +return errno_to_nvme_status (req,vfs_fsync (req->ns->file,1 )); +else +return errno_to_nvme_status (req,0 );
No need for the else, and the simple success case can just use the constant status and does not need a translation.
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Guixin Liu
drivers/nvme/target/io-cmd-bdev.c +1
-0@@ -333,10 +333,16 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)static void nvmet_bdev_execute_flush (struct nvmet_req *req) {struct bio *bio = &req->b.inline_bio; +struct request_queue *q = req->ns->bdev->bd_queue;
Quoted 5 lines
drivers/nvme/target/io-cmd-bdev.c static void nvmet_bdev_execute_rw(struct nvmet_req *req) · line 341
Quoted 4 lines
drivers/nvme/target/io-cmd-bdev.c +1
-0if (!nvmet_check_transfer_len (req,0 ))return ; +if (!test_bit (QUEUE_FLAG_WC , &q->queue_flags)) {This should be using a
bdev_write_cache.
I will change that in the v2, thanks.
Quoted 3 lines
But more importantly: if the backend does not have a volatile write cache, and we should not even receive flushes from the remote side.
The vwc is in the ctroller data struct, not every each namespace. Currently, the vwc in
the nvmet_ctrl is always 1 to avoid some of the namespacess vwc are present, other namespacess
vwc are not present, therefore we can not set vwc = 0 to avoid receive flushes.
Quoted 7 lines
drivers/nvme/target/io-cmd-file.c static void nvmet_file_execute_rw(struct nvmet_req *req) · line 274
Quoted 5 lines
drivers/nvme/target/io-cmd-file.c +4
-0+if (req->ns->buffered_io) +return errno_to_nvme_status (req,vfs_fsync (req->ns->file,1 )); +else +return errno_to_nvme_status (req,0 );No need for the else, and the simple success case can just use the constant status and does not need a translation.
I will fix that in v2, thanks.
Best regards,
Guixin Liu