1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F OpenNebula/one#5599: Prefer cgv1 (#1860)

This commit is contained in:
Daniel Clavijo Coca 2022-03-18 13:54:08 -06:00 committed by GitHub
parent dd48079ed7
commit 0b886172b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 33 deletions

View File

@ -120,46 +120,49 @@ class LXCVM < OpenNebulaVM
# rubocop:disable Layout/LineLength
# Add cgroup limitations
cg_version = get_cgroup_version
# rubocop:disable Style/ConditionalAssignment
cg_set = if cgroup_ver == 2
CGROUP_NAMES.keys[1]
else
CGROUP_NAMES.keys[0]
end
# rubocop:enable Style/ConditionalAssignment
if cg_version != 0
# rubocop:disable Style/ConditionalAssignment
cg_set = if cg_version == 2
CGROUP_NAMES.keys[1]
else
CGROUP_NAMES.keys[0]
end
# rubocop:enable Style/ConditionalAssignment
pre= "lxc.#{cg_set}."
pre= "lxc.#{cg_set}."
lxc["#{pre}cpu.#{CGROUP_NAMES[cg_set][:cpu]}"] = cpu_shares
lxc["#{pre}cpu.#{CGROUP_NAMES[cg_set][:cpu]}"] = cpu_shares
numa_nodes = get_numa_nodes
numa_nodes = get_numa_nodes
if !numa_nodes.empty?
nodes = []
cores = []
if !numa_nodes.empty?
nodes = []
cores = []
numa_nodes.each do |node|
nodes << node['MEMORY_NODE_ID']
cores << node['CPUS']
numa_nodes.each do |node|
nodes << node['MEMORY_NODE_ID']
cores << node['CPUS']
end
lxc["#{pre}cpuset.#{CGROUP_NAMES[cg_set][:cores]}"] = cores.join(',')
lxc["#{pre}cpuset.#{CGROUP_NAMES[cg_set][:nodes]}"] = nodes.join(',')
end
lxc["#{pre}cpuset.#{CGROUP_NAMES[cg_set][:cores]}"] = cores.join(',')
lxc["#{pre}cpuset.#{CGROUP_NAMES[cg_set][:nodes]}"] = nodes.join(',')
memory = limits_memory
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:memory_max]}"] = memory
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:memory_low]}"] = "#{(memory.chomp.to_f*0.9).ceil}M"
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:swap]}"] = limits_memory_swap('LXC_SWAP') if swap_limitable?
# Avoid OOM to kill the process when limit is reached
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:oom]}"] = 1
# rubocop:enable Layout/LineLength
end
memory = limits_memory
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:memory_max]}"] = memory
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:memory_low]}"] = "#{(memory.chomp.to_f*0.9).ceil}M"
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:swap]}"] = limits_memory_swap('LXC_SWAP') if swap_limitable?
# Avoid OOM to kill the process when limit is reached
lxc["#{pre}memory.#{CGROUP_NAMES[cg_set][:oom]}"] = 1
# rubocop:enable Layout/LineLength
# User mapping
# rubocop:disable Layout/LineLength

View File

@ -83,10 +83,11 @@ class OpenNebulaVM
end
# Returns cgroup version
def cgroup_ver
return 2 unless `mount | grep 'cgroup2 on '`.empty?
def get_cgroup_version
return 1 unless `mount | grep "type cgroup ("`.empty?
return 2 unless `mount | grep "type cgroup2 ("`.empty?
1
0
end
def wild?