Saturday 8 August 2015

Dynamically adding and reducing the resources on Hot VM's

Inside Dynamic Memory                                             Download PDF

What is Dynamic Memory?
Dynamic memory was introduced in Windows Server 2008 R2 with SP1.  It gave the Hyper-V hypervisor the capability to dynamically adjust the amount of memory assigned to a machine based on memory demand.  The reason we would want to do this is simple.  If we can put only the amount of memory a machine needs in the box, we can fit more machines on a host.  How’s that?  When you deploy a server you give it the amount of memory you think it will need at it’s maximum load.  So if when the server is the busiest it needs 4gb of memory it will have what it needs.  But, what if that server is only busy for an hour a week?  That is a waste of the 4gb of memory.  Dynamic memory allows Hyper-V to “Dynamically Reallocate” that memory to other servers that may need it.  Then when it needs the memory it can simply dynamically reallocate it back.

An important concept that you need to know about dynamic memory is that it is not the same as “memory overcommit.”  Dynamic memory is a much more accurate term to use for it because Hyper-V dynamically “allocates” memory based on workload “demand”  In this article, all of these terms and distinctions will be clearly defined.   Hyper-V DOES NOT OVERCOMMIT!  One of the biggest problems with “memory overcommit” is what happens under memory pressure.  When a server runs out of memory it pages (swaps to disk).  This is a very costly (slow performance) transaction so Hyper-V will not page at the host (with one very small exception shown below).  If there is going to be paging it has to be at the guest and only on the lower priority servers.

Dynamic Memory Requirements?
Dynamic Memory requires the following:
  • Windows Server 2012 or Hyper-V Server 2012 (click links for free downloads)  {Windows 2008 R2 SP1 or above; Windows 8 or above}
  • Hyper-V role.
  • Hyper-V Guest with Integration Components installed
  • Dynamic memory configured in the guest settings
How To add the integration component and enable Dynamic Memory on Windows Server 2003 or other Operating Systems
  1. Open the Virtual Machine Connection (Double-Click the machine in Hyper-V Manager)
  2. Click the Action menu the select “Insert Integration Services Setup Disks“
  3. Login to the server and run the Setup from the Integration Services Setup CD (if you get a message about uninstalling a previous version, go ahead and do it)
  4. You may then have to restart the server, once you do that, the newest integration components will be available including Dynamic Memory.
How To: Enable and Configure Dynamic Memory
Enable Dynamic Memory in Hyper-V Manager under the settings for the Virtual Machine {guest}
  1. Open Hyper-V Manager. {Start Keyboard Button – Hyper-V Manager}
  2. Click on your Host Machine Name in the left pane {This will display your Virtual Machines; if you do not have virtual machines, you will need to create them. see the lab “Install/Enable and Configure Hyper-V Getting Started”  at http://itproguru.com/hol}
  3. Right-Click Guest Machine Name {in the right pane) and choose Settings.  {This will open the box shown below}
  4. Click Memory – Turn on checkbox Enable Dynamic Memory then adjust settings as desired.  See explanation of settings below
  5. Click Apply or OK
Deep Dive into Windows Server 2012 Hyper-V Dynamic Memory - what all this stuff means/does..

1) Startup RAM: Specifies the amount of memory required to start the virtual machine. The value needs to be high enough to allow the guest operating system to start, but should be as low as possible to allow for optimal memory utilization and potentially higher consolidation ratios. Startup RAM is the amount of physical memory the Guest MUST be given when the machine is turned on (or rebooted).  If the host does not have this amount of memory it will try to get memory from dynamically changing the amount of memory on other guests on that host.  If physical memory cannot be allocated due to defined limits in other guest machines then Hyper-V will not allow you to turn the machine.  You should set this to the amount of memory the machine needs to efficiently boot.  Depending on the workload, you may want to be stringent or aggressive.  If you know you are going to be rebooting the machine in a host starving situation then be stringent and only give it what it needs to start.  If you want to have plenty of memory to start quickly, then be more aggressive and give it more memory.
2) Enable Dynamic Memory: turn on the checkbox to enable, turn off checkbox to disable. Cannot change setting while machine is running.

    a) Minimum RAM: Minimum RAM is the low value of what the guest will be allowed to use.  Hyper-V will never take more memory away from this machine than the Minimum RAM allows.  This machine will ALWAYS have at least this much memory.
The required memory to run an idle virtual machine is less than the required memory to start that virtual machine. By reclaiming unused memory from the idle virtual machines, you can potentially run more virtual machines on one host. To do this, you specify a smaller value for the minimum memory than for the startup memory. However, if you do this in Windows Server 2008 R2 with SP1, a virtual machine cannot restart when the host does not have enough physical memory. This limitation is more problematic in environments where many virtual machines are idle on a host, such as pooled VDI environments and server consolidation environments that are under low load (for example, during the night).  Hyper-V will auto-adjust the “assigned memory” down as the memory demand decreases or as the host needs more memory for higher priority workloads.

    b) Maximum RAM: Maximum RAM is the maximum amount of memory Hyper-V will give a guest regardless of demand.  This is very handy to make sure a server does not take more than their fair share.  As an example you may have a development server that you want to use Dynamic memory on so you can keep it from going rogue, with a memory leak, taking more resources than you want to allow them to take.
