Pve Helpers Open Source Project (2024)

This repository is a set of scripts to better handle some of the Proxmox functions:

  • automatically restart VMs on host suspend,
  • allow to use CPU pinning,
  • allow to set fifo scheduler
  • allow to set affinity mask for vfio devices

Why to do CPU pinning?

  • Usually, it is not needed as long as you don't use SMT
  • If you use SMT, each vCPU is not equal, CPU pinning allows to ensure that VMs receive a real threads
  • For having a good and predictable performance it is not needed to pin to exact cores, Linux can balance it very well
  • In general the less we configure the better it works. These settings are hints to define affinity masks for resources.

Installation

Clone and compile the repository:

# install dependenciessudo apt-get install -f ruby ruby-dev rubygems build-essentialsudo gem install fpm
# compile pve-helpersgit clone https://github.com/ayufan/pve-helperscd pve-helperssudo make install

Usage

1. Enable snippet

You need to configure each machine to enable the hookscript.

The snippet by default is installed in /var/lib/vzthat for Proxmox is present as local.

qm set 204 --hookscript=local:snippets/exec-cmds

2. Configure VM

Edit VM description and add a new line if one or both these two commands.

2.1. cpu_taskset

For the best performance you want to assign VM to physical cores,not a mix of physical and virtual cores.

For example for i7-8700 each core has two threads: 0-6, 1-7, 2-8.You can easily check that with lscpu -e, checking which cores areassigned twice.

CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE MAXMHZ MINMHZ0 0 0 0 0:0:0:0 yes 4600.0000 800.00001 0 0 1 1:1:1:0 yes 4600.0000 800.00002 0 0 2 2:2:2:0 yes 4600.0000 800.00003 0 0 3 3:3:3:0 yes 4600.0000 800.00004 0 0 4 4:4:4:0 yes 4600.0000 800.00005 0 0 5 5:5:5:0 yes 4600.0000 800.00006 0 0 0 0:0:0:0 yes 4600.0000 800.00007 0 0 1 1:1:1:0 yes 4600.0000 800.00008 0 0 2 2:2:2:0 yes 4600.0000 800.00009 0 0 3 3:3:3:0 yes 4600.0000 800.000010 0 0 4 4:4:4:0 yes 4600.0000 800.000011 0 0 5 5:5:5:0 yes 4600.0000 800.0000

For example it is advised to assign a one CPU less than a number ofphysical cores. For the i7-8700 it will be 5 cores.

Then, you can assign the 5 cores (with CPU pinning, but not pinning specificthreads) to VM:

cpu_taskset 7-11

This does assign to VM second thread of physical cores 1-6. We deliberatlychoose to not assign CORE 0.

If you have two VMs concurrently running, you can assign it on one thread,second on another thread, like this:

VM 1:cpu_taskset 1-5VM 2:cpu_taskset 7-11

2.2. use vendor-reset for fixing AMD Radeon reset bug

Instead of pci_unbind and pci_rescan install DKMS module from https://github.com/gnif/vendor-reset:

apt install dkmsgit clone https://github.com/gnif/vendor-reset.git /usr/src/vendor-reset-0.1.1dkms build vendor-reset/0.1.1dkms install vendor-reset/0.1.1echo vendor-reset >> /etc/modulesmodprobe vendor-reset

2.3. set_halt_poll

This setting changes the value of the kvm parameter halt_poll_ns in /sys/module/kvm/parameters/halt_poll_nsDifferent configurations benefit from different settings. Default value is 20000. In theory, a larger value would be beneficial for the performance/latency of a VM.In practice, most Ryzen systems work best with halt_poll_ns set to 0.

Usage example:

cat /etc/pve/qemu-server/110.conf##Set halt_poll_ns#set_halt_poll 0...

2.4. assign_interrupts

assign_interrupts [--sleep=10s] [cpu cores] [--all] [interrupt name] [interrupt name...]

This setting aims to simplify the process of assigning interrupts to the correct cpu cores in order to get the best performancewhile doing a gpu/usb controller/audio controller passthrough. The goal is to have the same cores assigned to the VM using cpu_taskset,be responsible for the interrupts generated by the devices that are fully passed through to the VM.This is very important for achieving the lowest possible latency and eliminating random latency spikes inside the VM.Ideally, you would also use something like irqbalance to move all other interrupts away from the VM assigned CPU cores and onto your other hypervisor-reserved cores. Same CPU mask can be used with irqbalance to have the VM cpu cores banned from getting any other interrupts.

Note: Isolating cpu cores with isolcpus while having its own small benefits, is not required to get these latency improvements.

