All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: Alexander Graf <agraf@suse.de>
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
Date: Wed, 12 Sep 2012 10:36:46 +1000	[thread overview]
Message-ID: <20120912003646.GK32642@bloggs.ozlabs.ibm.com> (raw)
In-Reply-To: <20120912003427.GH32642@bloggs.ozlabs.ibm.com>

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 <paulus@samba.org>
---
 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;
 
-- 
1.7.10.rc3.219.g53414


WARNING: multiple messages have this Message-ID (diff)
From: Paul Mackerras <paulus@samba.org>
To: Alexander Graf <agraf@suse.de>
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
Date: Wed, 12 Sep 2012 00:36:46 +0000	[thread overview]
Message-ID: <20120912003646.GK32642@bloggs.ozlabs.ibm.com> (raw)
In-Reply-To: <20120912003427.GH32642@bloggs.ozlabs.ibm.com>

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\x128M") 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 <paulus@samba.org>
---
 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;
 
-- 
1.7.10.rc3.219.g53414


  parent reply	other threads:[~2012-09-12  0:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12  0:34 [PATCH 0/3] KVM: PPC: Book3S HV: More flexible allocator for linear memory Paul Mackerras
2012-09-12  0:34 ` Paul Mackerras
2012-09-12  0:35 ` [PATCH 1/3] KVM: PPC: Book3S HV: Add a more " Paul Mackerras
2012-09-12  0:35   ` Paul Mackerras
2012-09-12  0:36 ` [PATCH 2/3] KVM: PPC: Book3S HV: Allocate user-requested size of HPT from preallocated pool Paul Mackerras
2012-09-12  0:36   ` Paul Mackerras
2012-09-12  0:36 ` Paul Mackerras [this message]
2012-09-12  0:36   ` [PATCH 3/3] KVM: PPC: Book3S HV: Add command-line option for amount of KVM linear memory Paul Mackerras
2012-09-13 23:32 ` [PATCH 0/3] KVM: PPC: Book3S HV: More flexible allocator for " Alexander Graf
2012-09-13 23:32   ` Alexander Graf
2012-09-14  8:11   ` Paul Mackerras
2012-09-14  8:11     ` Paul Mackerras
2012-09-14 12:13     ` Alexander Graf
2012-09-14 12:13       ` Alexander Graf
2012-09-14 12:13       ` Alexander Graf
2012-09-14 12:45       ` Paul Mackerras
2012-09-14 12:45         ` Paul Mackerras
2012-09-14 12:45         ` Paul Mackerras
2012-09-14 13:15         ` Alexander Graf
2012-09-14 13:15           ` Alexander Graf
2012-09-14 13:15           ` Alexander Graf
2012-10-26  1:17           ` Paul Mackerras
2012-10-26  1:17             ` Paul Mackerras
2012-10-26  1:17             ` Paul Mackerras
2012-10-30  9:12             ` Alexander Graf
2012-10-30  9:12               ` Alexander Graf
2012-10-30  9:12               ` Alexander Graf

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=20120912003646.GK32642@bloggs.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.