How to increase swap?

Hi! I added memory to my virtual machine and for this reason want to increase swap. As I know swap doesn’t work properly with btrfs, so I don’t want to use any workarounds. How can I increase swap?

Just to be clear, why do you want to increase swap just because you
increased RAM? Are you planning on hibernating this VM to its own swap?
Is your system using swap now, and do you expect it to need more for some
reason after adding more real memory (RAM)?

If you really need it, then expand a disk (or add a new one), add a new
partition, make sure it is of type swap (0x82 I think), and then use
‘mkswap’ and ‘swapon’ to make it available.


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.

[QUOTE=ab;40386]Just to be clear, why do you want to increase swap just because you
increased RAM? Are you planning on hibernating this VM to its own swap?

If you really need it, then expand a disk (or add a new one), add a new
partition, make sure it is of type swap (0x82 I think), and then use
‘mkswap’ and ‘swapon’ to make it available.
[/QUOTE]

I’m not planning, but this is the best practice swap=RAM link And Oracle requires more size swap link
I tried do this according to this instruction. But resize command doesn’t work.
I guess I have to resize disk outside of my system (rescue mode or liveCD). I don’t know how to do it. Have you got instructions?

Just to be clear, the TID you cited dies not recommend setting swap based
on RAM, and the linked PDF, which itself is also very old (2007, for the
Linux 2.6 kernels), explicitly states the following:

What is clear, however, is that the swap size should not only be a
function of the RAM size.

I only mention this in case you are adjusting swap simply because you gave
the virtual machine (VM) more RAM and you are using that addition as the
reasoning for increasing available swap. That is only a valid
recommendation if you want to Hibernate your system because, in that one
case only, you need a 1:1 ratio of swap to RAM, though that usually only
makes sense on laptops or other things that hibernate a lot (not servers).

In the Oracle documentation I also do not see any specific requirements,
though they have some old recommendations that probably date back to the
same time as the SUSE TID you cited.

Ignoring all of that, and getting back to your question, you’re allowed to
increase swap if you want, and it should work as long as you have disk
space, and your partitions are aligned properly.

The document you cited mentions resizing a Btrfs partition, and while that
may be possible, I do not know that it works for a running root
filesystem, though I also have not tried. Depending on the virtualization
solution you have you may be able to expand your disk on the fly, and then
re-partition to add a new partition that can be formatted as swap. More
likely to be possible since it will not impact your current disk is to add
a second disk. Again, assuming your virtualization software lets you do
it at runtime, you could add the new disk and then partition the whole
thing to be used for one big swap-based partition. This may also have
performance benefits since you would not have contention between the disk
doing everything else (your current disk) and the one used for (hopefully,
but not usually) high-performance virtual memory. One of the joys of
virtualization is that it does not matter much if you use the current disk
or a new one; disks are usually virtual too, just carved out from space in
some larger disk system (physical disks, SANs, iSCSI targets, etc.).


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below.

If you want to send me a private message, please let me know in the
forum as I do not use the web interface often.