KVM本身并不提供半虚拟化功能,是通过virtio来实现的

The benefits of virtio drivers are of lower overhead and higher performance.

Memory Ballooning (virtio_balloon)

memory ballooning可以动态调整guest的内存的大小

如果有-m参数,则向更大的内存调整时无效的,但是可以往小的里面调整

我们首先ssh到guest里面

ip netns exec qrouter-26a45e0e-a58a-443b-a972-d62c0c5a1323 ssh -i openstack.pem ubuntu@192.168.0.35

在虚拟机里面看内存的大小

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       2051748     478276    1573472          0      46620     345908
-/+ buffers/cache:      85748    1966000
Swap:            0          0          0

在Monitor上看balloon的大小

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=2048

我们试图往大里调整

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "balloon 4096"

发现无效

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=2048

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       2051748     478276    1573472          0      46628     345920
-/+ buffers/cache:      85728    1966020
Swap:            0          0          0

我们往小里调整内存

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "balloon 1024"

发现生效了

root:/home/cliu8# virsh qemu-monitor-command instance-00000024 --hmp "info balloon"
balloon: actual=1024

ubuntu@testinject19:~$ free
             total       used       free     shared    buffers     cached
Mem:       1003172     470796     532376          0      46636     345920
-/+ buffers/cache:      78240     924932
Swap:            0          0          0

有了balloon,如果guest需要更多的RAM,则可以给它增加一些内存。如果guest不需要那么多内存,可以通过balloon从中拿出一部分内存。这个过程,不需要启停虚拟机。

balloon driver像是一个特殊的process,运行在guest机器上,它可以扩大自己的内存,使得其他的应用程序的内存减少,也可以缩小内存,使得其他的应用程序内存增加。

guest中的balloon driver通过virtio channel和host进行交互,接收host发来的命令,比如发来的命令式减少内存,则balloon driver就扩大它的内存占有量。

然后balloon driver将自己占有的内存交回给host,使得host有了更多的内存。

对于libvirt而言,有currentMemory和maxMemory两种概念,maxMemory就是-m参数设定的,currentMemory就是balloon设定的。

Para-virtualized network interface cards (virtio_net)

-netdev tap,fd=32,id=hostnet0,vhost=on,vhostfd=37
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:d1:2d:99,bus=pci.0,addr=0x3

Para-virtualized block devices (virtio_blk)

-drive file=/var/lib/nova/instances/1f8e6f7e-5a70-4780-89c1-464dc0e7f308/disk,if=none,id=drive-virtio-disk0,format=qcow2,cache=none
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1

QEMU KVM Libvirt手册(8): 半虚拟化设备virtio的更多相关文章

  1. QEMU KVM Libvirt手册(7): 硬件虚拟化

    在openstack中,如果我们启动一个虚拟机,我们会看到非常复杂的参数 qemu-system-x86_64 -enable-kvm -name instance-00000024 -S -mach ...

  2. QEMU KVM Libvirt手册(11): Managing Storage

    When managing a VM Guest on the VM Host Server itself, it is possible to access the complete file sy ...

  3. QEMU KVM Libvirt手册(10):Managing Virtual Machines with libvirt

    libvirt is a library that provides a common API for managing popular virtualization solutions, among ...

  4. QEMU KVM libvirt 手册(1): 安装

    安装 对虚拟化的支持通常在BIOS中是禁掉的,必须开启才可以. 对于Intel CPU,我们可以通过下面的命令查看是否支持虚拟化. # grep "vmx" /proc/cpuin ...

  5. QEMU KVM libvirt手册(4) – images

    RAW raw是默认的格式,格式简单,容易转换为其他的格式.需要文件系统的支持才能支持sparse file 创建image # qemu-img create -f raw flat.img 10G ...

  6. QEMU KVM libvirt 手册(3) - Storage Media

    访问Hard Drive 使用-hda –hdb qemu-system-x86_64 -enable-kvm -name ubuntutest  -m 2048 -hda ubuntutest.im ...

  7. QEMU KVM Libvirt手册(10): KVM的各种限制

    Overcommits KVM allows for both memory and disk space overcommit. However, hard errors resulting fro ...

  8. QEMU KVM Libvirt手册(5) – snapshots

    前面讲了QEMU的qcow2格式的internal snapshot和external snapshot,这都是虚拟机文件格式的功能. 这是文件级别的. 还可以是文件系统级别的,比如很多文件系统支持s ...

  9. QEMU KVM libvirt手册(2): monitor

    Administrating Virtual Machines with QEMU Monitor When QEMU is running, a monitor console is provide ...

随机推荐

  1. 重磅推出:AutoProject Studio 自动化项目生成器

    AutoProject Studio 自动化项目生成器 核心架构图 AutoProject Studio 自动化项目生成器是一款基于C#.Net Framework 4.0为平台自主研发.专为软件设计 ...

  2. SpringBoot热部署

    SpringBoot的热部署方式分为两种  1.SpringLoader 方式一:以maven插件方式使用SpringLoader <!-- Springloader插件 --> 1.1 ...

  3. shiro登录密码加密

    密码加密 String passwd = new SimpleHash("SHA-1", "username", "password").t ...

  4. 一个类,有新增元素(add)和获取元素数量(size)方法。 启动两个线程。线程1向容器中新增数据。线程2监听容器元素数量,当容器元素数量为5时,线程2输出信息并终止

    方式一: /** * 两个线程要是可见的所以要加上votalile */public class Test_01 { public static void main(String[] args) { ...

  5. 从BAT这种公司平薪跳槽头条,是否值得?

    有一个朋友之前就职于阿里,之前交流关于跳槽的问题,具体是这样的:阿里工作3年,拿到了头条的offer.但是非常纠结要不要接的问题.于是几个朋友聚在了一起讨论了这个问题 而且最近好多读者也在参加面试,接 ...

  6. Git帮助之初始化项目设置向导

    初始化项目设置向导 Git设置: git config --global user.name "Your Name Here" # 设置Git提交时的默认用户名,推荐使用本站用户名 ...

  7. linux学习--2019-04-22

    1.写命令,vi编辑器 1)vi 文件名 2) 按 ‘i’ 进入编辑模式 3)编写完成后,按Esc,然后输入 “:wq” 推出编辑.(“q!”不存盘,强制退出vi) 2.命令补全 “Tab” 3.获取 ...

  8. selenium操作浏览器窗口最大化和刷新

    实际测试过程中经常遇到打开一个页面并不是全屏显示,但是却希望它能够全屏显示或者新增一条记录后需要刷新一下看能不能再列表中正常显示. 于是就有了今天的关于对浏览器窗口的最大化和刷新页面.需要说明的一点: ...

  9. Aspnet Mvc 前后端分离项目手记(二)关于token认证

    在前后端分离的项目中,首先我们要解决的问题就是身份认证 以往的时候,我们使用cookie+session,或者只用cookie来保持会话. 一,先来复习一下cookie和session 首先我们来复习 ...

  10. 普通用户添加sudo权限

    1.切换超级用户 su - root 2.编辑配置文件 vim /etc/sudoers ## Allow root to run any commands anywhere root ALL=(AL ...