[libvirt-users] Running all my virtual machines with a low priority

Hi all: I have an Ubuntu 18.04 system. What is the easiest way to run all of my virtual machines with a low priority? Say a "nice" level of 15. I just do not want my virtual machines to have too much of an impact in any other processes on the system. Thanks in advance, rdiez

On Tue, Apr 30, 2019 at 04:24:08PM +0200, R. Diez wrote:
Hi all:
I have an Ubuntu 18.04 system. What is the easiest way to run all of my virtual machines with a low priority? Say a "nice" level of 15.
You can use the <vcpusched> (and related elements) to control the schedular nice level up or down https://libvirt.org/formatdomain.html#elementsCPUTuning Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

I have an Ubuntu 18.04 system. What is the easiest way to run all of my virtual machines with a low priority? Say a "nice" level of 15.
You can use the <vcpusched> (and related elements) to control the schedular nice level up or down
Thanks for your quick answer. I took at look at that documentation, but I did not quite understand it. It talks about vCPUs and how they are scheduled. My guess is that it is all about how those virtual CPUs are scheduled against each other. However, I wanted to lower the priority of all virtual machines against other processes on the host system. Regards, rdiez

On Wed, May 01, 2019 at 11:41:17AM +0200, R. Diez wrote:
I have an Ubuntu 18.04 system. What is the easiest way to run all of my virtual machines with a low priority? Say a "nice" level of 15.
You can use the <vcpusched> (and related elements) to control the schedular nice level up or down
Thanks for your quick answer.
I took at look at that documentation, but I did not quite understand it. It talks about vCPUs and how they are scheduled. My guess is that it is all about how those virtual CPUs are scheduled against each other.
However, I wanted to lower the priority of all virtual machines against other processes on the host system.
You would have to set the priority of all vCPUs in each guest, as well as emulator threads in each guest (the latter needs very new libvirt). Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

You would have to set the priority of all vCPUs in each guest, as well as emulator threads in each guest (the latter needs very new libvirt).
This does not seem a viable option then with Ubuntu 18.04. And changing XML on all guest VMs is extra work. Is there no other way? For example, are all such virtual machines not some daemon or systemd unit or set of units? Would it be feasible to lower the priority on all of those? Or is that not easy to do either? Thanks again, rdiez

On Wed, May 01, 2019 at 11:58:23AM +0200, R. Diez wrote:
You would have to set the priority of all vCPUs in each guest, as well as emulator threads in each guest (the latter needs very new libvirt).
This does not seem a viable option then with Ubuntu 18.04. And changing XML on all guest VMs is extra work.
Is there no other way? For example, are all such virtual machines not some daemon or systemd unit or set of units? Would it be feasible to lower the priority on all of those? Or is that not easy to do either?
I'm not sure if we're resetting all the cgroup values, so it should be possible by setting this for the machine.slice cgroup (or somewhere around there) which would make it effective for all the VMs, right? I have not tested it, though, sorry.
Thanks again, rdiez
_______________________________________________ libvirt-users mailing list libvirt-users@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-users

On Thu, May 02, 2019 at 11:33:06AM +0200, Martin Kletzander wrote:
On Wed, May 01, 2019 at 11:58:23AM +0200, R. Diez wrote:
You would have to set the priority of all vCPUs in each guest, as well as emulator threads in each guest (the latter needs very new libvirt).
This does not seem a viable option then with Ubuntu 18.04. And changing XML on all guest VMs is extra work.
Is there no other way? For example, are all such virtual machines not some daemon or systemd unit or set of units? Would it be feasible to lower the priority on all of those? Or is that not easy to do either?
I'm not sure if we're resetting all the cgroup values, so it should be possible by setting this for the machine.slice cgroup (or somewhere around there) which would make it effective for all the VMs, right? I have not tested it, though, sorry.
You could perhaps set 'cpu.shares' cgroup setting on /machine.slice. This isn't really a nice level in the traditional sense, rather it is a relative weighting evaluated against other cgroups at the same level. So if you change it from 1024 to 512, then processes under /machine.slice will get 1/2 the CPU time vs stuff under /system.slice or /user.slice, when there is contention for CPU time. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

