VMware Cloud Community

Increasing memory on a linux vm, what about swap?

I just doubled the amount of memory allocated to a CentOS vm. Needless to say, now my swap is too small. My swap is I have tried to use lvmresize on my guest after turning swap off but, it can't increase the size.

#> lvm lvresize /dev/VolGroup00/LogVol01 -L +2G

Extending logical volume LogVol01 to 4 GB

Insufficient free space: 128 extents needed, but only 0 available

What is the best procedure for doing this?

I suppose I could create another virtual disk and use it as my swap and abandon the old swap space, but I am a newbie and somehow question if this is the best method.

0 Kudos
6 Replies

0 Kudos

I suggest to do not use LVM for swap partition.

You can add a new disk and build a swap partition on it.

Or you can use dd, create a fixed size file and format as a swap file.

I just doubled the amount of memory allocated to a CentOS vm. Needless to say, now my swap is too small.

Swap and RAM size are not related.

Only my virtual Linux box I use a fixed swap size independent of the RAM size.


Andrew | http://about.me/amauro | http://vinfrastructure.it/ | @Andrea_Mauro
0 Kudos


My way is to don't follow the rule which says "The swap file must be between 1 and 3 times the RAM size" for my virtual machines.

Why ?

Because when a server swap, its performances are very very very bad ... So I give them a swap space, but not too big... and imagine if you have 144Gb RAM ... You create a 288Gb SWAP partition ? 288 GB which will never used ...


Martin Pasquier

0 Kudos

By adding more RAM the guest should swap less..., I've never really understood the "between 1 and 3 times" thing for this reason.

However for virtualised servers there is good reason to have swap space equal to RAM size, namely that the balloon driver will use it when the host is short of physical RAM as a recovery mechanism for the host. However this becomes expensive in disk terms since for each VM we then need twice the allocated RAM of disk for swap (i.e. guest swap file and the vswap file).

Personally I have moved all my swaps (vSwap and guest paging) to an SSD, which seems to work well.


Please award points to any useful answer.

Unofficial List of USB Passthrough Working Devices

0 Kudos

To make what Andre suggests, more clear, these are the steps to follow:

To add a swap file:

  1. Determine the size of the new swap file in megabytes and multiply by 1024 to determine the number of blocks. For example, the block size of a 64 MB swap file is 65536.

  2. At a shell prompt as root, type the following command with count being equal to the desired block size:

    dd if=/dev/zero of=/swapfile bs=1024 count=65536
  3. Setup the swap file with the command:

    mkswap /swapfile
  4. To enable the swap file immediately but not automatically at boot time:

    swapon /swapfile
  5. To enable it at boot time, edit /etc/fstab to include the following entry:

    /swapfile          swap            swap    defaults        0 0

    The next time the system boots, it enables the new swap file.

  6. After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command cat /proc/swaps or free.

    Kind Regards,


0 Kudos
Hot Shot
Hot Shot

I would not bother increasing the swap file. If you do not have a big swap file but have loads of memory the perormance of the machine will not be affected at all.

Unless you have assigned very little memory to the VM chances are you will not be using it.

to see if you do need it check with free to see how much it is actually using. It it does do some paging I would consider adding more memory if possible and then if not increase swap.

I have seen plenty of  Linux servers that have minimal swap files as they tend to have  loads of memory.

0 Kudos