Skip to contentSkip to conversation

erofs: add per-cpu threads for decompression as an option

PATCH In review Gao Xiang 3 participants 9 messages Feb 8, 2023 – Feb 28, 2023 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH v5 1/1 erofs: add per-cpu threads for decompression as an option

From: Sandeep Dhavale <[email protected]>

Using per-cpu thread pool we can reduce the scheduling latency compared to workqueue implementation. With this patch scheduling latency and variation is reduced as per-cpu threads are high priority kthread_workers.

The results were evaluated on arm64 Android devices running 5.10 kernel.

The table below shows resulting improvements of total scheduling latency for the same app launch benchmark runs with 50 iterations. Scheduling latency is the latency between when the task (workqueue kworker vs kthread_worker) became eligible to run to when it actually started running.

+-------------------------+-----------+----------------+---------+
|                         | workqueue | kthread_worker |  diff   |
+-------------------------+-----------+----------------+---------+
| Average (us)            |     15253 |           2914 | -80.89% |
| Median (us)             |     14001 |           2912 | -79.20% |
| Minimum (us)            |      3117 |           1027 | -67.05% |
| Maximum (us)            |     30170 |           3805 | -87.39% |
| Standard deviation (us) |      7166 |            359 |         |
+-------------------------+-----------+----------------+---------+

Background: Boot times and cold app launch benchmarks are very important to the Android ecosystem as they directly translate to responsiveness from user point of view. While EROFS provides a lot of important features like space savings, we saw some performance penalty in cold app launch benchmarks in few scenarios. Analysis showed that the significant variance was coming from the scheduling cost while decompression cost was more or less the same.

Having per-cpu thread pool we can see from the above table that this variation is reduced by ~80% on average. This problem was discussed at LPC 2022. Link to LPC 2022 slides and talk at [1]

[1] https://lpc.events/event/16/contributions/1338/

[ Gao Xiang: At least, we have to add this until WQ_UNBOUND workqueue
issue [2] on many arm64 devices is resolved. ]
[2] https://lore.kernel.org/r/CAJkfWY490-m6wNubkxiTPsW59sfsQs37Wey279LmiRxKt7aQYg@mail.gmail.com

---
v4: https://lore.kernel.org/r/[email protected]/

changes since v4:
- need to fall back to workqueue rather than a global kthread and make this feature as an option for now.

 fs/erofs/Kconfig |  18 +++++
 fs/erofs/zdata.c | 190 ++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 188 insertions(+), 20 deletions(-)
fs/erofs/Kconfig +18 -0
index 85490370e0ca..704fb59577e0 100644
@@ -108,3 +108,21 @@ config EROFS_FS_ONDEMAND
 	  read support.
 
 	  If unsure, say N.
+
+config EROFS_FS_PCPU_KTHREAD
+	bool "EROFS per-cpu decompression kthread workers"
+	depends on EROFS_FS_ZIP
+	help
+	  Saying Y here enables per-CPU kthread workers pool to carry out
+	  async decompression for low latencies on some architectures.
+
+	  If unsure, say N.
+
+config EROFS_FS_PCPU_KTHREAD_HIPRI
+	bool "EROFS high priority per-CPU kthread workers"
+	depends on EROFS_FS_ZIP && EROFS_FS_PCPU_KTHREAD
+	help
+	  This permits EROFS to configure per-CPU kthread workers to run
+	  at higher priority.
+
+	  If unsure, say N.
fs/erofs/zdata.c +170 -20

251 lines not on this page · raw message

Signature · 1 line
2.24.4
#1 lore raw

Hi,

Quoted 7 lines · Gao Xiang

From: Sandeep Dhavale <[email protected]>

Using per-cpu thread pool we can reduce the scheduling latency compared to workqueue implementation. With this patch scheduling latency and variation is reduced as per-cpu threads are high priority kthread_workers.

The results were evaluated on arm64 Android devices running 5.10 kernel.