An optional --sleep=10s can be assigned to modifydefault 30s wait duration.

The --all can be used to automatically assign interrupts of all configured hostpci devices.

Usage example:

cat /etc/pve/qemu-server/110.conf##CPU pinning#cpu_taskset 1-5#assign_interrupts --sleep=10s 1-5 --all...

In this particular use case, all interrupts with vfio in their name are assigned to cores 4,12,5,13,6,14,7,15,2,10,3,11, which in term correspond to cores 2-7 and their SMT equivalents 10-15.In other words, cores 2,3,4,5,6,7 from an 8 core 3700x are assigned to the VM and to all of the interrupts from the GPU, the USB onboard controller, and the onboard audio controller.

2.5. qm_conflict and qm_depends

Sometimes some VMs are conflicting with each other due to dependency on the same resources,like disks, or VGA.

There are helper commands to shutdown (the qm_conflict) or start (the qm_depends)when main machine is being started.

cat /etc/pve/qemu-server/204.conf# qm_conflict 204# qm_depends 207...

This first qm_conflict will shuttdown VM with VMID 204 before starting the current one,and it will also start VMID 207, that might be a sibiling VM.

I use the qm_conflict or qm_depends to run Linux VM sometimes with VGA passthrough,sometimes as a sibiling VM without graphics cards passed, but running in a console mode.

Be careful if you use pci_unbind and pci_rebind, they should be after the qm_* commands.

2.6. pci_unbind and pci_rebind

It might be desirable to bind VGA to VM, but as soon as VM finishesunbind that and allow to use on a host.

The --all can be used to unbind all devices.

The simplest is to ensure that VGA can render output on a host beforestarting, then instruct Proxmox VE to unbind, and rebind devices:

cat /etc/pve/qemu-server/204.conf## Rebind VGA to host#pci_unbind 02 00 0#pci_unbind 02 00 1#pci_unbind --all#pci_rebind

3. Legacy features

These are features that are no really longer needed to achieve a good latency in a VM.

3.1. cpu_chrt no longer needed, outdated

Running virtualized environment always results in quite random latencydue to amount of other work being done. This is also, because Linuxhypervisor does balance all threads that has bad effects on DPCand ISR execution times. Latency in Windows VM can be measured with https://www.resplendence.com/latencymon. Ideally, we want to have the latency of < 300us.

To improve the latency you can switch to the usage of FIFO scheduler.This has a catastrophic effects to everything else that is not your VM,but this is likely acceptable for Gaming / daily use of passthrough VMs.

Configure VM description with:

cpu_chrt fifo 1

Note:It seems that if Hyper-V entitlements (they are enabled for ostype: win10) are enabled this is no longer needed.I now have amazing performance without using cpu_chrt.

3.2. pci_unbind and pci_rescan no longer needed, outdated

Just use vendor-reset.

There are multiple approaches to handle Radeon graphics cards. I did find thatto make it stable:

  1. VGA bios needs to be exported, put in /usr/share/kvm and passed as romfile of hostpci*,
  2. PCIE unbind/rescan needs to happen.

Exporting bios should happen ideally when running "natively", so with graphics card available,ideally on Windows, with GPU-Z. Once bios is exported, you should ensure that itcontains UEFI section: https://pve.proxmox.com/wiki/Pci_passthrough#How_to_known_if_card_is_UEFI_.28ovmf.29_compatible.Sometimes the bios can be found on https://www.techpowerup.com/vgabios/.Ensure that you find the exact one for you vid:pid of your graphics card.

This is how my config looks like once a bios is put in a correct place:

cat /etc/pve/qemu-server/204.conf## Fix VGA#pci_rescan#pci_unbind 02 00 0#pci_unbind 02 00 1...hookscript: local:snippets/exec-cmds...hostpci0: 02:00,pcie=1,romfile=215895.rom,x-vga=1...machine: q35...

The comment defines a commands to execute to unbind and rebind graphics card VM.

In cases where there are bugs in getting VM up, the suspend/resume cycle of Proxmoxhelps: systemctl suspend.

4. Suspend/resume

There's a set of scripts that try to perform restart of machineswhen Proxmox VE machine goes to sleep.

First, you might be interested in doing suspend on power button.Edit the /etc/systemd/logind.conf to modify:

HandlePowerKey=suspend

Then systemctl restart systemd-logind.service or reboot Proxmox VE.

After that every of your machines should restart alongside with Proxmox VEsuspend, thus be able to support restart on PCI passthrough devices,like GPU.

