Merge pull request #800 from homeski/feature/numa_nodes

Feature/numa nodes
This commit is contained in:
Darragh Bailey 2017-08-17 21:24:20 +01:00 committed by GitHub
commit c8a2ed8f34
4 changed files with 43 additions and 30 deletions

View File

@ -300,7 +300,16 @@ end
* `cpu_fallback` - Whether to allow libvirt to fall back to a CPU model close
to the specified model if features in the guest CPU are not supported on the
host. Defaults to 'allow' if not set. Allowed values: `allow`, `forbid`.
* `numa_nodes` - Number of NUMA nodes on guest. Must be a factor of `cpu`.
* `numa_nodes` - Specify an array of NUMA nodes for the guest. The syntax is similar to what would be set in the domain XML. `memory` must be in MB. Symmetrical and asymmetrical topologies are supported but make sure your total count of defined CPUs adds up to `v.cpus`.
The sum of all the memory defined here will act as your total memory for your guest VM. **This sum will override what is set in `v.memory`**
```
v.cpus = 4
v.numa_nodes = [
{:cpus => "0-1", :memory => "1024"},
{:cpus => "2-3", :memory => "4096"}
]
```
* `loader` - Sets path to custom UEFI loader.
* `volume_cache` - Controls the cache mechanism. Possible values are "default",
"none", "writethrough", "writeback", "directsync" and "unsafe". [See

View File

@ -23,10 +23,14 @@ module VagrantPlugins
libvirt_domain = env[:machine].provider.driver.connection.client.lookup_domain_by_uuid(env[:machine].id)
# libvirt API doesn't support modifying memory on NUMA enabled CPUs
# http://libvirt.org/git/?p=libvirt.git;a=commit;h=d174394105cf00ed266bf729ddf461c21637c736
if config.numa_nodes == nil
if config.memory.to_i * 1024 != libvirt_domain.max_memory
libvirt_domain.max_memory = config.memory.to_i * 1024
libvirt_domain.memory = libvirt_domain.max_memory
end
end
begin
# XML definition manipulation
descr = libvirt_domain.xml_desc(1)
@ -124,7 +128,7 @@ module VagrantPlugins
cpu.delete_element(svm_feature)
end
end
else
elsif config.numa_nodes == nil
unless cpu.elements.to_a.empty?
descr_changed = true
cpu.elements.each do |elem|

View File

@ -279,26 +279,27 @@ module VagrantPlugins
end
def _generate_numa
raise 'NUMA nodes must be a factor of CPUs' if @cpus % @numa_nodes != 0
if @memory % @numa_nodes != 0
raise 'NUMA nodes must be a factor of memory'
@numa_nodes.collect { |x|
# Perform some validation of cpu values
unless x[:cpus] =~ /^\d+-\d+$/
raise 'numa_nodes[:cpus] must be in format "integer-integer"'
end
numa = []
# Convert to KiB
x[:memory] = x[:memory].to_i * 1024
}
(1..@numa_nodes).each do |node|
numa_cpu_start = (@cpus / @numa_nodes) * (node - 1)
numa_cpu_end = (@cpus / @numa_nodes) * node - 1
numa_cpu = Array(numa_cpu_start..numa_cpu_end).join(',')
numa_mem = @memory / @numa_nodes
# Grab the value of the last @numa_nodes[:cpus] and verify @cpus matches
# Note: [:cpus] is zero based and @cpus is not, so we need to +1
last_cpu = @numa_nodes.last[:cpus]
last_cpu = last_cpu.scan(/\d+$/)[0]
last_cpu = last_cpu.to_i + 1
numa.push(id: node,
cpu: numa_cpu,
mem: numa_mem)
if @cpus != last_cpu.to_i
raise 'The total number of numa_nodes[:cpus] must equal config.cpus'
end
@numa_nodes = numa
@numa_nodes
end
def cpu_feature(options = {})

View File

@ -15,15 +15,14 @@
<% @cpu_features.each do |cpu_feature| %>
<feature name='<%= cpu_feature[:name] %>' policy='<%= cpu_feature[:policy] %>'/>
<% end %>
<% else %>
<% end %>
<% if @numa_nodes %>
<numa>
<% @numa_nodes.each do |node| %>
<cell id='<%= node[:id] %>' cpus='<%= node[:cpu] %>' memory='<%= node[:mem] %>'/>
<% @numa_nodes.each_with_index do |node, index| %>
<cell id='<%= index %>' cpus='<%= node[:cpus] %>' memory='<%= node[:memory] %>'/>
<% end %>
</numa>
<% end %>
<% end %>
</cpu>