From patchwork Wed Sep 12 00:36:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/3] KVM: PPC: Book3S HV: Add command-line option for amount of KVM linear memory Date: Tue, 11 Sep 2012 14:36:46 -0000 From: Paul Mackerras X-Patchwork-Id: 183220 Message-Id: <20120912003646.GK32642@bloggs.ozlabs.ibm.com> To: Alexander Graf Cc: kvm-ppc@vger.kernel.org, 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;