I see that this patch was upstreamed. Meanwhile, commit c25da5b7baf1d ("dm verity: stop using WQ_UNBOUND for verify_wq") was also upstreamed.

Why is this more complex solution better than simply removing WQ_UNBOUND?

- Eric

author
#2 lore raw

Hi Eric,

Quoted 9 lines · Eric Biggers

Hi,

Quoted 6 lines · Gao Xiang

From: Sandeep Dhavale <[email protected]>

Using per-cpu thread pool we can reduce the scheduling latency compared to workqueue implementation. With this patch scheduling latency and variation is reduced as per-cpu threads are high priority kthread_workers.

Quoted 6 lines
Quoted 1 line

The results were evaluated on arm64 Android devices running 5.10 kernel.

I see that this patch was upstreamed. Meanwhile, commit c25da5b7baf1d ("dm verity: stop using WQ_UNBOUND for verify_wq") was also upstreamed.

Why is this more complex solution better than simply removing WQ_UNBOUND?

I do think it's a specific issue on specific arm64 hardwares (assuming qualcomm, I don't know) since WQ_UNBOUND decompression once worked well on the hardwares I once used (I meant Hisilicon, and most x86_64 CPUs, I tested at that time) compared with per-cpu workqueue.

Also RT threads are also matchable with softirq approach. In addition, many configurations work without dm-verity.

I don't have more time to dig into it for now but it's important to resolve this problem on some arm64 hardwares first. Also it's an optional stuff, if the root cause of workqueue issue can be resolved, we could consider drop it then.

Thsnka,
Gao Xiang

Quoted 2 lines

- Eric

author
#3 lore raw
Quoted 19 lines · Gao Xiang

Hi Eric,

Quoted 9 lines · Eric Biggers

Hi,

Quoted 6 lines · Gao Xiang

From: Sandeep Dhavale <[email protected]>

Using per-cpu thread pool we can reduce the scheduling latency compared to workqueue implementation. With this patch scheduling latency and variation is reduced as per-cpu threads are high priority kthread_workers.

Quoted 6 lines
Quoted 1 line

The results were evaluated on arm64 Android devices running 5.10 kernel.

I see that this patch was upstreamed.  Meanwhile, commit c25da5b7baf1d ("dm verity: stop using WQ_UNBOUND for verify_wq") was also upstreamed.

Why is this more complex solution better than simply removing WQ_UNBOUND?

Quoted 7 lines

I do think it's a specific issue on specific arm64 hardwares (assuming qualcomm, I don't know) since WQ_UNBOUND decompression once worked well on the hardwares I once used (I meant Hisilicon, and most x86_64 CPUs, I tested at that time) compared with per-cpu workqueue.

Also RT threads are also matchable with softirq approach.  In addition, many configurations work without dm-verity.

Also for dm-verity use cases, EROFS will reuse the dm-verity context directly rather than kick off a new context. Yet I'm not sure there are still users using EROFS without dm-verity as I said above.

Anyway, the original scheduling issue sounds strange for me (with my own landing experiences) in the beginning, and I have no way to confirm the cases. Just hopefully it could be resolved from the developer inputs and finally benefit to end users.

I've already did my own stress test with this new configuration as well without explicit regression.

Quoted 11 lines

I don't have more time to dig into it for now but it's important to resolve this problem on some arm64 hardwares first.  Also it's an optional stuff, if the root cause of workqueue issue can be resolved, we could consider drop it then.

Thsnka,
Gao Xiang

Quoted 2 lines

- Eric

#4 lore raw
Quoted 35 lines · Gao Xiang
Quoted 19 lines · Gao Xiang

Hi Eric,

Quoted 9 lines · Eric Biggers

Hi,

Quoted 6 lines · Gao Xiang

From: Sandeep Dhavale <[email protected]>

Using per-cpu thread pool we can reduce the scheduling latency compared to workqueue implementation. With this patch scheduling latency and variation is reduced as per-cpu threads are high priority kthread_workers.

Quoted 6 lines
Quoted 1 line

