kvm userspace: ksm support
authorIzik Eidus <ieidus@redhat.com>
Tue, 28 Jul 2009 16:14:26 +0000 (28 19:14 +0300)
committerMark McLoughlin <markmc@redhat.com>
Mon, 28 Sep 2009 07:22:29 +0000 (28 08:22 +0100)
rfc for ksm support to kvm userpsace.

Signed-off-by: Izik Eidus <ieidus@redhat.com>
signed-off-by: Justin M. Forbes <jforbes@redhat.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Fedora-patch: qemu-add-ksm-support.patch

exec.c

diff --git a/exec.c b/exec.c
index 0655b4b..a0e2203 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -65,6 +65,9 @@
 #undef DEBUG_TB_CHECK
 #endif
 
+/* Quick hack to enable KSM support */
+#define MADV_MERGEABLE 12 /* KSM may merge identical pages */
+
 #define SMC_BITMAP_USE_THRESHOLD 10
 
 #if defined(TARGET_SPARC64)
@@ -2579,6 +2582,9 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size)
     new_block->host = file_ram_alloc(size, mem_path);
     if (!new_block->host) {
         new_block->host = qemu_vmalloc(size);
+#ifdef MADV_MERGEABLE
+        madvise(new_block->host, size, MADV_MERGEABLE);
+#endif
     }
     new_block->offset = last_ram_offset;
     new_block->length = size;