1. 程式人生 > >OpenStack中計算disk資源的方式(by quqi99)

OpenStack中計算disk資源的方式(by quqi99)

版權宣告:可以任意轉載,轉載時請務必以超連結形式標明文章原始出處和作者資訊及本版權宣告 (作者:張華 發表於:2018-06-22)

使用disk-overcommit引數可允許超載, 這時, 下面的disk_available_least是有可能為負數的. 例如建立一個和計算節點可用磁碟大小相同的虛機(eg: 該計算節點磁碟大小總數為38G)
$ nova hypervisor-show 2 |grep local_gb
| local_gb | 38 |
| local_gb_used | 0 |

nova flavor-create big-flavor auto 2048 38 1
openstack server create --wait --image xenial --flavor big-flavor --key-name testkey --nic net-id=$(neutron net-list |grep ’ private ’ |awk ‘{print $2}’) i1

$ nova hypervisor-show 2 |egrep -i ‘(disk|_gb)’
| disk_available_least | -3 |
| free_disk_gb | 0 |
| local_gb | 38 |
| local_gb_used | 38 |

注意一點, 想要成功建立上述虛機, 需配置(juju config nova-cloud-controller disk-allocation-ratio=5), 這樣nova-scheduler中的下列公式才能讓這個建立請求執行:
disk_mb_limit = total_usable_disk_mb * disk_allocation_ratio
used_disk_mb = total_usable_disk_mb - free_disk_mb
usable_disk_mb = disk_mb_limit - used_disk_mb
if not usable_disk_mb >= requested_disk:

這樣, 當做migrate的時候 (openstack server migrate --live juju-9effa2-xenial-mitaka-8 --block-migration --disk-overcommit i1 --debug), 如何充許超載, 就不能使用可為負數的disk_available_least, 而應該使用實際大小free_disk_gb ( https://review.openstack.org/#/c/536351/)
if disk_over_commit:
disk_available_gb = dst_compute_info[‘free_disk_gb’]
else:
disk_available_gb = dst_compute_info[‘disk_available_least’]

注: 上述disk_available_least經下列公式計算得出, 其中disk_over_committed為統計的每個虛機的 (virtual_size - disk_size) 之和.
available_least = disk_free_gb * units.Gi - disk_over_committed
disk_over_committed = The sum of (virtual_size - disk_size) for all virtual disk
[email protected]:~$ qemu-img info /var/lib/nova/instances/dfcd087a-5dff-439d-8875-2f702f081539/disk |grep size
virtual size: 38G (40802189312 bytes)
disk size: 21M
cluster_size: 65536

(Pdb) p disk_infos
[{u’disk_size’: 22806528, u’type’: u’qcow2’, u’virt_disk_size’: 40802189312, u’path’: u’/var/lib/nova/instances/dfcd087a-5dff-439d-8875-2f702f081539/disk’, u’backing_file’: u’b8a746c6056b30fe58188451cf31b51648210d9f’, u’over_committed_disk_size’: 40779382784}]

其中free_disk_gb是由get_available_resource in nova/virt/libvirt/driver.py用於統計磁碟資訊:
hddinfo = os.statvfs(path)
total = hddinfo.f_frsize * hddinfo.f_blocks
free = hddinfo.f_frsize * hddinfo.f_bavail
used = hddinfo.f_frsize * (hddinfo.f_blocks - hddinfo.f_bfree)

但nova直接使用了上面的total和used, 卻沒有直接使用free, 而是使用avaliable_least代替free:
available_least = disk_free_gb * units.Gi - disk_over_committed