KVM: remove dummy pages
cover KVM: remove dummy pages
Currently, kvm allocates some pages and use then as error indicators, it wastes memory and is not good for scalability.
In this patchset, we introduce some error code instead of the pages to indicate the error conditions.
PATCH 1/3 KVM: MMU: using kvm_release_pfn_clean to release pfn
The current code depends on fault_page is the normal page, but we will use the error code instead of dummy page in the later patch, so using kvm_release_pfn_clean to release pfn which will release error code probably
--- arch/x86/kvm/mmu.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kvm/mmu.c +1 -1
@@ -3275,7 +3275,7 @@ static bool try_async_pf(struct kvm_vcpu *vcpu, bool prefault, gfn_t gfn,if (!async)return false;/* *pfn has correct page already */ -put_page (pfn_to_page (*pfn)); +kvm_release_pfn_clean (*pfn);if (!prefault &&can_do_async_pf (vcpu)) {trace_kvm_try_async_get_page (gva, gfn);
Signature · 1 line
1.7.7.6
PATCH 2/3 KVM: use kvm_release_page_clean to guest page
In kvm_async_pf_wakeup_all, it uses bad_page to generate broadcast wakeup, and use put_page to release the page, the work depends on bad_page is the normal page. But we will use the error code instead of bad_page, so use kvm_release_page_clean to release the page which will release the error code probably
--- virt/kvm/async_pf.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
virt/kvm/async_pf.c +2 -2
@@ -112,7 +112,7 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) typeof(*work), link);list_del (&work->link);if (work->page) -put_page (work->page); +kvm_release_page_clean (work->page);kmem_cache_free (async_pf_cache, work); }spin_unlock (&vcpu->async_pf.lock);
@@ -139,7 +139,7 @@ void kvm_check_async_pf_completion(struct kvm_vcpu *vcpu)list_del (&work->queue); vcpu->async_pf.queued--;if (work->page) -put_page (work->page); +kvm_release_page_clean (work->page);kmem_cache_free (async_pf_cache, work); } }
Signature · 1 line
1.7.7.6
PATCH 3/3 KVM: remove dummy pages
In reply to Xiao GuangrongCurrently, kvm allocate some pages and use them as error indicators, it wastes memory and is not good for scalability. So we use the error code instead of the pages to indicate the error
--- include/linux/kvm_host.h | 3 +- virt/kvm/async_pf.c | 3 +- virt/kvm/kvm_main.c | 121 +++++++++++++++++++--------------------------- 3 files changed, 52 insertions(+), 75 deletions(-)
include/linux/kvm_host.h +2 -1
@@ -411,6 +411,7 @@ void kvm_arch_flush_shadow(struct kvm *kvm);int gfn_to_page_many_atomic (struct kvm *kvm,gfn_t gfn,struct page **pages,int nr_pages); +struct page *get_bad_page (void );struct page *gfn_to_page (struct kvm *kvm,gfn_t gfn);unsigned long gfn_to_hva (struct kvm *kvm,gfn_t gfn);void kvm_release_page_clean (struct page *page);
@@ -564,7 +565,7 @@ void kvm_arch_sync_events(struct kvm *kvm);int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu);void kvm_vcpu_kick (struct kvm_vcpu *vcpu); -int kvm_is_mmio_pfn (pfn_t pfn); +bool kvm_is_mmio_pfn (pfn_t pfn);struct kvm_irq_ack_notifier {struct hlist_node link;
virt/kvm/async_pf.c +1 -2
@@ -203,8 +203,7 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu)if (!work)return -ENOMEM ; - work->page = bad_page; -get_page (bad_page); + work->page =get_bad_page ();INIT_LIST_HEAD (&work->queue);/* for list_del to work */ spin_lock (&vcpu->async_pf.lock);
virt/kvm/kvm_main.c +49 -72
221 lines not on this page · raw message
Signature · 1 line
1.7.7.6
Quoted 6 lines · Xiao Guangrong
Currently, kvm allocates some pages and use then as error indicators, it wastes memory and is not good for scalability.
In this patchset, we introduce some error code instead of the pages to indicate the error conditions.
Sorry for the noise, there are some typos in the title and in the change-logs, I will correct them after you guys review the patches.