The results were evaluated on arm64 Android devices running 5.10 kernel.

I see that this patch was upstreamed. Meanwhile, commit c25da5b7baf1d ("dm verity: stop using WQ_UNBOUND for verify_wq") was also upstreamed.

Why is this more complex solution better than simply removing WQ_UNBOUND?

Quoted 7 lines

I do think it's a specific issue on specific arm64 hardwares (assuming qualcomm, I don't know) since WQ_UNBOUND decompression once worked well on the hardwares I once used (I meant Hisilicon, and most x86_64 CPUs, I tested at that time) compared with per-cpu workqueue.

Also RT threads are also matchable with softirq approach. In addition, many configurations work without dm-verity.

Also for dm-verity use cases, EROFS will reuse the dm-verity context directly rather than kick off a new context. Yet I'm not sure there are still users using EROFS without dm-verity as I said above.

Quoted 8 lines

Anyway, the original scheduling issue sounds strange for me (with my own landing experiences) in the beginning, and I have no way to confirm the cases. Just hopefully it could be resolved from the developer inputs and finally benefit to end users.

I've already did my own stress test with this new configuration as well without explicit regression.

Hi Eric,
From the dm-verity patch description of removing WQ_UNBOUND it seems Nathan saw the EROFS wait time was reduced by 51% whereas high pri per-cpu threads showed me sched latency reduced on avg by ~80%.

So from the description at least it does not look like both patches have equal benefits. I can't argue about the size and complexity of removing WQ_UNBOUND if it gives the same benefits, that would have been great.

I will do the app launch tests again to compare these and share.

Thanks,
Sandeep.

Quoted 11 lines
Quoted 11 lines

I don't have more time to dig into it for now but it's important to resolve this problem on some arm64 hardwares first. Also it's an optional stuff, if the root cause of workqueue issue can be resolved, we could consider drop it then.

Thsnka,
Gao Xiang

Quoted 2 lines

- Eric

#5 lore raw

Hi all,
I completed the tests and the results are consistent with our previous observation. We can see that removing WQ_UNBOUND helps but the scheduling latency by using high priority per cpu kthreads is even lower. Below is the table.

|---------------------+-------+-------+------+-------|
| Table               | avg   | med   | min  | max   |
|---------------------+-------+-------+------+-------|
| Default erofs       | 19323 | 19758 | 3986 | 35051 |
|---------------------+-------+-------+------+-------|
| !WQ_UNBOUND         | 11202 | 10798 | 3493 | 19822 |
|---------------------+-------+-------+------+-------|
| hipri pcpu kthreads | 7182  | 7017  | 2463 | 12300 |
|---------------------+-------+-------+------+-------|

Thanks,
Sandeep.

author
#6 lore raw

Hi Sandeep,

Quoted 6 lines · Sandeep Dhavale via Linux-erofs

Hi all,
I completed the tests and the results are consistent with our previous observation. We can see that removing WQ_UNBOUND helps but the scheduling latency by using high priority per cpu kthreads is even lower. Below is the table.

Quoted 9 lines
|---------------------+-------+-------+------+-------|
| Table               | avg   | med   | min  | max   |
|---------------------+-------+-------+------+-------|
| Default erofs       | 19323 | 19758 | 3986 | 35051 |
|---------------------+-------+-------+------+-------|
| !WQ_UNBOUND         | 11202 | 10798 | 3493 | 19822 |
|---------------------+-------+-------+------+-------|
| hipri pcpu kthreads | 7182  | 7017  | 2463 | 12300 |
|---------------------+-------+-------+------+-------|

May I ask did it test with different setup since the test results in the original commit message are:

+-------------------------+-----------+----------------+---------+
|                         | workqueue | kthread_worker |  diff   |
+-------------------------+-----------+----------------+---------+
| Average (us)            |     15253 |           2914 | -80.89% |
| Median (us)             |     14001 |           2912 | -79.20% |
| Minimum (us)            |      3117 |           1027 | -67.05% |
| Maximum (us)            |     30170 |           3805 | -87.39% |
| Standard deviation (us) |      7166 |            359 |         |
+-------------------------+-----------+----------------+---------+