You could perhaps set 'cpu.shares' cgroup setting on /machine.slice. This isn't really a nice level in the traditional sense, rather it is a relative weighting evaluated against other cgroups at the same level. So if you change it from 1024 to 512, then processes under /machine.slice will get 1/2 the CPU time vs stuff under /system.slice or /user.slice, when there is contention for CPU time.
Thanks for your help. There is no "machine.slice" on my system. This is an excerpt from "systemd-cgls". ??? ??????system.slice ??? ??????irqbalance.service ??? ??? ??????865 /usr/sbin/irqbalance --foreground [... blah blah ...] ??? ??????wpa_supplicant.service ??? ??? ??????878 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant ??? ??????libvirtd.service ??? ??? ?????? 987 /usr/sbin/libvirtd ??? ??? ?????? 1395 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper ??? ??? ?????? 1396 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper ??? ??? ??????12285 /usr/bin/qemu-system-x86_64 -name guest=UbuntuMATE1804,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-UbuntuMATE1804/master-key.aes -machine... But I guess there are differences depending on the libvirt version. I thought of 'nice' because it is an easy way to lower the priority for everything (CPU and disk) at once. This is actually getting too complicated. I am a lone developer and sysadmin in a small company. I would need to learn too many things about control groups etc. One of the reasons I am trying libvirt is because of the "Virtual Machine Manager" GUI. Is there not an easier way? I realised there is a "libvirtd.service" on my system. Is there a simple way in systemd to just lower the priority of everything under that service? I am assuming that this service is starting all the virtual machines. Best regards, rdiez

On Thu, May 02, 2019 at 12:10:54PM +0200, R. Diez wrote:
You could perhaps set 'cpu.shares' cgroup setting on /machine.slice. This isn't really a nice level in the traditional sense, rather it is a relative weighting evaluated against other cgroups at the same level. So if you change it from 1024 to 512, then processes under /machine.slice will get 1/2 the CPU time vs stuff under /system.slice or /user.slice, when there is contention for CPU time.
Thanks for your help.
There is no "machine.slice" on my system. This is an excerpt from "systemd-cgls".
??? ??????system.slice ??? ??????irqbalance.service ??? ??? ??????865 /usr/sbin/irqbalance --foreground [... blah blah ...] ??? ??????wpa_supplicant.service ??? ??? ??????878 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant ??? ??????libvirtd.service ??? ??? ?????? 987 /usr/sbin/libvirtd ??? ??? ?????? 1395 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper ??? ??? ?????? 1396 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper ??? ??? ??????12285 /usr/bin/qemu-system-x86_64 -name guest=UbuntuMATE1804,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-UbuntuMATE1804/master-key.aes -machine...
Runing: $ systemctl set-property machine.slice CPUShares=512 works for me on some random machine I tried. As far as I understand, Nice= was supported (for backward compatibility) but it is not now, or at least not for slices. Feel free to set other things with similar commands or just use systemctl edit machine.slice and configure that however you want. Looking for the proper documentation is left as an exercise for the reader.
But I guess there are differences depending on the libvirt version.
I thought of 'nice' because it is an easy way to lower the priority for everything (CPU and disk) at once.
This is actually getting too complicated. I am a lone developer and sysadmin in a small company. I would need to learn too many things about control groups etc. One of the reasons I am trying libvirt is because of the "Virtual Machine Manager" GUI.
I believe such basic settings should *not* be complicated, and I hope the above got you closer to the goal.
Is there not an easier way? I realised there is a "libvirtd.service" on my system. Is there a simple way in systemd to just lower the priority of everything under that service? I am assuming that this service is starting all the virtual machines.
We are also counting with the use case where you want the machine to take full advantage of the system and its resources, but you want to restrict the management of such virtual machines (libvirt in this case), so libvirt has to explicitly override any possibly inherited configuration for virtual machines it is starting. That's why setting anything on the libvirtd.service will not work.
Best regards, rdiez
participants (3)
-
Daniel P. Berrangé
-
Martin Kletzander
-
R. Diez