Home | Featured | Using The Dynamic Memory Feature on Microsoft Hyper-V

Using The Dynamic Memory Feature on Microsoft Hyper-V

0 Flares Twitter 0 Facebook 0 Google+ 0 StumbleUpon 0 Buffer 0 LinkedIn 0 Filament.io 0 Flares ×

WS08-R2_v_rgbMicrosoft recently released service pack 1 (SP1) of Windows Server 2008 R2, which includes the Dynamic Memory option.  This new feature is meant to aid memory management across a Hyper-V host with multiple guests.  Previously the memory assigned to a guest was static and couldn’t be changed without a power off and reboot of that guest.

I’ve upgraded The Storage Architect lab servers to R2 SP1 and have been looking at how Dynamic Memory operates.  There are links at the end of this post that provide the official line, but I’ll be discussing my findings and thoughts here first.

Why Is Dynamic Memory needed?

Virtualisation is all about sharing resources – CPU, memory, disk space and so on, in a way that enables those resources to be used more efficiently.  When Windows servers were using 25% or less of their CPU capacity, there was an opportunity to make use of that wasted resource by stacking multiple Windows onto the same hardware using a hypervisor like VMware or Hyper-V.  The virtualisation approach is more suitable to Windows as the O/S doesn’t play well with multiple application installations in one Windows instance.  In addition, for maintenance and other management reasons, it may not be appropriate for multiple business applications to share the same server.

Sharing processor time is relatively easy and is already built into all operating systems that run multiple tasks – so pretty much everything since DOS days has been able to “timeslice”.  Memory however is a little more problematic.  All operating systems (bar a few like z/OS) assume that the memory they detect at boot time is there forever (or at least until the O/S shuts down).  This is a pretty reasonable assumption as hot plugging memory is something I don’t see most server hardware having; the cost of implementing electrical isolation on the motherboard slots doesn’t really justify the cost.

However memory is inevitably overallocated to hosts on their initial creation, even if it is subsequently fully utilised at some stage in the future.  Memory is also the main resource that virtualisation platforms never have enough of, so it makes sense to be able to be more efficient with its use.  Dynamic Memory for Hyper-V enables a host to manage the memory provided to the guests in a more efficient manner by dynamically increasing and decreasing the memory available to each guest.  However there are some caveats:

  • The new feature requires the installation of SP1 on Windows Server 2008 R2 running Hyper-V (or Windows Hyper-V Server R2)
  • Dynamic memory is only supported on Windows 7, Windows Server 2008 with SP2, Windows Server 2008 R2, Windows Vista with SP1, Windows Server 2003 R2 with SP2 and Windows Server 2003 with SP2 along with either SP1 for that platform or the SP1 version of the integration services.  See here for the specific details.
  • Non-supported platforms will continue to use their full allocation of memory.

Integration Services is required on the guest O/S to fix the problem of notifying the O/S that the physical memory allocation has changed.  It looks like for Windows 7 and Windows Server 2008 SP2 that Service Pack 1 onwards effectively provides this capability and should be included in all future releases (although Microsoft would have to confirm that).

As you can imagine, adding and removing what appears to be physical memory isn’t a trivial task.  Remember that as far as the O/S is concerned, the memory it has access to is real physical memory.  Adding memory is no problem; the amount of apparent physical memory is simply increased.  However when taking memory back, the hypervisor needs to be aware that the memory slot may be in use.  In order to take it back from the guest O/S, the memory page would need to be released by paging the contents to disk or another memory page.  I don’t know the specifics of how Hyper-V performs dynamic memory management, but common sense would say that the pages to be retrieved should be the ones not in use by the guest.  Depending on how Windows views physical memory, it may not be possible to remove a non-sequential memory slot; there may be a requirement to remove memory from the end of the address space; it all depends on how Windows memory management algorithms work.  This is something I’ll speculate on after presenting the performance testing results.

Configuration

Dynamic Memory is specified using new options in guest Settings.  See the first screenshot.  Either Static or Dynamic is selected; for Static, a fixed amount of memory is selected; for Dynamic a Startup and Maximum figure is specified. A third parameter, Memory Buffer also needs to be set.  This represents an amount of memory Hyper-V attempts to reserve in addition to the in-use memory; so, if 1000MB have been assigned to a guest and the buffer is 20%, an additional 200MB is reserved.  There’s also an option to weight each guest in terms of priority; so less important virtual machines could be given lower priority when memory is low.

Testing Testing

The second screenshot shows my test environment.  This is a Hyper-V server with 8GB of RAM.  Initially memory is assigned to a number of Windows servers and two non-Windows servers; Memory Demand and Memory Status is shown for those guests running Integration Services.  Running the following command against one of the guests shows that the physical memory assumed by the guest is the initial value, in this case 512MB (screenshot 3).

get-wmiobject Win32_PhysicalMemory -computername hv41-win7-x64

This sort of makes sense, in that the physical memory slots seen at boot time is the value representing startup memory and so this value is also the minimum that the guest can have.  However as I found when testing, the reported memory assigned to a guest increases but never decreases.

To track memory usage, I wrote a small Powershell script that extracts the host and guest memory usage, displaying the results every 10 seconds.  The output is shown in the graph screenshot.  From a starting position of 512MB on the guest, I increased memory demand by starting Internet Explorer multiple times.  This increased memory figures for Guest Used and Physical.  It also increased the memory in use by the Host, all in step with each other.  Around 4 minutes into the test I started other guests on the host.  This immediately increased the Host Used memory sharply and as the Host became under pressure with memory, it caused the Guest’s assigned memory to drop to the bare minimum i.e. what was actually in use.  Once I relieved the pressure (around 9 minutes in) then started to close IE on the Guest, the memory figures returned to levels seen before the test.  There are some interesting pieces of information here:

  • The Guest Physical MB figure increased from the base 512MB to towards the maximum assigned (in this case 1024MB).  Even when memory demand in the guest drops, this figure never reduces and is always a high watermark.  There could be a temptation to set the Maximum memory for each guest very high.  I can’t imagine this being wise as increased demand would start paging at the Hyper-V level, impacting all guests.
  • At one stage I appeared to have more memory in use than Assigned (around 8 minutes in).  I’m not sure how this could happen, other than for Hyper-V to be paging some of the active guest memory to disk.

Memory usage within Windows was never clear in the first place; Dynamic  Memory just makes things more complex; correctly determining memory usage will require information from both the hypervisor and the guest.  I’m hoping to develop a tool that will make the process of understanding the configuration an easier one.  In the meantime I’d be interested in feedback on how other people have tested this new feature.

About Chris M Evans

Chris M Evans has worked in the technology industry since 1987, starting as a systems programmer on the IBM mainframe platform, while retaining an interest in storage. After working abroad, he co-founded an Internet-based music distribution company during the .com era, returning to consultancy in the new millennium. In 2009 Chris co-founded Langton Blue Ltd (www.langtonblue.com), a boutique consultancy firm focused on delivering business benefit through efficient technology deployments. Chris writes a popular blog at http://blog.architecting.it, attends many conferences and invitation-only events and can be found providing regular industry contributions through Twitter (@chrismevans) and other social media outlets.
0 Flares Twitter 0 Facebook 0 Google+ 0 StumbleUpon 0 Buffer 0 LinkedIn 0 Filament.io 0 Flares ×