Chapter 3. Configuring the host environment for real-time virtual machines
To ensure that your RHEL 10 can work as a host for real-time virtual machines, you must optimize the host’s performance and test its latency between input and system response.
3.1. Configuring TuneD for the real-time virtualization host Copy linkLink copied to clipboard!
To optimize your RHEL 10 system as a host for real-time virtual machines (VMs), configure and enable the realtime-virtual-host profile for TuneD.
Prerequisites
- Your host meets the system requirements for real-time virtualization.
The
irqbalanceservice is disabled. Ifirqbalanceis enabled, its handling of Interrupt requests (IRQs) might conflict with TuneD. To disableirqbalance:# systemctl stop irqbalance && systemctl disable irqbalance
Procedure
-
Start editing the configuration of the
realtime-virtual-hostprofile for TuneD. To do so, open the/etc/tuned/realtime-virtual-host-variables.conffile in a text editor. Adjust the configuration in
/etc/tuned/realtime-virtual-host-variables.confto suit your requirements. Consider especially the following factors in the setup:- The number of cores and NUMA nodes your machine has
- The number of RT guests that you plan to run
- The number of vCPUs that each RT guest will have
The most important modifications to
/etc/tuned/realtime-virtual-host-variables.confinclude the following:Update the
isolated_coresparameter to adjust which host cores per socket will be dedicated to RT virtualization tasks and which cores will remain for system maintenance on the host (also known as housekeeping).For example, the following setting uses core 3, core 6, and cores 8 to 15 for RT tasks, and all the other cores as housekeeping:
isolated_cores=3,6,8-15Note that by default, one core per socket (core 0) is used for housekeeping and all other cores for RT tasks.
ImportantCore 0 must always be set as a housekeeping core. Using core 0 for RT tasks disrupts the RT functionality.
Enable IRQ isolation for kernel-managed IRQs. To do so, ensure the following line is not commented out in the configuration:
isolate_managed_irq=YIf IRQ isolation is disabled, host kernel-managed IRQs can interrupt isolated cores, which might cause unexpected latency.
-
Uncomment the
netdev_queue_countparameter and set its value to the number of housekeeping cores.
-
Save the changes to
/etc/tuned/realtime-virtual-host-variables.conf. Activate the real-time virtual host profile.
# tuned-adm profile realtime-virtual-host- Restart the host.
Verification
3.2. Configuring huge pages for real-time virtualization hosts Copy linkLink copied to clipboard!
To further decrease latency in virtual machines (VMs) on RHEL 10, set the host to use huge memory pages. Huge pages can significantly enhance the performance of applications that use large amounts of memory, which is generally the case for RT applications.
For more information about huge pages, see Configuring huge pages.
Prerequisites
- Your host meets the system requirements for real-time virtualization.
- You have configured TuneD for real-time VM host. For instructions, see Configuring TuneD for the real-time virtualization host.
Procedure
Set up the default huge page size to be 1 gibibyte.
$ grubby --args "default_hugepagesz=1G" --update-kernel ALLReserve huge pages on the host.
$ echo <X> > /sys/devices/system/node/node_<Y>_/hugepages/<hugepages-size_dir>/nr-hugepagesIn this command, replace the variables as follows:
- <X> with the number of huge pages to reserve. This value depends on the number of VMs and how much memory they will have. If you are running a single VM, start with two 1GB pages.
- <Y> with the number of the NUMA node where real-time vCPUs are pinned.
-
<hugepage-size_dir> with the huge-page size in kB. For example, for 2MB hugepages, this would be
hugepages-2048kB.
ImportantThis command sets up huge pages transiently. As a result, you must use the command after every host reboot before you start any real-time VMs. To avoid this, perform the following optional step, which makes huge pages persistent.
Optional: If you want to make the huge-page configuration persistent, also do the following:
Create a file named
/usr/lib/systemd/system/hugetlb-gigantic-pages.servicewith the following contents:[Unit] Description=HugeTLB Gigantic Pages Reservation DefaultDependencies=no Before=dev-hugepages.mount ConditionPathExists=/sys/devices/system/node ConditionKernelCommandLine=default_hugepagesz=1G [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/lib/systemd/hugetlb-reserve-pages [Install] WantedBy=sysinit.targetCreate a file named
/usr/lib/systemd/hugetlb-reserve-pageswith the following contents:#!/bin/bash nodes_path=/sys/devices/system/node/ if [ ! -d $nodes_path ]; then echo "ERROR: $nodes_path does not exist" exit 1 fi reserve_pages() { echo $1 > $nodes_path/$2/hugepages/hugepages-1048576kB/nr_hugepages } # This example reserves 2 1G pages on node0 and 1 1G page on node1. You # can modify it to your needs or add more lines to reserve memory in # other nodes. Don't forget to uncomment the lines, otherwise then won't # be executed. # reserve_pages 2 node0 # reserve_pages 1 node1Enable early boot reservation by using the following commands:
$ chmod +x /usr/lib/systemd/hugetlb-reserve-pages $ sudo systemctl enable hugetlb-gigantic-pages $ sudo systemctl status hugetlb-gigantic-pages-
Uncomment the bottom two lines of
/usr/lib/systemd/hugetlb-reserve-pagesand update them based on your huge-page reservation requirements.
- Reboot to apply all the configuration changes.
3.3. Verifying the host BIOS setup for real-time virtualization Copy linkLink copied to clipboard!
To verify that the BIOS of your real-time host has been successfully set up for low-latency workloads, use the hwlatdetect program.
Prerequisites
-
You have configured
tunedfor real-time virtual machine host. For instructions, see Configuring TuneD for the real-time virtualization host. - You have set up huge memory pages for use with real-time virtualization. For instructions, see Configuring huge pages for real-time virtualization hosts.
Procedure
Run the
hwladetectutility for at least an hour, and ensure that the measured latency does not exceed 1 microsecond (μs).# hwlatdetect --threshold=1μs --duration=60m hwlatdetect: test duration 60 minutes parameters: Latency threshold: 1μs Sample window: 1000000μs Sample width: 500000μs Non-sampling period: 500000μs Output File: None Starting test test finished Max Latency: 0us Samples recorded: 0 Samples exceeding threshold: 0Optional: For improved validation, run the same test for 24 hours.
# hwlatdetect --threshold=1μs -duration=24h
3.4. Verifying the real-time virtualization host environment Copy linkLink copied to clipboard!
After you have configured the host for real-time virtual machines (VMs), you must verify that it is set up correctly. To do so, check the settings for the kernel, huge pages, and isolated CPUs, and ensure that the TuneD profile is active.
Prerequisites
-
You have configured
tunedfor real-time VMs. For instructions, see Configuring TuneD for the real-time virtualization host. - You have set up huge memory pages for use with real-time virtualization. For instructions, see Configuring huge pages for real-time virtualization hosts.
Procedure
View the content of the
/proc/cmdlinefile, and check that the values for the following parameters correspond with how you configured them:- Real-time kernel
- Huge pages
Isolated CPUs
For example:
cat /proc/cmdline BOOT_IMAGE=(hd0,msdos1)/vmlinuz-5.14.0-70.13.1.rt21.83.el10_0.x86_64 root=/dev/mapper/rhel_virtlab505-root ro crashkernel=auto resume=/dev/mapper/rhel_virtlab505-swap rd.lvm.lv=rhel_virtlab505/root rd.lvm.lv=rhel_virtlab505/swap console=ttyS1,115200 default_hugepages=1G skew_tick=1 isolcpus=1,3,5,7,9,11,13,14,15 intel_pstate=disable nosoftlockup tsc=nowatchdog nohz=on nohz_full=1,3,5,7,9,11,13,14,15 rcu_nocbs=1,3,5,7,9,11,13,14,15
Ensure that the
realtime-virtual-hosttuned profile is active.$ tuned-adm active Current active profile: realtime-virtual-hostCheck the number of huge memory pages. For example:
$ cat /sys/devices/system/node/node0/hugepages/hugepages-1048576kB/nr_hugepages 2
3.5. Stress testing the real-time virtualization system Copy linkLink copied to clipboard!
To ensure that the RHEL for Real Time host or guest that you set up maintains low latency when under heavy load, perform real-time latency stress tests.
Prerequisites
-
You have configured
tunedfor real-time virtual machine host. For instructions, see Configuring TuneD for the real-time virtualization host. - You have set up huge memory pages for use with real-time virtualization. For instructions, see Configuring huge pages for real-time virtualization hosts.
Procedure
Add stress to the housekeeping cores. To do so, start compiling the linux kernel on twice the number of housekeeping cores that you have set up in the previous sections.
Clone the Linux kernel repository and move to its directory.
# git clone https://github.com/torvalds/linux.git ; cd linuxCreate a default configuration for the kernel compilation.
# make defconfigStart compiling the Linux kernel.
# while true; do make -j <double-number-of-housekeeping-cpus> && make clean; done
Perform a
cyclictestprocedure on the host for 12 hours. In the following example, replace <list_isolated_cores> with a list of cores isolated for real-time tasks, such as1,3,5,7,9,11,13,14,15.# cyclictest -m -q -p95 --policy=fifo -D 12h -h60 -t <number_of_isolated_cpus> -a <list_isolated_cores> -mainaffinity <list_housekeeping_cpus> -i 200When using a modern high-end AMD64 or Intel 64 processor (also known as
x86_64), the optimal value ofMax Latenciesin the output is under 40 microsecond (μs). To terminate the test if the measured latency exceeds 40μs, add the-b 40option to the command.Perform an OS-level latency test (OSLAT) on the host for 12 hours.
# ./oslat --cpu-list <list_isolated_cores> --rtprio 1 --D 12h -w memmove -m 4KWhen using a modern high-end
x86_64processor, the optimal value ofMaximumin the output is under 20 μs. To terminate the test if the measured latency exceeds 20 μs, add the-T 20option to the command.