When configuring Linux virtual machines on VMware ESX/ESXi hosts, administrators often debate whether to allocate swap space within the guest OS or rely on hypervisor-level memory management. Let's examine the technical implications of both approaches through concrete examples.
Consider these two test scenarios:
# Scenario 1: Guest with swap partition
VM Configuration:
- 1GB RAM allocation
- 1GB swap partition
- Application consumes 1.5GB memory
# Scenario 2: Guest without swap
VM Configuration:
- 1GB RAM allocation
- No swap partition
- Application consumes 1.5GB memory
From a storage I/O perspective:
- Guest swap partition: Uses the VM's virtual disk (VMDK) for swapping operations
- Hypervisor swapping: Leverages the ESX host's swap file (typically on VMFS datastore)
Performance metrics show:
# Sample performance comparison (lower is better)
+---------------------+---------------+---------------+
| Metric | Guest Swap | Hypervisor |
+---------------------+---------------+---------------+
| Swap latency (ms) | 12.4 | 8.7 |
| Throughput (MB/s) | 87 | 120 |
| CPU overhead (%) | 15 | 9 |
+---------------------+---------------+---------------+
The Linux kernel's swappiness parameter (vm.swappiness) behaves differently:
# Current swappiness value
cat /proc/sys/vm/swappiness
# Recommended settings:
# With guest swap: vm.swappiness = 60 (default)
# Without guest swap: vm.swappiness = 10
Based on real-world testing:
- For performance-critical VMs: Disable guest swap and increase allocated RAM
- For memory-constrained environments: Use a minimal swap partition (25% of RAM)
- For predictable workloads: Configure memory reservations in ESX
Here's how to properly configure a CentOS VM without swap:
# Remove existing swap
swapoff -a
sed -i '/swap/d' /etc/fstab
# Adjust kernel parameters
echo "vm.swappiness = 10" >> /etc/sysctl.conf
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p
# Verify settings
grep -i swappiness /proc/sys/vm/
Key ESX metrics to watch:
# ESX CLI commands for memory monitoring
esxtop (then press 'm' for memory view)
esxcli system vm process list --mem-usage
vim-cmd hostsvc/hosthardware | grep memory
When configuring Linux VMs on VMware ESXi, administrators face a fundamental choice: whether to allocate a swap partition within the guest OS or rely solely on VMware's memory management. Both approaches involve swapping, but at different architectural layers:
# Scenario 1: Guest-level swap (traditional approach)
/dev/sda1 / ext4 defaults 0 1
/dev/sda2 swap swap defaults 0 0
# Scenario 2: No guest swap (VMware-managed)
/dev/sda1 / ext4 defaults 0 1
The memory hierarchy operates differently in each case:
Configuration | Memory Path | Latency Profile |
---|---|---|
Guest swap partition | App → Guest kernel → Virtual disk → VMFS → Storage | Higher (double virtualization) |
VMware host swap | App → ESXi hypervisor → VMFS → Storage | Lower (single virtualization) |
Modern Linux kernels (4.0+) implement these memory management behaviors:
- Swappiness: The vm.swappiness parameter (default 60) still affects guest-level swapping even when no swap partition exists
- Balloon driver: VMware Tools includes vmmemctl which coordinates with ESXi host memory management
- Memory compression: ESXi 6.5+ implements memory compression before swapping to disk
# Check current swappiness (works with or without swap partition)
cat /proc/sys/vm/swappiness
# Temporary adjustment (root required)
sysctl vm.swappiness=10
Based on workload characteristics:
- For memory-intensive workloads:
Allocate 50-100% RAM as swap (e.g., 8GB RAM → 4-8GB swap)
- For stateless/containerized workloads:
Disable swap completely and set swappiness=0
- For general-purpose servers:
Minimum 1GB swap or 0.5×RAM (whichever is smaller)
Essential diagnostics for both approaches:
# Guest swap usage
free -h
vmstat 1 5
# ESXi host-level swap
esxtop (then press 'm' for memory view)
# Detailed memory breakdown
cat /proc/meminfo | grep -E 'Swap|Mem'