From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: yoshikawa_takuya_b1@lab.ntt.co.jp, imammedo@redhat.com
Subject: [PATCH 1/3] kvm: memslots: track id_to_index changes during the insertion sort
Date: Fri, 14 Nov 2014 12:12:00 +0100 [thread overview]
Message-ID: <1415963522-5255-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1415963522-5255-1-git-send-email-pbonzini@redhat.com>
This completes the optimization from the previous patch, by
removing the KVM_MEM_SLOTS_NUM-iteration loop from insert_memslot.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
virt/kvm/kvm_main.c | 39 +++++++++++++++++++--------------------
1 file changed, 19 insertions(+), 20 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c0c2202e6c4f..c8ff99cc0ccb 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -677,31 +677,30 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
static void insert_memslot(struct kvm_memslots *slots,
struct kvm_memory_slot *new)
{
- int i = slots->id_to_index[new->id];
- struct kvm_memory_slot *old = id_to_memslot(slots, new->id);
+ int id = new->id;
+ int i = slots->id_to_index[id];
struct kvm_memory_slot *mslots = slots->memslots;
- if (new->npages == old->npages) {
- *old = *new;
- return;
- }
-
- while (1) {
- if (i < (KVM_MEM_SLOTS_NUM - 1) &&
- new->npages < mslots[i + 1].npages) {
- mslots[i] = mslots[i + 1];
- i++;
- } else if (i > 0 && new->npages > mslots[i - 1].npages) {
- mslots[i] = mslots[i - 1];
- i--;
- } else {
- mslots[i] = *new;
- break;
+ WARN_ON(mslots[i].id != id);
+ if (new->npages != mslots[i].npages) {
+ while (1) {
+ if (i < (KVM_MEM_SLOTS_NUM - 1) &&
+ new->npages < mslots[i + 1].npages) {
+ mslots[i] = mslots[i + 1];
+ slots->id_to_index[mslots[i].id] = i;
+ i++;
+ } else if (i > 0 &&
+ new->npages > mslots[i - 1].npages) {
+ mslots[i] = mslots[i - 1];
+ slots->id_to_index[mslots[i].id] = i;
+ i--;
+ } else
+ break;
}
}
- for (i = 0; i < KVM_MEM_SLOTS_NUM; i++)
- slots->id_to_index[slots->memslots[i].id] = i;
+ mslots[i] = *new;
+ slots->id_to_index[mslots[i].id] = i;
}
static void update_memslots(struct kvm_memslots *slots,
--
1.8.3.1
next prev parent reply other threads:[~2014-11-14 11:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-14 11:11 [PATCH 0/3] KVM: simplification to the memslots code Paolo Bonzini
2014-11-14 11:12 ` Paolo Bonzini [this message]
2014-11-14 13:34 ` [PATCH 1/3] kvm: memslots: track id_to_index changes during the insertion sort Igor Mammedov
2014-11-14 13:35 ` Radim Krčmář
2014-11-14 14:17 ` Igor Mammedov
2014-11-14 14:41 ` Radim Krčmář
2014-11-14 14:44 ` Paolo Bonzini
2014-11-14 14:29 ` Paolo Bonzini
2014-11-14 14:44 ` Radim Krčmář
2014-11-14 11:12 ` [PATCH 2/3] kvm: commonize allocation of the new memory slots Paolo Bonzini
2014-11-14 14:21 ` Igor Mammedov
2014-11-17 1:49 ` Takuya Yoshikawa
2014-11-14 11:12 ` [PATCH 3/3] kvm: simplify update_memslots invocation Paolo Bonzini
2014-11-14 14:24 ` Igor Mammedov
2014-11-17 1:56 ` [PATCH 0/3] KVM: simplification to the memslots code Takuya Yoshikawa
2014-11-17 9:23 ` Paolo Bonzini
2014-11-17 9:30 ` 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=1415963522-5255-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yoshikawa_takuya_b1@lab.ntt.co.jp \
/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
all inboxes | Powered by JetHome®