# How to increase swap?

**URL:** https://forums.suse.com/t/how-to-increase-swap/30610
**Category:** SLES Configure-Administer
**Created:** [November 30, 2017, 5:48pm UTC](https://forums.suse.com/t/how-to-increase-swap/30610 "2017-11-30T17:48:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![bm\_rec](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bm\_rec](https://forums.suse.com/u/bm_rec)
#### Post date: [November 30, 2017, 5:48pm UTC](https://forums.suse.com/t/how-to-increase-swap/30610/1 "2017-11-30T17:48:59Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)
#### Post date: [November 30, 2017, 7:34pm UTC](https://forums.suse.com/t/how-to-increase-swap/30610/2 "2017-11-30T19:34:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![bm\_rec](https://avatars.discourse-cdn.com/v4/letter/b/82dd89/32.png) [@bm\_rec](https://forums.suse.com/u/bm_rec)
#### Post date: [December 4, 2017, 10:22am UTC](https://forums.suse.com/t/how-to-increase-swap/30610/3 "2017-12-04T10:22:54Z")

</div>

[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](https://www.novell.com/support/kb/doc.php?id=7003601) And Oracle requires more size swap [link](https://docs.oracle.com/database/121/LTDQI/toc.htm#CHDJIAAI)  
I tried do this according to [this instruction](http://bogdan.org.ua/2016/04/14/how-to-easily-add-swap-partition-to-a-live-system-on-btrfs.html). 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?

---

<div class="post-metadata">

### Author: ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)
#### Post date: [December 4, 2017, 2:57pm UTC](https://forums.suse.com/t/how-to-increase-swap/30610/4 "2017-12-04T14:57:42Z")

</div>

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:

```auto
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.
