Skip to contentSkip to conversation

block: move non sync requests complete flow to softirq

PATCH Superseded ZhangHui 5 participants 14 messages Sep 3, 2024 – Sep 5, 2024 Block layer

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

ZhangHui

author
#0 lore raw

PATCH v3 1/1 block: move non sync requests complete flow to softirq

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

---
 block/blk-mq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq.c +3 -1
index e3c3c0c21b55..06b232edff11 100644
@@ -1193,6 +1193,8 @@ static void blk_mq_raise_softirq(struct request *rq)
 
 bool blk_mq_complete_request_remote(struct request *rq)
 {
+	const bool is_sync = rq_is_sync(rq);
+
 	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
 
 	/*
@@ -1210,7 +1212,7 @@ bool blk_mq_complete_request_remote(struct request *rq)
 		return true;
 	}
 
-	if (rq->q->nr_hw_queues == 1) {
+	if ((rq->q->nr_hw_queues == 1) || !is_sync) {
 		blk_mq_raise_softirq(rq);
 		return true;
 	}
Signature · 1 line
2.43.0
#1 lore raw
Quoted 10 lines · ZhangHui

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

Quoted 7 lines

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

An explanation is missing from the patch description why this issue cannot be solved by changing rq_affinity to 2.

Thanks,

Bart.

maintainer
#2 lore raw
Quoted 16 lines · Bart Van Assche
Quoted 15 lines · ZhangHui

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

Quoted 5 lines
Quoted 2 lines

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

An explanation is missing from the patch description why this issue cannot be solved by changing rq_affinity to 2.

And what's also missing is a changelog - to the poster, always include what's changed since the last version posted. Otherwise you just have 3 random patches posted and leave the discovery of why on earth there's now a v3 to the reader in having to pull in all 3 versions and see if the progression made sense.

Signature · 1 line
Jens Axboe
author
#3 lore raw
In reply to Bart Van Assche
Quoted 24 lines · Bart Van Assche

[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈

Quoted 11 lines · ZhangHui

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process,
such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

Quoted 7 lines

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

Quoted 7 lines

An explanation is missing from the patch description why this issue cannot be solved by changing rq_affinity to 2.

Thanks,

Bart.

hi Bart,

Does set rq_affinity to 2 mean QUEUE_FLAG_SAME_COMP?

This seems to determine on which core the current request is completed, rather than in the interrupt top or bottom half?

Thanks
Zhang

#4 lore raw
Quoted 1 line · 章辉

Does set rq_affinity to 2 mean QUEUE_FLAG_SAME_COMP?

From block/blk-sysfs.c:

	if (val == 2) {
		blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q);
		blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, q);
	}
Quoted 2 lines

This seems to determine on which core the current request is completed, rather than in the interrupt top or bottom half?

That's correct. I suggested this because I was wondering whether spreading the I/O completion workload over more CPU cores would help?

Thanks,

Bart.

author
#5 lore raw
Quoted 13 lines · Bart Van Assche
Quoted 1 line · 章辉

Does set rq_affinity to 2 mean QUEUE_FLAG_SAME_COMP?

From block/blk-sysfs.c:

       if (val == 2) { blk_queue_flag_set(QUEUE_FLAG_SAME_COMP, q); blk_queue_flag_set(QUEUE_FLAG_SAME_FORCE, q); }

Quoted 2 lines

This seems to determine on which core the current request is completed, rather than in the interrupt top or bottom half?

Quoted 7 lines

That's correct. I suggested this because I was wondering whether spreading the I/O completion workload over more CPU cores would help?

Thanks,

Bart.

hi Bart,

Increasing the CPU frequency or directly binding the interrupt to the big core processing will definitely help the end io processing delay, depending on the system's requirements for IO response delay.

But it does not seem to conflict with this modification to put the time-consuming operation in the lower half.

Thanks
Zhang

maintainer
#6 lore raw
In reply to ZhangHui
Quoted 12 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

Quoted 4 lines

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

The elephant in the room here is why an 80M completion takes 100 msec? That seems... insane.

That aside, doing writes that big isn't great for latencies in general, even if they are orders of magnitude smaller (as they should be). Maybe this is solvable by just limiting the write size here.

But it really seems out of line for a write that size to take 100 msec to process.

Signature · 1 line
Jens Axboe
author
#7 lore raw
Quoted 24 lines · Jens Axboe
Quoted 12 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

Quoted 4 lines

We measured that the 80M bio write operation on the little CPU will cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

The elephant in the room here is why an 80M completion takes 100 msec? That seems... insane.

That aside, doing writes that big isn't great for latencies in general, even if they are orders of magnitude smaller (as they should be). Maybe this is solvable by just limiting the write size here.

Quoted 6 lines

But it really seems out of line for a write that size to take 100 msec to process.

--
Jens Axboe

hi Jens,

This problem is strongly related to whether the CPU is a large core or a little core and the CPU frequency. On a large core, the time will obviously be shorter, but we cannot assume which core the IO will be completed on and the current CPU frequency...

Limiting the IO size is also a method, but how large to limit it is a problem, and I am worried whether it will cause bandwidth loss in some scenarios?

Thanks
Zhang

#8 lore raw
In reply to Jens Axboe
Quoted 9 lines · Jens Axboe

The elephant in the room here is why an 80M completion takes 100 msec? That seems... insane.

That aside, doing writes that big isn't great for latencies in general, even if they are orders of magnitude smaller (as they should be). Maybe this is solvable by just limiting the write size here.

But it really seems out of line for a write that size to take 100 msec to process.

pagecache state processing is quite inefficient, we had to limit the number of them for XFS to avoid latency problems a while ago. Note that moving to folios means you can process a lot more data with the same number of completion iterations as well. I'd suggest the submitter looks into that for whatever file system they are using.

author
#9 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jens Axboe

The elephant in the room here is why an 80M completion takes 100 msec? That seems... insane.

That aside, doing writes that big isn't great for latencies in general, even if they are orders of magnitude smaller (as they should be). Maybe this is solvable by just limiting the write size here.

Quoted 8 lines
Quoted 2 lines

But it really seems out of line for a write that size to take 100 msec to process.

pagecache state processing is quite inefficient, we had to limit the number of them for XFS to avoid latency problems a while ago. Note that moving to folios means you can process a lot more data with the same number of completion iterations as well. I'd suggest the submitter looks into that for whatever file system they are using.

hi Christoph,

The F2FS file system is used on the smartphone, and end_io uses page traversal instead of folio traversal.
I will confirm the plan to migrate to folio. Thank you!

Thanks
Zhang

#10 lore raw
In reply to ZhangHui
Quoted 7 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

Quoted 6 lines

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will

What is 80M bio?

It is one known issue that soft lockup may be triggered in case of N:M blk-mq mapping, but not sure if that is the case.

What is nr_hw_queues(blk_mq) and nr_cpus in your system?

Quoted 3 lines

cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

schedule is off too in softirq(bottom-half).

Quoted 3 lines

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

If you do care interrupt-off or schedule-off latency, you may have to move the IO handling into thread context in the driver.

BTW, threaded irq can't help you too.

Thanks,
Ming

author
#11 lore raw
Quoted 28 lines · Ming Lei
Quoted 7 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

Quoted 6 lines

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will

What is 80M bio?

It is one known issue that soft lockup may be triggered in case of N:M blk-mq mapping, but not sure if that is the case.

What is nr_hw_queues(blk_mq) and nr_cpus in your system?

Quoted 3 lines

cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

schedule is off too in softirq(bottom-half).

Quoted 2 lines

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

Quoted 9 lines

If you do care interrupt-off or schedule-off latency, you may have to move the IO handling into thread context in the driver.

BTW, threaded irq can't help you too.

Thanks,
Ming

hi Ming,

Very good reminder, thank you.

On smartphones, nr_hw_queues and nr_cpus are 1:1, I am more concerned about the interrupt-off latency, which is more obvious on little cores.

Moving time-consuming work to the bottom half may not help with schedule latency, but it is may helpful for interrupt response latency of other modules in the system?

Thanks
Zhang

#12 lore raw
Quoted 38 lines · 章辉
Quoted 28 lines · Ming Lei
Quoted 7 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

Quoted 6 lines

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will

What is 80M bio?

It is one known issue that soft lockup may be triggered in case of N:M blk-mq mapping, but not sure if that is the case.

What is nr_hw_queues(blk_mq) and nr_cpus in your system?

Quoted 3 lines

cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

schedule is off too in softirq(bottom-half).

Quoted 2 lines

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

Quoted 9 lines

If you do care interrupt-off or schedule-off latency, you may have to move the IO handling into thread context in the driver.

BTW, threaded irq can't help you too.

Thanks,
Ming

Quoted 6 lines

hi Ming,

Very good reminder, thank you.

On smartphones, nr_hw_queues and nr_cpus are 1:1, I am more concerned about the interrupt-off latency, which is more obvious on little cores.

So you submits 80M bytes from one CPU, and almost all these bios are completed in single interrupt, which looks very impossible, except that your UFS controller is far faster than the CPU.

Quoted 4 lines

Moving time-consuming work to the bottom half may not help with schedule latency, but it is may helpful for interrupt response latency of other modules in the system?

scheduling response latency is system-wide too.

Then please document the interrupt latency improvement instead of scheduling in your commit log, otherwise it is just misleading.

```
The CPU tick on a smartphone is only 4ms, which will undoubtedly affect
scheduling efficiency.
```

Thanks,
Ming

author
#13 lore raw
Quoted 41 lines · Ming Lei
Quoted 40 lines · 章辉
Quoted 28 lines · Ming Lei
Quoted 7 lines · ZhangHui

From: zhanghui <[email protected]>

Currently, for a controller that supports multiple queues, like UFS4.0, the mq_ops->complete is executed in the interrupt top-half. Therefore, the file system's end io is executed during the request completion process, such as f2fs_write_end_io on smartphone.

Quoted 6 lines

However, we found that the execution time of the file system end io is strongly related to the size of the bio and the processing speed of the CPU. Because the file system's end io will traverse every page in bio, this is a very time-consuming operation.

We measured that the 80M bio write operation on the little CPU will

What is 80M bio?

It is one known issue that soft lockup may be triggered in case of N:M blk-mq mapping, but not sure if that is the case.

What is nr_hw_queues(blk_mq) and nr_cpus in your system?

Quoted 3 lines

cause the execution time of the top-half to be greater than 100ms. The CPU tick on a smartphone is only 4ms, which will undoubtedly affect scheduling efficiency.

schedule is off too in softirq(bottom-half).

Quoted 2 lines

Let's fixed this issue by moved non sync request completion flow to softirq, and keep the sync request completion in the top-half.

Quoted 9 lines

If you do care interrupt-off or schedule-off latency, you may have to move the IO handling into thread context in the driver.

BTW, threaded irq can't help you too.

Thanks,
Ming

hi Ming,

Quoted 7 lines
Quoted 4 lines

Very good reminder, thank you.

On smartphones, nr_hw_queues and nr_cpus are 1:1, I am more concerned about the interrupt-off latency, which is more obvious on little cores.

So you submits 80M bytes from one CPU, and almost all these bios are completed in single interrupt, which looks very impossible, except that your UFS controller is far faster than the CPU.

The 80M bio bio refers to the bio sent by the file system. At the block layer, it will be split into many bios and form a bio chain. The time-consuming part is end_io of filesystem processing all page state. It will only be actually called after all the 80M BIOs in the bio chain are completed.

Quoted 8 lines
Quoted 3 lines

Moving time-consuming work to the bottom half may not help with schedule latency, but it is may helpful for interrupt response latency of other modules in the system?

scheduling response latency is system-wide too.

Then please document the interrupt latency improvement instead of scheduling in your commit log, otherwise it is just misleading.

Quoted 7 lines
```
The CPU tick on a smartphone is only 4ms, which will undoubtedly affect
scheduling efficiency.
```

Thanks,
Ming

hi Ming,

OK, I will update patch V4 later for comment update. Thank you for your suggestion!
Besides this,do you have any other concern?

Thanks
Zhang