Ensure that each of your machines does support Qemu Guest Agent.This function will not work if you don't have Qemu Guest Agent installedand running.

5. My setup

Here's a quick rundown of my environment that I currently usewith above quirks.

5.1. Hardware

  • i7-8700
  • 48GB DDR4
  • Intel iGPU used by Proxmox VE
  • AMD RX560 2GB used by Linux VM
  • GeForce RTX 2080 Super used by Windows VM
  • Audio is being output by both VMs to the shared speakers that are connected to Motherboard audio card
  • Each VM has it's own dedicated USB controller
  • Each VM has a dedicated amount of memory using 1G hugepages
  • Each VM does not use SMT, rather it is assigned to the thread 0 (Linux) or thread 1 (Windows) of each CPU, having only 5 vCPUs available to VM

5.2. Kernel config

GRUB_CMDLINE_LINUX=""GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX pci_stub.ids=10de:1e81,10de:10f8,10de:1ad8,10de:1ad9,10de:13c2,10de:0fbb,1002:67ef,1002:aae0"GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX intel_iommu=on kvm_intel.ept=Y kvm_intel.nested=Y i915.enable_hd_vgaarb=1 pcie_acs_override=downstream vfio-pci.disable_idle_d3=1"GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX cgroup_enable=memory swapaccount=1"GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX intel_pstate=disable"GRUB_CMDLINE_LINUX="$GRUB_CMDLINE_LINUX hugepagesz=1G hugepages=42"

5.3. Linux VM

I use Linux for regular daily development work.

My Proxmox VE config looks like this:

## CPU PIN#cpu_taskset 0-5#assign_interrupts 0-5 --all### Conflict (207 shares disks, 208 shares VGA)#qm_conflict 207#qm_conflict 208agent: 1args: -audiodev id=alsa,driver=alsa,out.period-length=100000,out.frequency=48000,out.channels=2,out.try-poll=off,out.dev=swapped -soundhw hdaballoon: 0bios: ovmfboot: dcnbootdisk: scsi0cores: 5cpu: hosthookscript: local:snippets/exec-cmdshostpci0: 02:00,romfile=215895.rom,x-vga=1hostpci1: 04:00hugepages: 1024ide2: none,media=cdrommemory: 32768name: ubuntu19-vganet0: virtio=32:13:40:C7:31:4C,bridge=vmbr0numa: 1onboot: 1ostype: l26scsi0: nvme-thin:vm-206-disk-1,discard=on,iothread=1,size=200G,ssd=1scsi1: ssd:vm-206-disk-0,discard=on,iothread=1,size=100G,ssd=1scsi10: ssd:vm-206-disk-1,iothread=1,replicate=0,size=32G,ssd=1scsihw: virtio-scsi-pciserial0: socketsockets: 1usb0: host=1050:0406vga: none

5.4. Windows VM

I use Windows for Gaming. It has dedicated RTX 2080 Super.

## CPU PIN#cpu_taskset 6-11#assign_interrupts 6-11 --allagent: 1args: -audiodev id=alsa,driver=alsa,out.period-length=100000,out.frequency=48000,out.channels=2,out.try-poll=off,out.dev=swapped -soundhw hdaballoon: 0bios: ovmfboot: dcbootdisk: scsi0cores: 5cpu: hostcpuunits: 10000efidisk0: nvme-thin:vm-204-disk-1,size=4Mhookscript: local:snippets/exec-cmdshostpci0: 01:00,pcie=1,x-vga=1,romfile=Gigabyte.RTX2080Super.8192.190820.romhugepages: 1024ide2: none,media=cdrommachine: pc-q35-3.1memory: 10240name: win10-vganet0: e1000=3E:41:0E:4D:3D:14,bridge=vmbr0numa: 1onboot: 1ostype: win10runningmachine: pc-q35-3.1scsi0: ssd:vm-204-disk-2,discard=on,iothread=1,size=64G,ssd=1scsi1: ssd:vm-204-disk-0,backup=0,discard=on,iothread=1,replicate=0,size=921604Mscsi3: nvme-thin:vm-204-disk-0,backup=0,discard=on,iothread=1,replicate=0,size=100Gscsihw: virtio-scsi-pcisockets: 1vga: none

5.5. Switching between VMs

To switch between VMs:

  1. Both VMs always run concurrently.
  2. I do change the monitor input.
  3. Audio is by default being output by both VMs, no need to switch it.
  4. I use Barrier (previously Synergy) for most of time.
  5. In other cases I have Logitech multi-device keyboard and mouse,so I switch it on keyboard.
  6. I also have a physical switch that I useto change lighting and monitor inputs.
  7. I have the monitor with PBP and PIP, so I can watch how Windowsis updating while doing development work on Linux.

