Need a Server? Build it in the cloud for free

       

Inside Dynamic Memory in Windows Server 2012 Hyper-V–Everything You NEED to Know

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 is constantly managing memory.  Some call this a disadvantage because it is always working.  I do not see it that way. I actually see it as a huge advantage.  First,   the probability of getting in a low memory state is much lower because Hyper-V is constantly watching demand and tweaking things for optimum performance.  Second, when there is memory pressure it does not have to do all that extra work to sort things out while in a starving situation.  Finally, causes minimal overhead to keep memory managed as opposed to getting memory under control when you have no memory to work with.

The most important thing to understand about Dynamic memory is that you can run more virtual machines with it.   Let’s say you have a 32gb of physical memory in your server; you look at task manager and you see that you are using 31gb or memory.  If you have another machine that needs 2gb of memory can you start it?  Answer: YES!   Hyper-V will simply take “buffer” memory away from other machines to give you the memory you need to run the machine.  If you need to start another 4gb server can you?  Answer: Yes!  As long as you have physical memory you can start more machines.  Hyper-V will grab buffer memory first, then available memory and finally it will grab real memory from lower priority machines to give you the memory you need to start your machines.  If you do not have any of these (Hopefully you do not run things that tight), then the machine will not start. 

 

Dynamic Memory Requirements?

Dynamic Memory requires the following: ď‚·

Dynamic memory works with OLD OS’s (eg. Windows Server 2003) as well as new OS’s (Windows 8/2012) running as a guest on Hyper-V.  You can find a complete compatibility list here.  This incredible technology is added with the Integration components. To add the integration component:

  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.

 

Startup Memory

In the previous version of Hyper-V, Dynamic Memory included “startup memory,” which is defined as the minimum amount of memory that a virtual machine can have. However, Windows requires more memory during startup than the steady state. Some of the virtual machines are assigned extra memory because earlier versions of Hyper-V cannot reclaim memory from these virtual machines after startup. The startup memory value is the amount of physical memory Hyper-V MUST have before it can start the machine.  Hyper-V will reserve this amount of memory to the machine for startup.   In some cases, you might want to give a machine more memory to start so it can complete startup processes faster.  With Windows Server 2012, you can now give it the memory it needs to be quick then just let Hyper-V take it back when it is done.  Startup RAM can ONLY be defined/changed while the machine is OFF.

image

 

Minimum 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 has the memory demand decreases or as the host needs more memory for higher priority workloads.  However, it can never (regardless of priority) take more than the minimum amount of memory away from a guest.  You can decrease the minimum amount of memory while the server is running but you cannot increase it (e.g. you can change the value from 1024 to 512; but you cannot change from 512 to 1024) 

image

 

image

 

Maximum Memory 
Maximum memory 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 then their fair share.  As an example you may have a development server that you want to use Dynamic memory on so you can reclaim resources when they are not being used but you do not want a rough application with a memory leak to take all the memory you have available in the host and start paging.  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). You can increase the maximum amount of memory while the server is running but you cannot decrease it (e.g. you can change the value from 4096 to 8192; but you cannot change from 8192 to 4096)

image

 

Dynamic Example

Because 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. For example, consider a virtual machine running SQL Server and configured with a maximum of 8 GB of RAM. Because of an increase in the size of the databases, 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.
Fast-growing organizations whose workloads are rapidly expanding often need to add more virtual machines to their host processors. These organizations want to optimize the number of virtual machines they can place on a host server to minimize the number of expensive host servers that they need. With the Hyper-V Dynamic Memory improvements in Windows Server 2012, IT administrators can now allocate virtual machine memory resources more efficiently and dramatically increase virtual machine consolidation ratios.

 

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.

Note: The buffer is not maintained when there is not enough physical memory available in the computer to give every virtual machine its requested memory buffer.

image

Note: You can change change the buffer while the machine is running.

 

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 of that virtual machine.  As an example, if a high priority machine has a higher demand than can be provided by available memory, Hyper-V will take memory away from a lower priority machine (starving the lower priority machine) to give the higher priority machine the resources it demands.

image

Note: You can change the  weight while the machine is running.

 

Memory Demand, Assigned and Status

Memory demand is how much memory your guest server needs.  Memory assigned is how much memory Hyper-V has allocated to your virtual machine. Memory status is an indicator to let you know of the health state of the memory of the machine.  If the status is OK then the assigned memory is higher than the demand.  However, you status can go into a warning state as the demand increases above what Hyper-V has assigned.  Remember, this can happen if the host is out of memory due to higher priority machines taking memory reserves away from this machine.

 

Configuring Dynamic Memory Step-By-Step

You can configure dynamic memory in Hyper-V Manager. Right-click the virtual machine (guest). Select Settings; Click Memory in the left pane; then turn on the “Enable Dynamic Memory” checkbox

 

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)

Hyper-V Smart Paging is a memory management technique that uses disk resources as additional, temporary memory when more memory is required to restart a virtual machine. This approach has both advantages and drawbacks. It provides a reliable way to keep the virtual machines running when no physical memory is available. However, it can degrade virtual machine performance because disk access speeds are much slower than memory access speeds.  Ok, I said above Hyper-V DOES NOT OVERCOMMIT!  Well, this is THE ONLY exception to the rule and it is only for a very limited time and reason! 

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.

 

Also of interest: 

This entry was posted in Private Cloud and tagged , , , , , by Dan Stolts ITProGuru. Bookmark the permalink.

About Dan Stolts ITProGuru

Dan Stolts (The "ITProGuru") is a technology expert who is a master of systems management and security. He is proficient in many Microsoft products especially in the server area (Windows Server, System Center, Exchange, SharePoint, Virtualization, Etc) and holds many certifications including MCT, MCITP, MCSE, TS, etc. Dan is currently specializing in System Management and Security and is also very passionate about virtualization technologies. Dan is and has been a very active member of the community. He is president of Boston User Groups, Founder of Virtualization Group Boston, Founder of North East Leaders and serves on many IT Community group boards. He is in the process of writing his first book on building technology communities. He is a believer in social networking and can be reached on twitter @ITProGuru. He has participated in many non-technology community groups such as: Rotary Club, Lions Club, local Chambers of Commerce and is a mentor for the local high schools. Dan is an enthusiastic advocate of technology and is passionate about helping others. Dan's lifelong passion has been and continues to be to help and teach others!

Leave a Reply