我在装有 Centos 6.5、qemu+KVM 和 2 个虚拟主机(位于 NAT 后面)的主机上。两个虚拟主机都配置了虚拟机管理器(其中一个装有 Windows 2003,另一个装有 Centos 6.5),两个都有固定的内存(8GB 和 4GB)。我有 2 个问题/疑问。
如果我在 Virt.manager 中配置了不固定的 RAM 容量(例如允许使用 4Gb 到 8Gb),我的虚拟机会占用主机中所有可用的内存(超过 8Gb)
在主机的 htop 中,我看到每个虚拟机都没有一个 qemu 进程,而是同一台虚拟机有很多进程。出了什么问题?
如果我进入 virt.machine 并检查 free -m,我会发现有很多可用内存。
添加(VM domxml):
<domain type='kvm'>
<name>myvm</name>
<uuid>27934a14-b54e-1e4e-65de-7f6d03b1e7ce</uuid>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static'>2</vcpu>
<os>
<type arch='x86_64' machine='rhel6.6.0'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/libexec/qemu-kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/var/lib/libvirt/images/myvm.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</disk>
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='network'>
<mac address='52:54:00:99:ee:4f'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='tablet' bus='usb'/>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
</domain>
添加了“ps -ef | grep myvm”的输出:
qemu 8105 1 21 四月23? 06:23:05 /usr/libexec/qemu-kvm -name myvm -S -M rhel6.6.0 -enable-kvm -m 8192 -realtime mlock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 27934a14-b54e-1e4e-65de-7f6d03b1e7ce -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/myvm.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-shutdown -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,总线=pci.0,多功能=开,地址=0x5 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,总线=pci.0,地址=0x5.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,总线=pci.0,地址=0x5.0x2 -drive file=/var/lib/libvirt/images/myvm.img,if=none,id=drive-virtio-disk0,format=raw,cache=none -device virtio-blk-pci,scsi=off,总线=pci.0,地址=0x6,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive如果=无,媒体=cdrom,id=drive-ide0-1-0,readonly=on,格式=raw -device ide-drive,总线=ide.1,单元=0,驱动器=drive-ide0-1-0,id=ide0-1-0 -netdev tap,fd=22,id=hostnet0,vhost=on,vhostfd=23 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:99:ee:4f,总线=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,总线=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,总线=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,总线=pci.0,addr=0x7 -msg 时间戳=on
答案1
- 使用的内存是已声明的页面,不一定在虚拟机中使用。如果情况紧急,KSM 可以清除这些页面(我通常在主机内存使用率达到 80% 时运行它)
- 每个虚拟 CPU 都是一个进程,因此您可以为每个虚拟核心(而不是每个 VM)获取一个进程。这也是 KVM 避免组调度的原因,就像您在 VMWare 中看到的那样。