diff options
author | Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> | 2012-07-02 04:59:33 -0400 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2012-07-18 15:55:04 -0400 |
commit | bcd3ef58283a471d6b65855b83f78bd39eb55391 (patch) | |
tree | d8814c9fbf17570a1cbed823b2dea7468fe9c1d9 | |
parent | f395302e09ef783b8f82d1160510a95aa8c66dbc (diff) |
KVM: MMU: Avoid handling same rmap_pde in kvm_handle_hva_range()
When we invalidate a THP page, we call the handler with the same
rmap_pde argument 512 times in the following loop:
for each guest page in the range
for each level
unmap using rmap
This patch avoids these extra handler calls by changing the loop order
like this:
for each level
for each rmap in the range
unmap using rmap
With the preceding patches in the patch series, this made THP page
invalidation more than 5 times faster on our x86 host: the host became
more responsive during swapping the guest's memory as a result.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r-- | arch/x86/kvm/mmu.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 58adec384489..a5d6ef785b7e 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -1277,7 +1277,7 @@ static int kvm_handle_hva_range(struct kvm *kvm, | |||
1277 | 1277 | ||
1278 | kvm_for_each_memslot(memslot, slots) { | 1278 | kvm_for_each_memslot(memslot, slots) { |
1279 | unsigned long hva_start, hva_end; | 1279 | unsigned long hva_start, hva_end; |
1280 | gfn_t gfn, gfn_end; | 1280 | gfn_t gfn_start, gfn_end; |
1281 | 1281 | ||
1282 | hva_start = max(start, memslot->userspace_addr); | 1282 | hva_start = max(start, memslot->userspace_addr); |
1283 | hva_end = min(end, memslot->userspace_addr + | 1283 | hva_end = min(end, memslot->userspace_addr + |
@@ -1286,19 +1286,27 @@ static int kvm_handle_hva_range(struct kvm *kvm, | |||
1286 | continue; | 1286 | continue; |
1287 | /* | 1287 | /* |
1288 | * {gfn(page) | page intersects with [hva_start, hva_end)} = | 1288 | * {gfn(page) | page intersects with [hva_start, hva_end)} = |
1289 | * {gfn, gfn+1, ..., gfn_end-1}. | 1289 | * {gfn_start, gfn_start+1, ..., gfn_end-1}. |
1290 | */ | 1290 | */ |
1291 | gfn = hva_to_gfn_memslot(hva_start, memslot); | 1291 | gfn_start = hva_to_gfn_memslot(hva_start, memslot); |
1292 | gfn_end = hva_to_gfn_memslot(hva_end + PAGE_SIZE - 1, memslot); | 1292 | gfn_end = hva_to_gfn_memslot(hva_end + PAGE_SIZE - 1, memslot); |
1293 | 1293 | ||
1294 | for (; gfn < gfn_end; ++gfn) { | 1294 | for (j = PT_PAGE_TABLE_LEVEL; |
1295 | for (j = PT_PAGE_TABLE_LEVEL; | 1295 | j < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++j) { |
1296 | j < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++j) { | 1296 | unsigned long idx, idx_end; |
1297 | unsigned long *rmapp; | 1297 | unsigned long *rmapp; |
1298 | 1298 | ||
1299 | rmapp = __gfn_to_rmap(gfn, j, memslot); | 1299 | /* |
1300 | ret |= handler(kvm, rmapp, memslot, data); | 1300 | * {idx(page_j) | page_j intersects with |
1301 | } | 1301 | * [hva_start, hva_end)} = {idx, idx+1, ..., idx_end}. |
1302 | */ | ||
1303 | idx = gfn_to_index(gfn_start, memslot->base_gfn, j); | ||
1304 | idx_end = gfn_to_index(gfn_end - 1, memslot->base_gfn, j); | ||
1305 | |||
1306 | rmapp = __gfn_to_rmap(gfn_start, j, memslot); | ||
1307 | |||
1308 | for (; idx <= idx_end; ++idx) | ||
1309 | ret |= handler(kvm, rmapp++, memslot, data); | ||
1302 | } | 1310 | } |
1303 | } | 1311 | } |
1304 | 1312 | ||