zram is a generic, compressed block device in RAM.
It has no relation to swap at all. There is (nearly) no swap specific code to it. It just happens to be useful for swap under the right circumstances.
That means there is no zram specific migration path to another swap partition or a swap file. The swap system itself also does not offer 1:1 swap device migrations.
You are supposed to use swapoff
. The kernel will then use other swap devices if and when required, thereby indirectly migrating it. Alternatively, you may add another swap device with a higher priority and wait for your lower priority swap devices to be tuned out over time.
That said, zram has an optional writeback feature, see zram: Optional Feature — writeback. You can use it to (temporarily) free up RAM. However, all requests would still go through the zram device and newly written pages would probably also end up in RAM first.
Support for this feature is not widespread yet (might not be enabled in kernel, zramctl
doesn't support it, etc.). You might have to activate it manually through the sysfs interface. You can try it and see if it suits your needs.
Since zram is a generic block device, you can apply generic block device migration methods on it. This would allow you to remove the zram device altogether without swapoff
.
For example, you could create RAID 1 and use mdadm --replace
to move it from zram to a physical partition. (mdadm --force
allows creating single disk RAID 1, so no mirroring is taking place while not migrating.)
For example, you could put LVM on it and use pvmove
to move it from zram to a physical volume.
However, it's hard to say whether this would have any benefit over just using swapoff
. Maybe setting swappiness to a higher value temporarily would affect swapoff
behavior as well.
(Just throwing ideas around — I never tested any of it.)