Nova:libvirt image 的生命周期

翻译自:http://www.pixelbeat.org/docs/openstack_libvirt_images/

The main stages of a Virtual Machine disk image as it transfers through OpenStack to be booted under libvirt are:

Initially the image is downloaded from glance and cached in libvirt base. We‘ll consider the options for handling a qcow2 image stored in glance, as that format can be downloaded quite efficiently from glance as it supports compression, and image sparseness can be maintained. This article will focus on the flow and transformations in "libvirt base", which is used to cache, preprocess and optionally back, VM disk images.

Configuration

First we‘ll summarize the config variables involved, before presenting the operations associated with each config combination, in each OpenStack release. Note I‘m describing upstream OpenStack here, and not my employer‘s Red Hat OpenStack which has back-ported enhancements between versions where appropriate.

Config Default Release Description
use_cow_images True Cactus Whether to use CoW images for "libvirt instance disks"
force_raw_images True Essex Allows disabling convert to raw in "libvirt base" for operational reasons
libvirt_images_type ‘default‘ Folsom Deprecates use_cow_images and allows selecting LVM libvirt images
[libvirt]/images_type ‘default‘ Icehouse Deprecates libvirt_images_type in the [DEFAULT] section
preallocate_images ‘none‘ Grizzly Instance disks preallocation mode. ‘space‘ => fallocate images
resize_fs_using_block_device False Havana Allows enabling of direct resize for qcow2 images

The main reason that raw images are written in "libvirt base" by default (since Diablo), is to remove possible compression from the qcow2 image received from glance. Note compression in qcow2 images is read only, and so this will impact reads from unwritten portions of the qcow2 image. Users may want to change this option, depending on CPU resources and I/O bandwidth available. For example, systems with slower I/O or less space available, may want to trade the higher CPU requirements of compression, to minimize input bandwidth. Note raw images are used unconditionally with libvirt_images_type=lvm.

Whether to use CoW images for the "libvirt instance disks" also depends on I/O characteristics of the user‘s system. Without CoW, more space will be used for common parts of the disk image, but on the flip side depending on the backing store and host caching, there may be better concurrency achieved by having each VM operate on its own copy.

Enabling preallocation of space for the "libvirt instance disks" can help with both space guarantees and I/O performance. Even when not using CoW instance disks, the copy each VM gets is sparse and so the VM may fail unexpectedly at run time with ENOSPC. By running fallocate(1) on the instance disk images, we immediately and efficiently allocate the space for them in the file system (if supported). Also run time performance should be improved as the file system doesn‘t have to dynamically allocate blocks at run time, reducing CPU overhead and more importantly file fragmentation.

Disk image operations

For each release and config combination, here are the created files and associated operations in getting a qcow2 image from glance through to being booted in a libvirt Virtual Machine.

Folsom, force_raw_images=True, use_cow_images=True

This results in each instance booting from a CoW image, backed by a resized raw image.

Nova command Source code Notes
wget http://glance/$image -O base_/$hex.part images.fetch  
qemu-img convert -O raw $hex.part $hex.converted images.fetch_to_raw Creates sparse file
mv $hex.converted $hex; rm $hex.part images.fetch_to_raw  
  imagebackend.create_image  
cp $hex $hex_$size   libvirt.utils.copy_image Creates sparse file
qemu-img resize $hex_$size $size   disk.extend  
resize2fs $hex_size   disk.extend Unpartitioned ext[234]
qemu-img create -f qcow2 -o backing_file=... $instance_dir/disk   libvirt.utils.create_image  

Folsom, force_raw_images=True, use_cow_images=False

This results in each instance booting from a copy of a resized raw image.

Nova command Source code Notes
wget http://glance/$image -O base_/$hex.part images.fetch  
qemu-img convert -O raw $hex.part $hex.converted images.fetch_to_raw Creates sparse file
mv $hex.converted $hex; rm $hex.part images.fetch_to_raw  
  imagebackend.create_image  
cp $hex $instance_dir/disk   libvirt.utils.copy_image  
qemu-img resize disk   disk.extend  
resize2fs disk   disk.extend Unpartitioned ext[234]

Folsom, force_raw_images=False, use_cow_images=False

This results in each instance booting from a copy of a resized qcow2 image.

Nova command Source code Notes
wget http://glance/$image -O base_/$hex.part images.fetch  
mv $hex.part $hex images.fetch_to_raw  
  imagebackend.create_image  
