Cpu limit virtual machines / cpu threads

Hi all,

When i limit the cpu to 4 in a vm i get 4 cpus and 4 threads in the vm. How can i make it 4 cores and 8 threads in the vm?

What’s the use case for this?

Incus always exposes cores on a single CPU to its VMs, unless limits.cpu is used to map to physical cores and threads, in which case Incus will replicate the physical topology in the VM

so when i dont set the limits.cpu is it using all the cores and threads?

sorry,

i got my answer. No i was curious. my cpu has 4 cores and 8 threads. so when i limit the cpu to 4 the vm gives me 4 cpus and 4 threads.

my idea was to give it 8 threads and 4 cores. however its no problem at all.

If you set limits.cpu=0-7 it should then pick up the same topology as your host CPU with its 4 cores and 8 total threads.

Hi,

could you please explain this topology. im trying to learn. What if i got 16 cpus with 32 cores?

You’d want to check incus info --resources this will show you all the cores and their threads.

You’ll want to set a range or set of specific CPU threads in limits.cpu.

For example you may end up with limits.cpu=0,1,16,17 to capture two cores with two threads per core, but how thread IDs are allocated can vary a fair bit between CPUs.

If you show your incus info --resources I can give you some pointers.

CPU:
Architecture: x86_64
Vendor: GenuineIntel
Name: Intel(R) Core™ i9-9920X CPU @ 3.50GHz
Caches:

  • Level 1 (type: Data): 32KiB
  • Level 1 (type: Instruction): 32KiB
  • Level 2 (type: Unified): 1MiB
  • Level 3 (type: Unified): 19MiB
    Cores:
  • Core 0
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 0, online: true, NUMA node: 0)
  • 1 (id: 12, online: true, NUMA node: 0)
  • Core 1
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 1, online: true, NUMA node: 0)
  • 1 (id: 13, online: true, NUMA node: 0)
  • Core 3
    Frequency: 2302Mhz
    Threads:
  • 0 (id: 2, online: true, NUMA node: 0)
  • 1 (id: 14, online: true, NUMA node: 0)
  • Core 4
    Frequency: 1199Mhz
    Threads:
  • 0 (id: 3, online: true, NUMA node: 0)
  • 1 (id: 15, online: true, NUMA node: 0)
  • Core 5
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 4, online: true, NUMA node: 0)
  • 1 (id: 16, online: true, NUMA node: 0)
  • Core 6
    Frequency: 4200Mhz
    Threads:
  • 0 (id: 5, online: true, NUMA node: 0)
  • 1 (id: 17, online: true, NUMA node: 0)
  • Core 8
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 6, online: true, NUMA node: 0)
  • 1 (id: 18, online: true, NUMA node: 0)
  • Core 9
    Frequency: 1800Mhz
    Threads:
  • 0 (id: 7, online: true, NUMA node: 0)
  • 1 (id: 19, online: true, NUMA node: 0)
  • Core 10
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 8, online: true, NUMA node: 0)
  • 1 (id: 20, online: true, NUMA node: 0)
  • Core 12
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 9, online: true, NUMA node: 0)
  • 1 (id: 21, online: true, NUMA node: 0)
  • Core 13
    Frequency: 1200Mhz
    Threads:
  • 0 (id: 10, online: true, NUMA node: 0)
  • 1 (id: 22, online: true, NUMA node: 0)
  • Core 14
    Frequency: 1199Mhz
    Threads:
  • 0 (id: 11, online: true, NUMA node: 0)
  • 1 (id: 23, online: true, NUMA node: 0)
    Frequency: 1591Mhz (min: 1200Mhz, max: 4400Mhz)

So 12 cpu and 24 threads. Say i want to assign 8 cpu with 24 threads how could i do this?

You can’t do 8 CPUs with 24 threads as that’s considered an invalid topology by Incus. You can do limits.cpu=24 which will use 24 threads on the host along with core scheduling to provide 24 virtual cores in the guest.

If you want topology to be passed through, it needs to map to hardware.
For example if you want to pass in 8 cores and 16 threads (2 threads per core), you could do that with:

limits.cpu=0-7,12-19
```

This will pin the VM to the first 8 physical cores and matching threads, which will then show up in the guest as 8 cores with 2 threads each.

Perfect.

Thank you @stgraber