The maximum amount will only be used if the guest actually needs it.  It is an upper limit on what can be given to the virtual machine guest. Simply set the maximum and if this machine needs more, too bad.  It will be as if that is all the memory that is available so the guest will have to get the memory somewhere else (like it’s page file).

    c) Dynamic Example in a physical world a memory upgrade requires shutting down the virtual machine, a common challenge for administrators is upgrading the maximum amount of memory for a virtual machine as demand increases.
Example 1: consider a virtual machine running IIS Server and configured with a maximum of 8 GB of RAM. Because of an increase in the size of the site or the traffic, the virtual machine now requires more memory. In Windows Server 2008 R2 with SP1, you must shut down the virtual machine to perform the upgrade, which requires planning for downtime and decreasing business productivity. With Windows Server 2012, you can apply that change while the virtual machine is running.

3) Memory Buffer: Specifies how much memory Hyper-V will attempt to assign to the virtual machine compared to the amount of memory actually needed by the applications and services running inside the virtual machine.
Memory buffer is specified as a percentage because the actual amount of memory that represents the buffer changes in response to changes in memory usage while the virtual machine is running. Hyper-V uses performance counters in the virtual machine that identify committed memory to determine the current memory requirements of the virtual machine and then calculates the amount of memory to add as a buffer. The buffer is determined using the following formula.

Amount of memory buffer = how much memory the virtual machine actually needs / (memory buffer value / 100).

For example, if the memory committed to the guest operating system is 1000 MB and the memory buffer is 20%, Hyper-V will attempt to allocate an additional 20% (200 MB) for a total of 1200 MB of physical memory allocated to the virtual machine.

4) Memory Weight: Memory Weight provides Hyper-V with a way to determine how to distribute memory among virtual machines if there is not enough physical memory available in the computer to give every virtual machine its requested amount of memory.
The higher the weight, the higher the priority when it comes time to give out memory.  It is also used for taking memory away.  The lower the weight, the most likely that machine is to lose memory when the host needs it.  Guests with a lower weight will get starved if need be in order to give higher weight guests the memory they desire.

Non-uniform memory access (NUMA)
Depending on the CPU settings of the machine, memory is managed differently. When you enable dynamic memory you also enable non-uniform memory access (NUMA).

A very import aspect of virtual machine memory configuration is Non-uniform memory access (NUMA). NUMA is a memory design that speeds up memory access by partitioning physical memory so each processor in a multi-CPU has its own memory. For example, in a system with 8 cores and 32 GB of RAM, each core or node has 4 GB of physical memory. If a virtual machine is configured to use 8 GB of RAM, the system has to use memory in another node. Because crossing the NUMA boundary can reduce virtual performance by as much as 8%, it is a best practice to configure a virtual machine to use resources from a single NUMA node.

If you only have a single processor on the virtual machine and you enable dynamic memory you may get a warning message:   

This virtual machine is configured with uniform memory access. virtual machines configured with a large amount of memory or many virtual processors can often benefit from non-uniform memory access.  Disable Dynamic memory to allow non-uniform memory access.

For more information about NUMA, refer to the following articles:
  • Understanding Non-uniform Memory Access
  • Determining NUMA node boundaries for modern CPUs
  • NUMA Node Balancing


Hyper-V Smart Paging
Windows Server 2012 also introduces Hyper-V Smart Paging for robust virtual machine restart. Although minimum memory increases virtual machine consolidation numbers, it also brings a challenge. If a virtual machine has a smaller amount of memory than its startup memory and it is restarted, Hyper-V needs additional memory to restart the machine. Due to host memory pressure or virtual machines’ states, Hyper-V may not always have additional memory available. This can cause sporadic virtual machine restart failures in customer environments. In Windows Server 2012, Hyper-V Smart Paging is used to bridge the memory gap between minimum memory and startup memory and let virtual machines restart reliably.  This gap is only temporary and should not be an issue beyond the time it takes to restart a server (10 minutes or less)

To minimize the performance impact of Smart Paging, Hyper-V uses it only when all of the following occur:
  • The virtual machine is being restarted.
  • No physical memory is available.
  • No memory can be reclaimed from other virtual machines that are running on the host.
Hyper-V Smart Paging is not used when:
  • A virtual machine is being started from an off state (instead of a restart).
  • Oversubscribing memory for a running virtual machine would result.
  • A virtual machine is failing over in Hyper-V clusters.
What if you are just OUT of physical Memory?
There will come a time when you simply have more workloads running that you have resources to run so what happens?  Hyper-V continues to rely on internal guest paging when host memory is oversubscribed because it is more effective than Hyper-V Smart Paging. With internal guest paging, the paging operation inside virtual machines is performed by Windows Memory Manager. Windows Memory Manager has more information than does the Hyper-V host about memory use within the virtual machine, which means it can provide Hyper-V with better information to use when it chooses the memory to be paged. Because of this, internal guest paging incurs less overhead to the system than Hyper-V Smart Paging.

How is Dynamic Memory different from other Virtualization Platforms like ESX? [Hyper-V Dynamic Memory vs. ESX Overcommit]
Now that you fully understand how Dynamic Memory works, let’s look at how it is different from other solutions.  Specifically, let’s look at VMWare and how they manage memory. VMware ESX leverages several techniques to manage memory.  They use transparent page sharing, ballooning, and host swapping.  Collectively, they call these technologies “Memory Overcommit”

No comments:

Post a Comment