Skip to contentSkip to conversation

nvmet: avoid unnecessary flush bio

PATCH Applied Guixin Liu 3 participants 5 messages Jul 29, 2022 – Sep 5, 2022

Subsystems (2)
lore
Share & tools
lore

Guixin Liu

author
#0 lore raw

PATCH v3 1/1 nvmet: avoid unnecessary flush bio

For no volatile write cache block device backend, sending flush bio is unnecessary, avoid to do that.

---

Changes on v3:
- Remove file backend change.

Changes on v2:
- Use bdev_write_cache instead of open code.
- Use NVME_SC_SUCCESS instead of translation, and remove "else".

Test log:
- Add printk log at new if branch.
- Use nvme_loop to emulate nvme device.
- Use tcm_loop and tcmu to emulate no volatile write cache block backend by setting emulate_write_cache=0.
- Send "nvme flush /dev/nvme0n1", there is a log print, and cmd return success.
- Send "nvme set-feature /dev/nvme0n1 --namespace-id=1 --feature-id=0x84 --value=1", there is a log print, and cmd return success.
- Format nvme0n1 to ext4 filesystem, then create a file, write data and save, there is a log print, and no error.

 drivers/nvme/target/io-cmd-bdev.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/nvme/target/io-cmd-bdev.c +8 -0
index 2dc1c10..8d527a8 100644
@@ -334,6 +334,11 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)
 {
 	struct bio *bio = &req->b.inline_bio;
 
+	if (!bdev_write_cache(req->ns->bdev)) {
+		nvmet_req_complete(req, NVME_SC_SUCCESS);
+		return;
+	}
+
 	if (!nvmet_check_transfer_len(req, 0))
 		return;
 
@@ -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;
Signature · 1 line
1.8.3.1
author
#1 lore raw

Hi,

Gentle ping.

thanks,

Guixin Liu

Quoted 53 lines · Guixin Liu

For no volatile write cache block device backend, sending flush bio is unnecessary, avoid to do that.

---

Changes on v3:
- Remove file backend change.

Changes on v2:
- Use bdev_write_cache instead of open code.
- Use NVME_SC_SUCCESS instead of translation, and remove "else".

Test log:
- Add printk log at new if branch.
- Use nvme_loop to emulate nvme device.
- Use tcm_loop and tcmu to emulate no volatile write cache block backend by setting emulate_write_cache=0.
- Send "nvme flush /dev/nvme0n1", there is a log print, and cmd return success.
- Send "nvme set-feature /dev/nvme0n1 --namespace-id=1 --feature-id=0x84 --value=1", there is a log print, and cmd return success.
- Format nvme0n1 to ext4 filesystem, then create a file, write data and save, there is a log print, and no error.

  drivers/nvme/target/io-cmd-bdev.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/nvme/target/io-cmd-bdev.c +8 -0
index 2dc1c10..8d527a8 100644
@@ -334,6 +334,11 @@ static void nvmet_bdev_execute_flush(struct nvmet_req *req)
  {
  	struct bio *bio = &req->b.inline_bio;
 
+	if (!bdev_write_cache(req->ns->bdev)) {
+		nvmet_req_complete(req, NVME_SC_SUCCESS);
+		return;
+	}
+
  	if (!nvmet_check_transfer_len(req, 0))
  		return;
 
@@ -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;
#2 lore raw
Quoted 3 lines · Guixin Liu

Hi,

Gentle ping.

I'll pick it up once the tree openes up for the next merge window.

Reviewed-by on v3 1/1
#3 lore raw
In reply to Guixin Liu
Quoted 24 lines · Guixin Liu

For no volatile write cache block device backend, sending flush bio is unnecessary, avoid to do that.

---

Changes on v3:
- Remove file backend change.

Changes on v2:
- Use bdev_write_cache instead of open code.
- Use NVME_SC_SUCCESS instead of translation, and remove "else".

Test log:
- Add printk log at new if branch.
- Use nvme_loop to emulate nvme device.
- Use tcm_loop and tcmu to emulate no volatile write cache block backend by setting emulate_write_cache=0.
- Send "nvme flush /dev/nvme0n1", there is a log print, and cmd return success.
- Send "nvme set-feature /dev/nvme0n1 --namespace-id=1 --feature-id=0x84 --value=1", there is a log print, and cmd return success.
- Format nvme0n1 to ext4 filesystem, then create a file, write data and save, there is a log print, and no error.

Quoted 3 lines
  drivers/nvme/target/io-cmd-bdev.c | 8 ++++++++
  1 file changed, 8 insertions(+)

Thanks for the test report, looks good.

-ck