PCIe passthrough is a technology that permits Virtual Machines direct access to the underlying hardware of a system. Want to play video games in a VM? Passthrough the GPU. Want to run OPNsense in a VM? Passthrough a dedicated NIC card.
What if you want to run Plex in a VM and take advantage of hardware accelerated decoding? Specifically to use the Intel Quick Sync functionality built-in to most modern Intel CPU graphics units. It's actually very easy with Proxmox, here's how to do it.
Also see this blog post which was helpful in my research for this topic.
Passing through an entire GPU is very useful for specific tasks but isn't a very efficient use of resources. Wouldn't it be nice if we could slice up 1 GPU and use it with multiple VMs at once?
That is precisely what GVT-g permits us to do! Take the iGPU and give a VM, or multiple VMs, a slice of that graphics chip to do with whatever it wants. In our case, we'll use the Quick Sync portion of the iGPU to transcode Plex H264 streams in one VM and Blue Iris streams in another.
If you're not convinced yet, take a look this video from Wendell who explains in a lot of detail why this technology is so cool! Intels rumoured upcoming XE graphics card might support it but until then, we'll have to make do with the iGPU in your CPU.
If you needed even more convincing, take a look at the following numbers and see just how incredibly power efficient Quick Sync is compared to software based transcoding with Plex. Full details in episode 34 of Self-Hosted (releases on Friday 18th Dec 2020).
|Idle (8 drives)
|4K Transcode (QS)
|4K Transcode (CPU)
|2x Xeon E5-2690v2
|EVGA 750 G+
This was a legitmate "holy shit!" moment for me. Quick Sync is capable of a 4k transcode at 35w! This is a 10x reduction from the Dual Xeon setup I'd been using previously.
On top of that, Quick Sync can handle in excess of 20 1080p streams and about 5 4k transcodes in my testing. Astonishing given the power draw. Less power draw means less heat and lower electricity bills - what's not to like?!
Setting up PCI passthrough
PCI passthrough requires a very particular set of hardware although things now are easier than they used to be a few years ago. For reference my hardware is an Intel i5 8500 and an AsRock Z370-I motherboard. I did an episode of Linux Unplugged where we went into full details on passthrough.
Full instructions are provided on the Proxmox wiki. Once you've enabled IOMMU verify you've done so correctly like so:
alex@unas:~$ dmesg | grep -e DMAR -e IOMMU -e AMD-Vi
[ 0.007086] ACPI: DMAR 0x00000000C547E208 0000A8 (v01 INTEL KBL 00000001 INTL 00000001)
[ 0.106528] DMAR: IOMMU enabled
[ 4.262872] DMAR: Intel(R) Virtualization Technology for Directed I/O
Next, using the same Proxmox wiki page navigate to the section entitled 'Mediated Devices (vGPU, GVT-g)'.
Mediated device setup (Intel GTV-g)
You already modified
/etc/modules in the previous step, you'll want to add
kvmgt as well in that file.
/etc/default/grub so that it looks like this when done:
alex@unas:~$ cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DISTRIBUTOR="Proxmox Virtual Environment"
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on i915.enable_gvt=1 drm.debug=0"
Regenerate initramfs with
update-initramfs -u -k all and reboot. To verify that mediated devices are now enabled take a look here:
root@unas:/home/alex# ls /sys/bus/pci/devices/0000\:00\:02.0/mdev_supported_types/
If you see
i915-GVTg_V5_4 you're good to go.
Adding the iGPU to a VM
So far, everything we've done was covered in the Proxmox wiki and the previously linked blog post but I wanted to use the iGPU for 2 VMs and there were a few small things to consider.
Navigate to the VM you'd like to configure. Click
Add -> PCI Device.
Select the device
0000:00:02.0 (this doesn't appear to change in my testing between different machines) and then from the
MDev Type drop down note that you have two options.
i915-GVTg_V5_4 is for some reason limited to 1 virtual device but
i915-GVTg_V5_8 presents us with 2 available devices. Select
V5_8 and hit
Add. Repeat these steps for the second VM you'd like to use the iGPU with.
Plex Hardware Acceleration
This is a Plex Pass only feature.
Some of you will think I'm crazy but I run my Perfect Media Server in a VM with an LSI HBA card passed through. On top of that abstraction I run each app in a container. Giving the container access to the hardware for GPU based transcoding requires adding a couple of lines to your container configuration - I use docker-compose.
The key here is
devices: /dev/dri:/dev/dri. Once you've got the container up and running you'll need to tell Plex to use hardware transcoding in settings.
Once that is done, install
intel-gpu-tools (assuming you're on Ubuntu this is available in the repos) and monitor the utilisation with
Hardware acceleration in Blue Iris
In the second VM I run Blue Iris, my NVR software of choice. It requires Windows which is a shame but the software works very well.
Under Blue Iris settings ensure you have
Cameras -> Hardware accelerated decode enabled and set to Intel.
I have 6 4k cameras coming into Blue Iris and these are the performance stats provided to me via Task Manager. I think you'll agree, very acceptable.
The power of Quick Sync is very impressive for the amount of energy it consumes. In my opinion, this is the holy grail of media server technologies. Used gear can be had quite cheaply now, the i5 8500 used here was $110 off of eBay.
Couple this with other great projects like PiKVM and consumer grade gear is really ready to be your next home server.