Skip to content

A comprehensive optimization tool specifically designed for Linux virtual machines running on Proxmox VE. This tool automatically detects your system configuration and applies optimal settings for memory management, disk I/O, network performance, and Proxmox-specific features.

License

Notifications You must be signed in to change notification settings

dtouzeau/proxmox-optimizer

Repository files navigation

Proxmox VM Optimizer

A comprehensive optimization tool specifically designed for Linux virtual machines running on Proxmox VE. This tool automatically detects your system configuration and applies optimal settings for memory management, disk I/O, network performance, and Proxmox-specific features.

Author: David Touzeau [email protected] License: MIT Language: Go 1.21+

Features

  • Memory Optimization

    • Dynamic swappiness adjustment based on available RAM
    • Cache pressure tuning
    • Transparent hugepages configuration
    • Dirty page ratio optimization
    • Optional cache dropping for cleanup
  • Disk I/O Optimization

    • Automatic SSD/HDD detection
    • Optimal I/O scheduler selection (none/mq-deadline for SSD, mq-deadline/bfq for HDD)
    • Read-ahead buffer tuning
    • I/O queue depth optimization
    • Persistent udev rules creation
  • Network Performance

    • TCP buffer size optimization
    • BBR/CUBIC congestion control
    • TCP Fast Open enablement
    • Connection tracking optimization
    • IPv6 optimizations
  • Proxmox VM Specific

    • QEMU Guest Agent installation and configuration
    • VirtIO driver optimization (multi-queue support)
    • VirtIO balloon driver support
    • Hardware RNG optimization
    • CPU governor tuning
    • Unnecessary service disabling
  • Safety Features

    • Automatic backup before changes
    • Full rollback capability
    • Dry-run mode
    • Persistent configuration across reboots

Installation

Prerequisites

  • Go 1.21 or higher
  • Root/sudo access
  • Linux kernel 4.0+ (recommended 5.0+)
  • Running on a Proxmox VM (for VM-specific optimizations)

Build

cd proxmox-optimizer
go mod init proxmox-optimizer
go mod tidy
go build -ldflags="-s -w" -o proxmox-optimizer

Install System-wide

sudo cp proxmox-optimizer /usr/local/bin/
sudo chmod +x /usr/local/bin/proxmox-optimizer

Usage

Basic Usage

Show system information:

sudo proxmox-optimizer -info

Apply all optimizations with automatic backup:

sudo proxmox-optimizer

Dry-run to see what would be changed:

sudo proxmox-optimizer -dry-run

Optimization Profiles

Apply specific optimization categories:

# Memory optimizations only
sudo proxmox-optimizer -optimize memory

# Disk I/O optimizations only
sudo proxmox-optimizer -optimize disk

# Network optimizations only
sudo proxmox-optimizer -optimize network

# Proxmox VM specific optimizations only
sudo proxmox-optimizer -optimize proxmox

# All optimizations (default)
sudo proxmox-optimizer -optimize all

Aggressive Mode

For high-performance systems (use with caution):

sudo proxmox-optimizer -aggressive

Aggressive mode applies:

  • Swappiness = 1 (minimal swapping)
  • Smaller dirty page ratios
  • BBR congestion control
  • Performance CPU governor
  • Cache dropping
  • Higher buffer sizes

Configuration File

Generate a sample configuration:

proxmox-optimizer -generate-config > optimizer-config.json

Use custom configuration:

sudo proxmox-optimizer -config optimizer-config.json

Example configuration file:

{
  "memory": {
    "swappiness": 10,
    "cache_pressure": 100,
    "dirty_ratio": 15,
    "dirty_background_ratio": 10,
    "enable_hugepages": true,
    "drop_caches": false
  },
  "disk": {
    "ssd_scheduler": "mq-deadline",
    "hdd_scheduler": "mq-deadline",
    "readahead_ssd": 256,
    "readahead_hdd": 2048,
    "nr_requests": 128,
    "enable_write_cache": false
  },
  "network": {
    "rmem_max": 16777216,
    "wmem_max": 16777216,
    "tcp_mem_min": 4096,
    "tcp_mem_default": 87380,
    "tcp_mem_max": 16777216,
    "congestion_control": "cubic",
    "netdev_max_backlog": 2000,
    "somaxconn": 1024,
    "enable_ipv6": true
  },
  "proxmox": {
    "enable_guest_agent": true,
    "optimize_virtio": true,
    "enable_balloon": true,
    "optimize_rng": true,
    "enable_timesync": true,
    "disable_unnecessary_services": false,
    "cpu_governor": "ondemand"
  }
}

Backup and Restore

Create backup without applying changes:

sudo proxmox-optimizer -backup -dry-run

Disable automatic backup:

sudo proxmox-optimizer -backup=false

Restore from backup:

sudo proxmox-optimizer -restore /var/backups/proxmox-optimizer/backup-20250114-120000.tar.gz

