public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Takuya Yoshikawa <takuya.yoshikawa@gmail.com>
Cc: mtosatti@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp
Subject: Re: [PATCH] KVM: Avoid wasting pages for small lpage_info arrays
Date: Sun, 13 May 2012 13:20:46 +0300	[thread overview]
Message-ID: <4FAF8AFE.4020007@redhat.com> (raw)
In-Reply-To: <20120510233328.d4a2623d3f8936c1b44b1f77@gmail.com>

On 05/10/2012 05:33 PM, Takuya Yoshikawa wrote:
> From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
>
> lpage_info is created for each large level even when the memory slot is
> not for RAM.  This means that when we add one slot for a PCI device, we
> end up allocating at least KVM_NR_PAGE_SIZES - 1 pages by vmalloc():
> this problem will become severer if we support more guests with more
> devices in the future.
>
> Although it is not easy to differentiate RAM slots from others, we can
> avoid wasting pages by making KVM_NR_PAGE_SIZES - 1 lpage_info arrays
> coalesce into one and using kmalloc() when the result is small enough.
>
> Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
> ---
>  arch/x86/kvm/x86.c |   56 ++++++++++++++++++++++++++++++---------------------
>  1 files changed, 33 insertions(+), 23 deletions(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 4de705c..716d543 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6300,35 +6300,52 @@ void kvm_arch_free_memslot(struct kvm_memory_slot *free,
>  {
>  	int i;
>  
> -	for (i = 0; i < KVM_NR_PAGE_SIZES - 1; ++i) {
> -		if (!dont || free->arch.lpage_info[i] != dont->arch.lpage_info[i]) {
> -			vfree(free->arch.lpage_info[i]);
> -			free->arch.lpage_info[i] = NULL;
> -		}
> -	}
> +	if (dont && free->arch.lpage_info[0] == dont->arch.lpage_info[0])
> +		return;
> +
> +	if (is_vmalloc_addr(free->arch.lpage_info[0]))
> +		vfree(free->arch.lpage_info[0]);
> +	else
> +		kfree(free->arch.lpage_info[0]);
> +
> +	for (i = 0; i < KVM_NR_PAGE_SIZES - 1; ++i)
> +		free->arch.lpage_info[i] = NULL;
>  }
>

I don't feel that the savings is worth the extra complication.  We save
two pages per memslot here.

What about using kvmalloc() instead of vmalloc()?  It's in
security/apparmor now, but can be made generic.

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2012-05-13 10:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10 14:33 [PATCH] KVM: Avoid wasting pages for small lpage_info arrays Takuya Yoshikawa
2012-05-13 10:20 ` Avi Kivity [this message]
2012-05-14 13:29   ` Takuya Yoshikawa
2012-05-15  8:02     ` Avi Kivity
2012-05-15 20:25       ` Andrew Morton
2012-05-16  9:26         ` Avi Kivity

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=4FAF8AFE.4020007@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=takuya.yoshikawa@gmail.com \
    --cc=yoshikawa.takuya@oss.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