Author, License

Kamil Trzciński, 2019-2021, MIT

Open Source Agenda is not affiliated with "Pve Helpers" Project. README Source: ayufan/pve-helpers

Pve Helpers Open Source Project (2024)

FAQs

Is Proxmox fully open source? ›

Proxmox Virtual Environment is a complete open-source platform for enterprise virtualization.

Can I run Proxmox without a subscription? ›

Proxmox VE Enterprise Repository

Please note that you need a valid subscription key to access the pve-enterprise repository.

Do companies use Proxmox? ›

Customers of Proxmox

Around the world in 2024, over 2244 companies have started using Proxmox as Virtualization Platform tool.

What is better than Proxmox? ›

Other important factors to consider when researching alternatives to Proxmox VE include storage. The best overall Proxmox VE alternative is VMware vSphere. Other similar apps like Proxmox VE are VirtualBox, Azure Virtual Machines, Oracle VM, and Virtuozzo.

What is the limitation of Proxmox? ›

Currently: 8096 logical cores per host are the upper limit, 256 to 512 are rather the upper end of systems out in the wild nowadays. ~ 128 TiBs per node, as we currently use 4-level page tables (5 level would be possible). Peta to Exabytes, depending on technology used.

Is Proxmox not free anymore? ›

Proxmox subscription and repositories. Proxmox itself is completely free to download and deploy without any cost. But a subscription offers an added level of stability to any node used in a production environment. Both free and subscribed versions have separate repositories and receive updates differently.

Is oVirt better than Proxmox? ›

In the Virtualization Platform market, Proxmox has a 0.93% market share in comparison to oVirt's 0.16%. Since it has a better market share coverage, Proxmox holds the 13th spot in 6sense's Market Share Ranking Index for the Virtualization Platform category, while oVirt holds the 29th spot.

Should I use Proxmox or VMware? ›

Proxmox is an open-source virtual environment while VMware is closes-source proprietary code. Proxmox offers fewer features in exchange for more accessibility and lighter usage. VMware offers a veritable cornucopia of features, most of which are best for corporate enterprise use.

Why do people use Proxmox? ›

Shared Storage: The Proxmox cluster enables efficient storage sharing among multiple hosts in the cluster, simplifying the management and allocation of storage resources for virtual machines and containers.

What browser is best for Proxmox? ›

Proxmox VE is simple. There is no need to install a separate management tool, and everything can be done through your web browser (Latest Firefox or Google Chrome is preferred). A built-in HTML5 console is used to access the guest console. As an alternative, SPICE can be used.

Can Proxmox use WIFI? ›

Setting up the Wi-Fi itself is not different in Proxmox VE than with a default Debian installation. But avoid installing advanced, network daemons like NetworkManager as those are normally suited for desktops only and may interfere with Proxmox VEs network requirements.

How much resources does Proxmox need? ›

Recommended Hardware

Memory, minimum 2 GB for OS and Proxmox VE services. Plus designated memory for guests. For Ceph or ZFS additional memory is required, approximately 1 GB memory for every TB used storage. Fast and redundant storage, best results with SSD disks.

Should I use Proxmox or Unraid? ›

The choice between Proxmox and Unraid depends on your specific needs. If you prioritize advanced virtualization features and the ability to create clusters, Proxmox is the better option. On the other hand, if you require versatile network-attached storage functionalities, Unraid might be more suitable for you.

Does Proxmox have a GUI? ›

When you are on the same computer you can open the web GUI of Proxmox via https://127.0.0.1:8006/.

Which version of Proxmox is free? ›

The Proxmox VE source code is free, released under the GNU Affero General Public License, v3 (GNU AGPLv3). This means that you are free to use the software, inspect the source code at any time and contribute to the project yourself.

Can you use Proxmox for free? ›

The Proxmox VE source code is free, released under the GNU Affero General Public License, v3 (GNU AGPLv3). This means that you are free to use the software, inspect the source code at any time and contribute to the project yourself.

Is Proxmox bare metal? ›

Note: Proxmox VE is a bare-metal installer, please be aware that the complete server is used and existing data on the selected disks will be removed.

Which is better, Proxmox or VirtualBox? ›

based on preference data from user reviews. Proxmox VE rates 4.6/5 stars with 30 reviews. By contrast, VirtualBox rates 4.5/5 stars with 276 reviews.

References

Top Articles
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 6012

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.