From: Paolo Bonzini <pbonzini@redhat.com>
To: Igor Mammedov <imammedo@redhat.com>, linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] kvm: memslots: replace heap sort with insertion sort
Date: Thu, 13 Nov 2014 17:58:30 +0100 [thread overview]
Message-ID: <5464E336.7020402@redhat.com> (raw)
In-Reply-To: <1415896267-2146-1-git-send-email-imammedo@redhat.com>
On 13/11/2014 17:31, Igor Mammedov wrote:
> memslots is a sorted array, when slot changes in it
> with current heapsort it would take O(n log n) time
> to update array, while using insertion sort like
> algorithm on array with 1 item out of order will
> take only O(n) time.
>
> Replace current heapsort with custom sort that
> takes advantage of memslots usage pattern and known
> position of changed slot.
>
> performance change of 128 memslots insersions with
> gradually increasing size (the worst case):
> heap sort custom sort
> max: 249747 15654 cycles
> min: 52536 5562 cycles
> with custom sort alg taking 90% less then original
> update time.
>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> virt/kvm/kvm_main.c | 54 +++++++++++++++++++++++++++++------------------------
> 1 file changed, 30 insertions(+), 24 deletions(-)
Nice! I think strictly speaking it's not an insertion sort because
insertion sort doesn't use swaps; it's more similar to a bubble sort.
But the code is very readable and we do not need ultimate
performance---we are just trying to avoid doing something stupid.
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo
next prev parent reply other threads:[~2014-11-13 16:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 15:52 [PATCH] kvm: x86: increase user memory slots to 509 Igor Mammedov
2014-11-06 16:23 ` Paolo Bonzini
2014-11-13 16:31 ` [PATCH] kvm: memslots: replace heap sort with insertion sort Igor Mammedov
2014-11-13 16:58 ` Paolo Bonzini [this message]
2014-11-13 23:00 ` [PATCH v2] " Igor Mammedov
2014-11-14 9:57 ` Paolo Bonzini
2014-11-14 10:58 ` Igor Mammedov
2014-11-14 14:10 ` [PATCH] kvm: x86: increase user memory slots to 509 Igor Mammedov
2014-11-14 14:53 ` Paolo Bonzini
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=5464E336.7020402@redhat.com \
--to=pbonzini@redhat.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.