KVM max memory allocation

I did some research regarding max VM memory allocation. Finding is that the memory limitation for KVM VMs is min(mmap can give, 1T). So in general, that's going to be the amount of virtual memory mmap can give unless the host has huge amount of physical memory/turns on blind memory overcommitment/has huge swap space. Below is some technical details on how this limitation is determined. 

The amount of physical memory that can be allocated to a guest is capped by the amount of virtual memory that the associated qemu process can obtain - https://github.com/qemu/qemu/blob/stable-2.0/util/oslib-posix.c#L119 (pc_init -> pc_memory_init -> memory_region_init_ram -> qemu_ram_alloc -> qemu_ram_alloc_from_ptr -> qemu_anon_ram_alloc). So the problem comes to how much memory mmap can allocate before it gives ENOMEM, which is determined by the overcommit setting, physical memory size, swap size, and current memory usage. 

On the other side, the guest physical address space size also affects the total amount of memory the VM can consume. The guest OS will find a vcpu’s physical address width by executing CPUID with 80000008H in EAX. With KVM this is set to be 40 bits for x86-64 cpus, even though EPT supports 48 bits guest physical address width. So the guest can address up to 1T memory in its physical address space. 

For all the x86 cpus that kvm supports - https://github.com/qemu/qemu/blob/stable-2.0/target-i386/cpu.c#L592, if it's 64 bits, the cpu will have 48 bits virtual, 40 bits physical address width - https://github.com/qemu/qemu/blob/stable-2.0/target-i386/cpu.c#L2344. For 32 bits cpus, they can have 36 bits or 32 bits physical address width depending on the presence of PAE, but I think the customer will not be interested in the information about 32 bits cpus. 

Qemu passes the cpuid information to the kernel - https://github.com/qemu/qemu/blob/stable-2.0/target-i386/kvm.c#L706, and the cpuid information will eventually be used to emulate cpuid instruction by KVM - https://github.com/torvalds/linux/blob/v3.13/arch/x86/kvm/emulate.c#L3279 (em_cpuid -> emulator_get_cpuid -> emulator_get_cpuid -> kvm_find_cpuid_entry). 

Note, above information applies to linux kernel 3.13 and qemu 2.0. 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值