cp $hex $instance_dir/disk   libvirt.utils.copy_image  
qemu-img resize disk   disk.extend  
resize2fs disk   disk.extend Ignored for qcow2 ¹

Folsom, force_raw_images=False, use_cow_images=True

This results in each instance booting from a CoW image, backed by a resized qcow2 image.

Nova command Source code Notes
wget http://glance/$image -O base_/$hex.part images.fetch  
mv $hex.part $hex images.fetch_to_raw  
  imagebackend.create_image  
cp $hex $hex_$size   libvirt.utils.copy_image  
qemu-img resize $hex_$size $size   disk.extend  
resize2fs $hex_size   disk.extend Ignored for qcow2 ¹
qemu-img create -f qcow2 -o backing_file=... $instance_dir/disk   libvirt.utils.create_image  

Grizzly, force_raw_images=True, use_cow_images=True

Grizzly introduces a change for use_cow_images=True, where it will resize in the $instance_dir rather than in base_. So the resize will not be cached, but this is minimal CPU tradeoff per instance boot, for the extra space saved in base_. We‘ll just present the default config values here which illustrates the only significant change from Folsom.
This results in each instance booting from a resized CoW image, backed by a raw image.

Nova command Source code Notes
wget http://glance/$image -O base_/$hex.part images.fetch  
qemu-img convert -O raw $hex.part $hex.converted images.fetch_to_raw Creates sparse file
mv $hex.converted $hex; rm $hex.part images.fetch_to_raw  
  imagebackend.create_image  
qemu-img create -f qcow2 -o backing_file=... $instance_dir/disk   libvirt.utils.create_image  
qemu-img resize disk $size   disk.extend  
resize2fs disk   disk.extend Grizzly always ignores ²

[² Update Sep 2013: Stanislaw Pitucha also noticed that the above referenced Grizzly change introduced a regression where unpartitioned qcow2 images were no longer resized. See the Havana resize_fs_using_block_device option below for details.]

Grizzly, preallocate_images=‘space‘

Grizzly also has new fallocate functionality in this area controlled by the preallocate_images config option. If that is set to ‘space‘, then after the operations above, the $instance_dir/ images will be fallocated to immediately determine if enough space is available, and to possibly improve VM I/O performance due to ongoing allocation avoidance, and better locality of block allocations.

¹ Havana, resize_fs_using_block_device=False

As noted in the first Grizzly change above, Stanislaw Pitucha noticed that change introduced a regression where unpartitioned qcow2 images were no longer resized. He supplied a fix to resize qcow directly rather than relying on the raw image being available, which would also cater for the force_raw_images=False case that even pre Grizzly did not. This new option can be used to enable this support, but there are some large performance and possible security issues so it‘s not enabled by default. This support will be available in the upcoming Havana release.

General performance considerations

Performance has improved in this area through each OpenStack release, with some of the main topics to consider, for past and future changes being:

Minimize I/O

Note these were implemented in Essex:

  • Copy images, then resize, rather than vice versa
  • Directly generating images in the $instance_dir/
  • Intelligent reading of sparse input
  • Reproduction of sparse input on output
  • Use compression

Note this was implemented in Folsom:

Minimize storage

  • Use compression
  • Use sparse output/generation
  • Avoid resized copies when not needed
  • Use CoW if appropriate

Improve caching

  • Avoid thrashing the page cache with large intermediate images
  • Improve low level caching through better storage allocation

Preprocessing

    • Preprocessing may be possible on images like preallocation=metadata which trades off initial CPU cost for possibly much better run time I/O performance
    • Such cost would be some what alleviated by having asynchronous population of the base_ cache
时间: 2024-12-14 03:11:46

Nova:libvirt image 的生命周期的相关文章

KVM 介绍(6):Nova 通过 libvirt 管理 QEMU/KVM 虚机 [Nova Libvirt QEMU/KVM Domain]

学习 KVM 的系列文章: (1)介绍和安装 (2)CPU 和 内存虚拟化 (3)I/O QEMU 全虚拟化和准虚拟化(Para-virtulizaiton) (4)I/O PCI/PCIe设备直接分配和 SR-IOV (5)libvirt 介绍 (6)Nova 通过 libvirt 管理 QEMU/KVM 虚机 1. Libvirt 在 OpenStack 架构中的位置 在 Nova Compute 节点上运行的 nova-compute 服务调用 Hypervisor API 去管理运行在该

iOS程序执行顺序和UIViewController 的生命周期(整理)

