For a single swap partition it is shorter syntax to replace with
swapoff without a parameter which will also fail if memory is too short.
Attempting to unmount a swap partition with either command will check
for the combination of RAM+remaining swap to see if there will be space
and fail when not true. If the combined room will work then swapped
memory on that devices is pushed out to RAM and remaining swap and then
it unmounts. Seems swapctl accepts a list of mount points so syntax
quickly becomes shorter with it. Using a list, it iterates through one
partition at a time as separate unmount calls so if you have 2 equally
sized partitions and 40% swap used with RAM effectively full then you
will first get 1 partition to unmount and the other is 80% full and when
it reaches the second partition it will fail with an error. Re-mounting
the first swap will bring you back to 40% full but for performance
reasons you will find all read calls now are always using I/O of the
second partition for currently stored memory until it gets swapped
out+in again.
The only way I know of to improve layout without closing+reopening
programs requires you have another swap partition large enough to hold
all swapped contents but is normally unmounted and mount it, unmount all
normally used partitions, mount all normally used partitions, and then
unmount the single large partition. I'm not sure that it is any formal
rule that it will always split the allocation across remaining drives
rather than filling them sequentially but it seemed to give that result
when I previously messed with it. If you have 3+ partitions and
accidentally unmounted multiple but not all of them and don't have a
spare large partition for such a shuffle, you can probably get to the
next closest state by mounting all partitions and then sequentially
unmount+remount any partitions that contained data before the mount;
this will leave you with at least one partition unpopulated and the
others carrying its load until swapped data gets pushed to RAM and back
to swap. If you have an extra swap partition that is not normally used
then you can have it in this sequence as the last partition to be
unmounted which will help reach closer to even data distribution but
with more steps and still not likely as well balanced.
As an interesting sidenote, manpage says 'swapctl -d' can also take
-f to have it proceed to unmount the partition but may deadlock the
system. Wouldn't it be more appropriate to kill processes as RAM becomes
exhausted as should be done in a low memory situation?