I plan to use zram as a device for swap.
The init-zram-swapping
script delivered with Ubuntu 18.04 LTS Bionic in package zram-config
is creating one zram device for each CPU.
https://packages.ubuntu.com/bionic/zram-config
The package is unchanged up to eoan.
Why is this being done? Is there any advantage of having multiple zram devices configured for swap?
I could imagine that it would help to not block on compression when working with the swap, but since kernel 4.7 it will always have multiple compression streams. One per online CPU. https://github.com/torvalds/linux/commit/43209ea2d17aae1540d4e28274e36404f72702f2
Even for older kernels I would have expected to see the max_comp_streams
attribute being used and having one zram device.
So was the script just not adjusted with newer kernel versions available or is there another benefit of having multiple zram devices?
When pagging occurs in a memory owned by a given CPU (especially in a NUMA configuration - imagine current EPYC processors with their 8-channel memory controllers and NUMA nodes) it's most effective to not copy this memory over to another CPU's memory (and disturb it's threads). So I bet it's for performance reasons.