]> www.infradead.org Git - users/jedix/linux-maple.git/commit
kvm: x86: reduce collisions in mmu_page_hash v4.1.12-110.0.20170822_0730
authorDavid Matlack <dmatlack@google.com>
Mon, 19 Dec 2016 21:58:25 +0000 (13:58 -0800)
committerChuck Anderson <chuck.anderson@oracle.com>
Tue, 22 Aug 2017 18:31:33 +0000 (11:31 -0700)
commit9e26622c100c2cdfdc7d4934b5bc90dcf272d45b
treee2e458c6e5b68a6ed604838bee7cf659f9ba358a
parent49db85b690d3f4c285e18ce9ace8437091e1dc1d
kvm: x86: reduce collisions in mmu_page_hash

When using two-dimensional paging, the mmu_page_hash (which provides
lookups for existing kvm_mmu_page structs), becomes imbalanced; with
too many collisions in buckets 0 and 512. This has been seen to cause
mmu_lock to be held for multiple milliseconds in kvm_mmu_get_page on
VMs with a large amount of RAM mapped with 4K pages.

The current hash function uses the lower 10 bits of gfn to index into
mmu_page_hash. When doing shadow paging, gfn is the address of the
guest page table being shadow. These tables are 4K-aligned, which
makes the low bits of gfn a good hash. However, with two-dimensional
paging, no guest page tables are being shadowed, so gfn is the base
address that is mapped by the table. Thus page tables (level=1) have
a 2MB aligned gfn, page directories (level=2) have a 1GB aligned gfn,
etc. This means hashes will only differ in their 10th bit.

hash_64() provides a better hash. For example, on a VM with ~200G
(99458 direct=1 kvm_mmu_page structs):

hash            max_mmu_page_hash_collisions
--------------------------------------------
low 10 bits     49847
hash_64         105
perfect         97

While we're changing the hash, increase the table size by 4x to better
support large VMs (further reduces number of collisions in 200G VM to
29).

Note that hash_64() does not provide a good distribution prior to commit
ef703f49a6c5 ("Eliminate bad hash multipliers from hash_32() and
hash_64()").

Signed-off-by: David Matlack <dmatlack@google.com>
Change-Id: I5aa6b13c834722813c6cca46b8b1ed6f53368ade
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Orabug: 26628797
(cherry picked from commit 114df303a7eeae8b50ebf68229b7e647714a9bea)
Signed-off-by: Govinda Tatti <Govinda.Tatti@Oracle.COM>
Reviewed-by: Jack Vogel <jack.vogel@oracle.com>
Tested-by: Eyal Moscovici <eyal.moscovici@oracle.com> [Ravello/BMCS Team]
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/mmu.c