From patchwork Wed Sep 12 00:36:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Mackerras X-Patchwork-Id: 1440461 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 8997C4025E for ; Wed, 12 Sep 2012 00:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754237Ab2ILAga (ORCPT ); Tue, 11 Sep 2012 20:36:30 -0400 Received: from ozlabs.org ([203.10.76.45]:48899 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753155Ab2ILAg2 (ORCPT ); Tue, 11 Sep 2012 20:36:28 -0400 Received: by ozlabs.org (Postfix, from userid 1003) id A19C92C0095; Wed, 12 Sep 2012 10:36:27 +1000 (EST) Date: Wed, 12 Sep 2012 10:36:46 +1000 From: Paul Mackerras To: Alexander Graf Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 3/3] KVM: PPC: Book3S HV: Add command-line option for amount of KVM linear memory Message-ID: <20120912003646.GK32642@bloggs.ozlabs.ibm.com> References: <20120912003427.GH32642@bloggs.ozlabs.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120912003427.GH32642@bloggs.ozlabs.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This adds a kernel command line option to allow the user to specify how much memory should be reserved in early boot for use for hashed page tables (HPTs) and real mode areas (RMAs) for KVM guests. The option is called "kvm_memory" and the amount can be specified as an absolute amount (for example, "kvm_memory=128M") or as a percentage of system RAM (for example, "kvm_memory=5%"). If the option is not given, it defaults to 3%, but this is only allocated on systems where KVM can run in HV mode. In particular it isn't allocated when the kernel is running as a guest, either of KVM or PowerVM. The amount actually allocated is the larger of the amount specified with the kvm_memory option, and the amount specified with the existing kvm_rma_count, kvm_rma_size and kvm_hpt_count options. The kvm_rma_count and kvm_hpt_count options default to 0. Signed-off-by: Paul Mackerras --- arch/powerpc/kvm/book3s_hv_builtin.c | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c index 0c4633c..2cebd02 100644 --- a/arch/powerpc/kvm/book3s_hv_builtin.c +++ b/arch/powerpc/kvm/book3s_hv_builtin.c @@ -431,6 +431,29 @@ static void kvm_release_linear(struct kvmppc_linear_info *ri) } /* + * Default to reserving 3% of RAM + * (it only gets reserved if HV KVM is possible on this processor). + */ +static u64 kvm_memory = 3; +static int kvm_memory_percent = 1; + +static int __init early_parse_kvm_memory(char *p) +{ + char *endp; + + if (!p) + return 1; + + kvm_memory = memparse(p, &endp); + kvm_memory_percent = 0; + if (*endp == '%') + kvm_memory_percent = 1; + + return 0; +} +early_param("kvm_memory", early_parse_kvm_memory); + +/* * Called at boot time while the bootmem allocator is active, * to allocate contiguous physical memory for the hash page * tables for guests. @@ -458,6 +481,23 @@ void __init kvm_linear_init(void) total += kvm_rma_count * kvm_rma_size; } + /* + * See if an explicit amount or percentage is requested; + * if so treat it as a minimum. + */ + if (kvm_memory) { + u64 memsize = max_pfn << PAGE_SHIFT; + + if (!kvm_memory_percent) { + if (kvm_memory < memsize && kvm_memory > total) + total = kvm_memory; + } else if (kvm_memory < 100) { + memsize = (memsize * kvm_memory) / 100; + if (memsize > total) + total = memsize; + } + } + if (!total) return;