Saturday, June 23, 2012

Virtual Machine Swap file size (.vswp)


Swap File Size Calculation

Every VM have some amount of Memory configured. So when we power on the VM, vmkernel have to create the Swap file for VM (this file is different file than vmdk file), so that in case of memory contention overallocated memory can be delivered (in the storage there must be free space available to create that file otherwise we can't power on the VM).

Swap File is calculated using the below formula:-

Allocated Memory to VM - Reserve Memory to VM = Size of Swap file (.vswp)

Suppose VM is configure with 2048 MB of Memory and Reserve for that VM is 512 MB then swap file size is 1536 MB as per above formula:-

2048 - 512 = 1536 MB.

Even you reserve 100 % allocated memory to VM swap file still created but with 0KB in size.

Swap file created even you have enough memory on host, but vmkernel only use this file (in case of memory contention)  if demand of memory is more than the available amount of Memory on Host (ESXi).



6 comments:

Neeraj said...

Really Good Post Sir.

failat said...

Hi

Can share what means by allocated memory and reserved memory.

E.g. we create a vm with 8gb memory.

failat said...

hi

what is means by allocated memory and reserved memory.

example, we create a vm with 8gb memory.

Ravinder Kumar said...

When you create a VM in VMware vSphere with any size of RAM allocation, like you take and example of 8 GB RAM. By default each VM get created with 0MB of reserve RAM. But if you think that out of 8 GB RAM, I want min 1GB RAM must be guarantied for that VM regardless of load on host. Then you have option under the VM setting in the resourse tab you can configure the same. Swap file created by vmkernel in this case 8GB RAM allocated - 1 GB RAM which you reserve for that VM.

mano said...

Hi,

I am really a newbie. I am found the .vswp swap file in the datastore and I have installed ubuntu as the OS. Unfortunately, I couldn't find the swap partition on the ubuntu OS. I really couldn't know if the .VSWP is same as for ubuntu swap inside os or on HD.

Do I need to create a separate swap Partition or swap file for my OS.

Any, help will be really appreciated.

Ravinder Kumar said...

When you create VM, you allocate some amount of Memory. That is the amount of RAM VM OS feel, to deliver that amount if physical host is out of RAM will start using .vswp file space.

But once VM use their allocated RAM, then traditional OS also start paging to fill the extra requirement, So still the OS page/swap space needed by guest OS to deal with demand of memory.

In short yes you need create swap partition for Linux OS as we have in case of Physical system.