* [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM
@ 2011-09-05 8:07 Avi Kivity
2011-09-05 10:10 ` Jan Kiszka
2011-09-09 18:34 ` Anthony Liguori
0 siblings, 2 replies; 4+ messages in thread
From: Avi Kivity @ 2011-09-05 8:07 UTC (permalink / raw)
To: qemu-devel
To make good use of transparent hugepages, KVM requires that guest-physical
and host-virtual addresses share the low 21 bits (as opposed to just the low
12 bits normally required).
Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
to avoid fragmentation.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
oslib-posix.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/oslib-posix.c b/oslib-posix.c
index 196099c..a304fb0 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -35,6 +35,13 @@
extern int daemon(int, int);
#endif
+#if defined(__linux__) && defined(__x86_64__)
+ /* Use 2MB alignment so transparent hugepages can be used by KVM */
+# define QEMU_VMALLOC_ALIGN (512 * 4096)
+#else
+# define QEMU_VMALLOC_ALIGN getpagesize()
+#endif
+
#include "config-host.h"
#include "sysemu.h"
#include "trace.h"
@@ -80,7 +87,12 @@ int qemu_daemon(int nochdir, int noclose)
void *qemu_vmalloc(size_t size)
{
void *ptr;
- ptr = qemu_memalign(getpagesize(), size);
+ size_t align = QEMU_VMALLOC_ALIGN;
+
+ if (size < align) {
+ align = getpagesize();
+ }
+ ptr = qemu_memalign(align, size);
trace_qemu_vmalloc(size, ptr);
return ptr;
}
--
1.7.6.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM
2011-09-05 8:07 [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM Avi Kivity
@ 2011-09-05 10:10 ` Jan Kiszka
2011-09-05 10:21 ` Avi Kivity
2011-09-09 18:34 ` Anthony Liguori
1 sibling, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2011-09-05 10:10 UTC (permalink / raw)
To: Avi Kivity; +Cc: qemu-devel
On 2011-09-05 10:07, Avi Kivity wrote:
> To make good use of transparent hugepages, KVM requires that guest-physical
> and host-virtual addresses share the low 21 bits (as opposed to just the low
> 12 bits normally required).
>
> Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
> to avoid fragmentation.
>
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
> oslib-posix.c | 14 +++++++++++++-
> 1 files changed, 13 insertions(+), 1 deletions(-)
>
> diff --git a/oslib-posix.c b/oslib-posix.c
> index 196099c..a304fb0 100644
> --- a/oslib-posix.c
> +++ b/oslib-posix.c
> @@ -35,6 +35,13 @@
> extern int daemon(int, int);
> #endif
>
> +#if defined(__linux__) && defined(__x86_64__)
> + /* Use 2MB alignment so transparent hugepages can be used by KVM */
Aren't transparent hugepages also available in TCG mode? Then just
remove "by KVM" from subject and comment.
Jan
> +# define QEMU_VMALLOC_ALIGN (512 * 4096)
> +#else
> +# define QEMU_VMALLOC_ALIGN getpagesize()
> +#endif
> +
> #include "config-host.h"
> #include "sysemu.h"
> #include "trace.h"
> @@ -80,7 +87,12 @@ int qemu_daemon(int nochdir, int noclose)
> void *qemu_vmalloc(size_t size)
> {
> void *ptr;
> - ptr = qemu_memalign(getpagesize(), size);
> + size_t align = QEMU_VMALLOC_ALIGN;
> +
> + if (size < align) {
> + align = getpagesize();
> + }
> + ptr = qemu_memalign(align, size);
> trace_qemu_vmalloc(size, ptr);
> return ptr;
> }
--
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM
2011-09-05 10:10 ` Jan Kiszka
@ 2011-09-05 10:21 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2011-09-05 10:21 UTC (permalink / raw)
To: Jan Kiszka; +Cc: qemu-devel
On 09/05/2011 01:10 PM, Jan Kiszka wrote:
> On 2011-09-05 10:07, Avi Kivity wrote:
> > To make good use of transparent hugepages, KVM requires that guest-physical
> > and host-virtual addresses share the low 21 bits (as opposed to just the low
> > 12 bits normally required).
> >
> > Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
> > to avoid fragmentation.
> >
> > Signed-off-by: Avi Kivity<avi@redhat.com>
> > ---
> > oslib-posix.c | 14 +++++++++++++-
> > 1 files changed, 13 insertions(+), 1 deletions(-)
> >
> > diff --git a/oslib-posix.c b/oslib-posix.c
> > index 196099c..a304fb0 100644
> > --- a/oslib-posix.c
> > +++ b/oslib-posix.c
> > @@ -35,6 +35,13 @@
> > extern int daemon(int, int);
> > #endif
> >
> > +#if defined(__linux__)&& defined(__x86_64__)
> > + /* Use 2MB alignment so transparent hugepages can be used by KVM */
>
> Aren't transparent hugepages also available in TCG mode? Then just
> remove "by KVM" from subject and comment.
They are, but they don't require the special alignment.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM
2011-09-05 8:07 [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM Avi Kivity
2011-09-05 10:10 ` Jan Kiszka
@ 2011-09-09 18:34 ` Anthony Liguori
1 sibling, 0 replies; 4+ messages in thread
From: Anthony Liguori @ 2011-09-09 18:34 UTC (permalink / raw)
To: Avi Kivity; +Cc: qemu-devel
On 09/05/2011 03:07 AM, Avi Kivity wrote:
> To make good use of transparent hugepages, KVM requires that guest-physical
> and host-virtual addresses share the low 21 bits (as opposed to just the low
> 12 bits normally required).
>
> Adjust qemu_vmalloc() to honor that requirement. Ignore it for small regions
> to avoid fragmentation.
>
> Signed-off-by: Avi Kivity<avi@redhat.com>
Applied. Thanks.
Regards,
Anthony Liguori
> ---
> oslib-posix.c | 14 +++++++++++++-
> 1 files changed, 13 insertions(+), 1 deletions(-)
>
> diff --git a/oslib-posix.c b/oslib-posix.c
> index 196099c..a304fb0 100644
> --- a/oslib-posix.c
> +++ b/oslib-posix.c
> @@ -35,6 +35,13 @@
> extern int daemon(int, int);
> #endif
>
> +#if defined(__linux__)&& defined(__x86_64__)
> + /* Use 2MB alignment so transparent hugepages can be used by KVM */
> +# define QEMU_VMALLOC_ALIGN (512 * 4096)
> +#else
> +# define QEMU_VMALLOC_ALIGN getpagesize()
> +#endif
> +
> #include "config-host.h"
> #include "sysemu.h"
> #include "trace.h"
> @@ -80,7 +87,12 @@ int qemu_daemon(int nochdir, int noclose)
> void *qemu_vmalloc(size_t size)
> {
> void *ptr;
> - ptr = qemu_memalign(getpagesize(), size);
> + size_t align = QEMU_VMALLOC_ALIGN;
> +
> + if (size< align) {
> + align = getpagesize();
> + }
> + ptr = qemu_memalign(align, size);
> trace_qemu_vmalloc(size, ptr);
> return ptr;
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-09-09 18:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-05 8:07 [Qemu-devel] [PATCH] qemu_vmalloc: align properly for transparent hugepages and KVM Avi Kivity
2011-09-05 10:10 ` Jan Kiszka
2011-09-05 10:21 ` Avi Kivity
2011-09-09 18:34 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).