How memory is allocated to a virtual machine?
When we create a new virtual machine through vsphere client the wizard asks us how much memory the virtual machine should have
The amount of memory we allocate on this screen is the amount of the guest operating system will see.
Example:. Assume we have given 1 GB of memory to virtual machine. the virtual machine will never able to use more than 1 GB.
Let us assume 4 GB of physical RAM avail to run the virtual machine.
Requirements: Need to create the 4 virtual machine with 1 GB RAM each.
First virtual machine will run with 1GB and leaving the 3GB to the other virtual machines
After configured 3 more virtual machine with 1GB each. Upto now all the machines will run as normal.
What happens when we launch a fifth machine ? will it run ? The answer is yes.
There are 3 technologies used to manage the memory.They are
- Idle page reclamation
- Transparent page sharing
- Balloon driver
Idle page reclamation:
Using this technology, ESX/ESXi will reclaim memory pages that are not being actively used by the virtual machine, clean-up the reclaimed pages and reallocate those memory pages to the other virtual machines.
Transparent page sharing:
In this technology, where the identical memory pages are shared among virtual machines to reduce the total number of memory pages need.
Balloon driver:
This driver will comes with VMware Tools. In this technology the driver forces a VM to use less memory than its configured maximum. The balloon driver requests memory from the guest operating system within virtual machine and then passes that memory back to the hyper-visor for use by other virtual machine
How Balloon driver works?
This driver is a part of the vmware Tools, It is a guest operating system specific driver, meaning that Linux VM’s would have a Linux-based balloon driver, Windows VMs would have a Windows-based balloon driver, and so.
When the ESX/ESXi host is running low on physical memory, the hyper-visor will signal the balloon driver to grow. To do this the balloon driver will request memory from the guest operating system. This causes the balloon driver’s memory footprint to grow. The memory that is granted to the balloon driver is then passed back to the hyper-visor. The hyper-visor can use these memory pages to supply memory for the other virtual machines, which reducing the need to swap and minimizing the performance impact of the memory. When the memory pressure on the host get cleared, the balloon driver will return memory to the guest operating system.
Controlling Memory Allocation
ESX/ESXi provides some additional settings in the virtual machines configuration that affect memory allocation and memory management..On the Resources tab of a virtual machine’s properties dialog box we can see three options for controlling how a virtual machine uses the memory assigned to it.
- Reservation
- Limit
- Shares
The following are the steps to edit the reservation, limit,or shares of a virtual machine
- Use the vSphere Client to connect to a vCenter Server or directly to an ESX/ESXi
- Scroll down through the inventory to find the virtual machine to be edited
- Right click the virtual machine, and select the Edit Settings option
- Click Resources tab
- On the Resources tab, select the CPU or Memory options from the Settings list on the left
- Adjust the Shares, Reservation and Limit values as needed
The memory reservation is optional settings for each virtual machine. The memory reservation amount specified on the Resouces tab of the virtual machine settings is the amount of actual, real physical memory that the ESX/ESXi host provide to this virtual machine for the virtual machine to power on..
The default is 0MB. 0 MB means the ESX/ESXi host does not have to provide the virtual machine with any physical memory.
A virtual machine with a reservation is guaranteed the amount of RAM configured in its Reservation settings.
If ESX/ESXi host is not required to provide actual RAM to the virtual machine, then how the virtual machine get its memory? The answer is that it provides swap, or more specifically something called VMkernel swap
VMkernel swap is a file created when a virtual machine is powered on with a .vswp extension. The pre-virtual machine swap files created by the VMkernel reside by default in the same data store location as the virtual machine’s configuration file and virtual disk files. By default this file will be equal to the size of the RAM that you configured the virtual machine.
Note: If the virtual machine configured with a reservation or a limit, the VMkernel swap file could differ.
Here you may get doubt. Does a virtual machine will get all of its memory from swap when ESX/ESXi host RAM is available? NO. ESX/ESXi will attempt to provide each virtual machine with all the memory it request, upto the maximum amount configured for the virtual machine.
Example: A virtual machine configured with only 1GB of RAM cannot request more than 1GB of RAM. However when an ESX/ESXi host does not have enough RAM available to satisfy the memory needs of the virtual machines it is hosting. The technologies such as transparent page sharing, idle page reclamation and the balloon driver aren’t enough, the VMkernel is forces to page some of each virtual machine’s memory out to the individual virtual machine’s memory out to the individual virtual machine’s VMkernel swap file.
Did we can control how much of an individual virtual machine’s memory allocation can provided by swap and how much must be provided by real physical RAM? Yes. This is where a memory reservation comes into picture. By default a virtual machine has a memory reservation of 0MB, which means that potentially all of the virtual machine has a memory pages out to the VMkernel swap file if necessary.
No comments:
Post a Comment