I can't imagine why a swap file needs to be fixed size. Why not let it resize dynamically, like the hard drive image file for a virtual box?
I can't imagine why a swap file needs to be fixed size. Why not let it resize dynamically, like the hard drive image file for a virtual box?
It doesn't look like Linux supports dynamic swap file sizing (at any rate, I couldn't get it to detect that a swap file had changed size without a
swapoff
/swapon
).Presumably it is easier to assume that a swap file doesn't change file size dynamically when writing code for supporting it. I don't see any great use for it either. Since you can use multiple swap files, nothing's preventing you from creating more swap files as needed.
Also note this paragraph from the
swapon
manpage:I'd think the same problem would apply to a dynamically-sized swap file.
SwapSpace is a utility that will allow you to make dynamically sized swap if that is what you are looking for. I do believe it is available in Ubuntu.
I know it is late, but I think the best solution for dynamic swap is to:
then setting
CONF_SWAPFACTOR=2
in/etc/dphys-swapfile
and finallySwap space can be added to a running system by using the
swapon
command. It needs an existing (unused) swapfile/partition. To create one, use thedd
command to allocate a contiguous file, and thenmkswap
to add the correct control information to the file / partition.To remove a swapfile, use
swapoff
; the file can then be deleted.I suspect that is what
SwapSpace
dæmon that @user231695 mentioned does.Note that swapoff can be a slow operation if the swapfile is in use; all the data has to be transferred to another swap area.
There appears to be a program named
swapspace
. Available from Ubuntu 18.04 onward.The corresponding GitHub page. They recommend using a static swap file if you want to suspend and resume work. They also do not recommend using it for systems that need to be responsive.
People have asked about how to use it. Those details are mentioned in the readme file.