这篇文章主要介绍如何实现openstack主机内存ram超额分配,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
openstack提供资源利用率的方式一种主要途径是创建虚拟机时对内存进行超额分配。在对物理主机的选择策略如下代码所示:
def host_passes(self, host_state, filter_properties):
"""Only return hosts with sufficient available RAM."""
instance_type = filter_properties.get('instance_type')
requested_ram = instance_type['memory_mb']
free_ram_mb = host_state.free_ram_mb
total_usable_ram_mb = host_state.total_usable_ram_mb
ram_allocation_ratio = self._get_ram_allocation_ratio(host_state,
filter_properties)
memory_mb_limit = total_usable_ram_mb * ram_allocation_ratio
used_ram_mb = total_usable_ram_mb - free_ram_mb
usable_ram = memory_mb_limit - used_ram_mb
if not usable_ram >= requested_ram:
LOG.debug("%(host_state)s does not have %(requested_ram)s MB "
"usable ram, it only has %(usable_ram)s MB usable ram.",
{'host_state': host_state,
'requested_ram': requested_ram,
'usable_ram': usable_ram})
return False
# save oversubscription limit for compute node to test against:
host_state.limits['memory_mb'] = memory_mb_limit
return True
total_usable_ram_mb为物理主机所能提供的物理内存,如4G,8G,ram_allocation_ration为内存超额分配系数,在nova.conf中设置。openstack默认超额分配系数为1.5。free_ram_mb为主机剩余内存值,该值可为负数。used_ram_mb为以分配内存,一般为该主机上已创建虚拟机内存总和。memory_mb_limit为超额后的内存,当剩余可以可用的useble_ram内存小于虚拟机的创建时所需内存时,表示该主机无法创建虚拟机,系统将不会选择该主机创建虚拟机。
以上是“如何实现openstack主机内存ram超额分配”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注天达云行业资讯频道!