Skip to contentSkip to conversation

mm: zswap: multiple zpools support

PATCH Superseded Yosry Ahmed 2 participants 3 messages May 31, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm: zswap: multiple zpools support

Support using multiple zpools of the same type in zswap, for concurrency purposes. Add CONFIG_ZSWAP_NR_ZPOOLS_ORDER to control the number of zpools. The order is specific by the config rather than the absolute number to guarantee a power of 2. This is useful so that we can use deterministically link each entry to a zpool by hashing the zswap_entry pointer.

On a setup with zswap and zsmalloc, comparing a single zpool (current default) to 32 zpools (by setting CONFIG_ZSWAP_NR_ZPOOLS_ORDER=32) shows improvements in the zsmalloc lock contention, especially on the swap out path.

The following shows the perf analysis of the swapout path when 10 workloads are simulatenously reclaiming and refaulting tmpfs pages. There are some improvements on the swap in path as well, but much less significant.

1 zpool:

|--28.99%--zswap_frontswap_store

       |
       <snip>
       |
       |--8.98%--zpool_map_handle
       |     |
       |      --8.98%--zs_zpool_map
       |           |
       |            --8.95%--zs_map_object
       |                 |
       |                  --8.38%--_raw_spin_lock
       |                       |
       |                        --7.39%--queued_spin_lock_slowpath
       |
       |--8.82%--zpool_malloc
       |     |
       |      --8.82%--zs_zpool_malloc
       |           |
       |            --8.80%--zs_malloc
       |                 |
       |                 |--7.21%--_raw_spin_lock
       |                 |     |
       |                 |      --6.81%--queued_spin_lock_slowpath
       <snip>

32 zpools:

|--16.73%--zswap_frontswap_store

       |
       <snip>
       |
       |--1.81%--zpool_malloc
       |     |
       |      --1.81%--zs_zpool_malloc
       |           |
       |            --1.79%--zs_malloc
       |                 |
       |                  --0.73%--obj_malloc
       |
       |--1.06%--zswap_update_total_size
       |
       |--0.59%--zpool_map_handle
       |     |
       |      --0.59%--zs_zpool_map
       |           |
       |            --0.57%--zs_map_object
       |                 |
       |                  --0.51%--_raw_spin_lock
       <snip>

---

v1 -> v2:
- Prettified perf graph in commit log.
- Changed zswap_nr_zpools to a macro, changed zswap_pool->zpools to a fixed size array instead of a flex array.
- Removed stale comment.

---
 mm/Kconfig | 12 +++++++
 mm/zswap.c | 91 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 73 insertions(+), 30 deletions(-)
mm/Kconfig +12 -0
index 92c30879bf67..de1da56d2c07 100644
@@ -59,6 +59,18 @@ config ZSWAP_EXCLUSIVE_LOADS
 	  The cost is that if the page was never dirtied and needs to be
 	  swapped out again, it will be re-compressed.
 
+config ZSWAP_NR_ZPOOLS_ORDER
+	int "Number of zpools in zswap, as power of 2"
+	default 0
+	depends on ZSWAP
+	help
+	  This options determines the number of zpools to use for zswap, it
+	  will be 1 << CONFIG_ZSWAP_NR_ZPOOLS_ORDER.
+
+	  Having multiple zpools helps with concurrency and lock contention
+	  on the swap in and swap out paths, but uses a little bit of extra
+	  space.
+
 choice
 	prompt "Default compressor"
 	depends on ZSWAP
mm/zswap.c +61 -30

235 lines not on this page · raw message

Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
#1 lore raw
Quoted 8 lines · Yosry Ahmed

Support using multiple zpools of the same type in zswap, for concurrency purposes. Add CONFIG_ZSWAP_NR_ZPOOLS_ORDER to control the number of zpools. The order is specific by the config rather than the absolute number to guarantee a power of 2. This is useful so that we can use deterministically link each entry to a zpool by hashing the zswap_entry pointer.

Quoted 7 lines

On a setup with zswap and zsmalloc, comparing a single zpool (current default) to 32 zpools (by setting CONFIG_ZSWAP_NR_ZPOOLS_ORDER=32) shows improvements in the zsmalloc lock contention, especially on the swap out path.

The following shows the perf analysis of the swapout path when 10 workloads are simulatenously reclaiming and refaulting tmpfs pages.

simultaneously

Quoted 2 lines

There are some improvements on the swap in path as well, but much less significant.

...

Quoted 10 lines
---
 mm/Kconfig | 12 +++++++
 mm/zswap.c | 91 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 73 insertions(+), 30 deletions(-)
mm/Kconfig +0 -0
index 92c30879bf67..de1da56d2c07 100644

mm/Kconfig config ZSWAP_EXCLUSIVE_LOADS · line 67

Quoted 9 lines
mm/Kconfig +6 -0
@@ -59,6 +59,18 @@ config ZSWAP_EXCLUSIVE_LOADS
          The cost is that if the page was never dirtied and needs to be
          swapped out again, it will be re-compressed.
 
+config ZSWAP_NR_ZPOOLS_ORDER
+       int "Number of zpools in zswap, as power of 2"
+       default 0
+       depends on ZSWAP
+       help
+         This options determines the number of zpools to use for zswap, it

option

#2 lore raw
Quoted 38 lines · Yu Zhao
Quoted 8 lines · Yosry Ahmed

Support using multiple zpools of the same type in zswap, for concurrency purposes. Add CONFIG_ZSWAP_NR_ZPOOLS_ORDER to control the number of zpools. The order is specific by the config rather than the absolute number to guarantee a power of 2. This is useful so that we can use deterministically link each entry to a zpool by hashing the zswap_entry pointer.

Quoted 7 lines

On a setup with zswap and zsmalloc, comparing a single zpool (current default) to 32 zpools (by setting CONFIG_ZSWAP_NR_ZPOOLS_ORDER=32) shows improvements in the zsmalloc lock contention, especially on the swap out path.

The following shows the perf analysis of the swapout path when 10 workloads are simulatenously reclaiming and refaulting tmpfs pages.

simultaneously

Quoted 2 lines

There are some improvements on the swap in path as well, but much less significant.

...

Quoted 13 lines
---
 mm/Kconfig | 12 +++++++
 mm/zswap.c | 91 ++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 73 insertions(+), 30 deletions(-)
mm/Kconfig +0 -0
index 92c30879bf67..de1da56d2c07 100644
@@ -59,6 +59,18 @@ config ZSWAP_EXCLUSIVE_LOADS
          The cost is that if the page was never dirtied and needs to be
          swapped out again, it will be re-compressed.
 
Quoted 8 lines

mm/Kconfig config ZSWAP_EXCLUSIVE_LOADS · line 67

Quoted 6 lines
mm/Kconfig +6 -0
+config ZSWAP_NR_ZPOOLS_ORDER
+       int "Number of zpools in zswap, as power of 2"
+       default 0
+       depends on ZSWAP
+       help
+         This options determines the number of zpools to use for zswap, it

option

Thanks for taking a look. Will correct both in v3 (if any). Otherwise, I hope Andrew will fix them in-place :)