From: Alex Williamson <alex.williamson@redhat.com>
To: mtosatti@redhat.com, gleb@redhat.com
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: [PATCH 04/10] kvm: Minor memory slot optimization
Date: Thu, 06 Dec 2012 15:20:51 -0700 [thread overview]
Message-ID: <20121206222051.24968.86664.stgit@bling.home> (raw)
In-Reply-To: <20121206214722.24968.6043.stgit@bling.home>
If a slot is removed or moved in the guest physical address space, we
first allocate and install a new slot array with the invalidated
entry. The old array is then freed. We then proceed to allocate yet
another slot array to install the permanent replacement. Re-use the
original array when this occurs and avoid the extra kfree/kmalloc.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
virt/kvm/kvm_main.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index d27c135..24a67f0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -711,7 +711,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
unsigned long npages;
struct kvm_memory_slot *memslot, *slot;
struct kvm_memory_slot old, new;
- struct kvm_memslots *slots, *old_memslots;
+ struct kvm_memslots *slots = NULL, *old_memslots;
r = check_memory_region_flags(mem);
if (r)
@@ -827,18 +827,25 @@ int __kvm_set_memory_region(struct kvm *kvm,
* - kvm_is_visible_gfn (mmu_check_roots)
*/
kvm_arch_flush_shadow_memslot(kvm, slot);
- kfree(old_memslots);
+ slots = old_memslots;
}
r = kvm_arch_prepare_memory_region(kvm, &new, old, mem, user_alloc);
if (r)
- goto out_free;
+ goto out_slots;
r = -ENOMEM;
- slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
- GFP_KERNEL);
- if (!slots)
- goto out_free;
+ /*
+ * We can re-use the old_memslots from above, the only difference
+ * from the currently installed memslots is the invalid flag. This
+ * will get overwritten by update_memslots anyway.
+ */
+ if (!slots) {
+ slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
+ GFP_KERNEL);
+ if (!slots)
+ goto out_free;
+ }
/* map new memory slot into the iommu */
if (npages) {
next prev parent reply other threads:[~2012-12-06 22:20 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-06 22:20 [PATCH 00/10] kvm: memory slot cleanups, fix, and increase Alex Williamson
2012-12-06 22:20 ` [PATCH 01/10] kvm: Restrict non-existing slot state transitions Alex Williamson
2012-12-06 22:20 ` [PATCH 02/10] kvm: Check userspace_addr when modifying a memory slot Alex Williamson
2012-12-07 18:17 ` Jason Baron
2012-12-07 18:32 ` Alex Williamson
2012-12-07 18:44 ` Jason Baron
2012-12-06 22:20 ` [PATCH 03/10] kvm: Fix iommu map/unmap to handle memory slot moves Alex Williamson
2012-12-06 22:20 ` Alex Williamson [this message]
2012-12-06 22:20 ` [PATCH 05/10] kvm: Rename KVM_MEMORY_SLOTS -> KVM_USER_MEM_SLOTS Alex Williamson
2012-12-06 22:21 ` [PATCH 06/10] kvm: Make KVM_PRIVATE_MEM_SLOTS optional Alex Williamson
2012-12-06 22:21 ` [PATCH 07/10] kvm: struct kvm_memory_slot.user_alloc -> bool Alex Williamson
2012-12-06 22:21 ` [PATCH 08/10] kvm: struct kvm_memory_slot.flags -> u32 Alex Williamson
2012-12-06 22:21 ` [PATCH 09/10] kvm: struct kvm_memory_slot.id -> short Alex Williamson
2012-12-06 22:21 ` [PATCH 10/10] kvm: Increase user memory slots on x86 to 125 Alex Williamson
2012-12-07 14:02 ` Takuya Yoshikawa
2012-12-07 16:09 ` Alex Williamson
2012-12-10 13:48 ` Takuya Yoshikawa
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=20121206222051.24968.86664.stgit@bling.home \
--to=alex.williamson@redhat.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.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).