Skip to contentSkip to conversation

nvmet: avoid unnecessary fsync and flush bio

PATCH Superseded Guixin Liu 3 participants 5 messages Jul 25, 2022 – Jul 27, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

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
index 2dc1c10..e63fe87 100644
@@ -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
index 64b47e2..fdff026 100644
@@ -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
#2 lore raw
In reply to Guixin Liu

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.

author
#3 lore raw
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

#4 lore raw
Quoted 9 lines · Guixin Liu
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Guixin Liu

  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;

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