D
D
Drovosek012022-01-05 19:10:49
linux
Drovosek01, 2022-01-05 19:10:49

How to make swap file with dynamic size in Linux?

In Windows, the pagefile.sys file is responsible for the swap and it can be configured so that it gains weight as needed, no more than a certain size, and so that it takes a strictly defined size all the time.

In Linux, I am not strong in those guides that I read, either they created a partition of a strictly specified size for swap, or they created a file of a given size and assigned it as a swap.

How to create a swap file in Linux so that it increases and decreases in size depending on whether data from RAM needs to be moved to swap or not?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
AVKor, 2022-01-05
@AVKor

How to create a dynamically sized swap file in Linux?

No way.
Moreover, this is not necessary, since it is necessary to use a partition, not a file (it is written to the partition directly, and to the file - over the FS, which is less efficient).

R
rPman, 2022-01-06
@rPman

There is no dynamic swap file in linux (initially, only a fixed-size partition could be a swap, but then the placement on file systems was added, if they support it, with reservations), but it is possible to dynamically connect and disconnect new swap files or devices using the swapon and swapoff console commands, the contents of the file must be 'formatted' by mkswap before being included, this avoids the mistake of specifying a normal file.
Swap can be placed as a file on popular file systems such as ext4 or network nfs, iscsi devices can be used, there should be no 'holes' (sparce files) in the file, i.e. it will not be possible to allocate a fast place using dd seek, (on something like fat it will work), and compression and cow should also be turned off (see chattr) if btrfs is used for example

S
SOTVM, 2022-01-06
@sotvm

if you don’t have an old computer and have more than 4GB, and you don’t suffer from sleep mode,
then you don’t need swap,
at least some crooked applications / programs require
me 8 RAM + 1GB / swap in the file
in the sysctl configs

kernel.sysrq = 1
vm.swappiness = 15
vm.vfs_cache_pressure = 50

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question