On 05/10/2012 05:33 PM, Takuya Yoshikawa wrote:
> From: Takuya Yoshikawa <[email protected]>
>
> 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 <[email protected]>
> ---
>  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

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to