说明:此文是自己的总结笔记,主要参考: iOS程序的启动执行顺序 AppDelegate 及 UIViewController 的生命周期 UIView的生命周期 言叶之庭.jpeg 一. iOS程序的启动执行顺序 程序启动顺序图 iOS启动原理图.png 具体执行流程 程序入口进入main函数,设置AppDelegate称为函数的代理 程序完成加载[AppDelegate application:didFinishLaunchingWithOptions:] 创建window窗口 程序被激活[

android Activity 的生命周期 以及横屏竖屏切换时 Activity 的状态变化

生命周期Android 系统在Activity 生命周期中加入一些钩子,我们可以在这些系统预留的钩子中做一些事情.例举了 7 个常用的钩子:protected void onCreate(Bundle savedInstanceState)protected void onStart()protected void onResume()protected void onPause()protected void onStop()protected void onRestart()protecte

连载《一个程序猿的生命周期》-《发展篇》- 12.向生活妥协的选择之路,你也面临吗?

本篇文章的主角是第二个加入我们团队的,暂且称他为G兄.是我第二家公司的同事,但是当时并没有交集,后来经过其他同事说起,被我招过来的.关于第二家公司的情况,请参见<而立之年,第一次跳槽,寻求转型> 在加入我们团队之前,G兄在一个不大不小的公司做内部OA系统,众所周知不会有什么太大发展,他当时也不太满意.在和他交流的过程中,我说的很直接:1.开发公司内部OA,并非公司实际产品,无法直接创造利润,就算是公司的产品,现在做OA的多了去了.2.OA开发完成后,只剩运维人员,假设裁掉一部分人员的话,你怎么

【Vue】详解Vue生命周期

Vue实例的生命周期全过程(图) (这里的红边圆角矩形内的都是对应的Vue实例的钩子函数) 在beforeCreate和created钩子函数间的生命周期 在beforeCreate和created之间,进行数据观测(data observer) ,也就是在这个时候开始监控data中的数据变化了,同时初始化事件 created钩子函数和beforeMount间的生命周期 对于created钩子函数和beforeMount间可能会让人感到有些迷惑,下面我就来解释一下: el选项的有无对生命周期过程

vue 生命周期初探

vue 以后发之势加上其独有的特性(压缩后很小),轻量级的MVVM框架,目前github star已有5.94万,而react 7万.由此可见是两个非常热门前端框架.这里就vue的生命周期做个初步体验. 发现看视频,动手之后,过段时间还是会忘,所以写一篇短文以备不时之需. 先附上官网的图片:vue生命周期 生命周期的钩子函数如果使用得当,会大大增加开发效率: 生命周期实践: 为了更好的查看beforeUpdate.updated,beforeDestroy,destroy钩子函数,使用v-on绑

1.2软件生命周期&amp;测试流程

软件的生命周期 可行性分析-需求分析-软件设计-软件编码-软件测试-软件维护 1.可行性分析 主要确定软件开发的目的和可行性(PM) 2.需求分析 对软件的功能进行详细的分析(PM),输出需求规格说明书(原型图) 3.软件设计(DEV) 把需求分析得到的结果转换为软件结构和数据结构,形成系统架构 概要设计:搭建架构.模块功能.接口连接和数据传输 详细设计:模块深入分析,对各模块组合进行分析,伪代码   包含数据库设计说明 4.软件编码(DEV) 可运行的程序代码 5.软件测试 5.1.单元测试(

ASP.NET页面生命周期与控件生命周期

ASP.NET页面生命周期 (1)PreInit 预初始化(2)Init 初始化(3)InitComplete 初始化完成(4)PreLoad 预加载(5)Load 加载(6)LoadComplete 加载完成(7)PreRender 预输出(8)PreRenderComplete 预输出完成(9)Unload 卸载 ASP.NET控件生命周期 -- 实例化(Instantiate) 控件被页面或另一个控件通过调用它的构造器所实例化.这个步骤之后所列出的阶段,仅当控件加入控件树中才会发生. --

Servlet简介与生命周期

转载请注明原文地址: 一:Servlet是什么 Servlet是运行在Web服务器上的Java程序,作为处理来自 Web 浏览器或其他 HTTP 客户端的请求和 HTTP 服务器上的数据库或应用程序之间的中间层.JSP在web服务器上要先转换成servlet,然后才能在JVM运行,并把结果拼接成浏览器可识别的文件(如html)传回浏览器显示. 二:Servlet的应用场景 单纯地对客户端的请求做处理时,如果我们用纯JSP文件(即:只有Java语句)来处理的话,还需要先转换为servlet才能运行