Using the vSphere Client you can view information about and make changes to memory allocation settings. To administer your memory resources effectively, you must also be familiar with memory overhead, idle memory tax, and how ESXi hosts reclaim memory.
When administering memory resources, you can specify memory allocation. If you do not customize memory allocation, the ESXi host uses defaults that work well in most situations.
You can specify memory allocation in several ways.
- Use the attributes and special features available through the vSphere Client. The vSphere Client allows you to connect to the ESXi host or vCenter Server system.
- Use advanced settings.
- Use the vSphere SDK for scripted memory allocation.
Understanding Memory Overhead
Virtualization of memory resources has some associated overhead.
ESXi virtual machines can incur two kinds of memory overhead.
- The additional time to access memory within a virtual machine.
- The extra space needed by the ESXi host for its own code and data structures, beyond the memory allocated to each virtual machine.
ESXi memory virtualization adds little time overhead to memory accesses. Because the processor's paging hardware uses page tables (shadow page tables for software-based approach or two level page tables for hardware-assisted approach) directly, most memory accesses in the virtual machine can execute without address translation overhead.
The memory space overhead has two components.
- A fixed, system-wide overhead for the VMkernel.
- Additional overhead for each virtual machine.
Overhead memory includes space reserved for the virtual machine frame buffer and various virtualization data structures, such as shadow page tables. Overhead memory depends on the number of virtual CPUs and the configured memory for the guest operating system.
Overhead Memory on Virtual Machines
Virtual machines require a certain amount of available overhead memory to power on. You should be aware of the amount of this overhead.
The amount of overhead memory needed for a virtual machine depends on a large number of factors, including the number of vCPUs and memory size, the number and types of devices, the execution mode that the monitor is using and the hardware version of the virtual machine. The version of vSphere you are using can also effect the amount of memory needed. VMX automatically calculates the amount of overhead memory needed for a virtual machine.
In order to find out how much overhead memory is needed for your specific configuration, first power on the virtual machine in question. Look in the vmware.log file. When the virtual machine powers on, the amount of overhead memory it needs is printed to the log. Search within the log for VMMEM to see the initial and precise amount of overhead memory reserved for the virtual machine.
How ESXi Hosts Allocate Memory
A host allocates the memory specified by the Limit parameter to each virtual machine, unless memory is overcommitted. ESXi never allocates more memory to a virtual machine than its specified physical memory size.
For example, a 1GB virtual machine might have the default limit (unlimited) or a user-specified limit (for example 2GB). In both cases, the ESXi host never allocates more than 1GB, the physical memory size that was specified for it.
When memory is overcommitted, each virtual machine is allocated an amount of memory somewhere between what is specified by Reservation and what is specified by Limit. The amount of memory granted to a virtual machine above its reservation usually varies with the current memory load.
A host determines allocations for each virtual machine based on the number of shares allocated to it and an estimate of its recent working set size.
- Shares — ESXi hosts use a modified proportional-share memory allocation policy. Memory shares entitle a virtual machine to a fraction of available physical memory.
- Working set size — ESXi hosts estimate the working set for a virtual machine by monitoring memory activity over successive periods of virtual machine execution time. Estimates are smoothed over several time periods using techniques that respond rapidly to increases in working set size and more slowly to decreases in working set size.
This approach ensures that a virtual machine from which idle memory is reclaimed can ramp up quickly to its full share-based allocation when it starts using its memory more actively.
Memory activity is monitored to estimate the working set sizes for a default period of 60 seconds. To modify this default , adjust the Mem.SamplePeriod advanced setting. See Set Advanced Host Attributes.
Memory Tax for Idle Virtual Machines
If a virtual machine is not actively using all of its currently allocated memory, ESXi charges more for idle memory than for memory that is in use. This is done to help prevent virtual machines from hoarding idle memory.
The idle memory tax is applied in a progressive fashion. The effective tax rate increases as the ratio of idle memory to active memory for the virtual machine rises. (In earlier versions of ESXi that did not support hierarchical resource pools, all idle memory for a virtual machine was taxed equally.)
You can modify the idle memory tax rate with the Mem.IdleTax option. Use this option, together with the Mem.SamplePeriod advanced attribute, to control how the system determines target memory allocations for virtual machines. See Set Advanced Host Attributes.
VMX Swap Files
Virtual machine executable (VMX) swap files allow the host to greatly reduce the amount of overhead memory reserved for the VMX process.
ESXi reserves memory per virtual machine for a variety of purposes. Memory for the needs of certain components, such as the virtual machine monitor (VMM) and virtual devices, is fully reserved when a virtual machine is powered on. However, some of the overhead memory that is reserved for the VMX process can be swapped. The VMX swap feature reduces the VMX memory reservation significantly (for example, from about 50MB or more per virtual machine to about 10MB per virtual machine). This allows the remaining memory to be swapped out when host memory is overcommitted, reducing overhead memory reservation for each virtual machine.
The host creates VMX swap files automatically, provided there is sufficient free disk space at the time a virtual machine is powered on.
Memory Reclamation
ESXi hosts can reclaim memory from virtual machines.
A host allocates the amount of memory specified by a reservation directly to a virtual machine. Anything beyond the reservation is allocated using the host’s physical resources or, when physical resources are not available, handled using special techniques such as ballooning or swapping. Hosts can use two techniques for dynamically expanding or contracting the amount of memory allocated to virtual machines.
- ESXi systems use a memory balloon driver (
vmmemctl
), loaded into the guest operating system running in a virtual machine. See Memory Balloon Driver. - ESXi system swaps out a page from a virtual machine to a server swap file without any involvement by the guest operating system. Each virtual machine has its own swap file.
Memory Balloon Driver
The memory balloon driver (vmmemctl
) collaborates with the server to reclaim pages that are considered least valuable by the guest operating system.
The driver uses a proprietary ballooning technique that provides predictable performance that closely matches the behavior of a native system under similar memory constraints. This technique increases or decreases memory pressure on the guest operating system, causing the guest to use its own native memory management algorithms. When memory is tight, the guest operating system determines which pages to reclaim and, if necessary, swaps them to its own virtual disk.
If necessary, you can limit the amount of memory vmmemctl
reclaims by setting the sched.mem.maxmemctl parameter for a specific virtual machine. This option specifies the maximum amount of memory that can be reclaimed from a virtual machine in megabytes (MB). See Set Advanced Virtual Machine Attributes.
Sharing Memory Across Virtual Machines
Many ESXi workloads present opportunities for sharing memory across virtual machines (as well as within a single virtual machine).
ESXi memory sharing runs as a background activity that scans for sharing opportunities over time. The amount of memory saved varies over time. For a fairly constant workload, the amount generally increases slowly until all sharing opportunities are exploited.
To determine the effectiveness of memory sharing for a given workload, try running the workload, and use resxtop
or esxtop
to observe the actual savings. Find the information in the PSHARE
field of the interactive mode in the Memory page.
Use the Mem.ShareScanTime and Mem.ShareScanGHz advanced settings to control the rate at which the system scans memory to identify opportunities for sharing memory.
You can also configure sharing for individual virtual machines by setting the sched.mem.pshare.enable option.
Due to security concerns, inter-virtual machine transparent page sharing is deactivated by default and page sharing is being restricted to intra-virtual machine memory sharing. This means page sharing does not occur across virtual machines and only occurs inside of a virtual machine. The concept of salting has been introduced to help address concerns system administrators may have over the security implications of transparent page sharing. Salting can be used to allow more granular management of the virtual machines participating in transparent page sharing than was previously possible. With the new salting settings, virtual machines can share pages only if the salt value and contents of the pages are identical. A new host config option Mem.ShareForceSalting can be configured to activate or deactivate salting.
See Advanced Attributes in vSphere for information on how to set advanced options.
Memory Compression
ESXi provides a memory compression cache to improve virtual machine performance when you use memory overcommitment. Memory compression is activated by default. When a host's memory becomes overcommitted, ESXi compresses virtual pages and stores them in memory.
Because accessing compressed memory is faster than accessing memory that is swapped to disk, memory compression in ESXi allows you to overcommit memory without significantly hindering performance. When a virtual page needs to be swapped, ESXi first attempts to compress the page. Pages that can be compressed to 2 KB or smaller are stored in the virtual machine's compression cache, increasing the capacity of the host.
You can set the maximum size for the compression cache and deactivate memory compression using the Advanced Settings dialog box in the vSphere Client.
Activate or Deactivate the Memory Compression Cache
Memory compression is activated by default. You can use Advanced System Settings in the vSphere Client to activate or deactivate memory compression for a host.
Procedure
- Browse to the host in the vSphere Client.
- Click Configure.
- Under System, select Advanced System Settings.
- Locate Mem.MemZipEnable and click the Edit button.
- Enter 1 to activate or enter 0 to deactivate the memory compression cache.
- Click OK.
Set the Maximum Size of the Memory Compression Cache
You can set the maximum size of the memory compression cache for the host's virtual machines.
You set the size of the compression cache as a percentage of the memory size of the virtual machine. For example, if you enter 20 and a virtual machine's memory size is 1000 MB, ESXi can use up to 200MB of host memory to store the compressed pages of the virtual machine.
If you do not set the size of the compression cache, ESXi uses the default value of 10 percent.
Procedure
Measuring and Differentiating Types of Memory Usage
The Performance tab of the vSphere Client displays several metrics that can be used to analyze memory usage.
Some of these memory metrics measure guest physical memory while other metrics measure machine memory. For instance, two types of memory usage that you can examine using performance metrics are guest physical memory and machine memory. You measure guest physical memory using the Memory Granted metric (for a virtual machine) or Memory Shared (for a host). To measure machine memory, however, use Memory Consumed (for a virtual machine) or Memory Shared Common (for a host). Understanding the conceptual difference between these types of memory usage is important for knowing what these metrics are measuring and how to interpret them.
The VMkernel maps guest physical memory to machine memory, but they are not always mapped one-to-one. Multiple regions of guest physical memory might be mapped to the same region of machine memory (when memory sharing) or specific regions of guest physical memory might not be mapped to machine memory (when the VMkernel swaps out or balloons guest physical memory). In these situations, calculations of guest physical memory usage and machine memory usage for an individual virtual machine or a host differ.
Consider the example in the following figure, which shows two virtual machines running on a host. Each block represents 4 KB of memory and each color/letter represents a different set of data on a block.
The performance metrics for the virtual machines can be determined as follows:
- To determine Memory Granted (the amount of guest physical memory that is mapped to machine memory) for virtual machine 1, count the number of blocks in virtual machine 1's guest physical memory that have arrows to machine memory and multiply by 4 KB. Since there are five blocks with arrows, Memory Granted is 20 KB.
- Memory Consumed is the amount of machine memory allocated to the virtual machine, accounting for savings from shared memory. First, count the number of blocks in machine memory that have arrows from virtual machine 1's guest physical memory. There are three such blocks, but one block is shared with virtual machine 2. So count two full blocks plus half of the third and multiply by 4 KB for a total of 10 KB Memory Consumed.
- Memory Shared for the host is the sum of each virtual machine's Memory Shared. Calculate shared memory by looking at each virtual machine's guest physical memory and counting the number of blocks that have arrows to machine memory blocks that themselves have more than one arrow pointing at them. There are six such blocks in the example, so Memory Shared for the host is 24 KB.
- Memory Shared Common is the amount of machine memory shared by virtual machines. To determine common memory, look at the machine memory and count the number of blocks that have more than one arrow pointing at them. There are three such blocks, so Memory Shared Common is 12 KB.
The memory metrics that measure guest physical memory and machine memory might appear contradictory. In fact, they are measuring different aspects of a virtual machine's memory usage. By understanding the differences between these metrics, you can better use them to diagnose performance issues.
Memory Reliability
Memory reliability, also known as error isolation, allows ESXi to stop using parts of memory when it determines that a failure might occur, as well as when a failure did occur.
When enough corrected errors are reported at a particular address, ESXi stops using this address to prevent the corrected error from becoming an uncorrected error.
Memory reliability provides better VMkernel reliability despite corrected and uncorrected errors in RAM. It also enables the system to avoid using memory pages that might contain errors.
Correcting an Error Isolation Notification
With memory reliability, VMkernel stops using pages that receive an error isolation notification.
The user receives an event in the vSphere Client when VMkernel recovers from an uncorrectable memory error, when VMkernel retires a significant percentage of system memory due to a large number of correctable errors, or if there are a large number of pages that are unable to retire.
Procedure
- Vacate the host.
- Migrate the virtual machines.
- Run memory related hardware tests.
System Swap
System swap is a memory reclamation process that can take advantage of unused memory resources across an entire system.
System swap allows the system to reclaim memory from memory consumers that are not virtual machines. When system swap is enabled you have a tradeoff between the impact of reclaiming the memory from another process and the ability to assign the memory to a virtual machine that can use it. The amount of space required for the system swap is 1GB.
Memory is reclaimed by taking data out of memory and writing it to background storage. Accessing the data from background storage is slower than accessing data from memory, so it is important to carefully select where to store the swapped data.
ESXi determines automatically where the system swap should be stored, this is the Preferred swap file location. This decision can be aided by selecting a certain set of options. The system selects the best possible enabled option. If none of the options are feasible then system swap is not activated.
The available options are:
- Datastore - Allow the use of the datastore specified. Please note that a vSAN datastore or a VMware vSphere® Virtual VolumesTM datastore cannot be specified for system swap files.
- Host Swap Cache - Allow the use of part of the host swap cache.
- Preferred swap file location - Allow the use of the preferred swap file location configured for the host.
Configure System Swap
You can customize the options that determine the system swap location.
Prerequisites
Select the Enabled check box in the Edit System Swap Settings dialog box.
Procedure
- Browse to the host in the vSphere Client.
- Click Configure.
- Under System, select System Swap.
- Click Edit.
- Select the check boxes for each option that you want to enable.
- If you select the datastore option, select a datastore from the drop-down menu.
- Click OK.