Message ID | 502B99D0.8010808@msgid.tls.msk.ru |
---|---|
State | New |
Headers | show |
On 08/15/2012 03:45 PM, Michael Tokarev wrote: > > But apparently, THP does not work still, even with 2Mb > alignment: when running a guest, AnonHugePages in > /proc/meminfo stays at 0 - either in kvm mode or in tcg > mode. Any idea why? What else is needed for THP to work? It does for me: AnonHugePages: 368640 kB Note the patch you reference doesn't impact thp, just kvm's ability to propagate them to the shadow page table. > > This is quite a frequent question in #kvm IRC channel, > and I always suggested using -mem-path for this, but > I'm curios why it doesn't work automatically when it > probably should? > Please provide extra info, like the setting of /sys/kernel/mm/transparent_hugepage/enabled.
On 15.08.2012 16:51, Avi Kivity wrote: > On 08/15/2012 03:45 PM, Michael Tokarev wrote: >> >> But apparently, THP does not work still, even with 2Mb >> alignment: when running a guest, AnonHugePages in >> /proc/meminfo stays at 0 - either in kvm mode or in tcg >> mode. Any idea why? What else is needed for THP to work? > > It does for me: > > AnonHugePages: 368640 kB > > Note the patch you reference doesn't impact thp, just kvm's ability to > propagate them to the shadow page table. > >> >> This is quite a frequent question in #kvm IRC channel, >> and I always suggested using -mem-path for this, but >> I'm curios why it doesn't work automatically when it >> probably should? >> > > Please provide extra info, like the setting of > /sys/kernel/mm/transparent_hugepage/enabled. That was it - sort of. Default value here is enabled=madvise. When setting it to always the effect finally started appearing, so it is actually working. But can't qemu set MADV_HUGEPAGE flag too, so it works automatically? Thanks, /mjt
On 08/15/2012 05:22 PM, Michael Tokarev wrote: >> >> Please provide extra info, like the setting of >> /sys/kernel/mm/transparent_hugepage/enabled. > > That was it - sort of. Default value here is enabled=madvise. > When setting it to always the effect finally started appearing, > so it is actually working. > > But can't qemu set MADV_HUGEPAGE flag too, so it works automatically? It can and should.
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 @@ void *qemu_memalign(size_t alignment, size_t size) 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; }