(this is the modification for qemu to make it work with ksm)

--
woof.

>From 813266c7d59acb64c104448c255cc2c9d4f0187e Mon Sep 17 00:00:00 2001
From: Izik Eidus <[EMAIL PROTECTED]>
Date: Mon, 21 Jan 2008 17:41:09 +0200
Subject: [PATCH] qemu: register the memory of qemu with ksm,
 so it can be shared

Signed-off-by: Izik Eidus <[EMAIL PROTECTED]>
---
 qemu/vl.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/qemu/vl.c b/qemu/vl.c
index 756e13d..691db36 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -21,6 +21,8 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
+
+#include "ksm.h"
 #include "hw/hw.h"
 #include "hw/boards.h"
 #include "hw/usb.h"
@@ -8501,6 +8503,37 @@ void qemu_get_launch_info(int *argc, char ***argv, int *opt_daemonize, const cha
     *opt_incoming = incoming;
 }
 
+int ksm_register_memory(void)
+{
+    int fd;
+    int ksm_fd;
+    int r = 1;
+    struct ksm_memory_region ksm_region;
+
+    fd = open("/dev/ksm", O_RDWR | O_TRUNC, (mode_t)0600);
+    if (fd == -1)
+        goto out;
+
+    ksm_fd = ioctl(fd, KSM_CREATE_SHARED_MEMORY_AREA);
+    if (ksm_fd == -1)
+        goto out_free;
+
+    ksm_region.npages = phys_ram_size / TARGET_PAGE_SIZE;
+    ksm_region.addr = phys_ram_base;
+    r = ioctl(ksm_fd, KSM_REGISTER_MEMORY_REGION, &ksm_region);
+    if (r)
+        goto out_free1;
+
+    return r;
+
+out_free1:
+    close(ksm_fd);
+out_free:
+    close(fd);
+out:
+    return r;
+}
+
 int main(int argc, char **argv)
 {
 #ifdef CONFIG_GDBSTUB
@@ -9353,6 +9386,8 @@ int main(int argc, char **argv)
     }
 #endif
 
+    ksm_register_memory();
+
     bdrv_init();
 
     /* we always create the cdrom drive, even if no disk is there */
-- 
1.5.3.6

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to