List available backups:

ls -lh /var/backups/proxmox-optimizer/

What Gets Optimized

Sysctl Parameters

The tool modifies the following kernel parameters:

Memory:

  • vm.swappiness - Controls swap usage preference
  • vm.vfs_cache_pressure - Inode/dentry cache reclaim pressure
  • vm.dirty_ratio - Percentage of RAM that can be filled with dirty pages
  • vm.dirty_background_ratio - Background writeback threshold
  • vm.min_free_kbytes - Minimum free memory reserved
  • vm.page-cluster - Swap readahead pages (0 for SSD)

Network:

  • net.core.rmem_max / net.core.wmem_max - Maximum socket buffer sizes
  • net.ipv4.tcp_rmem / net.ipv4.tcp_wmem - TCP buffer sizes
  • net.ipv4.tcp_mem - TCP memory allocation
  • net.ipv4.tcp_congestion_control - Congestion control algorithm
  • net.core.netdev_max_backlog - Network device backlog
  • net.core.somaxconn - Socket listen backlog
  • net.ipv4.tcp_fastopen - TCP Fast Open
  • net.ipv4.tcp_mtu_probing - Path MTU discovery
  • Many more TCP/IP optimizations...

Disk Settings

Per-device optimizations:

  • I/O scheduler (/sys/block/*/queue/scheduler)
  • Read-ahead buffer (/sys/block/*/queue/read_ahead_kb)
  • I/O queue depth (/sys/block/*/queue/nr_requests)
  • Write cache settings (/sys/block/*/queue/write_cache)
  • Entropy collection (/sys/block/*/queue/add_random)

Persistent rules:

  • Udev rules created at /etc/udev/rules.d/60-proxmox-optimizer-disk.rules

System Services

Installed/Enabled:

  • qemu-guest-agent - Communication with Proxmox host
  • rng-tools - Hardware RNG utilization
  • systemd-timesyncd - Time synchronization

Potentially Disabled (in aggressive mode):

  • bluetooth.service
  • ModemManager.service
  • avahi-daemon.service
  • cups.service

Verification

Check applied settings:

# Check sysctl values
sysctl vm.swappiness
sysctl net.ipv4.tcp_congestion_control

# Check disk scheduler
cat /sys/block/sda/queue/scheduler

# Check QEMU guest agent
systemctl status qemu-guest-agent

# View all custom settings
cat /etc/sysctl.d/99-proxmox-optimizer.conf

Performance Testing

Before and after benchmarks:

# Disk I/O
sudo fio --name=randread --ioengine=libaio --iodepth=16 --rw=randread --bs=4k --direct=1 --size=1G --numjobs=4 --runtime=60 --group_reporting

# Network throughput
iperf3 -c <server-ip>

# Memory bandwidth
sysbench memory run

Compatibility

Tested on:

  • Debian 11/12
  • Ubuntu 20.04/22.04/24.04
  • Proxmox VE 7.x/8.x guests
  • Kernel 5.4+

Should work on any systemd-based Linux distribution.

Safety & Warnings

  • Always test in a development environment first
  • Backups are created automatically at /var/backups/proxmox-optimizer/
  • Aggressive mode may cause issues on systems with limited resources
  • Some optimizations require reboot to take full effect
  • BBR congestion control requires kernel module support

Troubleshooting

BBR not available

# Check if BBR module is available
modprobe tcp_bbr
lsmod | grep bbr

# If not available, use cubic (default)

Permission denied errors

# Ensure you're running as root
sudo proxmox-optimizer -info

Changes not persisting after reboot

# Verify sysctl config
cat /etc/sysctl.d/99-proxmox-optimizer.conf

# Manually reload
sudo sysctl --system

Udev rules not applying

# Reload udev
sudo udevadm control --reload-rules
sudo udevadm trigger

Uninstall

Remove all optimizations:

# Restore from latest backup
LATEST_BACKUP=$(ls -t /var/backups/proxmox-optimizer/backup-*.tar.gz | head -1)
sudo proxmox-optimizer -restore "$LATEST_BACKUP"

# Or manually remove
sudo rm /etc/sysctl.d/99-proxmox-optimizer.conf
sudo rm /etc/udev/rules.d/60-proxmox-optimizer-disk.rules
sudo sysctl --system
sudo udevadm control --reload-rules && sudo udevadm trigger

Contributing

This tool is part of a larger system optimization toolkit. Improvements welcome!

License

MIT License - See LICENSE file for details

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Author

David Touzeau [email protected]

Created for optimizing Proxmox VE virtual machines in production environments.

See Also

About

A comprehensive optimization tool specifically designed for Linux virtual machines running on Proxmox VE. This tool automatically detects your system configuration and applies optimal settings for memory management, disk I/O, network performance, and Proxmox-specific features.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published