kvm主机内存与来宾内存

kvm主机内存与来宾内存

我现在尝试了解 qemu-kvm 内存开销。从主机操作系统中,我们可以找到-m 8192,这意味着我已经为客户分配了8GB内存。

qemu     2813877  0.5  0.2 30472752 1103620 ?    Sl   Jan05 1178:13 /usr/libexec/qemu-kvm -name instance-000003db -S -machine pc-i440fx-rhel7.1.0,accel=kvm,usb=off -cpu Haswell,+abm,+pdpe1gb,+rdrand,+f16c,+osxsave,+dca,+pdcm,+xtpr,+tm2,+est,+smx,+vmx,+ds_cpl,+dtes64,+pbe,+tm,+ht,+ss,+acpi,+ds,+vme,-rtm,-hle -m 8192 -realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid 886db7b2-79b6-4a8a-8b34-4e7001377da9 -smbios type=1,manufacturer=Fedora Project,product=OpenStack Nova,version=12.0.5-2.el7.centos.ustack,serial=168f720b-7801-453d-8d2e-99aed5ade6cd,uuid=886db7b2-79b6-4a8a-8b34-4e7001377da9,family=Virtual Machine -no-user-config -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/domain-instance-000003db/monitor.sock,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=discard -no-hpet -no-shutdown -boot strict=on -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=rbd:openstack-00/886db7b2-79b6-4a8a-8b34-4e7001377da9_disk.config:id=admin:key=AQD7kyJQQGoOBhAAqrPAqSopSwPrrfMMomzVdw==:auth_supported=cephx\;none:mon_host=55.3.52.1\:6789\;55.3.52.11\:6789\;55.3.52.21\:6789,if=none,id=drive-ide0-1-1,readonly=on,format=raw,cache=writeback -device ide-cd,bus=ide.1,unit=1,drive=drive-ide0-1-1,id=ide0-1-1 -drive file=rbd:openstack-00/volume-beeea3a3-44c8-4c36-835c-08bfdc9f61db:id=admin:key=AQD7kyJQQGoOBhAAqrPAqSopSwPrrfMMomzVdw==:auth_supported=cephx\;none:mon_host=55.3.52.1\:6789\;55.3.52.11\:6789\;55.3.52.21\:6789,if=none,id=drive-virtio-disk0,format=raw,serial=beeea3a3-44c8-4c36-835c-08bfdc9f61db,cache=writeback -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 -drive file=rbd:openstack-00/volume-3be22eb0-6847-4366-a1ac-fcc8ddd87761:id=admin:key=AQD7kyJQQGoOBhAAqrPAqSopSwPrrfMMomzVdw==:auth_supported=cephx\;none:mon_host=55.3.52.1\:6789\;55.3.52.11\:6789\;55.3.52.21\:6789,if=none,id=drive-virtio-disk1,format=raw,serial=3be22eb0-6847-4366-a1ac-fcc8ddd87761,cache=writeback -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk1,id=virtio-disk1 -drive file=rbd:openstack-00/volume-4630e604-d404-4492-b861-44785274595f:id=admin:key=AQD7kyJQQGoOBhAAqrPAqSopSwPrrfMMomzVdw==:auth_supported=cephx\;none:mon_host=55.3.52.1\:6789\;55.3.52.11\:6789\;55.3.52.21\:6789,if=none,id=drive-virtio-disk2,format=raw,serial=4630e604-d404-4492-b861-44785274595f,cache=writeback -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x6,drive=drive-virtio-disk2,id=virtio-disk2 -netdev tap,fd=31,id=hostnet0,vhost=on,vhostfd=32 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=fa:16:3e:43:9b:d4,bus=pci.0,addr=0x3 -chardev file,id=charserial0,path=/var/lib/nova/instances/886db7b2-79b6-4a8a-8b34-4e7001377da9/console.log -device isa-serial,chardev=charserial0,id=serial0 -chardev pty,id=charserial1 -device isa-serial,chardev=charserial1,id=serial1 -device usb-tablet,id=input0 -vnc 0.0.0.0:2 -k en-us -device cirrus-vga,id=video0,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x7 -msg timestamp=on

另外,我在 ; 下找到了这部分内存/proc/pid/smaps;由此我们可以知道它等于8192MB。

7f6714000000-7f6914000000 rw-p 00000000 00:00 0
Size:            8388608 kB ===>8192MB
Rss:              953304 kB
Pss:              953304 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:      8508 kB
Private_Dirty:    944796 kB
Referenced:       927352 kB
Anonymous:        953304 kB
AnonHugePages:    839680 kB
Swap:             455556 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:                0 kB

但是,当我使用“free”检查 guest OS 下的内存大小时,guestOS 上只剩下 7872MB 了。

[root@host-10-3-0-221 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          7872        950       6921          0        220        303
-/+ buffers/cache:        426       7446
Swap:         8191          0       8191

我想知道为什么guest中的总大小小于8192MB。

答案1

我在 KVM 和 VMWare 中都看到了这一点,原因是虚拟机管理程序用于处理虚拟机的内存开销,例如让内存过度使用、动态分配和共享内存工作。

我还没有找到任何 kvm 特定的论文,但 vmware 论坛上有一个关于这个问题的很好的帖子:https://communities.vmware.com/message/1994605

相关内容