0

What policy does KVM follow while allocating memory for VMs? I did some mmap on my VM and /proc/meminfo indicated it was hugepages (AnonHugepage size was increasing).

  • I want to know, from what policy it decide that it have to allocate HugePages?
  • On X86 system, does it allocate pages of size greater than 2MB?

While reading the x86/kvm/mmu linux source code. I found out that kvm_tdp_page_fault is calling page_num = KVM_PAGES_PER_HPAGE(max_level). For max_level (=3), it will return 2^18. How is that possible? Isn't maximum 4KB pages in hugepage is equal to 512? (considering 2MB hugepage)? I have attached the macro definitions from linux kernel. Please help me understand this.

/* KVM Hugepage definitions for x86 */
enum {
    PT_PAGE_TABLE_LEVEL   = 1,
    PT_DIRECTORY_LEVEL    = 2,
    PT_PDPE_LEVEL         = 3,
    /* set max level to the biggest one */
    PT_MAX_HUGEPAGE_LEVEL = PT_PDPE_LEVEL,
};
#define KVM_NR_PAGE_SIZES   (PT_MAX_HUGEPAGE_LEVEL - \
                 PT_PAGE_TABLE_LEVEL + 1)
#define KVM_HPAGE_GFN_SHIFT(x)  (((x) - 1) * 9) // (3-1)*9=18
#define KVM_HPAGE_SHIFT(x)  (PAGE_SHIFT + KVM_HPAGE_GFN_SHIFT(x)) // 12+18
#define KVM_HPAGE_SIZE(x)   (1UL << KVM_HPAGE_SHIFT(x)) // 2^30
#define KVM_HPAGE_MASK(x)   (~(KVM_HPAGE_SIZE(x) - 1))
#define KVM_PAGES_PER_HPAGE(x)  (KVM_HPAGE_SIZE(x) / PAGE_SIZE) // 2^18
shivank
  • 67
  • 1
  • 10

0 Answers0