Otherwise it looks good to me for now, hopefully helpful to Android users.

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Sandeep.

#7 lore raw
Quoted 20 lines · Gao Xiang

Hi Sandeep,

Quoted 6 lines · Sandeep Dhavale via Linux-erofs

Hi all,
I completed the tests and the results are consistent with our previous observation. We can see that removing WQ_UNBOUND helps but the scheduling latency by using high priority per cpu kthreads is even lower. Below is the table.

Quoted 9 lines
|---------------------+-------+-------+------+-------|
| Table               | avg   | med   | min  | max   |
|---------------------+-------+-------+------+-------|
| Default erofs       | 19323 | 19758 | 3986 | 35051 |
|---------------------+-------+-------+------+-------|
| !WQ_UNBOUND         | 11202 | 10798 | 3493 | 19822 |
|---------------------+-------+-------+------+-------|
| hipri pcpu kthreads | 7182  | 7017  | 2463 | 12300 |
|---------------------+-------+-------+------+-------|
Quoted 3 lines

May I ask did it test with different setup since the test results in the original commit message are:

Hi Gao,
Yes I did the test on the different (older) hardware than my original testing (but the same one Nathan had used) to remove that as a variable.

Thanks,
Sandeep.

Quoted 20 lines
+-------------------------+-----------+----------------+---------+
|                         | workqueue | kthread_worker |  diff   |
+-------------------------+-----------+----------------+---------+
| Average (us)            |     15253 |           2914 | -80.89% |
| Median (us)             |     14001 |           2912 | -79.20% |
| Minimum (us)            |      3117 |           1027 | -67.05% |
| Maximum (us)            |     30170 |           3805 | -87.39% |
| Standard deviation (us) |      7166 |            359 |         |
+-------------------------+-----------+----------------+---------+

Otherwise it looks good to me for now, hopefully helpful to Android users.

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Sandeep.

author
#8 lore raw
Quoted 21 lines · Sandeep Dhavale
Quoted 20 lines · Gao Xiang

Hi Sandeep,

Quoted 15 lines · Sandeep Dhavale via Linux-erofs

Hi all,
I completed the tests and the results are consistent with our previous observation. We can see that removing WQ_UNBOUND helps but the scheduling latency by using high priority per cpu kthreads is even lower. Below is the table.

|---------------------+-------+-------+------+-------|
| Table               | avg   | med   | min  | max   |
|---------------------+-------+-------+------+-------|
| Default erofs       | 19323 | 19758 | 3986 | 35051 |
|---------------------+-------+-------+------+-------|
| !WQ_UNBOUND         | 11202 | 10798 | 3493 | 19822 |
|---------------------+-------+-------+------+-------|
| hipri pcpu kthreads | 7182  | 7017  | 2463 | 12300 |
|---------------------+-------+-------+------+-------|
Quoted 6 lines
Quoted 3 lines

May I ask did it test with different setup since the test results in the original commit message are:

Hi Gao,
Yes I did the test on the different (older) hardware than my original testing (but the same one Nathan had used) to remove that as a variable.

Ok, good to know that.

Quoted 24 lines

Thanks,
Sandeep.

Quoted 20 lines
+-------------------------+-----------+----------------+---------+
|                         | workqueue | kthread_worker |  diff   |
+-------------------------+-----------+----------------+---------+
| Average (us)            |     15253 |           2914 | -80.89% |
| Median (us)             |     14001 |           2912 | -79.20% |
| Minimum (us)            |      3117 |           1027 | -67.05% |
| Maximum (us)            |     30170 |           3805 | -87.39% |
| Standard deviation (us) |      7166 |            359 |         |
+-------------------------+-----------+----------------+---------+

Otherwise it looks good to me for now, hopefully helpful to Android users.

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Sandeep.