nvmet: avoid unnecessary fsync and flush bio
Subsystems (2)
PATCH v2 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.
---
Changes on v2:
- Use bdev_write_cache instead of open code.
- Use NVME_SC_SUCCESS instead of translation, and remove "else".
drivers/nvme/target/io-cmd-bdev.c | 8 ++++++++ drivers/nvme/target/io-cmd-file.c | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/nvme/target/io-cmd-bdev.c +8 -0
@@ -337,6 +337,11 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)if (!nvmet_check_transfer_len (req,0 ))return ; +if (!bdev_write_cache (req->ns->bdev)) { +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 +352,9 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)u16 nvmet_bdev_flush (struct nvmet_req *req) { +if (!bdev_write_cache (req->ns->bdev)) +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 +3 -1
@@ -268,7 +268,9 @@ 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 )); +return NVME_SC_SUCCESS ; }static void nvmet_file_flush_work (struct work_struct *w)
Signature · 1 line
1.8.3.1
Quoted 5 lines · Guixin Liu
For none
buffered_iofile backend and no volatile write cache block device backend, fsync and flush bio are both unnecessary, avoid to do that.Signed-off-by Guixin Liu <[email protected]>
Looks good to me, I believe you have tested this patch.
-ck
Christoph Hellwig
maintainerdrivers/nvme/target/io-cmd-file.c static void nvmet_file_execute_rw(struct nvmet_req *req) · line 273
Quoted 6 lines · Guixin Liu
u16
nvmet_file_flush(struct nvmet_req *req)
{drivers/nvme/target/io-cmd-file.c +3
-1-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 )); +return NVME_SC_SUCCESS ;
This is broken. Even direct I/O needs an fsync to commit metadata changes.
Quoted 9 lines · Christoph Hellwig
drivers/nvme/target/io-cmd-file.c static void nvmet_file_execute_rw(struct nvmet_req *req) · line 273
Quoted 6 lines · Guixin Liu
u16 nvmet_file_flush(struct nvmet_req *req) {drivers/nvme/target/io-cmd-file.c +3
-1-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 )); +return NVME_SC_SUCCESS ;This is broken. Even direct I/O needs an fsync to commit metadata changes.
Well, you are right, I will send V3 patch with remove this change.
Thanks,
Guixin Liu
Quoted 9 lines · Guixin Liu
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Guixin Liu
u16
nvmet_file_flush(struct nvmet_req *req)
{
- returnerrno_to_nvme_status(req, vfs_fsync(req->ns->file, 1)); + if (req->ns->buffered_io)
+ returnerrno_to_nvme_status(req, vfs_fsync(req->ns->file, 1)); + returnNVME_SC_SUCCESS;
Quoted 9 lines
Quoted 2 lines
This is broken. Even direct I/O needs an fsync to commit metadata changes.
Well, you are right, I will send V3 patch with remove this change.
Thanks,
Guixin Liu
Please provide the testlog for this patch with V3.
-ck