Ubuntu 是否支持动态交换文件大小?

Tom*_*cer 17 swap 17.04

我无法想象为什么交换文件需要固定大小。为什么不让它动态调整大小,就像虚拟盒子的硬盘映像文件一样?

mur*_*uru 12

看起来 Linux 不支持动态交换文件大小调整(无论如何,我无法检测到交换文件在没有swapoff/ 的情况下更改了大小swapon)。

据推测,在编写支持它的代码时,更容易假设交换文件不会动态更改文件大小。我也看不出它有什么大用处。由于您可以使用多个交换文件,因此没有什么可以阻止您根据需要创建更多交换文件。

还要注意从本段swapon手册页

The  swap file implementation in the kernel expects to be able to write
to the file directly, without the assistance of the  filesystem.   This
is  a problem on preallocated files (e.g.  fallocate(1)) on filesystems
like XFS or ext4, and on copy-on-write filesystems like btrfs.
Run Code Online (Sandbox Code Playgroud)

我认为同样的问题适用于动态大小的交换文件。


小智 5

SwapSpace是一个实用程序,如果您需要的话,它可以让您进行动态大小的交换。我相信它可以在 Ubuntu 中使用。