linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vipin Sharma <vipinsh@google.com>
To: seanjc@google.com, pbonzini@redhat.com, bgardon@google.com,
	dmatlack@google.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Vipin Sharma <vipinsh@google.com>
Subject: [Patch] KVM: x86/mmu: Make optimized __handle_changed_spte() for clear dirty log
Date: Wed, 25 Jan 2023 13:38:57 -0800	[thread overview]
Message-ID: <20230125213857.824959-1-vipinsh@google.com> (raw)

Use a tone down version of __handle_changed_spte() when clearing dirty
log. Remove checks which will not be needed when dirty logs are cleared.

This change shows ~13% improvement in clear dirty log calls in
dirty_log_perf_test

Before tone down version:
Clear dirty log over 3 iterations took 10.006764203s. (Avg 3.335588067s/iteration)

After tone down version:
Clear dirty log over 3 iterations took 8.686433554s. (Avg 2.895477851s/iteration)

Signed-off-by: Vipin Sharma <vipinsh@google.com>
---
 arch/x86/kvm/mmu/tdp_mmu.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index bba33aea0fb0..ca21b33c4386 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -504,6 +504,19 @@ static void handle_removed_pt(struct kvm *kvm, tdp_ptep_t pt, bool shared)
 	call_rcu(&sp->rcu_head, tdp_mmu_free_sp_rcu_callback);
 }
 
+static void handle_changed_spte_clear_dirty_log(int as_id, gfn_t gfn,
+						u64 old_spte, u64 new_spte,
+						int level)
+{
+	if (old_spte == new_spte)
+		return;
+
+	trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte);
+
+	if (is_dirty_spte(old_spte) &&  !is_dirty_spte(new_spte))
+		kvm_set_pfn_dirty(spte_to_pfn(old_spte));
+}
+
 /**
  * __handle_changed_spte - handle bookkeeping associated with an SPTE change
  * @kvm: kvm instance
@@ -736,7 +749,12 @@ static u64 __tdp_mmu_set_spte(struct kvm *kvm, int as_id, tdp_ptep_t sptep,
 
 	old_spte = kvm_tdp_mmu_write_spte(sptep, old_spte, new_spte, level);
 
-	__handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level, false);
+	if (record_dirty_log)
+		__handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte,
+				      level, false);
+	else
+		handle_changed_spte_clear_dirty_log(as_id, gfn, old_spte,
+						    new_spte, level);
 
 	if (record_acc_track)
 		handle_changed_spte_acc_track(old_spte, new_spte, level);
-- 
2.39.1.456.gfc5497dd1b-goog


             reply	other threads:[~2023-01-25 21:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 21:38 Vipin Sharma [this message]
2023-01-25 22:00 ` [Patch] KVM: x86/mmu: Make optimized __handle_changed_spte() for clear dirty log David Matlack
2023-01-25 22:25   ` Ben Gardon
2023-01-26  0:40     ` Vipin Sharma
2023-01-26  1:49     ` Sean Christopherson
2023-01-28 17:20       ` Vipin Sharma
2023-01-30 18:09         ` Sean Christopherson
2023-01-30 20:17           ` Vipin Sharma
2023-01-30 22:49             ` Sean Christopherson
2023-01-30 22:12       ` David Matlack
2023-01-30 23:49         ` Sean Christopherson
2023-01-31 17:41           ` David Matlack
2023-01-31 18:01             ` Vipin Sharma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230125213857.824959-1-vipinsh@google.com \
    --to=vipinsh@google.com \
    --cc=bgardon@google.com \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).