10 VMware Memory Allocation Best Practices

If you're running VMware, you need to know these 10 best practices for memory allocation.

Memory is one of the most important resources in a virtualized environment. Allocating memory properly can help improve performance and prevent resource contention.

In this article, we will discuss 10 best practices for allocating memory in a VMware environment. By following these best practices, you can help ensure that your environment is running optimally.

1. Configure the memory reservation for each virtual machine

When you set a memory reservation, VMware ensures that the virtual machine will always have access to that amount of memory, even if the host is under heavy load. This can help prevent performance issues caused by memory contention.

It’s important to note that you should only set a memory reservation if you’re confident that the virtual machine will actually need that much memory. If you set a reservation that’s too high, it could lead to wasted resources.

To set a memory reservation, open the vSphere Client and navigate to the Configure tab for the relevant virtual machine. Under Hardware, select Memory. In the right-hand pane, click Edit… next to Reservation. Enter the desired amount of memory and click OK.

2. Use Memory Shares to set relative importance of VMs

If you have two VMs, and one is set to use 50% of the available memory while the other is set to use 100% of the available memory, what happens when both VMs are active and need to use more than 50% of the available memory?

The answer is that the VM with the higher shares setting will get priority access to memory, and the VM with the lower shares setting will be forced to wait. This can lead to performance problems for the VM with the lower shares setting, so it’s important to use shares wisely.

One way to think about shares is in terms of how important a VM is to your business. If a VM is mission-critical, you’ll want to give it a high shares setting so that it gets priority access to memory. On the other hand, if a VM is less important, you can give it a lower shares setting.

3. Monitor memory usage on ESXi hosts and in vCenter Server

If you’re not monitoring memory usage, you won’t be able to tell when a host or cluster is running low on memory. This can lead to performance problems for virtual machines (VMs) that are running on the host or in the cluster.

To avoid this, make sure you’re monitoring memory usage using vCenter Server’s performance charts. You should also set up alarms so that you’re notified if memory usage exceeds a certain threshold.

4. Ensure that swap files are located on a high-performance datastore

When a virtual machine is powered on, the VMware hypervisor allocates a certain amount of memory to the VM. This is the “active” or “working set” of memory that the VM uses for its operations.

However, the working set is not always static. As the VM runs programs and processes, it may need more memory than what was initially allocated. When this happens, the hypervisor will start using disk space to store the extra memory needed by the VM, in the form of a swap file.

The problem is that accessing disk storage is much slower than accessing RAM, so having to constantly read and write to the swap file can severely impact performance. That’s why it’s important to ensure that the swap file is located on a high-performance datastore, such as an SSD or NVMe drive.

5. Set up alarms to monitor memory usage

If you’re not monitoring your memory usage, you could be in for a nasty surprise when your system runs out of memory and starts to swap. Swapping is when the system starts to write memory pages to disk instead of keeping them in RAM, and it’s a sure sign that you’re overcommitting your memory.

To avoid this, set up alarms that trigger when your memory usage reaches a certain threshold. That way, you can take action to increase your memory allocation before things start to get slow.

6. Use VMware Tools ballooning to reclaim unused VM memory

When a VM is running low on memory, the VMware Tools balloon driver can be used to reclaim some of the unused memory from the VM. The balloon driver runs inside the guest OS and allocates a portion of the VM’s memory for itself, which effectively reduces the amount of memory available to the guest OS.

This process is known as “ballooning” and it’s a great way to reclaim memory that would otherwise go unused. It’s also important to note that ballooning is a completely safe process that doesn’t impact the stability or performance of the VM.

7. Overcommit memory using transparent page sharing (TPS)

TPS is a memory management technique that allows the physical memory of a system to be used more efficiently by sharing common pages of memory among virtual machines. When TPS is enabled, VMware ESXi will periodically scan the memory of running virtual machines and look for pages of identical content. When it finds pages with identical content, it will replace those pages with pointers to a single copy of the page, which is stored in physical memory.

The net result is that you can run more virtual machines on a given amount of physical memory because the memory is being used more efficiently. In addition, because TPS reduces the amount of physical memory that is used by virtual machines, it can also help reduce power consumption and improve performance by reducing contention for physical memory.

To enable TPS, go to the Configure tab of the vSphere Client, select Memory, and check the Enable Transparent Page Sharing box.

8. Disable TPS when running applications with large amounts of duplicate data

TPS (Transparent Page Sharing) is a memory optimization feature in VMware that allows the hypervisor to share identical memory pages between virtual machines. This can be beneficial in some cases, but for applications with large amounts of duplicate data, it can actually lead to decreased performance.

When TPS is enabled, the hypervisor needs to spend extra time scanning for duplicate memory pages, which can add up and lead to increased CPU utilization. In addition, when TPS is enabled, the guest operating system will also need to spend extra time managing the shared memory pages, which can also lead to decreased performance.

For these reasons, it’s generally best to disable TPS when running applications with large amounts of duplicate data. You can do this by setting the “Mem.ShareForceSalting” option to “1” in the VM’s configuration file.

9. Enable hyperthreading

Hyperthreading is a process that allows a single physical processor to appear as two logical processors to the operating system. This means that two threads can be executed simultaneously on a single core, which can improve performance by up to 30%.

While hyperthreading can improve performance, it can also increase the risk of resource contention and reduce overall stability. Therefore, it’s important to carefully consider whether or not to enable hyperthreading on your VMware servers.

If you do decide to enable hyperthreading, make sure to monitor your server closely for any signs of instability.

10. Enable CPU hot add

CPU hot add allows you to add vCPUs to a running virtual machine without having to power it down first. This is useful if you need to increase the number of vCPUs available to a VM but can’t afford to have it down for even a few minutes.

To enable CPU hot add, go to the VM’s settings in the vSphere Client and select the “Options” tab. Then, expand the “Advanced” section and check the “Enable CPU Hot Add” box.


10 Terraform File Structure Best Practices

Back to Insights

10 AWS Secrets Manager Best Practices