Rate This Document
Findability
Accuracy
Completeness
Readability

Configuring the VM Cache

You can use libvirt or QEMU to start a VM. The following describes the cache size configuration for the two VM startup modes.

Starting a VM Using libvirt

To start a VM using libvirt, you need to modify the cache configuration in the XML configuration file of the VM.

After modifying the VM XML file, you need to restart the VM for the configuration to take effect.

  • If the L1 cache uses the instruction-data separation structure (for example, the Arm architecture), the configuration is as follows:
    1
    2
    3
    4
    5
    6
    7
    8
        ... 
        <cpu mode='host-passthrough'>
            <cacheinfo cache='l1d' size='<l1d cache_size>'/> //Example 32768
            <cacheinfo cache='l1i' size='<l1i cache_size>'/> //Example 32768
            <cacheinfo cache='l2' size='<l2 cache_size>'/> //Example 1048576
            <cacheinfo cache='l3' size='<l3 cache_size>'/> //Example 50331648
        </cpu>
        ... 
    
  • If the L1 cache uses the unified cache structure, the configuration is as follows:
    1
    2
    3
    4
    5
    6
    7
      ... 
        <cpu mode='host-passthrough'>
            <cacheinfo cache='l1' size='<l1 cache_size>'/> //Example 32768
            <cacheinfo cache='l2' size='<l2 cache_size>'/> //Example 1048576
            <cacheinfo cache='l3' size='<l3 cache_size>'/> //Example 50331648
        </cpu>
        ...
    

(Optional) Starting the VM Using the QEMU Command or Device Tree

If the QEMU command or device tree is used to start a VM, you need to modify the cache configuration in the QEMU command.

  • If the L1 cache uses the instruction-data separation structure (for example, the Arm architecture), the configuration is as follows:
    1
    2
    3
    4
    5
    -machine virt,\
    smp-cache.0.cache=l1i,smp-cache.0.size=<l1i cache_size>,\ //Example 32768
    smp-cache.1.cache=l1d,smp-cache.1.size=<l1d cache_size>,\ //Example 32768
    smp-cache.2.cache=l2,smp-cache.2.size=<l2 cache_size>,\ //Example 1048576
    smp-cache.3.cache=l3,smp-cache.3.size=<l3 cache_size>\ //Example 50331648
    
  • If the L1 cache uses the unified cache structure, the configuration is as follows:
    1
    2
    3
    4
    -machine virt,\
    smp-cache.0.cache=l1,smp-cache.0.size=<l1 cache_size>,\ //Example 32768
    smp-cache.2.cache=l2,smp-cache.2.size=<l2 cache_size>,\ //Example 1048576
    smp-cache.3.cache=l3,smp-cache.3.size=<l3 cache_size>\ //Example 50331648
    
  • The l1i cache_size, l1d cache_size, l2 cache_size, and l3 cache_size are the cache sizes displayed on the VM. To ensure accuracy, ensure that the cache size is the same as that used by the VM.
  • If the L1 cache uses the instruction-data separation structure, configure l1d and l1i. Otherwise, configure l1.
  • The cache size must be greater than 0.