From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] KVM: Avoid wasting pages for small lpage_info arrays Date: Sun, 13 May 2012 13:20:46 +0300 Message-ID: <4FAF8AFE.4020007@redhat.com> References: <20120510233328.d4a2623d3f8936c1b44b1f77@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: mtosatti@redhat.com, kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp To: Takuya Yoshikawa Return-path: Received: from mx1.redhat.com ([209.132.183.28]:48814 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751636Ab2EMKUv (ORCPT ); Sun, 13 May 2012 06:20:51 -0400 In-Reply-To: <20120510233328.d4a2623d3f8936c1b44b1f77@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: On 05/10/2012 05:33 PM, Takuya Yoshikawa wrote: > From: Takuya Yoshikawa > > 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 > --- > 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