Skip to contentSkip to conversation

zswap: change zswap's default allocator to zsmalloc

PATCH Applied Nhat Pham 4 participants 6 messages Sep 8, 2023 – Sep 26, 2023

Subsystems (2)
lore
Share & tools
lore

Nhat Pham

author
#0 lore raw

PATCH 1/1 zswap: change zswap's default allocator to zsmalloc

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

A historical objection to the selection of zsmalloc as the default allocator for zswap is its lack of writeback capability. However, this has changed, with the zsmalloc writeback patchset, and the subsequent zswap LRU refactor. With this, there is not a lot of good reasons to keep zbud, an otherwise inferior allocator, as the default instead of zswap.

This patch changes the default allocator to zsmalloc. The only exception is on settings without MMU, in which case zbud will remain as the default.

---
 mm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
mm/Kconfig +1 -0
index 721dc88423c7..e0217deca084 100644
@@ -130,6 +130,7 @@ config ZSWAP_COMPRESSOR_DEFAULT
 choice
 	prompt "Default allocator"
 	depends on ZSWAP
+	default ZSWAP_ZPOOL_DEFAULT_ZSMALLOC if MMU
 	default ZSWAP_ZPOOL_DEFAULT_ZBUD
 	help
 	  Selects the default allocator for the compressed cache for
Signature · 1 line
2.34.1
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Nhat Pham

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

A historical objection to the selection of zsmalloc as the default allocator for zswap is its lack of writeback capability. However, this has changed, with the zsmalloc writeback patchset, and the subsequent zswap LRU refactor. With this, there is not a lot of good reasons to keep zbud, an otherwise inferior allocator, as the default instead of zswap.

Quoted 5 lines

This patch changes the default allocator to zsmalloc. The only exception is on settings without MMU, in which case zbud will remain as the default.

Acked-by on v1 1/1
#2 lore raw
In reply to Nhat Pham
Quoted 14 lines · Nhat Pham

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

A historical objection to the selection of zsmalloc as the default allocator for zswap is its lack of writeback capability. However, this has changed, with the zsmalloc writeback patchset, and the subsequent zswap LRU refactor. With this, there is not a lot of good reasons to keep zbud, an otherwise inferior allocator, as the default instead of zswap.

Quoted 5 lines

This patch changes the default allocator to zsmalloc. The only exception is on settings without MMU, in which case zbud will remain as the default.

Quoted 19 lines
---
 mm/Kconfig | 1 +
 1 file changed, 1 insertion(+)
mm/Kconfig +1 -1
index 721dc88423c7..e0217deca084 100644
@@ -130,6 +130,7 @@ config ZSWAP_COMPRESSOR_DEFAULT
 choice
        prompt "Default allocator"
        depends on ZSWAP
+       default ZSWAP_ZPOOL_DEFAULT_ZSMALLOC if MMU
        default ZSWAP_ZPOOL_DEFAULT_ZBUD
        help
          Selects the default allocator for the compressed cache for
--

2.34.1

#3 lore raw
In reply to Nhat Pham
Quoted 5 lines · Nhat Pham

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

Dumb question from an outside, why do we then even keep the other two allocators around?

author
#4 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Nhat Pham

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

Dumb question from an outside, why do we then even keep the other two allocators around?

Maybe legacy users who explicitly configure zbud/z3fold? We have a couple internally, and have to manually undo those configuration after we stop compiling these 2 allocators.

But yeah, I don't see why we should keep these 2 allocators around. Time to deprecate them? :)

#5 lore raw
Quoted 13 lines · Nhat Pham
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Nhat Pham

Out of zswap's 3 allocators, zsmalloc is the clear superior in terms of memory utilization, both in theory and as observed in practice, with its high storage density and low internal fragmentation. zsmalloc is also more actively developed and maintained, since it is the allocator of choice for zswap for many users, as well as the only allocator for zram.

Dumb question from an outside, why do we then even keep the other two allocators around?

Quoted 7 lines

Maybe legacy users who explicitly configure zbud/z3fold? We have a couple internally, and have to manually undo those configuration after we stop compiling these 2 allocators.

But yeah, I don't see why we should keep these 2 allocators around. Time to deprecate them? :)

I agree we should try to get rid of them. The best reason for them I can come up with is that they're more "lightweight". But I'm not sure that pans out in practice. Even if loads and stores are marginally faster, the poor density means you have to reclaim more/hotter anon pages for the equivalent reduction in memory usage. In most cases this will increase the overall amount of ongoing paging. That should quickly dwarve the minor advantage in per-transaction overhead.

We could do something similar as we did for slab and mark them deprecated for a few cycles:

commit eb07c4f39c3e858a7d0cc4bb15b8a304f83f0497

Author: Vlastimil Babka <[email protected]>
Date:   Tue May 23 09:06:34 2023 +0200

mm/slab: rename CONFIG_SLAB to CONFIG_SLAB_DEPRECATED

Then if nobody complains give them the ax.