Skip to contentSkip to conversation

KVM: x86/mmu: Speed up slot_rmap_walk_next for sparsely populated rmaps

PATCH Applied Vipin Sharma 2 participants 2 messages May 2, 2022 – May 3, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: x86/mmu: Speed up slot_rmap_walk_next for sparsely populated rmaps

Avoid calling handlers on empty rmap entries and skip to the next non empty rmap entry.

Empty rmap entries are noop in handlers.

---

v2:
- Removed noinline from slot_rmap_walk_next signature

v1:
- https://lore.kernel.org/lkml/[email protected]

 arch/x86/kvm/mmu/mmu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +4 -2
index 77785587332e..4e8d546431eb 100644
@@ -1501,9 +1501,11 @@ static bool slot_rmap_walk_okay(struct slot_rmap_walk_iterator *iterator)
 
 static void slot_rmap_walk_next(struct slot_rmap_walk_iterator *iterator)
 {
-	if (++iterator->rmap <= iterator->end_rmap) {
+	while (++iterator->rmap <= iterator->end_rmap) {
 		iterator->gfn += (1UL << KVM_HPAGE_GFN_SHIFT(iterator->level));
-		return;
+
+		if (iterator->rmap->val)
+			return;
 	}
 
 	if (++iterator->level > iterator->end_level) {

base-commit: 71d7c575a673d42ad7175ad5fc27c85c80330311

Signature · 1 line
2.36.0.464.gb9c8b46e94-goog
maintainer Applied
#1 lore raw
Quoted 37 lines · Vipin Sharma

Avoid calling handlers on empty rmap entries and skip to the next non empty rmap entry.

Empty rmap entries are noop in handlers.

---

v2:
- Removed noinline from slot_rmap_walk_next signature

v1:
- https://lore.kernel.org/lkml/[email protected]

  arch/x86/kvm/mmu/mmu.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +4 -2
index 77785587332e..4e8d546431eb 100644
@@ -1501,9 +1501,11 @@ static bool slot_rmap_walk_okay(struct slot_rmap_walk_iterator *iterator)
 
  static void slot_rmap_walk_next(struct slot_rmap_walk_iterator *iterator)
  {
-	if (++iterator->rmap <= iterator->end_rmap) {
+	while (++iterator->rmap <= iterator->end_rmap) {
  		iterator->gfn += (1UL << KVM_HPAGE_GFN_SHIFT(iterator->level));
-		return;
+
+		if (iterator->rmap->val)
+			return;
  	}
 
  	if (++iterator->level > iterator->end_level) {
Quoted 1 line

base-commit: 71d7c575a673d42ad7175ad5fc27c85c80330311

Queued, thanks.

Paolo