mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
F #4089: add CPU limitations
This commit is contained in:
parent
b0ffa98b49
commit
48216ca955
@ -54,6 +54,8 @@ end
|
||||
|
||||
# Start VNC (only started if necessary)
|
||||
microvm.vnc('start')
|
||||
# Set cpu.shares (only if configured)
|
||||
microvm.set_cpu_limit
|
||||
|
||||
# Set deploy_id
|
||||
puts "one-#{vm_id}"
|
||||
|
@ -58,6 +58,11 @@
|
||||
#
|
||||
# Timeout to wait a cgroup to be empty after shutdown/cancel a microVM
|
||||
:cgroup_delete_timeout: 60
|
||||
#
|
||||
# If true the cpu.shares will be set acording to the VM CPU value if false the
|
||||
# cpu.shares is left by default which means that all the resources are shared
|
||||
# equally acrros the VMs
|
||||
:cgroup_cpu_shares: true
|
||||
|
||||
################################################################################
|
||||
# NUMA placement Options
|
||||
|
@ -148,6 +148,18 @@ class MicroVM
|
||||
rescue Errno::ENOENT # rubocop:disable Lint/SuppressedException
|
||||
end
|
||||
|
||||
def cpu_shares(cpu)
|
||||
# default value for cpu.shares
|
||||
default_value = 1024
|
||||
|
||||
shares_val = (cpu * default_value).round
|
||||
|
||||
# The value specified in the cpu.shares file must be 2 or higher.
|
||||
shares_val = 2 if shares_val < 2
|
||||
|
||||
shares_val
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# VNC
|
||||
#---------------------------------------------------------------------------
|
||||
@ -253,4 +265,14 @@ class MicroVM
|
||||
# rubocop:enable Naming/AccessorMethodName
|
||||
# rubocop:enable Layout/LineLength
|
||||
|
||||
def set_cpu_limit
|
||||
return unless @one.fcrc[:cgroup_cpu_shares]
|
||||
|
||||
shares_location = "#{@one.fcrc[:cgroup_location]}/cpu/" \
|
||||
"firecracker/one-#{@one.vm_id}/cpu.shares"
|
||||
|
||||
cmd = "echo #{cpu_shares(@one.get_cpu)} > #{shares_location}"
|
||||
`echo "AAA#{Command.execute_once(cmd, false)}" > /tmp/a`
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -99,6 +99,10 @@ class OpenNebulaVM
|
||||
@vm_name && !@vm_name.include?('one-')
|
||||
end
|
||||
|
||||
def get_cpu
|
||||
Float(@xml['//TEMPLATE/CPU'])
|
||||
end
|
||||
|
||||
# Returns a Hash representing the LXC configuration for this OpenNebulaVM
|
||||
def to_fc
|
||||
fc = {}
|
||||
@ -127,9 +131,10 @@ class OpenNebulaVM
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Container Attribute Mapping
|
||||
# MicroVM Attribute Mapping
|
||||
#---------------------------------------------------------------------------
|
||||
# Creates a dictionary for Firecracker containing $MEMORY RAM allocated
|
||||
# Creates a dictionary for Firecracker containing vm information
|
||||
|
||||
def boot_source(hash)
|
||||
hash['kernel_image_path'] = 'kernel'
|
||||
hash['boot_args'] = @boot_args
|
||||
|
Loading…
x
Reference in New Issue
Block a user