public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
To: Jesper Juhl <jj@chaosbits.net>
Cc: kvm@vger.kernel.org, Avi Kivity <avi@redhat.com>,
	Avi Kivity <avi@qumranet.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	Yaniv Kamay <yaniv@qumranet.com>,
	Amit Shah <amit.shah@qumranet.com>,
	Ben-Ami Yassour <benami@il.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM x86: remove memset, use vzalloc and don't assign the same value to a variable twice
Date: Mon, 01 Nov 2010 09:49:54 +0900	[thread overview]
Message-ID: <4CCE0EB2.9070302@oss.ntt.co.jp> (raw)
In-Reply-To: <alpine.LNX.2.00.1010302020150.1572@swampdragon.chaosbits.net>

(2010/10/31 3:28), Jesper Juhl wrote:
> Hi,
>
> We can improve kvm_vm_ioctl_get_dirty_log() slightly by using vzalloc()
> rather than first allocating and then manually zero the memory with
> memset(). Also, while I was looking at this I noticed that we assign

I personally prefer this new vzalloc() to vmalloc() + memset().

Just from my interest, is there real performance difference not just
the cleanup effect?  If so, we'd better do this for other places too.


> -ENOMEM to the 'r' variable twice even though none of the code inbetween
> the two assignments can change 'r', so I removed the second assignment.
>
> Patch has been compile tested only.
>
> Please consider merging and please CC me on all replies as I'm not
> subscribed to the kvm mailing list.
>
>
> Signed-off-by: Jesper Juhl<jj@chaosbits.net>
> ---
>   x86.c |    4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 2288ad8..29f9c0a 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -3174,12 +3174,10 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
>   		spin_unlock(&kvm->mmu_lock);

This patch is not based on kvm.git, I guess.

>
>   		r = -ENOMEM;
> -		dirty_bitmap = vmalloc(n);
> +		dirty_bitmap = vzalloc(n);
>   		if (!dirty_bitmap)
>   			goto out;
> -		memset(dirty_bitmap, 0, n);
>
> -		r = -ENOMEM;

This one is here because this belongs to a different code block from the
previous one.  This keeps it easy to insert another codes in between these
two blocks.  The optimization will be done at compile time.
IIRC, I did like this based on Avi's advise.

   Takuya

>   		slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
>   		if (!slots) {
>   			vfree(dirty_bitmap);
>
>

  reply	other threads:[~2010-11-01  0:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-30 18:28 [PATCH] KVM x86: remove memset, use vzalloc and don't assign the same value to a variable twice Jesper Juhl
2010-11-01  0:49 ` Takuya Yoshikawa [this message]
2010-11-01 18:42   ` Jesper Juhl
2010-11-02  1:49     ` Takuya Yoshikawa
2010-11-02  4:11       ` Jesper Juhl
2010-11-03 12:47         ` Marcelo Tosatti

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=4CCE0EB2.9070302@oss.ntt.co.jp \
    --to=yoshikawa.takuya@oss.ntt.co.jp \
    --cc=amit.shah@qumranet.com \
    --cc=avi@qumranet.com \
    --cc=avi@redhat.com \
    --cc=benami@il.ibm.com \
    --cc=jj@chaosbits.net \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=yaniv@qumranet.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