Google is working on a new code change for ChromeOS that could boost VM performance on Chromebooks. ChromeOS uses a custom VM, or virtual machine, to run Linux on Chromebooks, as well as for Android apps. The change would enable CPU affinity, which is a way to constrain or enable the VM to use certain processors on a multi-core Chromebook.
What’s changing for VM performance on Chromebooks
Here’s the description of the code change:
When –host-cpu-topology flag is specified, crosvm will create 1:1 affinity masks between host CPUs and VM’s vCPUs. Extend this mechanims to also pass the cluster IDs and CPU capacity information to the guest.
There are a few things to unpack here.
First, the code change is specific to crosvm, which, if you’re not familiar with, is the custom VM monitor that Google created specifically for ChromeOS. It’s very lightweight compared to typical virtual machines that you may be familiar with, such as Parallels Desktop, QEMU or VirtualBox.
Any time you open Linux on a Chromebook, for example, crosvm executes to create a VM. Inside that VM, Linux runs in a container which helps add more security between Linux and the ChromeOS system. Both the VM and the container do add overhead since the CPUs are running a virtualized, or software-based, computer instance.
What is CPU affinity?
So, what is CPU affinity and how could it affect the VM running on Chromebooks? Essentially, CPU affinity is a way to optimize and balance the CPU cores between its regular operating system and a virtual one.
Given that Chromebooks use multi-core processors, CPU affinity can allocate a greater number of cores for the two systems. It can also reduce or limit the cores if that’s required. However, I don’t think that’s the main reason for this code change.
I’m also over-simplifying this a bit to aid in understanding. There’s quite a bit going on at the system level with regards to CPU affinity and task scheduling.
This is an older Linux forum post from 2008 about CPU affinity but the principle still applies on the benefits:
One of these useful linux utilities is called taskset which allows setting the cpu affinity of a process. This is just a fancy way of saying bonding a process to a specific set of cpu(s). Why would you want to do this? The short answer is Load balancing. With multicore cpus becoming the de facto standard, there are some very practical uses of this when it comes to virtualization.
On a typical multicore cpu today, each core has enough power to easily run a physical machine so you can see the practical application of this; pin a virtual machine to a cpu core. This is applicable for most applications. If your application needs more cpu cycles you can scale up by pinning your virtual machine to multiple cores.
Let’s talk about cores!
Think of it this way, using the Framework Chromebook. It has a 12th gen Intel Core i5 processor with 12 cores. All of the running tasks are spread out among the cores as needed, to balance performance and efficiency. The above image shows how much each individual CPU core is in use.
You can see the various tasks are spread out between the many CPU cores. In that example, I’m just using ChromeOS for web browsing.
Here’s what happens when I start doing something in Linux, which is running in a VM on the Chromebook:
You can see that two of the physical CPU cores are handling most of the load for the VM and Linux at that point in time. That kind of seems like a waste of resources when there are plenty of other cores to balance out the load.
How CPU affinity could boost VM performance on Chromebooks
With CPU affinity enabled and configured on a Chromebook, constraints on how many cores used for the VM can be adjusted. That would allow the VM to enjoy the same performance and efficiency optimizations as ChromeOS itself.
Instead of the VM using just a few CPU cores, for example, half of them could essentially be devoted to ChromeOS. The other half could be focused on the VM tasks. Note that even with CPU affinity, a physical CPU core can never be fully allocated to a virtual machine.
According to Parallels, this approach could provide a 20 percent performance boost; at least for that company’s VM product:
If your physical server has several processors installed, you can bind a virtual machine or Container to specific CPUs so that only these CPUs are used to handle the processes running in the virtual machine or Container. The feature of binding certain processes to certain CPUs is known as CPU affinity. Establishing CPU affinity between virtual machines and Containers and physical processors can help you increase your system performance up to 20%.
Obviously, without more details specific to crovm , and since I can’t currently test performance of this upcoming change now, I don’t know how much of a performance boost CPU affinity may bring. It’s definitely something I will test once the change is made, however.
And if I recall correctly, Google is leveraging its effort on crosvm for all virtualized activities on Chromebooks. So it’s possible, likely even, that Android apps could gain some performance here too.